Code: Select all
-- stores upper left corner coordinates for each block to use in collision detection
self.coordinates = {{x = self.blockA.x, y = self.blockA.y}, {x = self.blockB.x, y = self.blockB.y},
{x = self.blockC.x, y = self.blockC.y}, {x = self.blockD.x, y = self.blockD.y}}
Code: Select all
function Piece:collides()
for _, v in pairs(self.coordinates) do
if v.y >= 50 then
return true
end
end
return false
end
Finally, here is my love.update() function in main, where it's called:
Code: Select all
function love.update(dt)
if gameState == 'play' then
piece.dy = GRAVITY
if love.keyboard.isDown('left') then
piece.dx = -25
elseif love.keyboard.isDown('right') then
piece.dx = 25
else
piece.dx = 0
end
if love.keyboard.isDown('down') then
piece:drop()
else
piece.dy = GRAVITY
end
if piece:collides() then
piece.dy = 0
end
piece:update(piece.dx, piece.dy, dt)
end
end
Code: Select all
function Piece:drop()
self.dy = GRAVITY * 5
end
I'm really not sure where to go from here. As far as I can tell it seems to be only calling Piece:collides() once when gameState turns to 'play', but I see no reason why that should be happening.
Please let me know if there's any other code I should post.