fpv/source/scripts/groundSprite.lua

51 lines
1.1 KiB
Lua
Raw Permalink Normal View History

2024-06-01 16:52:11 +03:00
Ground = {}
2024-06-02 20:25:27 +03:00
class("Ground").extends(NobleSprite)
2024-06-01 16:52:11 +03:00
function Ground:init(x, y, player)
2024-06-02 20:25:27 +03:00
Ground.super.init(self, "assets/sprites/groundFin")
2024-06-01 16:52:11 +03:00
-- Collision properties
2024-06-03 00:31:15 +03:00
self:setZIndex(ZIndex.ground)
2024-06-01 16:52:11 +03:00
self:setTag(3)
2024-06-03 00:31:15 +03:00
self:setGroups(CollideGroups.wall)
2024-06-01 16:52:11 +03:00
self:setCollideRect(0, 28, 800, 10)
2024-06-03 00:31:15 +03:00
self:setCollidesWithGroups(
{
CollideGroups.player
})
2024-06-02 20:25:27 +03:00
self:setSize(800, 32)
2024-06-01 16:52:11 +03:00
-- Main properties
Ground.moveSpeed = 2
Ground.player = player
2024-06-02 20:25:27 +03:00
self:add()
2024-06-01 16:52:11 +03:00
self:moveTo(x, y)
end
function Ground:setMoveSpeed(speed)
Ground.moveSpeed = speed
end
function Ground:update()
2024-06-01 22:46:36 +03:00
-- Stop ground
if Ground.moveSpeed == 0 then
return
end
2024-06-01 16:52:11 +03:00
-- 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
2024-06-02 20:25:27 +03:00
self:moveWithCollisions(self.x - Ground.moveSpeed, self.y)
end