From 5368b94f88076041b1b4be08fe34b82d449da9b3 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Fri, 20 May 2022 19:11:23 +0200 Subject: [PATCH] feat: get hitbox and z position from datas --- .../world/actors/fighters/mixins/movements.lua | 12 +++++++++++- .../world/actors/fighters/mixins/sprites.lua | 9 ++++++++- .../world/actors/fighters/player/identity.lua | 15 +++++++++++++++ .../world/actors/fighters/player/init.lua | 6 ++---- 4 files changed, 36 insertions(+), 6 deletions(-) create mode 100644 sonic-radiance.love/game/modules/subgames/world/actors/fighters/player/identity.lua diff --git a/sonic-radiance.love/game/modules/subgames/world/actors/fighters/mixins/movements.lua b/sonic-radiance.love/game/modules/subgames/world/actors/fighters/mixins/movements.lua index c6d1599..19c4f6d 100644 --- a/sonic-radiance.love/game/modules/subgames/world/actors/fighters/mixins/movements.lua +++ b/sonic-radiance.love/game/modules/subgames/world/actors/fighters/mixins/movements.lua @@ -3,7 +3,9 @@ local PlayerMovement = Object:extend() local SPEED = 160 function PlayerMovement:initMovements() - self:setGravity(480 * 2) + if (not self:isAerial()) then + self:setGravity(480 * 2) + end end function PlayerMovement:updateMovements() @@ -41,4 +43,12 @@ function PlayerMovement:isNotJumping() return self.onGround end +function PlayerMovement:getStartZ() + if (self:isAerial()) then + return 16 + else + return 0 + end +end + return PlayerMovement diff --git a/sonic-radiance.love/game/modules/subgames/world/actors/fighters/mixins/sprites.lua b/sonic-radiance.love/game/modules/subgames/world/actors/fighters/mixins/sprites.lua index 4f8e90a..6a1404b 100644 --- a/sonic-radiance.love/game/modules/subgames/world/actors/fighters/mixins/sprites.lua +++ b/sonic-radiance.love/game/modules/subgames/world/actors/fighters/mixins/sprites.lua @@ -5,11 +5,18 @@ function FighterSprite:changeSprite(name) self.assets:addSprite(name, self:getSpritePath(name)) end self.assets.sprites[name]:setCustomSpeed(16) - self:setSprite(name, true, 8, 10) + local ox, oy = self:getOrigin() + self:setSprite(name, true, ox, oy) self:changeAnimation("idle") self:setDirection(self.direction or self.defaultDir) end +function FighterSprite:getOrigin() + local _, _, d = self:getFighterHitbox() + + return 8, (d - 14) +end + function FighterSprite:updateSprites(dt) self.sprite:setCustomSpeed(self:getCustomSpeed()) self:setDirection(self.xsp) diff --git a/sonic-radiance.love/game/modules/subgames/world/actors/fighters/player/identity.lua b/sonic-radiance.love/game/modules/subgames/world/actors/fighters/player/identity.lua new file mode 100644 index 0000000..434f314 --- /dev/null +++ b/sonic-radiance.love/game/modules/subgames/world/actors/fighters/player/identity.lua @@ -0,0 +1,15 @@ +local PlayerHitboxes = Object:extend() + +function PlayerHitboxes:getAbstract() + return game.characters.list[game.characters:getActiveCharacter()] +end + +function PlayerHitboxes:getFighterHitbox() + return 16, 12, 24 +end + +function PlayerHitboxes:isAerial() + return false +end + +return PlayerHitboxes \ No newline at end of file diff --git a/sonic-radiance.love/game/modules/subgames/world/actors/fighters/player/init.lua b/sonic-radiance.love/game/modules/subgames/world/actors/fighters/player/init.lua index 55e629c..e0d81b9 100644 --- a/sonic-radiance.love/game/modules/subgames/world/actors/fighters/player/init.lua +++ b/sonic-radiance.love/game/modules/subgames/world/actors/fighters/player/init.lua @@ -4,6 +4,7 @@ local Player = Parent:extend() local Score = require "game.modules.subgames.world.actors.fighters.player.score" local Sprites = require "game.modules.subgames.world.actors.fighters.player.sprites" local Controls = require "game.modules.subgames.world.actors.fighters.player.controls" +local Identity = require "game.modules.subgames.world.actors.fighters.player.identity" local Team = require "scenes.overworld.actors.player.team" @@ -11,6 +12,7 @@ Player:implement(Score) Player:implement(Sprites) Player:implement(Team) Player:implement(Controls) +Player:implement(Identity) function Player:new(world, x, y, z, id) self.defaultDir = 1 @@ -20,10 +22,6 @@ function Player:new(world, x, y, z, id) self:initTeam() end -function Player:getAbstract() - return game.characters.list[game.characters:getActiveCharacter()] -end - function Player:updateStart(dt) self:applyInputs() end