40 lines
860 B
Lua
40 lines
860 B
Lua
local Base = require "gamecore.modules.world.actors.actor2D"
|
|
local Player = Base:extend()
|
|
|
|
function Player:new(world, x, y, id)
|
|
Player.super.new(self, world, "player", x, y, 16, 24, true)
|
|
self:setSprite("player", 8, 12)
|
|
self:cloneSprite()
|
|
self:setYGravity(480)
|
|
end
|
|
|
|
function Player:update(dt)
|
|
self.xfrc = 480*3
|
|
|
|
if self.keys["up"].isPressed and (self.onGround) then
|
|
self.ysp = -280
|
|
end
|
|
if self.keys["down"].isDown then
|
|
--self.ysp = 120
|
|
end
|
|
if self.keys["left"].isDown then
|
|
self.xsp = -120
|
|
end
|
|
if self.keys["right"].isDown then
|
|
self.xsp = 120
|
|
end
|
|
|
|
self:setDirection(self.xsp)
|
|
|
|
Player.super.update(self, dt)
|
|
end
|
|
|
|
function Player:setDirection(direction)
|
|
direction = direction or 0
|
|
if direction ~= 0 then
|
|
direction = utils.math.sign(direction)
|
|
self:setSpriteScallingX(direction)
|
|
end
|
|
end
|
|
|
|
return Player
|