feat(action3D): add player multiple hitboxes

This commit is contained in:
Kazhnuz 2019-07-20 17:57:46 +02:00
parent dd15c329c8
commit 215aed8684
2 changed files with 31 additions and 0 deletions

View File

@ -0,0 +1,13 @@
return {
["idle"] = {
{
{"main", 0, 0, 0, 16, 16, 24, true}
}
},
["punch"] = {
{
{"main", 0, 0, 0, 16, 16, 24, true},
{"punch", 16, 2, 6, 12, 12, 12, false}
}
}
}

View File

@ -8,6 +8,7 @@ function Player:new(world, x, y, z, id)
self:setSprite("player", 8, 12)
self:cloneSprite()
self:setHitboxFile("examples.gameplay.action3D.actors.hitboxes.player")
end
function Player:updateStart(dt)
@ -29,6 +30,17 @@ function Player:updateStart(dt)
if self.keys["A"].isDown and (self.onGround) then
self.zsp = 280
end
if self.keys["B"].isDown then
self.isPunching = true
else
self.isPunching = false
end
if (self.isPunching) then
self:checkHitboxesCollisions()
end
end
function Player:updateEnd(dt)
@ -69,6 +81,12 @@ function Player:collisionResponse(collision)
end
end
function Player:hitboxResponse(name, type, collision)
if (collision.other.type == "coin") and (type == "punch") then
collision.other.owner:takeCoin(self)
end
end
function Player:draw()
Player.super.draw(self)
end