noble engine migration
This commit is contained in:
41
source/scripts/groundSprite.lua
Normal file
41
source/scripts/groundSprite.lua
Normal file
@@ -0,0 +1,41 @@
|
||||
Ground = {}
|
||||
class("Ground").extends(Graphics.sprite)
|
||||
|
||||
local groundImage = playdate.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()
|
||||
-- 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
|
||||
Reference in New Issue
Block a user