31 lines
729 B
Lua
31 lines
729 B
Lua
class("Ground").extends(playdate.graphics.sprite)
|
|
|
|
function Ground:init(x, y, player)
|
|
local groundImage = playdate.graphics.image.new("sprites/groundFin")
|
|
Ground.super.init(self, groundImage)
|
|
self:moveTo(x, y)
|
|
self:setZIndex(100)
|
|
self:setTag(3)
|
|
self:setCollideRect(0, 28, 800, 10)
|
|
|
|
Ground.moveSpeed = 2
|
|
Ground.player = player
|
|
end
|
|
|
|
function Ground:setMoveSpeed(speed)
|
|
Ground.moveSpeed = speed
|
|
end
|
|
|
|
function Ground:update()
|
|
if Ground.player.isMovingRight() == false then
|
|
Ground.moveSpeed = 0.2
|
|
else
|
|
Ground.moveSpeed = 1
|
|
end
|
|
|
|
if self.x <= 0 then
|
|
self:moveWithCollisions(400, self.y)
|
|
end
|
|
|
|
self:moveWithCollisions(self.x-Ground.moveSpeed, self.y)
|
|
end |