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 0000000..a9690ef Binary files /dev/null and b/data/fly.png differ diff --git a/main.lua b/main.lua index 70adf30..a755f33 100644 --- a/main.lua +++ b/main.lua @@ -1,208 +1,96 @@ -beep = love.audio.newSource("beep.wav", "static") -death = love.audio.newSource("death.wav", "static") ---dif determines fps, this can make the game faster and therefore harder -diff = 10 -frames = 0 -fps = 1/diff -hgrid = 20 -vgrid = 11 -bgCol = { - r = 0, - g = 0, - b = 0 -} - -player = { - x = 1, - y = 1, - w = love.graphics.getWidth()/hgrid, - xvel = 0, - yvel = 0, - mode = "fill", - col = { - r = 1, - g = 1, - b = 1 - }, - blocks = { - - }, - tar = { - x = 8, - y = 3, - } -} - - -function player:reset() - self.xvel = 0 - self.yvel = 0 -end - -function player:hardreset() - self.xvel = 0 - self.yvel = 0 - self.x = 10 - self.y = 10 - self.blocks = {} - love.graphics.setScreen("top") - self.w = love.graphics.getWidth()/hgrid -end - -function player:move(xvel, yvel) - if self.xvel == -xvel and self.yvel == -yvel then - - else - self.xvel = xvel - self.yvel = yvel - end -end - -function player:update() - if self.x > 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