2019-04-29 16:13:09 +02:00
|
|
|
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)
|
2019-05-01 11:17:01 +02:00
|
|
|
self:setSprite("player", 8, 12)
|
2019-05-05 13:18:06 +02:00
|
|
|
self:cloneSprite()
|
2019-05-02 19:51:43 +02:00
|
|
|
self:setYGravity(480)
|
2019-04-29 16:13:09 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function Player:update(dt)
|
|
|
|
self.xfrc = 480*3
|
|
|
|
|
2019-05-02 20:10:41 +02:00
|
|
|
if self.keys["up"].isPressed and (self.onGround) then
|
|
|
|
self.ysp = -280
|
2019-04-29 16:13:09 +02:00
|
|
|
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
|
|
|
|
|
2019-05-01 11:17:01 +02:00
|
|
|
self:setDirection(self.xsp)
|
|
|
|
|
2019-04-29 16:13:09 +02:00
|
|
|
Player.super.update(self, dt)
|
2019-05-05 15:23:04 +02:00
|
|
|
self:setAnimation()
|
|
|
|
end
|
|
|
|
|
|
|
|
function Player:setAnimation()
|
|
|
|
self:setCustomSpeed(math.abs(self.xsp) / 12)
|
|
|
|
if (self.onGround) then
|
|
|
|
if math.abs(self.xsp) > 0 then
|
|
|
|
self:changeAnimation("walk", false)
|
|
|
|
else
|
|
|
|
self:changeAnimation("idle", true)
|
|
|
|
end
|
|
|
|
else
|
|
|
|
self:changeAnimation("jump", true)
|
|
|
|
end
|
2019-04-29 16:13:09 +02:00
|
|
|
end
|
|
|
|
|
2019-05-01 11:17:01 +02:00
|
|
|
function Player:setDirection(direction)
|
|
|
|
direction = direction or 0
|
|
|
|
if direction ~= 0 then
|
|
|
|
direction = utils.math.sign(direction)
|
|
|
|
self:setSpriteScallingX(direction)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-04-29 16:13:09 +02:00
|
|
|
return Player
|