75 lines
1.6 KiB
Lua
75 lines
1.6 KiB
Lua
|
local cwd = (...):gsub('%.player$', '') .. "."
|
||
|
local Parent = require(cwd .. "parent")
|
||
|
local Player = Parent:extend()
|
||
|
|
||
|
function Player:new(world, x, y, z, id)
|
||
|
Player.super.new(self, world, "player", x, y, 0, 16, 16, 24, true)
|
||
|
self:setGravity(480)
|
||
|
|
||
|
self:setSprite("sonic", 8, 12)
|
||
|
self:cloneSprite()
|
||
|
end
|
||
|
|
||
|
function Player:updateStart(dt)
|
||
|
self.xfrc, self.yfrc = 480*3, 480*3
|
||
|
|
||
|
if self.keys["up"].isDown then
|
||
|
self.ysp = -120
|
||
|
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
|
||
|
|
||
|
if self.keys["A"].isDown and (self.onGround) then
|
||
|
self.zsp = 280
|
||
|
end
|
||
|
end
|
||
|
|
||
|
function Player:updateEnd(dt)
|
||
|
self:setAnimation()
|
||
|
end
|
||
|
|
||
|
function Player:setAnimation()
|
||
|
local gsp = utils.math.pointDistance(0, 0, self.xsp, self.ysp)
|
||
|
self:setCustomSpeed(math.abs(gsp) / 12)
|
||
|
self:setDirection(self.xsp)
|
||
|
if (self.isPunching) then
|
||
|
self:changeAnimation("walk", false)
|
||
|
else
|
||
|
if (self.onGround) then
|
||
|
if (math.abs(self.xsp) > 0) or (math.abs(self.ysp) > 0) then
|
||
|
self:changeAnimation("walk", false)
|
||
|
else
|
||
|
self:changeAnimation("idle", false)
|
||
|
end
|
||
|
else
|
||
|
self:changeAnimation("idle", true)
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
|
function Player:setDirection(direction)
|
||
|
direction = direction or 0
|
||
|
if direction ~= 0 then
|
||
|
direction = utils.math.sign(direction)
|
||
|
self.direction = direction
|
||
|
self:setSpriteScallingX(direction)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
function Player:draw()
|
||
|
Player.super.draw(self)
|
||
|
end
|
||
|
|
||
|
function Player:drawHUD(id)
|
||
|
love.graphics.print(id .. " test", 4, 4)
|
||
|
end
|
||
|
|
||
|
return Player
|