From 94e3556fadb15a248f6cf772d170e895de75552b Mon Sep 17 00:00:00 2001 From: Beppe Vanrolleghem Date: Thu, 30 Aug 2018 02:15:26 +0200 Subject: [PATCH] started work on the flyswatter game, right now am able to display a fly on the screen, but having trouble with the scaling, movement is also already hapening, don't know about animation because the scale is so big --- beep.wav => data/beep.wav | Bin death.wav => data/death.wav | Bin data/fly.png | Bin 0 -> 16137 bytes main.lua | 210 ++++++------------------------------ readme.md | 7 ++ snake.lua | 159 +++++++++++++++++++++++++++ swat.lua | 122 +++++++++++++++++++++ 7 files changed, 322 insertions(+), 176 deletions(-) rename beep.wav => data/beep.wav (100%) rename death.wav => data/death.wav (100%) create mode 100644 data/fly.png create mode 100644 readme.md create mode 100644 snake.lua create mode 100644 swat.lua diff --git a/beep.wav b/data/beep.wav similarity index 100% rename from beep.wav rename to data/beep.wav diff --git a/death.wav b/data/death.wav similarity index 100% rename from death.wav rename to data/death.wav diff --git a/data/fly.png b/data/fly.png new file mode 100644 index 0000000000000000000000000000000000000000..a9690effa0eebab519135c2f5273f29a43d6a949 GIT binary patch literal 16137 zcmeHNdt4LOw%#*&@G>P90ToN)v6ZT*SglY6XH+a$t-(iqB2c9jJStSJMi6GAR`F4x zQmeH}P*HrDpMek`ek75t5dP|S+x;R!QZ(6r{49A$Q`z+I-YWR< zox;2NQEz;G>q(*h-jp@jWueXA`;1T7e#M~r>X!u3BfjlN>bNcmLGo?IQkq4te$Y1w z;!Otc)#LyC&$R9qN%#E2I(R_ABVCZquEuSDdI7B=X;JsWZu9&RRo$TYEk?Ry<{wnk z4T^41bf=G3dA2)gzDgI}{MgNpf8F}A*4}(S&eD}_5~d6%5M+mAwzb&Vz^G^8W@BvZ zbh^d0<qAMMC#2b^Z=W_Jjh}z&mAC|Wr7|^kt(3s zj`r#(@q6Qn0JVYqHcZQ~qrMIIkgZ+_T$MuF*up|0m5^#iqHy^kJFzs$t`;kloJ3cL z`=r$V#0qFX!5d=x-iV}mG`j>{*ZVt3X{l2o=1~?(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9de3&{@YMLfQ(m1Nswa z%x)?#J%aO1ISllvUjrq6lNraE{l8qD8ag()U7rugY!yRP z^G>kV5<+Y`5D%hcT^n_A{dt1AI9?BSVwVs}mGe-pz7@{%`U|X9C#8n57649h9ka4) zDKCEIMqPjF$cdC*J%{9#HGTNDjn2pJNQ}&E9~ZEKfNorC1P7-V$6wt6j6!kEQSn}0k2(Ni4KR#U&MnwPh98gg$v7Kd;WK$DG zUGYBlQqqQL;Z~NTrkn5xXnj2PY36DYqo#T!X(*Uu&g03m4~$L2pZ-5Li`BbeGOK$aRs%pAmz~~ky^isR|JVV}w>shv zE5U;9U@yOmD`)(1rC93al7V`I>tDa~$3O4Z2=eiRn<;U rD;m2C_}?3!Zb)=P;@@mS6__XVoU!M8VQ3eEKa(d-^FKWyYy hgrid then - self.x = 0 - end - if self.x < 0 then - self.x = hgrid - end - if self.y > vgrid then - self.y = 0 - end - if self.y < 0 then - self.y = vgrid - end - if self.tar.x == self.x and self.tar.y == self.y then - table.insert(self.blocks, {x = self.x, y = self.y}) - self.tar.x = math.floor(math.random() * (hgrid)) - self.tar.y = math.floor(math.random() * vgrid) - beep:play() - end - for i = table.getn(self.blocks), 1, -1 do - if i == 1 then - self.blocks[i].x = self.x - self.blocks[i].y = self.y - else - self.blocks[i].x = self.blocks[i-1].x - self.blocks[i].y = self.blocks[i-1].y - end - end - self.x = self.x+self.xvel - self.y = self.y+self.yvel - for i in ipairs(self.blocks) do - if self.x == self.blocks[i].x and self.y == self.blocks[i].y then - death:play() - player:hardreset() - return - --love.event.quit() - end - end -end - -function player:draw() - love.graphics.setScreen('top') - love.graphics.setColor(0,255,0) - temp = 0 - for i in ipairs(self.blocks) do - temp = temp+1 - x = self.blocks[i].x - y = self.blocks[i].y - love.graphics.rectangle(self.mode, self.blocks[i].x*self.w, self.blocks[i].y*self.w, self.w, self.w) - end - love.graphics.setColor(self.col.r*255, 0, 0) - love.graphics.rectangle(self.mode, self.tar.x * self.w, self.tar.y * self.w, self.w, self.w) - love.graphics.setColor(self.col.r*255, self.col.g*255, self.col.b*255) - love.graphics.rectangle(self.mode, self.x*self.w, self.y*self.w, self.w, self.w) -end - +require "snake" +require "swat" function love.load() --love.graphics.set3D(true) - player:hardreset() + snakeplayer:hardreset() end + + function love.update(dt) - if frames >= fps then - player:update() - frames = 0 - end - frames = frames+dt - + snakeplayer:update(dt) + swat:update(dt) end + + function love.draw() - love.graphics.setBackgroundColor(bgCol.r, bgCol.g, bgCol.b) - --topscreen only works on 3ds, so look out - --love.graphics.setScreen('top') - player:draw() - --bottom screen - --love.graphics.setScreen('bottom') + love.graphics.setScreen('top') + snakeplayer:draw() + love.graphics.setScreen('bottom') + fly:draw() end + + + function love.keypressed(key) if (key == "start") then love.event.quit() end if (key == "up") then - player:move(0, -1) + snakeplayer:move(0, -1) end if (key == "down") then - player:move(0, 1) + snakeplayer:move(0, 1) end if (key == "left") then - player:move(-1, 0) + snakeplayer:move(-1, 0) end if (key == "right") then - player:move(1, 0) + snakeplayer:move(1, 0) end if (key == "cstickup") then - player:move(0, -1) + snakeplayer:move(0, -1) end if (key == "cstickdown") then - player:move(0, 1) + snakeplayer:move(0, 1) end if (key == "cstickleft") then - player:move(-1, 0) + snakeplayer:move(-1, 0) end if (key == "cstickright") then - player:move(1, 0) + snakeplayer:move(1, 0) end if (key == "cpadup") then - player:move(0, -1) + snakeplayer:move(0, -1) end if (key == "cpaddown") then - player:move(0, 1) + snakeplayer:move(0, 1) end if (key == "cpadleft") then - player:move(-1, 0) + snakeplayer:move(-1, 0) end if (key == "cpadright") then - player:move(1, 0) + snakeplayer:move(1, 0) end if (key == "x") then - player:move(0, -1) + snakeplayer:move(0, -1) end if (key == "b") then - player:move(0, 1) + snakeplayer:move(0, 1) end if (key == "y") then - player:move(-1, 0) + snakeplayer:move(-1, 0) end if (key == "a") then - player:move(1, 0) + snakeplayer:move(1, 0) end if (key == "select") then - player:hardreset() + snakeplayer:hardreset() + fly:newFly() end if (key == "lbutton") then diff = diff - 10 @@ -239,33 +127,3 @@ end - - - ---[[ - buttons for 3ds: - a - b - x - y - up - down - left - right - cpadup - cpaddown - cpadleft - cpadright - cstickup - cstickdown - cstickleft - cstickright - lbutton - rbutton - lzbutton - rzbutton - start - select - - -]] diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..f5ad866 --- /dev/null +++ b/readme.md @@ -0,0 +1,7 @@ +# Experimental + +So i'm changing my plans right now, this experimental branch is going to test out how it would work if i ran 2 games seperatly on 2 screens and the player has to deal with both. + +# whats the second game + +probably gonna be swatting flies from wario ware but on the bottom screen diff --git a/snake.lua b/snake.lua new file mode 100644 index 0000000..b75cd1e --- /dev/null +++ b/snake.lua @@ -0,0 +1,159 @@ + +--[[ + + so 3ds uses 2 screens, what if i wanted to make this game cover 2 screens, or even what if i wanted to play 2 games on 2 screens + actually loving that second idea. gonna try to make it + + + +]] + + +snake = { + beep = love.audio.newSource("data/beep.wav", "static"), + death = love.audio.newSource("data/death.wav", "static"), + fps = 10, + frames = 0, + hgrid = 20, + vgrid = 11, + bgCol = { + r = 0, + g = 0, + b = 0 + } +} + + +snakeplayer = { + x = 1, + y = 1, + w = 1, + xvel = 0, + yvel = 0, + mode = "fill", + col = { + r = 1, + g = 1, + b = 1 + }, + blocks = { + + }, + tar = { + x = 8, + y = 3, + } +} + +function snakeplayer:reset() + self.xvel = 0 + self.yvel = 0 +end + +function snakeplayer:hardreset() + self.xvel = 0 + self.yvel = 0 + self.x = 10 + self.y = 10 + self.blocks = {} + love.graphics.setScreen("top") + self.w = love.graphics.getWidth()/snake.hgrid +end + +function snakeplayer:move(xvel, yvel) + if self.xvel == -xvel and self.yvel == -yvel then + + else + self.xvel = xvel + self.yvel = yvel + end +end + +function snakeplayer:update(dt) + if snake.frames >= 1/snake.fps then + if self.x > snake.hgrid then + self.x = 0 + end + if self.x < 0 then + self.x = snake.hgrid + end + if self.y > snake.vgrid then + self.y = 0 + end + if self.y < 0 then + self.y = snake.vgrid + end + if self.tar.x == self.x and self.tar.y == self.y then + table.insert(self.blocks, {x = self.x, y = self.y}) + self.tar.x = math.floor(math.random() * snake.hgrid) + self.tar.y = math.floor(math.random() * snake.vgrid) + snake.beep:play() + end + for i = table.getn(self.blocks), 1, -1 do + if i == 1 then + self.blocks[i].x = self.x + self.blocks[i].y = self.y + else + self.blocks[i].x = self.blocks[i-1].x + self.blocks[i].y = self.blocks[i-1].y + end + end + self.x = self.x+self.xvel + self.y = self.y+self.yvel + for i in ipairs(self.blocks) do + if self.x == self.blocks[i].x and self.y == self.blocks[i].y then + snake.death:play() + snakeplayer:hardreset() + return + --love.event.quit() + end + end + snake.frames = 0 + end + snake.frames = snake.frames+dt +end + +function snakeplayer:draw() + love.graphics.setScreen('top') + love.graphics.setColor(snake.bgCol.r, snake.bgCol.g, snake.bgCol.b) + love.graphics.rectangle("fill", 0, 0, love.graphics.getWidth(), love.graphics.getHeight()) + love.graphics.setColor(0,255,0) + temp = 0 + for i in ipairs(self.blocks) do + love.graphics.rectangle(self.mode, self.blocks[i].x*self.w, self.blocks[i].y*self.w, self.w, self.w) + end + love.graphics.setColor(self.col.r*255, 0, 0) + love.graphics.rectangle(self.mode, self.tar.x * self.w, self.tar.y * self.w, self.w, self.w) + love.graphics.setColor(self.col.r*255, self.col.g*255, self.col.b*255) + love.graphics.rectangle(self.mode, self.x*self.w, self.y*self.w, self.w, self.w) +end + + + +--[[ + buttons for 3ds: + a + b + x + y + up + down + left + right + cpadup + cpaddown + cpadleft + cpadright + cstickup + cstickdown + cstickleft + cstickright + lbutton + rbutton + lzbutton + rzbutton + start + select + + +]] diff --git a/swat.lua b/swat.lua new file mode 100644 index 0000000..f0dee81 --- /dev/null +++ b/swat.lua @@ -0,0 +1,122 @@ +fly = { + sx = 0, + sy = 0, + x = 50, + y = 50, + sprite = love.graphics.newImage("data/fly.png"), + af = love.graphics.newQuad(0, 0, 512, 512, 1024, 512), + bf = love.graphics.newQuad(513, 0, 512, 512, 1024, 512), + rot = 0, + scl = 9, + anf = 0, + anc = false, + ans = 10, + alive = true, + ttl = 4, + tl = 0, + timer = false +} + +swat = { + score = 0, + diff = 1, + frames = 0, + width = 1, + height = 1, + bgCol = { + r = 255, + g = 255, + b = 255 + } +} + +function swat:load() + love.graphics.setScreen("bottom") + swat.width = love.graphics.getWidth() + swat.height = love.graphics.getHeight() + swat.score = 0 + swat.frames = 0 + fly:newFly() +end + + +function swat:update( dt) + if swat.frames == swat.diff then + + swat.frames = 0 + end + swat.frames = swat.frames+dt + fly.anf = fly.anf +dt + if fly.timer then + fly.tl = fly.tl + dt + end + if fly.alive then + --draw the existing fly if he's not on path, move him on his path. + if fly.sx ~= fly.x or fly.sy ~= fly.y then + if fly.sx < fly.x then + fly.sx = fly.sx +1 + end + if fly.sx > fly.x then + fly.sx = fly.sx - 1 + end + if fly.sy > fly.y then + fly.sy = fly.sy -1 + end + if fly.sy < fly.y then + fly.sy = fly.sy +1 + end + else + --reached position, enable timer + fly.timer = true + + end + else + --make a new fly + fly:newFly() + end +end + +function fly:draw() + love.graphics.setScreen("bottom") + love.graphics.setColor(swat.bgCol.r, swat.bgCol.g, swat.bgCol.b) + love.graphics.rectangle("fill", 0, 0, love.graphics.getWidth(), love.graphics.getHeight()) + if fly.anf > fly.ans then + fly.anf = 0 + if fly.anc then + fly.anc = false + else + fly.anc = true + end + end + if fly.anc then + love.graphics.draw(fly.sprite, fly.af, fly.sx, fly.sy, fly.rot, fly.scl, fly.scl) + else + love.graphics.draw(fly.sprite, fly.bf, fly.sx, fly.sy, fly.rot, fly.scl, fly.scl) + + end + +end + +function fly:newFly() + fly.x = math.floor(math.random() * swat.width) + fly.y = math.floor(math.random() * swat.height) + temp = math.floor(math.random() * 4) + 1 + if temp <= 1 then + fly.sx = math.floor(math.random() * swat.width) + fly.sy = 0 + elseif temp <= 2 then + fly.sy = math.floor(math.random() * swat.height) + fly.sx = 0 + elseif temp <= 3 then + fly.sx = math.floor(math.random() * swat.width) + fly.sy = swat.height + else + fly.sy = math.floor(math.random() * swat.height) + fly.sx = swat.width + end + fly.alive = true + fly.ttl = 4 + fly.tl = 0 + fly.timer = false + fly.anf = 0 +end \ No newline at end of file