fpv/source/scripts/groundSprite.lua
2024-06-01 22:46:36 +03:00

47 lines
1.0 KiB
Lua

Ground = {}
class("Ground").extends(Graphics.sprite)
local groundImage = Graphics.image.new("assets/sprites/groundFin")
function Ground:init(x, y, player)
Ground.super.init(self, groundImage)
-- Collision properties
self:setZIndex(100)
self:setTag(3)
self:setCollideRect(0, 28, 800, 10)
-- Main properties
Ground.moveSpeed = 2
Ground.player = player
-- Move to initial position
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