fpv/source/scripts/groundSprite.lua
2024-06-02 20:25:27 +03:00

46 lines
973 B
Lua

Ground = {}
class("Ground").extends(NobleSprite)
function Ground:init(x, y, player)
Ground.super.init(self, "assets/sprites/groundFin")
-- Collision properties
self:setZIndex(100)
self:setTag(3)
self:setCollideRect(0, 28, 800, 10)
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