feat(action3D): add player multiple hitboxes
This commit is contained in:
parent
dd15c329c8
commit
215aed8684
2 changed files with 31 additions and 0 deletions
13
examples/gameplay/action3D/actors/hitboxes/player.lua
Normal file
13
examples/gameplay/action3D/actors/hitboxes/player.lua
Normal 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}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -8,6 +8,7 @@ function Player:new(world, x, y, z, id)
|
||||||
|
|
||||||
self:setSprite("player", 8, 12)
|
self:setSprite("player", 8, 12)
|
||||||
self:cloneSprite()
|
self:cloneSprite()
|
||||||
|
self:setHitboxFile("examples.gameplay.action3D.actors.hitboxes.player")
|
||||||
end
|
end
|
||||||
|
|
||||||
function Player:updateStart(dt)
|
function Player:updateStart(dt)
|
||||||
|
@ -29,6 +30,17 @@ function Player:updateStart(dt)
|
||||||
if self.keys["A"].isDown and (self.onGround) then
|
if self.keys["A"].isDown and (self.onGround) then
|
||||||
self.zsp = 280
|
self.zsp = 280
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if self.keys["B"].isDown then
|
||||||
|
self.isPunching = true
|
||||||
|
else
|
||||||
|
self.isPunching = false
|
||||||
|
end
|
||||||
|
|
||||||
|
if (self.isPunching) then
|
||||||
|
self:checkHitboxesCollisions()
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function Player:updateEnd(dt)
|
function Player:updateEnd(dt)
|
||||||
|
@ -69,6 +81,12 @@ function Player:collisionResponse(collision)
|
||||||
end
|
end
|
||||||
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()
|
function Player:draw()
|
||||||
Player.super.draw(self)
|
Player.super.draw(self)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue