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

This commit is contained in:
2018-08-30 02:15:26 +02:00
parent 3d1356eec3
commit 94e3556fad
7 changed files with 322 additions and 176 deletions

BIN
data/fly.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

210
main.lua
View File

@@ -1,208 +1,96 @@
beep = love.audio.newSource("beep.wav", "static") require "snake"
death = love.audio.newSource("death.wav", "static") require "swat"
--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
function love.load() function love.load()
--love.graphics.set3D(true) --love.graphics.set3D(true)
player:hardreset() snakeplayer:hardreset()
end end
function love.update(dt) function love.update(dt)
if frames >= fps then snakeplayer:update(dt)
player:update() swat:update(dt)
frames = 0
end
frames = frames+dt
end end
function love.draw() function love.draw()
love.graphics.setBackgroundColor(bgCol.r, bgCol.g, bgCol.b) love.graphics.setScreen('top')
--topscreen only works on 3ds, so look out snakeplayer:draw()
--love.graphics.setScreen('top') love.graphics.setScreen('bottom')
player:draw() fly:draw()
--bottom screen
--love.graphics.setScreen('bottom')
end end
function love.keypressed(key) function love.keypressed(key)
if (key == "start") then if (key == "start") then
love.event.quit() love.event.quit()
end end
if (key == "up") then if (key == "up") then
player:move(0, -1) snakeplayer:move(0, -1)
end end
if (key == "down") then if (key == "down") then
player:move(0, 1) snakeplayer:move(0, 1)
end end
if (key == "left") then if (key == "left") then
player:move(-1, 0) snakeplayer:move(-1, 0)
end end
if (key == "right") then if (key == "right") then
player:move(1, 0) snakeplayer:move(1, 0)
end end
if (key == "cstickup") then if (key == "cstickup") then
player:move(0, -1) snakeplayer:move(0, -1)
end end
if (key == "cstickdown") then if (key == "cstickdown") then
player:move(0, 1) snakeplayer:move(0, 1)
end end
if (key == "cstickleft") then if (key == "cstickleft") then
player:move(-1, 0) snakeplayer:move(-1, 0)
end end
if (key == "cstickright") then if (key == "cstickright") then
player:move(1, 0) snakeplayer:move(1, 0)
end end
if (key == "cpadup") then if (key == "cpadup") then
player:move(0, -1) snakeplayer:move(0, -1)
end end
if (key == "cpaddown") then if (key == "cpaddown") then
player:move(0, 1) snakeplayer:move(0, 1)
end end
if (key == "cpadleft") then if (key == "cpadleft") then
player:move(-1, 0) snakeplayer:move(-1, 0)
end end
if (key == "cpadright") then if (key == "cpadright") then
player:move(1, 0) snakeplayer:move(1, 0)
end end
if (key == "x") then if (key == "x") then
player:move(0, -1) snakeplayer:move(0, -1)
end end
if (key == "b") then if (key == "b") then
player:move(0, 1) snakeplayer:move(0, 1)
end end
if (key == "y") then if (key == "y") then
player:move(-1, 0) snakeplayer:move(-1, 0)
end end
if (key == "a") then if (key == "a") then
player:move(1, 0) snakeplayer:move(1, 0)
end end
if (key == "select") then if (key == "select") then
player:hardreset() snakeplayer:hardreset()
fly:newFly()
end end
if (key == "lbutton") then if (key == "lbutton") then
diff = diff - 10 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
]]

7
readme.md Normal file
View File

@@ -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

159
snake.lua Normal file
View File

@@ -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
]]

122
swat.lua Normal file
View File

@@ -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