almost finished the game, added movement and easyer translation, added targets, added the tail, added collision with tail and added a death sound.

This commit is contained in:
2018-08-29 19:20:08 +02:00
parent b49b441632
commit 2af8fecb7e

View File

@@ -1,11 +1,11 @@
beep = love.audio.newSource("beep.wav", "static") 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 --dif determines fps, this can make the game faster and therefore harder
diff = 10 diff = 10
frames = 0 frames = 0
fps = 1/diff fps = 1/diff
hgrid = 20
vgrid = 14
bgCol = { bgCol = {
r = 0, r = 0,
g = 0, g = 0,
@@ -15,8 +15,7 @@ bgCol = {
player = { player = {
x = 1, x = 1,
y = 1, y = 1,
w = 20, w = love.graphics.getWidth()/hgrid,
s = 20,
xvel = 0, xvel = 0,
yvel = 0, yvel = 0,
mode = "fill", mode = "fill",
@@ -25,7 +24,13 @@ player = {
g = 1, g = 1,
b = 1 b = 1
}, },
blocks = {} blocks = {
},
tar = {
x = 8,
y = 3,
}
} }
--[[ --[[
@@ -64,41 +69,77 @@ end
function player:hardreset() function player:hardreset()
self.xvel = 0 self.xvel = 0
self.yvel = 0 self.yvel = 0
self.x = 1 self.x = 10
self.y = 1 self.y = 10
self.blocks = {} self.blocks = {}
end end
function player:move(xvel, yvel) function player:move(xvel, yvel)
self.xvel = xvel if self.xvel == -xvel and self.yvel == -yvel then
self.yvel = yvel
else
self.xvel = xvel
self.yvel = yvel
end
end end
function player:update() function player:update()
if self.x > love.graphics.getWidth() - self.w then if self.x > hgrid then
self.x = 0 self.x = 0
end end
if self.x < 0 then if self.x < 0 then
self.x = love.graphics.getWidth()-self.w self.x = hgrid
end end
if self.y > love.graphics.getHeight() - self.w then if self.y > vgrid then
self.y = 0 self.y = 0
end end
if self.y < 0 then if self.y < 0 then
self.y = love.graphics.getHeight() - self.w self.y = vgrid
end
if self.tar.x == self.x and self.tar.y == self.y then
table.insert(self.blocks, {x = self.tar.x, self.tar.y})
self.tar.x = math.floor(love.math.random() * hgrid)
self.tar.y = math.floor(love.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
player:hardreset()
death:play()
end
end end
self.x = self.x+self.xvel*self.s
self.y = self.y+self.yvel*self.s
end end
function player:draw() function player:draw()
love.graphics.rectangle(self.mode, self.x, self.y, self.w, self.w) love.graphics.setColor(0,1,0)
temp = 0
for i in ipairs(self.blocks) do
temp = temp+1
love.graphics.rectangle(self.mode, self.blocks[i].x*self.w, self.blocks[i].y*self.w, self.w, self.w)
end
love.graphics.print(temp)
love.graphics.setColor(self.col.r, 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, self.col.g, self.col.b)
love.graphics.rectangle(self.mode, self.x*self.w, self.y*self.w, self.w, self.w)
end end
function love.load() function love.load()
--love.graphics.set3D(true) --love.graphics.set3D(true)
beep:play()
player:hardreset()
end end
function love.update(dt) function love.update(dt)
@@ -114,7 +155,6 @@ function love.draw()
love.graphics.setBackgroundColor(bgCol.r, bgCol.g, bgCol.b) love.graphics.setBackgroundColor(bgCol.r, bgCol.g, bgCol.b)
--topscreen only works on 3ds, so look out --topscreen only works on 3ds, so look out
love.graphics.setScreen('top') love.graphics.setScreen('top')
--love.graphics.rectangle("fill", 1, 1, 30, 30)
player:draw() player:draw()
--bottom screen --bottom screen
--love.graphics.setScreen('bottom') --love.graphics.setScreen('bottom')