2020-04-05 18:18:13 +02:00
|
|
|
local Base = require "birb.modules.world.actors.actor2D"
|
2019-04-29 16:13:09 +02:00
|
|
|
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-06-27 21:03:34 +02:00
|
|
|
self:setGravity(480)
|
2019-06-22 22:11:22 +02:00
|
|
|
|
|
|
|
self.isPunching = false
|
|
|
|
self.direction = 1
|
2019-09-08 12:34:16 +02:00
|
|
|
self.startx, self.starty = self.x, self.y
|
|
|
|
self.isDead = false
|
2019-06-23 10:19:01 +02:00
|
|
|
|
|
|
|
self.punchName = ""
|
2020-04-05 18:18:13 +02:00
|
|
|
self:setHitboxFile("scenes.gameplay.plateform.actors.hitboxes.player")
|
2019-04-29 16:13:09 +02:00
|
|
|
end
|
|
|
|
|
2019-06-13 18:44:13 +02:00
|
|
|
function Player:updateStart(dt)
|
2019-04-29 16:13:09 +02:00
|
|
|
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
|
2019-06-22 20:17:36 +02:00
|
|
|
self.mainHitbox:modify(0, 8, 16, 16)
|
|
|
|
else
|
|
|
|
self.mainHitbox:modify(0, 0, 16, 24)
|
2019-04-29 16:13:09 +02:00
|
|
|
end
|
2019-06-22 22:11:22 +02:00
|
|
|
if self.keys["left"].isDown and (not self.isPunching) then
|
2019-04-29 16:13:09 +02:00
|
|
|
self.xsp = -120
|
|
|
|
end
|
2019-06-22 22:11:22 +02:00
|
|
|
if self.keys["right"].isDown and (not self.isPunching) then
|
2019-04-29 16:13:09 +02:00
|
|
|
self.xsp = 120
|
|
|
|
end
|
|
|
|
|
2019-06-22 22:11:22 +02:00
|
|
|
if self.keys["A"].isDown then
|
|
|
|
self.isPunching = true
|
|
|
|
else
|
|
|
|
self.isPunching = false
|
|
|
|
end
|
|
|
|
|
|
|
|
if (self.isPunching) then
|
2019-06-23 15:53:51 +02:00
|
|
|
self:checkHitboxesCollisions()
|
2019-06-22 22:11:22 +02:00
|
|
|
end
|
|
|
|
|
2019-05-30 13:49:46 +02:00
|
|
|
if self.keys["start"].isPressed then
|
2019-06-16 16:37:22 +02:00
|
|
|
--self.world:switchActivity()
|
|
|
|
--self.assets:switchActivity()
|
|
|
|
self.scene.menusystem:activate()
|
|
|
|
self.scene.menusystem:switchMenu("PauseMenu")
|
2019-05-30 13:49:46 +02:00
|
|
|
self.scene:flushKeys()
|
|
|
|
end
|
|
|
|
|
2019-05-01 11:17:01 +02:00
|
|
|
self:setDirection(self.xsp)
|
2019-06-13 18:44:13 +02:00
|
|
|
end
|
2019-05-01 11:17:01 +02:00
|
|
|
|
2019-06-13 18:44:13 +02:00
|
|
|
function Player:updateEnd(dt)
|
2019-05-05 15:23:04 +02:00
|
|
|
self:setAnimation()
|
2019-09-08 12:34:16 +02:00
|
|
|
|
|
|
|
local width, height = self.world:getDimensions()
|
|
|
|
|
|
|
|
if (self.y > height + self.h) and (self.isDead == false) then
|
|
|
|
self:addTimer("respawn", 1)
|
|
|
|
self.isDead = true
|
|
|
|
end
|
2019-05-05 15:23:04 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function Player:setAnimation()
|
|
|
|
self:setCustomSpeed(math.abs(self.xsp) / 12)
|
2019-06-22 22:11:22 +02:00
|
|
|
if (self.isPunching) then
|
|
|
|
self:changeAnimation("punch", false)
|
|
|
|
else
|
2019-05-05 15:23:04 +02:00
|
|
|
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-06-22 22:11:22 +02:00
|
|
|
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)
|
2019-06-22 22:11:22 +02:00
|
|
|
self.direction = direction
|
2019-05-01 11:17:01 +02:00
|
|
|
self:setSpriteScallingX(direction)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-09-08 12:34:16 +02:00
|
|
|
function Player:timerResponse(timer)
|
|
|
|
if timer == "respawn" then
|
|
|
|
self.x, self.y = self.startx, self.starty
|
|
|
|
self.xspeed = 0
|
|
|
|
self.yspeed = 0
|
|
|
|
self.isDead = false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-05-05 19:46:13 +02:00
|
|
|
function Player:collisionResponse(collision)
|
|
|
|
if collision.other.type == "coin" then
|
2019-06-22 19:28:28 +02:00
|
|
|
collision.other.owner:takeCoin(self)
|
2019-05-05 19:46:13 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-06-22 22:11:22 +02:00
|
|
|
function Player:hitboxResponse(name, type, collision)
|
|
|
|
if (collision.other.type == "coin") and (type == "punch") then
|
|
|
|
collision.other.owner:takeCoin(self)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-06-22 19:28:28 +02:00
|
|
|
function Player:draw()
|
|
|
|
Player.super.draw(self)
|
2019-06-22 22:11:22 +02:00
|
|
|
self:drawHitboxes()
|
2019-06-22 19:28:28 +02:00
|
|
|
utils.graphics.resetColor()
|
|
|
|
end
|
|
|
|
|
2019-06-21 17:11:32 +02:00
|
|
|
function Player:drawHUD(id)
|
|
|
|
love.graphics.print(id .. " test", 4, 4)
|
|
|
|
end
|
2019-05-05 19:46:13 +02:00
|
|
|
|
2019-04-29 16:13:09 +02:00
|
|
|
return Player
|