fpv/source/scripts/groundSprite.lua
2024-06-03 00:31:15 +03:00

51 lines
1.1 KiB
Lua

Ground = {}
class("Ground").extends(NobleSprite)
function Ground:init(x, y, player)
Ground.super.init(self, "assets/sprites/groundFin")
-- Collision properties
self:setZIndex(ZIndex.ground)
self:setTag(3)
self:setGroups(CollideGroups.wall)
self:setCollideRect(0, 28, 800, 10)
self:setCollidesWithGroups(
{
CollideGroups.player
})
self:setSize(800, 32)
-- Main properties
Ground.moveSpeed = 2
Ground.player = player
self:add()
self:moveTo(x, y)
end
function Ground:setMoveSpeed(speed)
Ground.moveSpeed = speed
end
function Ground:update()
-- Stop ground
if Ground.moveSpeed == 0 then
return
end
-- Speedup when player is moving right
if Ground.player.isMovingRight() == false then
Ground.moveSpeed = 0.2
else
Ground.moveSpeed = 1
end
-- Reset position
if self.x <= 0 then
self:moveWithCollisions(400, self.y)
end
-- Move ground
self:moveWithCollisions(self.x - Ground.moveSpeed, self.y)
end