From 215aed8684bad55b0238acfe667473e7392fcb7f Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sat, 20 Jul 2019 17:57:46 +0200 Subject: [PATCH] feat(action3D): add player multiple hitboxes --- .../action3D/actors/hitboxes/player.lua | 13 +++++++++++++ examples/gameplay/action3D/actors/player.lua | 18 ++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 examples/gameplay/action3D/actors/hitboxes/player.lua diff --git a/examples/gameplay/action3D/actors/hitboxes/player.lua b/examples/gameplay/action3D/actors/hitboxes/player.lua new file mode 100644 index 0000000..ffbd964 --- /dev/null +++ b/examples/gameplay/action3D/actors/hitboxes/player.lua @@ -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} + } + } +} diff --git a/examples/gameplay/action3D/actors/player.lua b/examples/gameplay/action3D/actors/player.lua index 6d65ddb..b3b550b 100644 --- a/examples/gameplay/action3D/actors/player.lua +++ b/examples/gameplay/action3D/actors/player.lua @@ -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