From 1bb9d13e5d8e5f7957caf76b08b5bc09968a048e Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Wed, 11 May 2022 20:44:00 +0200 Subject: [PATCH 01/23] feat: add more keys --- sonic-radiance.love/datas/inputs.lua | 19 +++++++++++++++++-- sonic-radiance.love/datas/keys.lua | 22 +++++++++++++++++++++- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/sonic-radiance.love/datas/inputs.lua b/sonic-radiance.love/datas/inputs.lua index 053f97c..202d071 100644 --- a/sonic-radiance.love/datas/inputs.lua +++ b/sonic-radiance.love/datas/inputs.lua @@ -6,11 +6,26 @@ return { ["right"] = "right", ["up"] = "up", ["down"] = "down", + + ["dleft"] = "k", + ["dright"] = "m", + ["dup"] = "o", + ["ddown"] = "l", + ["A"] = "a", ["B"] = "z", - ["C"] = "e", + ["X"] = "e", + ["Y"] = "r", + + ["C"] = "n", + ["start"] = "return", - ["select"] = "space" + ["select"] = "space", + + ["R1"] = "w", + ["R2"] = "q", + ["L1"] = "x", + ["L2"] = "s", } } } diff --git a/sonic-radiance.love/datas/keys.lua b/sonic-radiance.love/datas/keys.lua index 7467ebe..3eca23a 100644 --- a/sonic-radiance.love/datas/keys.lua +++ b/sonic-radiance.love/datas/keys.lua @@ -1 +1,21 @@ -return {"up", "down", "left", "right", "A", "B", "C", "start", "select"} +return { + "up", + "down", + "left", + "right", + "dup", + "ddown", + "dleft", + "dright", + "A", + "B", + "X", + "Y", + "C", + "start", + "select", + "R1", + "R2", + "L1", + "L2", +} -- 2.30.2 From 6c7e0caf4bc98a810f26a28e2f680dbb017db0e7 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Wed, 11 May 2022 20:44:14 +0200 Subject: [PATCH 02/23] improvement: refactor subgame Player --- .../subgames/world/actors/player/actions.lua | 13 +++ .../subgames/world/actors/player/init.lua | 106 +++--------------- .../world/actors/player/movements.lua | 40 +++++++ .../subgames/world/actors/player/score.lua | 22 ++++ .../subgames/world/actors/player/sprites.lua | 41 +++++++ 5 files changed, 131 insertions(+), 91 deletions(-) create mode 100644 sonic-radiance.love/game/modules/subgames/world/actors/player/actions.lua create mode 100644 sonic-radiance.love/game/modules/subgames/world/actors/player/movements.lua create mode 100644 sonic-radiance.love/game/modules/subgames/world/actors/player/score.lua create mode 100644 sonic-radiance.love/game/modules/subgames/world/actors/player/sprites.lua diff --git a/sonic-radiance.love/game/modules/subgames/world/actors/player/actions.lua b/sonic-radiance.love/game/modules/subgames/world/actors/player/actions.lua new file mode 100644 index 0000000..37a0422 --- /dev/null +++ b/sonic-radiance.love/game/modules/subgames/world/actors/player/actions.lua @@ -0,0 +1,13 @@ +local PlayerActions = Object:extend() + +function PlayerActions:initActions() + self.action = "normal" +end + +function PlayerActions:doActions() + if self.keys["B"].isPressed and (self.onGround) then + -- Nothing for the moment + end +end + +return PlayerActions \ No newline at end of file diff --git a/sonic-radiance.love/game/modules/subgames/world/actors/player/init.lua b/sonic-radiance.love/game/modules/subgames/world/actors/player/init.lua index 9a33c9e..0d10cb8 100644 --- a/sonic-radiance.love/game/modules/subgames/world/actors/player/init.lua +++ b/sonic-radiance.love/game/modules/subgames/world/actors/player/init.lua @@ -2,57 +2,27 @@ local cwd = (...):gsub('%.player$', '') .. "." local Parent = require(cwd .. "parent") local Player = Parent:extend() +local Actions = require "game.modules.subgames.world.actors.player.actions" +local Movements = require "game.modules.subgames.world.actors.player.movements" +local Score = require "game.modules.subgames.world.actors.player.score" +local Sprites = require "game.modules.subgames.world.actors.player.sprites" + +Player:implement(Actions) +Player:implement(Movements) +Player:implement(Score) +Player:implement(Sprites) + function Player:new(world, x, y, z, id) Player.super.new(self, world, "player", x, y, 0, 16, 12, 24, true) - self:setGravity(480*2) - - self:initPlayer() - - self.action = "normal" - - self.rings = 0 - self.score = 0 -end - -function Player:initPlayer() - self.charName = game.characters:getActiveCharacter() - self.assets:addSprite(self.charName, "datas/gamedata/characters/" .. self.charName .. "/sprites") - self:setSprite(self.charName, true, 8, 10) + self:initMovements() + self:initCharactersSprites() + self:initScore() + self:initActions() end function Player:updateStart(dt) - self.xfrc, self.yfrc = 480*3, 480*3 - self:basicMovements() - - if self.keys["A"].isPressed and (self.onGround) then - self.zsp = 280*1.33 - end - - if self.keys["B"].isPressed and (self.onGround) then - -- Nothing for the moment - end -end - -function Player:basicMovements() - - if self.keys["up"].isDown then - self.ysp = -160 - end - if self.keys["down"].isDown then - self.ysp = 160 - end - if (self.world.autorun == true) then - self.xsp = 160 - else - if self.keys["left"].isDown then - self.xsp = -160 - end - if self.keys["right"].isDown then - self.xsp = 160 - end - end - + self:doActions() end function Player:collisionResponse(collision) @@ -69,38 +39,6 @@ function Player:updateEnd(dt) self:setAnimation() end -function Player:setAnimation() - local gsp = utils.math.pointDistance(0, 0, self.xsp, self.ysp) - self:setCustomSpeed(math.abs(gsp) / 12) - self:setDirection(self.xsp) - if (self.action == "punching") then - --the animation system is already active - else - if (self.onGround) then - if (math.abs(self.xsp) > 0) or (math.abs(self.ysp) > 0) then - self:changeAnimation("walk", false) - else - self:changeAnimation("idle", false) - end - else - if (self.zsp) > 0 then - self:changeAnimation("jump", false) - else - self:changeAnimation("fall", false) - end - end - end -end - -function Player:setDirection(direction) - direction = direction or 0 - if direction ~= 0 then - direction = utils.math.sign(direction) - self.direction = direction - self.sprite:setScallingX(direction) - end -end - function Player:getViewCenter() local x, y = Player.super.getViewCenter(self) return x, y-16 @@ -110,18 +48,4 @@ function Player:draw() Player.super.draw(self) end -function Player:setRing(value, isRelative) - if (isRelative == false) then - self.rings = 0 - end - self.rings = self.rings + value -end - -function Player:setScore(value, isRelative) - if (isRelative == false) then - self.score = 0 - end - self.score = self.score + value -end - return Player diff --git a/sonic-radiance.love/game/modules/subgames/world/actors/player/movements.lua b/sonic-radiance.love/game/modules/subgames/world/actors/player/movements.lua new file mode 100644 index 0000000..132021d --- /dev/null +++ b/sonic-radiance.love/game/modules/subgames/world/actors/player/movements.lua @@ -0,0 +1,40 @@ +local PlayerMovement = Object:extend() + +function PlayerMovement:initMovements() + self:setGravity(480 * 2) +end + +function PlayerMovement:basicMovements() + self:setFrc() + + if self.keys["up"].isDown then + self.ysp = -160 + end + if self.keys["down"].isDown then + self.ysp = 160 + end + if (self.world.autorun == true) then + self.xsp = 160 + else + if self.keys["left"].isDown then + self.xsp = -160 + end + if self.keys["right"].isDown then + self.xsp = 160 + end + end + + self:jump() +end + +function PlayerMovement:setFrc() + self.xfrc, self.yfrc = 480 * 3, 480 * 3 +end + +function PlayerMovement:jump() + if self.keys["A"].isPressed and (self.onGround) then + self.zsp = 280 * 1.33 + end +end + +return PlayerMovement diff --git a/sonic-radiance.love/game/modules/subgames/world/actors/player/score.lua b/sonic-radiance.love/game/modules/subgames/world/actors/player/score.lua new file mode 100644 index 0000000..bccfc8a --- /dev/null +++ b/sonic-radiance.love/game/modules/subgames/world/actors/player/score.lua @@ -0,0 +1,22 @@ +local PlayerScore = Object:extend() + +function PlayerScore:initScore() + self.rings = 0 + self.score = 0 +end + +function PlayerScore:setRing(value, isRelative) + if (isRelative == false) then + self.rings = 0 + end + self.rings = self.rings + value +end + +function PlayerScore:setScore(value, isRelative) + if (isRelative == false) then + self.score = 0 + end + self.score = self.score + value +end + +return PlayerScore diff --git a/sonic-radiance.love/game/modules/subgames/world/actors/player/sprites.lua b/sonic-radiance.love/game/modules/subgames/world/actors/player/sprites.lua new file mode 100644 index 0000000..36efdb0 --- /dev/null +++ b/sonic-radiance.love/game/modules/subgames/world/actors/player/sprites.lua @@ -0,0 +1,41 @@ +local SpritedPlayer = Object:extend() + +function SpritedPlayer:initCharactersSprites() + self.charName = game.characters:getActiveCharacter() + self.assets:addSprite(self.charName, "datas/gamedata/characters/" .. self.charName .. "/sprites") + self:setSprite(self.charName, true, 8, 10) +end + +function SpritedPlayer:setAnimation() + local gsp = utils.math.pointDistance(0, 0, self.xsp, self.ysp) + self.sprite:setCustomSpeed(math.abs(gsp) / 12) + self:setDirection(self.xsp) + if (self.action == "punching") then + --the animation system is already active + else + if (self.onGround) then + if (math.abs(self.xsp) > 0) or (math.abs(self.ysp) > 0) then + self.sprite:changeAnimation("walk", false) + else + self.sprite:changeAnimation("idle", false) + end + else + if (self.zsp) > 0 then + self.sprite:changeAnimation("jump", false) + else + self.sprite:changeAnimation("fall", false) + end + end + end +end + +function SpritedPlayer:setDirection(direction) + direction = direction or 0 + if direction ~= 0 then + direction = utils.math.sign(direction) + self.direction = direction + self.sprite:setScallingX(direction) + end +end + +return SpritedPlayer -- 2.30.2 From f5bff3e1b953144f1420b4cd42ed81dd2e982c73 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Wed, 11 May 2022 23:07:19 +0200 Subject: [PATCH 03/23] improvement: adapt overworld to changes --- .../scenes/overworld/actors/player/actions.lua | 9 ++++++--- .../scenes/overworld/actors/player/team.lua | 15 ++++++++++----- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/sonic-radiance.love/scenes/overworld/actors/player/actions.lua b/sonic-radiance.love/scenes/overworld/actors/player/actions.lua index 3aa3dfe..a28c9f2 100644 --- a/sonic-radiance.love/scenes/overworld/actors/player/actions.lua +++ b/sonic-radiance.love/scenes/overworld/actors/player/actions.lua @@ -158,13 +158,16 @@ function PlayerActions:endFly() end function PlayerActions:actionSwitch() - if self.keys["select"].isPressed and (self.currentAction == "idle") then + if self.keys["L1"].isPressed and (self.currentAction == "idle") then self:switchActiveCharacter() end + if self.keys["R1"].isPressed and (self.currentAction == "idle") then + self:switchActiveCharacter(-1) + end end function PlayerActions:actionRun() - if self.keys["C"].isPressed then + if self.keys["X"].isPressed then if (self:canDoAction("run") and self.speedFactor > 0) then self.dashJustStarted = true if (utils.table.contain({"run", "idle"}, self.currentAction)) then @@ -174,7 +177,7 @@ function PlayerActions:actionRun() end self.xsp, self.ysp = self:getDash() end - elseif (not self.keys["C"].isDown) then + elseif (not self.keys["X"].isDown) then if (self.currentAction == "run") then self.currentAction = "idle" elseif (self.currentAction == "jumpdash") then diff --git a/sonic-radiance.love/scenes/overworld/actors/player/team.lua b/sonic-radiance.love/scenes/overworld/actors/player/team.lua index eba901a..fc4eaa3 100644 --- a/sonic-radiance.love/scenes/overworld/actors/player/team.lua +++ b/sonic-radiance.love/scenes/overworld/actors/player/team.lua @@ -1,8 +1,13 @@ local Team = Object:extend() -function Team:initTeam() +function Team:initTeam(forceCanGameOver) self.active = game.characters:getActiveCharacterData() self.canChangeActive = true + if (forceCanKO == true) then + self.canKO = true + else + self.canKO = game.difficulty:get("playerKoChar") == false + end end function Team:updateActiveCharacter() @@ -16,7 +21,7 @@ function Team:updateActiveCharacter() if (everybodyIsKo) then self.scene:gameover() else - if ((self.active.hp == 0) and not game.difficulty:get("playerKoChar")) then + if ((self.active.hp == 0) and self.canKO) then self:switchActiveCharacter() end end @@ -26,9 +31,9 @@ function Team:getCurrentCharType() return self.active.data.class end -function Team:switchActiveCharacter() - if (self.canChangeActive) then - local count = game.characters:setActiveCharacter() +function Team:switchActiveCharacter(direction) + if (self.canChangeActive and self.scene.gui:getElement("teamEmblems") ~= nil) then + local count = game.characters:setActiveCharacter(direction) self.active = game.characters:getActiveCharacterData() self.canChangeActive = false self.tweens:newTimer(0.3, "changeCharacter") -- 2.30.2 From cdc5b083ca40774b05960592ea3d4f3462cae25e Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Wed, 11 May 2022 23:07:55 +0200 Subject: [PATCH 04/23] feat: add character switching to subgames --- .../game/modules/subgames/hud.lua | 62 +++++++++++++++++++ .../game/modules/subgames/init.lua | 2 + .../subgames/world/actors/player/actions.lua | 9 +++ .../subgames/world/actors/player/init.lua | 20 ++++++ .../subgames/world/actors/player/sprites.lua | 14 ++++- 5 files changed, 104 insertions(+), 3 deletions(-) create mode 100644 sonic-radiance.love/game/modules/subgames/hud.lua diff --git a/sonic-radiance.love/game/modules/subgames/hud.lua b/sonic-radiance.love/game/modules/subgames/hud.lua new file mode 100644 index 0000000..ce9f9c3 --- /dev/null +++ b/sonic-radiance.love/game/modules/subgames/hud.lua @@ -0,0 +1,62 @@ +local GuiScreen = require "birb.modules.gui.screen" +local OWScreen = GuiScreen:extend() + +local Composite = require "birb.modules.gui.elements.composite" +local Counter = require "birb.modules.gui.elements.counter" +local Asset = require "birb.modules.gui.elements.assets" + +local Emblems = require "scenes.overworld.gui.hudelements.emblems" + +local show = { + -- {"rings", "movement", 0, 0.3, 16, 16, "inOutQuart"}, + -- {"time", "movement", 0, 0.3, 408, 250, "inOutQuart"}, + {"teamEmblems", "movement", 0, 0.3, 368, 24, "inOutQuart"}, + -- {"lifebars", "movement", 0, 0.3, 8, 168, "inOutQuart"}, +} + +local hide = { + -- {"rings", "movement", 0, 0.3, -16, -16, "inOutQuart"}, + -- {"time", "movement", 0, 0.3, 408, 250, "inOutQuart"}, + {"teamEmblems", "movement", 0, 0.3, 500, 24, "inOutQuart"}, + -- {"lifebars", "movement", 0, 0.3, -124, 168, "inOutQuart"}, +} + +local showMenu = { + -- {"rings", "movement", 0, 0.5, 8, 8, "inOutQuart"}, + -- {"time", "movement", 0, 0.5, 408, 221, "inOutQuart"}, + {"teamEmblems", "movement", 0, 0.3, 500, 24, "inOutQuart"}, + -- {"lifebars", "movement", 0, 0.3, -124, 168, "inOutQuart"}, +} + +local hideMenu = { + -- {"rings", "movement", 0, 0.5, 16, 16, "inOutQuart"}, + -- {"time", "movement", 0, 0.5, 408, 250, "inOutQuart"}, + {"teamEmblems", "movement", 0, 0.3, 368, 24, "inOutQuart"}, + -- {"lifebars", "movement", 0, 0.3, 8, 168, "inOutQuart"} +} + +function OWScreen:new() + OWScreen.super.new(self, "hud") + self:addTransform("show", show) + self:addTransform("hide", hide) + self:addTransform("pause", showMenu) + self:addTransform("unpause", hideMenu) + self:show() +end + +function OWScreen:createElements() + local list = { + -- {Composite("rings", -16, -16, { + -- {Asset("guiRing", "images", "guiRing", -1, -1), 0, 0}, + -- {Counter("turnCnt", "hudnbrs", game.loot, "rings", 3, -1, -1), 14, 1} + -- }), 0, -100}, + -- {TimeElement("hudnbrs", 408, 250, "right"), 0, -100}, + Emblems(500, 24), + -- Lifebars(-124, 168), + -- Interactions() + } + + return list +end + +return OWScreen diff --git a/sonic-radiance.love/game/modules/subgames/init.lua b/sonic-radiance.love/game/modules/subgames/init.lua index f1c1942..eb1192b 100644 --- a/sonic-radiance.love/game/modules/subgames/init.lua +++ b/sonic-radiance.love/game/modules/subgames/init.lua @@ -3,6 +3,7 @@ local PlayStyle = Scene:extend() local TweenManager = require "birb.classes.time" local PauseScreen = require("game.modules.subgames.pause") +local HUD = require("game.modules.subgames.hud") local TestWorld = require("game.modules.subgames.world.parent") function PlayStyle:new(supportedLevels, missionfile) @@ -17,6 +18,7 @@ function PlayStyle:new(supportedLevels, missionfile) self.tweens = TweenManager(self) PauseScreen() + HUD() self.haveStarted = false self.canPause = true diff --git a/sonic-radiance.love/game/modules/subgames/world/actors/player/actions.lua b/sonic-radiance.love/game/modules/subgames/world/actors/player/actions.lua index 37a0422..80c82af 100644 --- a/sonic-radiance.love/game/modules/subgames/world/actors/player/actions.lua +++ b/sonic-radiance.love/game/modules/subgames/world/actors/player/actions.lua @@ -10,4 +10,13 @@ function PlayerActions:doActions() end end +function PlayerActions:actionSwitch() + if self.keys["L1"].isPressed and (self.action == "normal") and (self.onGround) then + self:switchActiveCharacter() + end + if self.keys["R1"].isPressed and (self.action == "normal") and (self.onGround) then + self:switchActiveCharacter(-1) + end +end + return PlayerActions \ No newline at end of file diff --git a/sonic-radiance.love/game/modules/subgames/world/actors/player/init.lua b/sonic-radiance.love/game/modules/subgames/world/actors/player/init.lua index 0d10cb8..9a067c0 100644 --- a/sonic-radiance.love/game/modules/subgames/world/actors/player/init.lua +++ b/sonic-radiance.love/game/modules/subgames/world/actors/player/init.lua @@ -2,15 +2,19 @@ local cwd = (...):gsub('%.player$', '') .. "." local Parent = require(cwd .. "parent") local Player = Parent:extend() +local TweenManager = require "birb.classes.time" + local Actions = require "game.modules.subgames.world.actors.player.actions" local Movements = require "game.modules.subgames.world.actors.player.movements" local Score = require "game.modules.subgames.world.actors.player.score" local Sprites = require "game.modules.subgames.world.actors.player.sprites" +local Team = require "scenes.overworld.actors.player.team" Player:implement(Actions) Player:implement(Movements) Player:implement(Score) Player:implement(Sprites) +Player:implement(Team) function Player:new(world, x, y, z, id) Player.super.new(self, world, "player", x, y, 0, 16, 12, 24, true) @@ -18,19 +22,35 @@ function Player:new(world, x, y, z, id) self:initCharactersSprites() self:initScore() self:initActions() + self:initTeam() + + self.tweens = TweenManager(self) end function Player:updateStart(dt) self:basicMovements() self:doActions() + self:actionSwitch() end +function Player:update(dt) + Player.super.update(self, dt) + self.tweens:update(dt) +end + + function Player:collisionResponse(collision) if collision.other.type == "collectible" then collision.other.owner:getPicked(self) end end +function Player:timerResponse(response) + if (response == "changeCharacter") then + self:endCharacterSwitchAnimation() + end +end + function Player:animationEnded(name) end diff --git a/sonic-radiance.love/game/modules/subgames/world/actors/player/sprites.lua b/sonic-radiance.love/game/modules/subgames/world/actors/player/sprites.lua index 36efdb0..cd751d5 100644 --- a/sonic-radiance.love/game/modules/subgames/world/actors/player/sprites.lua +++ b/sonic-radiance.love/game/modules/subgames/world/actors/player/sprites.lua @@ -1,9 +1,11 @@ local SpritedPlayer = Object:extend() function SpritedPlayer:initCharactersSprites() - self.charName = game.characters:getActiveCharacter() - self.assets:addSprite(self.charName, "datas/gamedata/characters/" .. self.charName .. "/sprites") - self:setSprite(self.charName, true, 8, 10) + for id, name in ipairs(game.characters.team) do + self.assets:addSprite(name, "datas/gamedata/characters/" .. name .. "/sprites") + end + self.direction = 1 + self:updateCurrentCharset() end function SpritedPlayer:setAnimation() @@ -38,4 +40,10 @@ function SpritedPlayer:setDirection(direction) end end +function SpritedPlayer:updateCurrentCharset() + self.charName = game.characters:getActiveCharacter() + self:setSprite(self.charName, true, 8, 10) + self.sprite:setScallingX(self.direction) +end + return SpritedPlayer -- 2.30.2 From 102fc467ebd827d948cfbd152a4ab326eacf1db0 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Thu, 12 May 2022 13:29:38 +0200 Subject: [PATCH 05/23] feat: add statutbar to new cbs --- .../game/modules/subgames/hud.lua | 2 ++ .../gui/hudelements/statutbar.lua | 33 +++++++++++++++---- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/sonic-radiance.love/game/modules/subgames/hud.lua b/sonic-radiance.love/game/modules/subgames/hud.lua index ce9f9c3..d986430 100644 --- a/sonic-radiance.love/game/modules/subgames/hud.lua +++ b/sonic-radiance.love/game/modules/subgames/hud.lua @@ -6,6 +6,7 @@ local Counter = require "birb.modules.gui.elements.counter" local Asset = require "birb.modules.gui.elements.assets" local Emblems = require "scenes.overworld.gui.hudelements.emblems" +local StatusBar = require "scenes.battlesystem.gui.hudelements.statutbar" local show = { -- {"rings", "movement", 0, 0.3, 16, 16, "inOutQuart"}, @@ -52,6 +53,7 @@ function OWScreen:createElements() -- }), 0, -100}, -- {TimeElement("hudnbrs", 408, 250, "right"), 0, -100}, Emblems(500, 24), + StatusBar(), -- Lifebars(-124, 168), -- Interactions() } diff --git a/sonic-radiance.love/scenes/battlesystem/gui/hudelements/statutbar.lua b/sonic-radiance.love/scenes/battlesystem/gui/hudelements/statutbar.lua index 2754ebe..0fac00b 100644 --- a/sonic-radiance.love/scenes/battlesystem/gui/hudelements/statutbar.lua +++ b/sonic-radiance.love/scenes/battlesystem/gui/hudelements/statutbar.lua @@ -7,16 +7,37 @@ local ComplexHPBar = require "game.modules.gui.complexhpbar" local DIST_STATUSBAR = 106 local Y = 200 -local STATUSBAR_W = 90 +local STATUSBAR_W = 128 +local HPBAR_W = STATUSBAR_W - 32 -function StatusBar:new(fighter, i) +function StatusBar:new(fighter, i, y) self:initAbstract(fighter) - StatusBar.super.new(self, self.abstract.name .. "StatutBar", (i-0.5)*DIST_STATUSBAR-(STATUSBAR_W/2), Y, STATUSBAR_W, 64) + local x = 16 + local y = 16 + if (i == 0) then + x = (i-0.5)*DIST_STATUSBAR-(STATUSBAR_W/2) + y = Y + end + + StatusBar.super.new(self, self.abstract.name .. "StatutBar", x, y, STATUSBAR_W, 64) self:createParts(self.scene) end +function StatusBar:update(dt) + StatusBar.super.update(self, dt) + if (self.currentChar ~= nil and self.currentChar ~= game.characters:getActiveCharacter()) then + self:initAbstract() + self:createParts(self.scene) + end +end + function StatusBar:initAbstract(fighter) - self.abstract = fighter.abstract + if (fighter == nil) then + self.currentChar = game.characters:getActiveCharacter() + self.abstract = game.characters:getActiveCharacterData() + else + self.abstract = fighter.abstract + end self.hp = self.abstract.hp self.pp = self.abstract.pp self.stats = self.abstract:getStats() @@ -25,8 +46,8 @@ end function StatusBar:createParts(scene) self.emblem = Emblem(self.abstract, scene) - self.hpbar = ComplexHPBar(58) - self.ppbar = ComplexHPBar(58) + self.hpbar = ComplexHPBar(HPBAR_W) + self.ppbar = ComplexHPBar(HPBAR_W) self.hpbar:setColorForeground(248 / 255, 160 / 255, 0, 1) self.hpbar:setColorBackground(112 / 255, 0, 0) self.ppbar:setColorForeground(0, 248 / 255, 248 / 255, 1) -- 2.30.2 From a35079f1c7ba4e7b90ca51b5e5278c6b4b5fbb70 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Thu, 12 May 2022 17:07:27 +0200 Subject: [PATCH 06/23] feat: initial new battles scene --- sonic-radiance.love/scenes/battles/init.lua | 44 ++++++++++++++++ .../scenes/battles/world/init.lua | 16 ++++++ .../scenes/battles/world/map.lua | 50 +++++++++++++++++++ sonic-radiance.love/scenes/init.lua | 2 +- 4 files changed, 111 insertions(+), 1 deletion(-) create mode 100644 sonic-radiance.love/scenes/battles/init.lua create mode 100644 sonic-radiance.love/scenes/battles/world/init.lua create mode 100644 sonic-radiance.love/scenes/battles/world/map.lua diff --git a/sonic-radiance.love/scenes/battles/init.lua b/sonic-radiance.love/scenes/battles/init.lua new file mode 100644 index 0000000..2be5e90 --- /dev/null +++ b/sonic-radiance.love/scenes/battles/init.lua @@ -0,0 +1,44 @@ +-- scenes/battles :: the Radiance Custom Battle System + +--[[ + Copyright © 2022 Kazhnuz + + Permission is hereby granted, free of charge, to any person obtaining a copy of + this software and associated documentation files (the "Software"), to deal in + the Software without restriction, including without limitation the rights to + use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + the Software, and to permit persons to whom the Software is furnished to do so, + subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +]] + +local PlayStyle = require "game.modules.subgames" +local CBS = PlayStyle:extend() + +local World = require "scenes.battles.world" + +function CBS:new(battleData) + CBS.super.new(self, {"shoot", "test", "battle"}, "testmissions", {"sonic"}) + self.assets:batchImport("assets.battle") + self:playMusic(battleData.music) +end + +function CBS:playMusic(music) + self.assets:setMusic("assets/music/" .. music .. ".mp3") + self.assets:playMusic() +end + +function CBS:initWorld() + World(self, self.map) +end + +return CBS diff --git a/sonic-radiance.love/scenes/battles/world/init.lua b/sonic-radiance.love/scenes/battles/world/init.lua new file mode 100644 index 0000000..85d21f3 --- /dev/null +++ b/sonic-radiance.love/scenes/battles/world/init.lua @@ -0,0 +1,16 @@ +local ParentWorld = require "game.modules.subgames.world.parent" +local CBSWorld = ParentWorld:extend() + +local Map = require "scenes.battles.world.map" + +function CBSWorld:new(scene, mapname) + CBSWorld.super.new(self, scene, "battle", mapname) + self.mapname = mapname +end + +function CBSWorld:createMapController() + Map(self, self.mapname) + self.cameras:lockY(10) +end + +return CBSWorld diff --git a/sonic-radiance.love/scenes/battles/world/map.lua b/sonic-radiance.love/scenes/battles/world/map.lua new file mode 100644 index 0000000..6351360 --- /dev/null +++ b/sonic-radiance.love/scenes/battles/world/map.lua @@ -0,0 +1,50 @@ +local BaseMap = require "birb.modules.world.maps.parent" +local CBSMap = BaseMap:extend() + +local TILESIZE = 31 +local TESTZONE = "forest" + +local zoneDatas = require "datas.gamedata.maps.shoot.zones" +local Background = require "game.modules.drawing.parallaxBackground" + +function CBSMap:new(world, type) + CBSMap.super.new(self, world) + + self:setPadding(0, 0, 0, 0) + self.parallaxBackground = Background(world.scene, 6, 0, TESTZONE) + self.layout = {} + self.chunklist = {} +end + +function CBSMap:loadCollisions() + local w, h = self:getDimensions() + + self.world:newCollision("fakefloor", 0, 0, -48, w, h, 48) + self.world:newCollision("invisible", 0, 0, -48, w, h, 48) +end + +function CBSMap:addBlock(x, y, w, h, top, bottom) + -- Empty Placeholder function +end + +function CBSMap:getDimensions() + return 424, 120 +end + +function CBSMap:loadPlayers() + self.world:addPlayer(16, 50, 0, 1) +end + +function CBSMap:loadActors() + -- Empty Placeholder function +end + +function CBSMap:drawParallax(x, y, w, h) + self.parallaxBackground:drawParallax(x, y, w, h) +end + +function CBSMap:draw() + +end + +return CBSMap diff --git a/sonic-radiance.love/scenes/init.lua b/sonic-radiance.love/scenes/init.lua index fd9789c..8f86cbe 100644 --- a/sonic-radiance.love/scenes/init.lua +++ b/sonic-radiance.love/scenes/init.lua @@ -1,7 +1,7 @@ return { test = require "scenes.subgames.testBattle", test2 = require "scenes.subgames.testShoot", - cbs = require "scenes.battlesystem", + cbs = require "scenes.battles", menus = require "scenes.menus", overworld = require "scenes.overworld" } -- 2.30.2 From 27bd6da3737d0e402c857f8541c841676bde17bf Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Thu, 19 May 2022 12:34:16 +0200 Subject: [PATCH 07/23] improvement(player): separate inputs --- .../subgames/world/actors/player/actions.lua | 17 +--- .../subgames/world/actors/player/controls.lua | 79 +++++++++++++++++++ .../subgames/world/actors/player/init.lua | 8 +- .../world/actors/player/movements.lua | 50 ++++++------ 4 files changed, 112 insertions(+), 42 deletions(-) create mode 100644 sonic-radiance.love/game/modules/subgames/world/actors/player/controls.lua diff --git a/sonic-radiance.love/game/modules/subgames/world/actors/player/actions.lua b/sonic-radiance.love/game/modules/subgames/world/actors/player/actions.lua index 80c82af..1f45708 100644 --- a/sonic-radiance.love/game/modules/subgames/world/actors/player/actions.lua +++ b/sonic-radiance.love/game/modules/subgames/world/actors/player/actions.lua @@ -1,22 +1,7 @@ local PlayerActions = Object:extend() function PlayerActions:initActions() - self.action = "normal" -end - -function PlayerActions:doActions() - if self.keys["B"].isPressed and (self.onGround) then - -- Nothing for the moment - end -end - -function PlayerActions:actionSwitch() - if self.keys["L1"].isPressed and (self.action == "normal") and (self.onGround) then - self:switchActiveCharacter() - end - if self.keys["R1"].isPressed and (self.action == "normal") and (self.onGround) then - self:switchActiveCharacter(-1) - end + self.action = "idle" end return PlayerActions \ No newline at end of file diff --git a/sonic-radiance.love/game/modules/subgames/world/actors/player/controls.lua b/sonic-radiance.love/game/modules/subgames/world/actors/player/controls.lua new file mode 100644 index 0000000..23afb89 --- /dev/null +++ b/sonic-radiance.love/game/modules/subgames/world/actors/player/controls.lua @@ -0,0 +1,79 @@ +local PlayerControls = Object:extend() + +function PlayerControls:applyInputs() + if (self.world.autorun == true) then + self:applyAutorunInput() + else + self:applyMoveInput() + end + self:applyJumpInput() + self:applyActionsInputs() + self:applySwitchInputs() +end + +function PlayerControls:applyMoveInput() + local angle, strenght = self:dpadToAngle() + if (strenght ~= 0) then + self:goTowardDir(angle, strenght) + end +end + + +function PlayerControls:applyAutorunInput() + self:goX() + if self.keys["up"].isDown then + self:goY(-1) + end + if self.keys["down"].isDown then + self:goY(1) + end +end + +function PlayerControls:dpadToAngle() + local xsp, ysp = 0, 0 + local strenght = 0 + local angle = 0 + if self.keys["up"].isDown then + ysp = -1 + end + if self.keys["down"].isDown then + ysp = 1 + end + if self.keys["left"].isDown then + xsp = -1 + end + if self.keys["right"].isDown then + xsp = 1 + end + + if (xsp ~= 0 or ysp ~= 0) then + angle = utils.math.pointDirection(0, 0, xsp, ysp) + strenght = 1 + end + + return angle, strenght +end + +function PlayerControls:applyJumpInput() + if self.keys["A"].isPressed and (self:isNotJumping()) then + self:jump() + end +end + + +function PlayerControls:applyActionsInputs() + if self.keys["B"].isPressed and (self.onGround) then + -- Nothing for the moment + end +end + +function PlayerControls:applySwitchInputs() + if self.keys["L1"].isPressed and (self.action == "normal") and (self.onGround) then + self:switchActiveCharacter() + end + if self.keys["R1"].isPressed and (self.action == "normal") and (self.onGround) then + self:switchActiveCharacter(-1) + end +end + +return PlayerControls \ No newline at end of file diff --git a/sonic-radiance.love/game/modules/subgames/world/actors/player/init.lua b/sonic-radiance.love/game/modules/subgames/world/actors/player/init.lua index 9a067c0..9552408 100644 --- a/sonic-radiance.love/game/modules/subgames/world/actors/player/init.lua +++ b/sonic-radiance.love/game/modules/subgames/world/actors/player/init.lua @@ -8,6 +8,8 @@ local Actions = require "game.modules.subgames.world.actors.player.actions" local Movements = require "game.modules.subgames.world.actors.player.movements" local Score = require "game.modules.subgames.world.actors.player.score" local Sprites = require "game.modules.subgames.world.actors.player.sprites" +local Controls = require "game.modules.subgames.world.actors.player.controls" + local Team = require "scenes.overworld.actors.player.team" Player:implement(Actions) @@ -15,6 +17,7 @@ Player:implement(Movements) Player:implement(Score) Player:implement(Sprites) Player:implement(Team) +Player:implement(Controls) function Player:new(world, x, y, z, id) Player.super.new(self, world, "player", x, y, 0, 16, 12, 24, true) @@ -28,12 +31,11 @@ function Player:new(world, x, y, z, id) end function Player:updateStart(dt) - self:basicMovements() - self:doActions() - self:actionSwitch() + self:applyInputs() end function Player:update(dt) + self:updateMovements(dt) Player.super.update(self, dt) self.tweens:update(dt) end diff --git a/sonic-radiance.love/game/modules/subgames/world/actors/player/movements.lua b/sonic-radiance.love/game/modules/subgames/world/actors/player/movements.lua index 132021d..c6d1599 100644 --- a/sonic-radiance.love/game/modules/subgames/world/actors/player/movements.lua +++ b/sonic-radiance.love/game/modules/subgames/world/actors/player/movements.lua @@ -1,40 +1,44 @@ local PlayerMovement = Object:extend() +local SPEED = 160 + function PlayerMovement:initMovements() self:setGravity(480 * 2) end -function PlayerMovement:basicMovements() +function PlayerMovement:updateMovements() self:setFrc() - - if self.keys["up"].isDown then - self.ysp = -160 - end - if self.keys["down"].isDown then - self.ysp = 160 - end - if (self.world.autorun == true) then - self.xsp = 160 - else - if self.keys["left"].isDown then - self.xsp = -160 - end - if self.keys["right"].isDown then - self.xsp = 160 - end - end - - self:jump() end +-- GOTO FUNCTIONS +-- Help the movable go toward something + +function PlayerMovement:goTowardDir(angle, strenght) + self.xsp, self.ysp = utils.math.lengthdir(SPEED, angle) +end + +function PlayerMovement:goX(dir) + self.xsp = SPEED * (dir or 1) +end + +function PlayerMovement:goY(dir) + self.ysp = SPEED * (dir or 1) +end + +-- FRICTION + function PlayerMovement:setFrc() self.xfrc, self.yfrc = 480 * 3, 480 * 3 end +-- JUMP FUNCTIONS + function PlayerMovement:jump() - if self.keys["A"].isPressed and (self.onGround) then - self.zsp = 280 * 1.33 - end + self.zsp = 280 * 1.33 +end + +function PlayerMovement:isNotJumping() + return self.onGround end return PlayerMovement -- 2.30.2 From 62b382a4d6914d01111f9bafe2a23dd75bdf5c99 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Thu, 19 May 2022 12:34:52 +0200 Subject: [PATCH 08/23] chore(fighter): rename folder --- .../subgames/world/actors/{player => fighters}/actions.lua | 0 .../subgames/world/actors/{player => fighters}/controls.lua | 0 .../modules/subgames/world/actors/{player => fighters}/init.lua | 0 .../subgames/world/actors/{player => fighters}/movements.lua | 0 .../modules/subgames/world/actors/{player => fighters}/score.lua | 0 .../subgames/world/actors/{player => fighters}/sprites.lua | 0 6 files changed, 0 insertions(+), 0 deletions(-) rename sonic-radiance.love/game/modules/subgames/world/actors/{player => fighters}/actions.lua (100%) rename sonic-radiance.love/game/modules/subgames/world/actors/{player => fighters}/controls.lua (100%) rename sonic-radiance.love/game/modules/subgames/world/actors/{player => fighters}/init.lua (100%) rename sonic-radiance.love/game/modules/subgames/world/actors/{player => fighters}/movements.lua (100%) rename sonic-radiance.love/game/modules/subgames/world/actors/{player => fighters}/score.lua (100%) rename sonic-radiance.love/game/modules/subgames/world/actors/{player => fighters}/sprites.lua (100%) diff --git a/sonic-radiance.love/game/modules/subgames/world/actors/player/actions.lua b/sonic-radiance.love/game/modules/subgames/world/actors/fighters/actions.lua similarity index 100% rename from sonic-radiance.love/game/modules/subgames/world/actors/player/actions.lua rename to sonic-radiance.love/game/modules/subgames/world/actors/fighters/actions.lua diff --git a/sonic-radiance.love/game/modules/subgames/world/actors/player/controls.lua b/sonic-radiance.love/game/modules/subgames/world/actors/fighters/controls.lua similarity index 100% rename from sonic-radiance.love/game/modules/subgames/world/actors/player/controls.lua rename to sonic-radiance.love/game/modules/subgames/world/actors/fighters/controls.lua diff --git a/sonic-radiance.love/game/modules/subgames/world/actors/player/init.lua b/sonic-radiance.love/game/modules/subgames/world/actors/fighters/init.lua similarity index 100% rename from sonic-radiance.love/game/modules/subgames/world/actors/player/init.lua rename to sonic-radiance.love/game/modules/subgames/world/actors/fighters/init.lua diff --git a/sonic-radiance.love/game/modules/subgames/world/actors/player/movements.lua b/sonic-radiance.love/game/modules/subgames/world/actors/fighters/movements.lua similarity index 100% rename from sonic-radiance.love/game/modules/subgames/world/actors/player/movements.lua rename to sonic-radiance.love/game/modules/subgames/world/actors/fighters/movements.lua diff --git a/sonic-radiance.love/game/modules/subgames/world/actors/player/score.lua b/sonic-radiance.love/game/modules/subgames/world/actors/fighters/score.lua similarity index 100% rename from sonic-radiance.love/game/modules/subgames/world/actors/player/score.lua rename to sonic-radiance.love/game/modules/subgames/world/actors/fighters/score.lua diff --git a/sonic-radiance.love/game/modules/subgames/world/actors/player/sprites.lua b/sonic-radiance.love/game/modules/subgames/world/actors/fighters/sprites.lua similarity index 100% rename from sonic-radiance.love/game/modules/subgames/world/actors/player/sprites.lua rename to sonic-radiance.love/game/modules/subgames/world/actors/fighters/sprites.lua -- 2.30.2 From 4d22e35288a8aa9d41d9dad9499bd69cc4442034 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Thu, 19 May 2022 12:45:20 +0200 Subject: [PATCH 09/23] improvement: add a fighter parent --- .../subgames/world/actors/fighters/init.lua | 73 ------------------- .../actors/fighters/{ => mixins}/actions.lua | 0 .../fighters/{ => mixins}/movements.lua | 0 .../subgames/world/actors/fighters/parent.lua | 34 +++++++++ .../actors/fighters/{ => player}/controls.lua | 0 .../world/actors/fighters/player/init.lua | 51 +++++++++++++ .../actors/fighters/{ => player}/score.lua | 0 .../actors/fighters/{ => player}/sprites.lua | 0 .../modules/subgames/world/actors/init.lua | 2 +- 9 files changed, 86 insertions(+), 74 deletions(-) delete mode 100644 sonic-radiance.love/game/modules/subgames/world/actors/fighters/init.lua rename sonic-radiance.love/game/modules/subgames/world/actors/fighters/{ => mixins}/actions.lua (100%) rename sonic-radiance.love/game/modules/subgames/world/actors/fighters/{ => mixins}/movements.lua (100%) create mode 100644 sonic-radiance.love/game/modules/subgames/world/actors/fighters/parent.lua rename sonic-radiance.love/game/modules/subgames/world/actors/fighters/{ => player}/controls.lua (100%) create mode 100644 sonic-radiance.love/game/modules/subgames/world/actors/fighters/player/init.lua rename sonic-radiance.love/game/modules/subgames/world/actors/fighters/{ => player}/score.lua (100%) rename sonic-radiance.love/game/modules/subgames/world/actors/fighters/{ => player}/sprites.lua (100%) diff --git a/sonic-radiance.love/game/modules/subgames/world/actors/fighters/init.lua b/sonic-radiance.love/game/modules/subgames/world/actors/fighters/init.lua deleted file mode 100644 index 9552408..0000000 --- a/sonic-radiance.love/game/modules/subgames/world/actors/fighters/init.lua +++ /dev/null @@ -1,73 +0,0 @@ -local cwd = (...):gsub('%.player$', '') .. "." -local Parent = require(cwd .. "parent") -local Player = Parent:extend() - -local TweenManager = require "birb.classes.time" - -local Actions = require "game.modules.subgames.world.actors.player.actions" -local Movements = require "game.modules.subgames.world.actors.player.movements" -local Score = require "game.modules.subgames.world.actors.player.score" -local Sprites = require "game.modules.subgames.world.actors.player.sprites" -local Controls = require "game.modules.subgames.world.actors.player.controls" - -local Team = require "scenes.overworld.actors.player.team" - -Player:implement(Actions) -Player:implement(Movements) -Player:implement(Score) -Player:implement(Sprites) -Player:implement(Team) -Player:implement(Controls) - -function Player:new(world, x, y, z, id) - Player.super.new(self, world, "player", x, y, 0, 16, 12, 24, true) - self:initMovements() - self:initCharactersSprites() - self:initScore() - self:initActions() - self:initTeam() - - self.tweens = TweenManager(self) -end - -function Player:updateStart(dt) - self:applyInputs() -end - -function Player:update(dt) - self:updateMovements(dt) - Player.super.update(self, dt) - self.tweens:update(dt) -end - - -function Player:collisionResponse(collision) - if collision.other.type == "collectible" then - collision.other.owner:getPicked(self) - end -end - -function Player:timerResponse(response) - if (response == "changeCharacter") then - self:endCharacterSwitchAnimation() - end -end - -function Player:animationEnded(name) - -end - -function Player:updateEnd(dt) - self:setAnimation() -end - -function Player:getViewCenter() - local x, y = Player.super.getViewCenter(self) - return x, y-16 -end - -function Player:draw() - Player.super.draw(self) -end - -return Player diff --git a/sonic-radiance.love/game/modules/subgames/world/actors/fighters/actions.lua b/sonic-radiance.love/game/modules/subgames/world/actors/fighters/mixins/actions.lua similarity index 100% rename from sonic-radiance.love/game/modules/subgames/world/actors/fighters/actions.lua rename to sonic-radiance.love/game/modules/subgames/world/actors/fighters/mixins/actions.lua diff --git a/sonic-radiance.love/game/modules/subgames/world/actors/fighters/movements.lua b/sonic-radiance.love/game/modules/subgames/world/actors/fighters/mixins/movements.lua similarity index 100% rename from sonic-radiance.love/game/modules/subgames/world/actors/fighters/movements.lua rename to sonic-radiance.love/game/modules/subgames/world/actors/fighters/mixins/movements.lua diff --git a/sonic-radiance.love/game/modules/subgames/world/actors/fighters/parent.lua b/sonic-radiance.love/game/modules/subgames/world/actors/fighters/parent.lua new file mode 100644 index 0000000..4c8facf --- /dev/null +++ b/sonic-radiance.love/game/modules/subgames/world/actors/fighters/parent.lua @@ -0,0 +1,34 @@ +local Parent = require("game.modules.subgames.world.actors.parent") +local FighterParent = Parent:extend() + +local TweenManager = require "birb.classes.time" + +local Actions = require "game.modules.subgames.world.actors.fighters.mixins.actions" +local Movements = require "game.modules.subgames.world.actors.fighters.mixins.movements" + +FighterParent:implement(Actions) +FighterParent:implement(Movements) +FighterParent:implement(Score) +FighterParent:implement(Sprites) +FighterParent:implement(Team) +FighterParent:implement(Controls) + +function FighterParent:new(world, x, y, w, h, d, fighterType) + FighterParent.super.new(self, world, fighterType, x, y, 0, w, h, d, true) + self:initMovements() + self:initActions() + + self.tweens = TweenManager(self) +end + +function FighterParent:update(dt) + self:updateMovements(dt) + FighterParent.super.update(self, dt) + self.tweens:update(dt) +end + +function FighterParent:animationEnded(name) + +end + +return FighterParent diff --git a/sonic-radiance.love/game/modules/subgames/world/actors/fighters/controls.lua b/sonic-radiance.love/game/modules/subgames/world/actors/fighters/player/controls.lua similarity index 100% rename from sonic-radiance.love/game/modules/subgames/world/actors/fighters/controls.lua rename to sonic-radiance.love/game/modules/subgames/world/actors/fighters/player/controls.lua 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 new file mode 100644 index 0000000..2b805ab --- /dev/null +++ b/sonic-radiance.love/game/modules/subgames/world/actors/fighters/player/init.lua @@ -0,0 +1,51 @@ +local Parent = require("game.modules.subgames.world.actors.fighters.parent") +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 Team = require "scenes.overworld.actors.player.team" + +Player:implement(Score) +Player:implement(Sprites) +Player:implement(Team) +Player:implement(Controls) + +function Player:new(world, x, y, z, id) + Player.super.new(self, world, x, y, 16, 12, 24, "fighter") + self:initCharactersSprites() + self:initScore() + self:initTeam() +end + +function Player:updateStart(dt) + self:applyInputs() +end + +function Player:collisionResponse(collision) + if collision.other.type == "collectible" then + collision.other.owner:getPicked(self) + end +end + +function Player:timerResponse(response) + if (response == "changeCharacter") then + self:endCharacterSwitchAnimation() + end +end + +function Player:animationEnded(name) + +end + +function Player:updateEnd(dt) + self:setAnimation() +end + +function Player:getViewCenter() + local x, y = Player.super.getViewCenter(self) + return x, y-16 +end + +return Player diff --git a/sonic-radiance.love/game/modules/subgames/world/actors/fighters/score.lua b/sonic-radiance.love/game/modules/subgames/world/actors/fighters/player/score.lua similarity index 100% rename from sonic-radiance.love/game/modules/subgames/world/actors/fighters/score.lua rename to sonic-radiance.love/game/modules/subgames/world/actors/fighters/player/score.lua diff --git a/sonic-radiance.love/game/modules/subgames/world/actors/fighters/sprites.lua b/sonic-radiance.love/game/modules/subgames/world/actors/fighters/player/sprites.lua similarity index 100% rename from sonic-radiance.love/game/modules/subgames/world/actors/fighters/sprites.lua rename to sonic-radiance.love/game/modules/subgames/world/actors/fighters/player/sprites.lua diff --git a/sonic-radiance.love/game/modules/subgames/world/actors/init.lua b/sonic-radiance.love/game/modules/subgames/world/actors/init.lua index fea28f9..484af22 100644 --- a/sonic-radiance.love/game/modules/subgames/world/actors/init.lua +++ b/sonic-radiance.love/game/modules/subgames/world/actors/init.lua @@ -2,7 +2,7 @@ local Obj = {} -- On charge toutes les différentes types d'acteurs local cwd = (...):gsub('%.init$', '') .. "." -Obj.Player = require(cwd .. "player") +Obj.Player = require(cwd .. "fighters.player") Obj.Ring = require(cwd .. "items.ring") Obj.index = {} -- 2.30.2 From 084d31a13c8cffe3bda46ac5d49509005d468ece Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Fri, 20 May 2022 14:46:08 +0200 Subject: [PATCH 10/23] improvement: mise en commun de fonction de sprite --- .../world/actors/fighters/mixins/sprites.lua | 28 +++++++++++++++++++ .../subgames/world/actors/fighters/parent.lua | 9 ++++-- .../world/actors/fighters/player/init.lua | 7 ++--- .../world/actors/fighters/player/sprites.lua | 28 ++++++------------- 4 files changed, 44 insertions(+), 28 deletions(-) create mode 100644 sonic-radiance.love/game/modules/subgames/world/actors/fighters/mixins/sprites.lua 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 new file mode 100644 index 0000000..4f8e90a --- /dev/null +++ b/sonic-radiance.love/game/modules/subgames/world/actors/fighters/mixins/sprites.lua @@ -0,0 +1,28 @@ +local FighterSprite = Object:extend() + +function FighterSprite:changeSprite(name) + if (self.assets.sprites[name] == nil) then + self.assets:addSprite(name, self:getSpritePath(name)) + end + self.assets.sprites[name]:setCustomSpeed(16) + self:setSprite(name, true, 8, 10) + self:changeAnimation("idle") + self:setDirection(self.direction or self.defaultDir) +end + +function FighterSprite:updateSprites(dt) + self.sprite:setCustomSpeed(self:getCustomSpeed()) + self:setDirection(self.xsp) + self:setAnimation() +end + +function FighterSprite:setDirection(direction) + direction = direction or 0 + if (direction ~= 0) then + direction = utils.math.sign(direction) + self.direction = direction + self.sprite:setScallingX(direction) + end +end + +return FighterSprite \ No newline at end of file diff --git a/sonic-radiance.love/game/modules/subgames/world/actors/fighters/parent.lua b/sonic-radiance.love/game/modules/subgames/world/actors/fighters/parent.lua index 4c8facf..f01a787 100644 --- a/sonic-radiance.love/game/modules/subgames/world/actors/fighters/parent.lua +++ b/sonic-radiance.love/game/modules/subgames/world/actors/fighters/parent.lua @@ -5,16 +5,15 @@ local TweenManager = require "birb.classes.time" local Actions = require "game.modules.subgames.world.actors.fighters.mixins.actions" local Movements = require "game.modules.subgames.world.actors.fighters.mixins.movements" +local Sprites = require "game.modules.subgames.world.actors.fighters.mixins.sprites" FighterParent:implement(Actions) FighterParent:implement(Movements) -FighterParent:implement(Score) FighterParent:implement(Sprites) -FighterParent:implement(Team) -FighterParent:implement(Controls) function FighterParent:new(world, x, y, w, h, d, fighterType) FighterParent.super.new(self, world, fighterType, x, y, 0, w, h, d, true) + self.defaultDir = self.defaultDir or -1 self:initMovements() self:initActions() @@ -27,6 +26,10 @@ function FighterParent:update(dt) self.tweens:update(dt) end +function FighterParent:updateEnd(dt) + self:updateSprites() +end + function FighterParent:animationEnded(name) end 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 2b805ab..9c10773 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 @@ -13,8 +13,9 @@ Player:implement(Team) Player:implement(Controls) function Player:new(world, x, y, z, id) + self.defaultDir = 1 Player.super.new(self, world, x, y, 16, 12, 24, "fighter") - self:initCharactersSprites() + self:updateCurrentCharset() self:initScore() self:initTeam() end @@ -39,10 +40,6 @@ function Player:animationEnded(name) end -function Player:updateEnd(dt) - self:setAnimation() -end - function Player:getViewCenter() local x, y = Player.super.getViewCenter(self) return x, y-16 diff --git a/sonic-radiance.love/game/modules/subgames/world/actors/fighters/player/sprites.lua b/sonic-radiance.love/game/modules/subgames/world/actors/fighters/player/sprites.lua index cd751d5..41724e7 100644 --- a/sonic-radiance.love/game/modules/subgames/world/actors/fighters/player/sprites.lua +++ b/sonic-radiance.love/game/modules/subgames/world/actors/fighters/player/sprites.lua @@ -1,17 +1,15 @@ local SpritedPlayer = Object:extend() -function SpritedPlayer:initCharactersSprites() - for id, name in ipairs(game.characters.team) do - self.assets:addSprite(name, "datas/gamedata/characters/" .. name .. "/sprites") - end - self.direction = 1 - self:updateCurrentCharset() +function SpritedPlayer:getSpritePath(name) + return "datas/gamedata/characters/" .. name .. "/sprites" +end + +function SpritedPlayer:getCustomSpeed() + local gsp = utils.math.pointDistance(0, 0, self.xsp, self.ysp) + return math.abs(gsp) / 12 end function SpritedPlayer:setAnimation() - local gsp = utils.math.pointDistance(0, 0, self.xsp, self.ysp) - self.sprite:setCustomSpeed(math.abs(gsp) / 12) - self:setDirection(self.xsp) if (self.action == "punching") then --the animation system is already active else @@ -31,19 +29,9 @@ function SpritedPlayer:setAnimation() end end -function SpritedPlayer:setDirection(direction) - direction = direction or 0 - if direction ~= 0 then - direction = utils.math.sign(direction) - self.direction = direction - self.sprite:setScallingX(direction) - end -end - function SpritedPlayer:updateCurrentCharset() self.charName = game.characters:getActiveCharacter() - self:setSprite(self.charName, true, 8, 10) - self.sprite:setScallingX(self.direction) + self:changeSprite(self.charName) end return SpritedPlayer -- 2.30.2 From 303bee4e377b11cd1e488efc2d0e797f6cce243a Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Fri, 20 May 2022 18:25:07 +0200 Subject: [PATCH 11/23] feat: add support for abstract --- .../subgames/world/actors/fighters/mixins/abstract.lua | 7 +++++++ .../modules/subgames/world/actors/fighters/player/init.lua | 4 ++++ .../subgames/world/actors/fighters/player/sprites.lua | 1 + 3 files changed, 12 insertions(+) create mode 100644 sonic-radiance.love/game/modules/subgames/world/actors/fighters/mixins/abstract.lua diff --git a/sonic-radiance.love/game/modules/subgames/world/actors/fighters/mixins/abstract.lua b/sonic-radiance.love/game/modules/subgames/world/actors/fighters/mixins/abstract.lua new file mode 100644 index 0000000..92c0f91 --- /dev/null +++ b/sonic-radiance.love/game/modules/subgames/world/actors/fighters/mixins/abstract.lua @@ -0,0 +1,7 @@ +local FighterAbstract = Object:extend() + +function FighterAbstract:initAbstract() + self.abstract = self:getAbstract() +end + +return FighterAbstract \ 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 9c10773..55e629c 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 @@ -20,6 +20,10 @@ 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 diff --git a/sonic-radiance.love/game/modules/subgames/world/actors/fighters/player/sprites.lua b/sonic-radiance.love/game/modules/subgames/world/actors/fighters/player/sprites.lua index 41724e7..bc6ab0d 100644 --- a/sonic-radiance.love/game/modules/subgames/world/actors/fighters/player/sprites.lua +++ b/sonic-radiance.love/game/modules/subgames/world/actors/fighters/player/sprites.lua @@ -31,6 +31,7 @@ end function SpritedPlayer:updateCurrentCharset() self.charName = game.characters:getActiveCharacter() + self:initAbstract() self:changeSprite(self.charName) end -- 2.30.2 From 4bb1635cceec9729911bc06f94a7fc6fed80a304 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Fri, 20 May 2022 18:25:49 +0200 Subject: [PATCH 12/23] chore: add forgotten file to commit --- .../game/modules/subgames/world/actors/fighters/parent.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sonic-radiance.love/game/modules/subgames/world/actors/fighters/parent.lua b/sonic-radiance.love/game/modules/subgames/world/actors/fighters/parent.lua index f01a787..66efe6c 100644 --- a/sonic-radiance.love/game/modules/subgames/world/actors/fighters/parent.lua +++ b/sonic-radiance.love/game/modules/subgames/world/actors/fighters/parent.lua @@ -6,10 +6,12 @@ local TweenManager = require "birb.classes.time" local Actions = require "game.modules.subgames.world.actors.fighters.mixins.actions" local Movements = require "game.modules.subgames.world.actors.fighters.mixins.movements" local Sprites = require "game.modules.subgames.world.actors.fighters.mixins.sprites" +local Abstract = require "game.modules.subgames.world.actors.fighters.mixins.abstract" FighterParent:implement(Actions) FighterParent:implement(Movements) FighterParent:implement(Sprites) +FighterParent:implement(Abstract) function FighterParent:new(world, x, y, w, h, d, fighterType) FighterParent.super.new(self, world, fighterType, x, y, 0, w, h, d, true) -- 2.30.2 From 5368b94f88076041b1b4be08fe34b82d449da9b3 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Fri, 20 May 2022 19:11:23 +0200 Subject: [PATCH 13/23] 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 -- 2.30.2 From b4f7cdb44babfc3e458e91816b41fc1a121d879a Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Fri, 20 May 2022 19:11:48 +0200 Subject: [PATCH 14/23] chore: forgot something again woops --- .../modules/subgames/world/actors/fighters/parent.lua | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/sonic-radiance.love/game/modules/subgames/world/actors/fighters/parent.lua b/sonic-radiance.love/game/modules/subgames/world/actors/fighters/parent.lua index 66efe6c..e5cff40 100644 --- a/sonic-radiance.love/game/modules/subgames/world/actors/fighters/parent.lua +++ b/sonic-radiance.love/game/modules/subgames/world/actors/fighters/parent.lua @@ -13,8 +13,13 @@ FighterParent:implement(Movements) FighterParent:implement(Sprites) FighterParent:implement(Abstract) -function FighterParent:new(world, x, y, w, h, d, fighterType) - FighterParent.super.new(self, world, fighterType, x, y, 0, w, h, d, true) +function FighterParent:new(world, x, y, fighterType) + self.abstract = self:getAbstract() + + local w, h, d = self:getFighterHitbox() + local z = self:getStartZ() + + FighterParent.super.new(self, world, fighterType, x, y, z, w, h, d, true) self.defaultDir = self.defaultDir or -1 self:initMovements() self:initActions() -- 2.30.2 From b1bd072f940b142ab292db5b14c8f7a714a7ca43 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sun, 22 May 2022 19:43:01 +0200 Subject: [PATCH 15/23] fix: fix zsorting crash --- .../modules/world/actors/utils/hitbox3D.lua | 4 + .../birb/modules/world/utils/compare.lua | 74 ++++++++++++++++ .../birb/modules/world/world3D.lua | 85 ++----------------- 3 files changed, 83 insertions(+), 80 deletions(-) create mode 100644 sonic-radiance.love/birb/modules/world/utils/compare.lua diff --git a/sonic-radiance.love/birb/modules/world/actors/utils/hitbox3D.lua b/sonic-radiance.love/birb/modules/world/actors/utils/hitbox3D.lua index 261e104..64ec5e0 100644 --- a/sonic-radiance.love/birb/modules/world/actors/utils/hitbox3D.lua +++ b/sonic-radiance.love/birb/modules/world/actors/utils/hitbox3D.lua @@ -123,6 +123,10 @@ function Hitbox3D:getCenter() return self.x + (self.w/2), self.y + (self.h/2), self.z + (self.d/2) end +function Hitbox3D:getCube() + return self.world.bodies:getCube(self) +end + -- COLLISION FUNCTIONS -- Handle Hitbox position diff --git a/sonic-radiance.love/birb/modules/world/utils/compare.lua b/sonic-radiance.love/birb/modules/world/utils/compare.lua new file mode 100644 index 0000000..adfd13e --- /dev/null +++ b/sonic-radiance.love/birb/modules/world/utils/compare.lua @@ -0,0 +1,74 @@ +local comparisons = {} + +function comparisons.zsort(itemA, itemB) + local _, aY, aZ, _, aH, aD = itemA.mainHitbox:getCube() + local aDepth, aID, aType + aDepth = itemA.depth + aID = itemA.creationID + aType = itemA.type + aZ = math.ceil(aZ) + aY = math.ceil(aY) + + local _, bY, bZ, _, bH, bD = itemB.mainHitbox:getCube() + local bDepth, bID, bType + bDepth = itemB.depth + bID = itemB.creationID + bType = itemB.type + bZ = math.ceil(bZ) + bY = math.ceil(bY) + + + --print("comparing " .. aID .. " to " .. bID) + + --print("a", aY, aZ, aH, aD, aDepth, aID, itemA.type) + --print("b", bY, bZ, bH, bD, bDepth, bID, itemB.type) + + local comparison = 0 + + if aZ >= bZ + bD then + -- item A is completely above item B + --graph:add(itemB, itemA) + comparison = 1 + elseif bZ >= aZ + aD then + -- item B is completely above item A + --graph:add(itemA, itemB) + comparison = -1 + elseif aY + aH <= bY then + -- item A is completely behind item B + --graph:add(itemA, itemB) + comparison = -1 + elseif bY + bH <= aY then + -- item B is completely behind item A + --graph:add(itemB, itemA) + comparison = 1 + elseif aY + aH > bY + bH then --(aY - aZ) + aH > (bY - bZ) + bH then + -- item A's forward-most point is in front of item B's forward-most point + --graph:add(itemB, itemA) + comparison = 1 + elseif aY + aH < bY + bH then --aY < (bY - bZ) + bH then + -- item B's forward-most point is in front of item A's forward-most point + --graph:add(itemA, itemB) + comparison = -1 + else + -- item A's forward-most point is the same than item B's forward-most point + if aDepth > bDepth then + --graph:add(itemB, itemA) + comparison = 1 + elseif aDepth < bDepth then + --graph:add(itemA, itemB) + comparison = -1 + else + if aID > bID then + --graph:add(itemA, itemB) + comparison = 1 + elseif aID < bID then + --graph:add(itemB, itemA) + comparison = -1 + end + end + end + + return comparison == -1 +end + +return comparisons diff --git a/sonic-radiance.love/birb/modules/world/world3D.lua b/sonic-radiance.love/birb/modules/world/world3D.lua index 42ee40b..622f53b 100644 --- a/sonic-radiance.love/birb/modules/world/world3D.lua +++ b/sonic-radiance.love/birb/modules/world/world3D.lua @@ -31,6 +31,8 @@ local Bump3D = require(cwd .. "libs.bump-3dpd") local Tsort = require(cwd .. "libs.tsort") local CameraSystem = require(cwd .. "camera") +local comparisons = require(cwd .. "utils.compare") + local PADDING_VALUE = 10/100 function World3D:new(scene, actorlist, mapfile, maptype) @@ -183,87 +185,10 @@ end -- Functions to draw the world function World3D:zSortItems(items) - -- zSorting algorithm taken from bump3D example, adapted to gamecore. - local graph = Tsort.new() - local noOverlap = {} + -- TODO : take from a self.shapes:queryRect() + table.sort(items, comparisons.zsort) - -- Iterate through all visible items, and calculate ordering of all pairs - -- of overlapping items. - -- TODO: Each pair is calculated twice currently. Maybe this is slow? - for _, itemA in ipairs(items) do repeat - local x, y, w, h = self.shapes:getRect(itemA) - local otherItemsFilter = function(other) return other ~= itemA end - local overlapping, len = self.shapes:queryRect(x, y, w, h, otherItemsFilter) - - if len == 0 then - table.insert(noOverlap, itemA) - - break - end - - local _, aY, aZ, _, aH, aD = self.bodies:getCube(itemA.mainHitbox) - local aDepth, aID, aType - aDepth = itemA.depth - aID = itemA.creationID - aType = itemA.type - aZ = math.ceil(aZ) - aY = math.ceil(aY) - - for _, itemB in ipairs(overlapping) do - local _, bY, bZ, _, bH, bD = self.bodies:getCube(itemB.mainHitbox) - local bDepth, bID, bType - bDepth = itemB.depth - bID = itemB.creationID - bType = itemB.type - bZ = math.ceil(bZ) - bY = math.ceil(bY) - - if aZ >= bZ + bD then - -- item A is completely above item B - graph:add(itemB, itemA) - elseif bZ >= aZ + aD then - -- item B is completely above item A - graph:add(itemA, itemB) - elseif aY + aH <= bY then - -- item A is completely behind item B - graph:add(itemA, itemB) - elseif bY + bH <= aY then - -- item B is completely behind item A - graph:add(itemB, itemA) - elseif (aY - aZ) + aH > (bY - bZ) + bH then - -- item A's forward-most point is in front of item B's forward-most point - graph:add(itemB, itemA) - elseif (aY - aZ) + aH < (bY - bZ) + bH then - -- item B's forward-most point is in front of item A's forward-most point - graph:add(itemA, itemB) - else - -- item A's forward-most point is the same than item B's forward-most point - if aDepth > bDepth then - graph:add(itemB, itemA) - elseif aDepth < bDepth then - graph:add(itemA, itemB) - else - if aID > bID then - graph:add(itemA, itemB) - elseif aID < bID then - graph:add(itemB, itemA) - else - error("two object can't have the same ID") - end - end - end - end - until true end - - local sorted, err = graph:sort() - if err then - error(err) - end - for _, item in ipairs(noOverlap) do - table.insert(sorted, item) - end - - return sorted + return items end -- 2.30.2 From aa2b14a509e6e8376b8f312c8ffef9675de0ea9c Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Thu, 26 May 2022 11:21:57 +0200 Subject: [PATCH 16/23] improvement: make fighter non-solid --- .../game/modules/subgames/world/actors/fighters/parent.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sonic-radiance.love/game/modules/subgames/world/actors/fighters/parent.lua b/sonic-radiance.love/game/modules/subgames/world/actors/fighters/parent.lua index e5cff40..28f3f71 100644 --- a/sonic-radiance.love/game/modules/subgames/world/actors/fighters/parent.lua +++ b/sonic-radiance.love/game/modules/subgames/world/actors/fighters/parent.lua @@ -19,7 +19,7 @@ function FighterParent:new(world, x, y, fighterType) local w, h, d = self:getFighterHitbox() local z = self:getStartZ() - FighterParent.super.new(self, world, fighterType, x, y, z, w, h, d, true) + FighterParent.super.new(self, world, fighterType, x, y, z, w, h, d, false) self.defaultDir = self.defaultDir or -1 self:initMovements() self:initActions() -- 2.30.2 From 7993e6b6fede3de0c6ba0a26a98be35b61306de5 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Thu, 26 May 2022 11:22:17 +0200 Subject: [PATCH 17/23] fix: fix player initialization --- .../game/modules/subgames/world/actors/fighters/player/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 e0d81b9..33c43cf 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 @@ -16,7 +16,7 @@ Player:implement(Identity) function Player:new(world, x, y, z, id) self.defaultDir = 1 - Player.super.new(self, world, x, y, 16, 12, 24, "fighter") + Player.super.new(self, world, x, y, "player") self:updateCurrentCharset() self:initScore() self:initTeam() -- 2.30.2 From 84e48c03209263de620a411a04e3f9f5450e8b62 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Thu, 26 May 2022 13:09:47 +0200 Subject: [PATCH 18/23] fix: add fallback for animations --- .../birb/modules/assets/types/animator.lua | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/sonic-radiance.love/birb/modules/assets/types/animator.lua b/sonic-radiance.love/birb/modules/assets/types/animator.lua index 38a7f3f..5787e09 100644 --- a/sonic-radiance.love/birb/modules/assets/types/animator.lua +++ b/sonic-radiance.love/birb/modules/assets/types/animator.lua @@ -87,9 +87,18 @@ function Animator:changeAnimation(name, restart) restart = restart or false end - self.currentAnimation = name + if (self.sprite.data.animations[name] ~= nil) then + self.currentAnimation = name + else + self.currentAnimation = self.sprite.data.metadata.defaultAnim + end + self.animationData = self.sprite.data.animations[self.currentAnimation] + if (self.animationData == nil) then + error("animation " .. self.currentAnimation .. " not found.") + end + if (restart == true) then self.frame = self.animationData.startAt self.frameTimer = 0 -- 2.30.2 From 75145f14851f73a6964db3ee6d5720b2cc437398 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Thu, 26 May 2022 13:12:08 +0200 Subject: [PATCH 19/23] feat: add a finite state machine to actors --- .../birb/classes/states/init.lua | 102 ++++++++++++++++++ .../birb/modules/world/actors/actor2D.lua | 5 + .../birb/modules/world/actors/actor3D.lua | 5 + .../birb/modules/world/actors/mixins/base.lua | 1 + 4 files changed, 113 insertions(+) create mode 100644 sonic-radiance.love/birb/classes/states/init.lua diff --git a/sonic-radiance.love/birb/classes/states/init.lua b/sonic-radiance.love/birb/classes/states/init.lua new file mode 100644 index 0000000..e370413 --- /dev/null +++ b/sonic-radiance.love/birb/classes/states/init.lua @@ -0,0 +1,102 @@ +-- classes/states :: a finite state machine for objects + +--[[ + Copyright © 2022 Kazhnuz + + Permission is hereby granted, free of charge, to any person obtaining a copy of + this software and associated documentation files (the "Software"), to deal in + the Software without restriction, including without limitation the rights to + use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + the Software, and to permit persons to whom the Software is furnished to do so, + subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +]] + +local StateMachine = Object:extend() + +function StateMachine.addState(self, name, state, isDefault) + if (self.states == nil) then + self.states = {} + self.states.list = {} + end + + self.states.list[name] = state + + if (isDefault == true) then + self.states.default = name + end +end + +function StateMachine.addStates(self, statesPath, default) + local states = require(statesPath) + for i, stateName in ipairs(states) do + local state = require(statesPath .. "." .. stateName) + self:addState(stateName, state) + end + self.states.default = default +end + +function StateMachine:initStates() + if (self.states == nil) then + self.states = {} + self.states.list = {} + end + self.currentState = self.states.default or "none" +end + +function StateMachine:updateState(dt) + self:playStateFunc("update", dt) +end + +function StateMachine:haveState(state) + return (self.states.list[state] ~= nil) +end + +function StateMachine:setState(state) + if (not self:haveState(state)) then + return self.currentState + end + self:playStateFunc("stop", state) + local currentState = self.currentState + self.currentState = state + self:playStateFunc("start", currentState) + return state +end + +function StateMachine:getState() + return self.states.list[self.currentState] +end + +function StateMachine:getStateVar(varName, default) + local state = self:getState() + if (state == nil) then + return nil + end + local var = state[varName] + if (var == nil) then + return default + end + return var +end + +function StateMachine:playStateFunc(funcName, ...) + local state = self:getState() + if (state == nil) then + return + end + local func = state[funcName] + if (func ~= nil) then + func(self, ...) + end +end + +return StateMachine \ No newline at end of file diff --git a/sonic-radiance.love/birb/modules/world/actors/actor2D.lua b/sonic-radiance.love/birb/modules/world/actors/actor2D.lua index 90e4b0b..2897710 100644 --- a/sonic-radiance.love/birb/modules/world/actors/actor2D.lua +++ b/sonic-radiance.love/birb/modules/world/actors/actor2D.lua @@ -29,6 +29,8 @@ local TimedActor = require("birb.modules.world.actors.mixins.timers") local InputActor = require("birb.modules.world.actors.mixins.inputs") local PhysicalActor = require("birb.modules.world.actors.mixins.physics") +local StateMachine = require("birb.classes.states") + local Actor2D = Rect:extend() Actor2D:implement(BaseActor) Actor2D:implement(SpritedActor) @@ -36,6 +38,8 @@ Actor2D:implement(TimedActor) Actor2D:implement(InputActor) Actor2D:implement(PhysicalActor) +Actor2D:implement(StateMachine) + local Hitbox = require "birb.modules.world.actors.utils.hitbox2D" -- INIT FUNCTIONS @@ -49,6 +53,7 @@ function Actor2D:new(world, type, x, y, w, h, isSolid) self:initTimers() self:initSprite() self:initKeys() + self:initStates() end function Actor2D:destroy() diff --git a/sonic-radiance.love/birb/modules/world/actors/actor3D.lua b/sonic-radiance.love/birb/modules/world/actors/actor3D.lua index e99964c..3ce7534 100644 --- a/sonic-radiance.love/birb/modules/world/actors/actor3D.lua +++ b/sonic-radiance.love/birb/modules/world/actors/actor3D.lua @@ -33,6 +33,8 @@ local InputActor = require("birb.modules.world.actors.mixins.inputs") local PhysicalActor = require("birb.modules.world.actors.mixins.physics") local Shape3DActor = require("birb.modules.world.actors.mixins.shapes") +local StateMachine = require("birb.classes.states") + local Actor3D = BasicBox:extend() Actor3D:implement(BaseActor) Actor3D:implement(SpritedActor) @@ -41,6 +43,8 @@ Actor3D:implement(InputActor) Actor3D:implement(PhysicalActor) Actor3D:implement(Shape3DActor) +Actor3D:implement(StateMachine) + -- INIT FUNCTIONS -- Initialise the actor and its base functions @@ -52,6 +56,7 @@ function Actor3D:new(world, type, x, y, z, w, h, d, isSolid) self:initSprite() self:initKeys() self:initShape(Boxes, true) + self:initStates() end function Actor3D:destroy() diff --git a/sonic-radiance.love/birb/modules/world/actors/mixins/base.lua b/sonic-radiance.love/birb/modules/world/actors/mixins/base.lua index 0bfcee3..eb0f7df 100644 --- a/sonic-radiance.love/birb/modules/world/actors/mixins/base.lua +++ b/sonic-radiance.love/birb/modules/world/actors/mixins/base.lua @@ -88,6 +88,7 @@ end function BaseActor:update(dt) self:updateStart(dt) self:applyUpdateFunctions(dt) + self:updateState(dt) self:updateEnd(dt) end -- 2.30.2 From 3545e6b898954a4236ef25b4521bb4ea1b376e26 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Fri, 27 May 2022 09:29:39 +0200 Subject: [PATCH 20/23] improvement: replace actions by the state machine --- .../world/actors/fighters/mixins/actions.lua | 7 ------ .../world/actors/fighters/mixins/sprites.lua | 24 +++++++++++++++++++ .../subgames/world/actors/fighters/parent.lua | 7 +++--- .../world/actors/fighters/player/controls.lua | 14 ++++++----- .../world/actors/fighters/player/sprites.lua | 20 ---------------- .../world/actors/fighters/states/idle.lua | 7 ++++++ .../world/actors/fighters/states/init.lua | 3 +++ 7 files changed, 46 insertions(+), 36 deletions(-) delete mode 100644 sonic-radiance.love/game/modules/subgames/world/actors/fighters/mixins/actions.lua create mode 100644 sonic-radiance.love/game/modules/subgames/world/actors/fighters/states/idle.lua create mode 100644 sonic-radiance.love/game/modules/subgames/world/actors/fighters/states/init.lua diff --git a/sonic-radiance.love/game/modules/subgames/world/actors/fighters/mixins/actions.lua b/sonic-radiance.love/game/modules/subgames/world/actors/fighters/mixins/actions.lua deleted file mode 100644 index 1f45708..0000000 --- a/sonic-radiance.love/game/modules/subgames/world/actors/fighters/mixins/actions.lua +++ /dev/null @@ -1,7 +0,0 @@ -local PlayerActions = Object:extend() - -function PlayerActions:initActions() - self.action = "idle" -end - -return PlayerActions \ No newline at end of file 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 6a1404b..180b364 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 @@ -23,6 +23,30 @@ function FighterSprite:updateSprites(dt) self:setAnimation() end +function FighterSprite:setAnimation() + if (self:getStateVar("defaultAnim", false)) then + self:defaultAnim() + else + self:playStateFunc("changeAnimation") + end +end + +function FighterSprite:defaultAnim() + if (self.onGround or self:isAerial()) then + if (math.abs(self.xsp) > 0) or (math.abs(self.ysp) > 0) then + self.sprite:changeAnimation("walk", false) + else + self.sprite:changeAnimation("idle", false) + end + else + if (self.zsp) > 0 then + self.sprite:changeAnimation("jump", false) + else + self.sprite:changeAnimation("fall", false) + end + end +end + function FighterSprite:setDirection(direction) direction = direction or 0 if (direction ~= 0) then diff --git a/sonic-radiance.love/game/modules/subgames/world/actors/fighters/parent.lua b/sonic-radiance.love/game/modules/subgames/world/actors/fighters/parent.lua index 28f3f71..e0e5819 100644 --- a/sonic-radiance.love/game/modules/subgames/world/actors/fighters/parent.lua +++ b/sonic-radiance.love/game/modules/subgames/world/actors/fighters/parent.lua @@ -3,16 +3,18 @@ local FighterParent = Parent:extend() local TweenManager = require "birb.classes.time" -local Actions = require "game.modules.subgames.world.actors.fighters.mixins.actions" local Movements = require "game.modules.subgames.world.actors.fighters.mixins.movements" local Sprites = require "game.modules.subgames.world.actors.fighters.mixins.sprites" local Abstract = require "game.modules.subgames.world.actors.fighters.mixins.abstract" -FighterParent:implement(Actions) FighterParent:implement(Movements) FighterParent:implement(Sprites) FighterParent:implement(Abstract) +local states = {"idle"} + +FighterParent:addStates("game.modules.subgames.world.actors.fighters.states", "idle") + function FighterParent:new(world, x, y, fighterType) self.abstract = self:getAbstract() @@ -22,7 +24,6 @@ function FighterParent:new(world, x, y, fighterType) FighterParent.super.new(self, world, fighterType, x, y, z, w, h, d, false) self.defaultDir = self.defaultDir or -1 self:initMovements() - self:initActions() self.tweens = TweenManager(self) end diff --git a/sonic-radiance.love/game/modules/subgames/world/actors/fighters/player/controls.lua b/sonic-radiance.love/game/modules/subgames/world/actors/fighters/player/controls.lua index 23afb89..ed110af 100644 --- a/sonic-radiance.love/game/modules/subgames/world/actors/fighters/player/controls.lua +++ b/sonic-radiance.love/game/modules/subgames/world/actors/fighters/player/controls.lua @@ -55,7 +55,7 @@ function PlayerControls:dpadToAngle() end function PlayerControls:applyJumpInput() - if self.keys["A"].isPressed and (self:isNotJumping()) then + if self.keys["A"].isPressed and (self:isNotJumping() and self:getStateVar("canJump", false)) then self:jump() end end @@ -68,11 +68,13 @@ function PlayerControls:applyActionsInputs() end function PlayerControls:applySwitchInputs() - if self.keys["L1"].isPressed and (self.action == "normal") and (self.onGround) then - self:switchActiveCharacter() - end - if self.keys["R1"].isPressed and (self.action == "normal") and (self.onGround) then - self:switchActiveCharacter(-1) + if (self.onGround and self:getStateVar("canSwitch", false)) then + if self.keys["L1"].isPressed then + self:switchActiveCharacter() + end + if self.keys["R1"].isPressed then + self:switchActiveCharacter(-1) + end end end diff --git a/sonic-radiance.love/game/modules/subgames/world/actors/fighters/player/sprites.lua b/sonic-radiance.love/game/modules/subgames/world/actors/fighters/player/sprites.lua index bc6ab0d..99fff27 100644 --- a/sonic-radiance.love/game/modules/subgames/world/actors/fighters/player/sprites.lua +++ b/sonic-radiance.love/game/modules/subgames/world/actors/fighters/player/sprites.lua @@ -9,26 +9,6 @@ function SpritedPlayer:getCustomSpeed() return math.abs(gsp) / 12 end -function SpritedPlayer:setAnimation() - if (self.action == "punching") then - --the animation system is already active - else - if (self.onGround) then - if (math.abs(self.xsp) > 0) or (math.abs(self.ysp) > 0) then - self.sprite:changeAnimation("walk", false) - else - self.sprite:changeAnimation("idle", false) - end - else - if (self.zsp) > 0 then - self.sprite:changeAnimation("jump", false) - else - self.sprite:changeAnimation("fall", false) - end - end - end -end - function SpritedPlayer:updateCurrentCharset() self.charName = game.characters:getActiveCharacter() self:initAbstract() diff --git a/sonic-radiance.love/game/modules/subgames/world/actors/fighters/states/idle.lua b/sonic-radiance.love/game/modules/subgames/world/actors/fighters/states/idle.lua new file mode 100644 index 0000000..525e969 --- /dev/null +++ b/sonic-radiance.love/game/modules/subgames/world/actors/fighters/states/idle.lua @@ -0,0 +1,7 @@ +local idleState = {} + +idleState.canSwitch = true +idleState.canJump = true +idleState.defaultAnim = true + +return idleState \ No newline at end of file diff --git a/sonic-radiance.love/game/modules/subgames/world/actors/fighters/states/init.lua b/sonic-radiance.love/game/modules/subgames/world/actors/fighters/states/init.lua new file mode 100644 index 0000000..92e78a1 --- /dev/null +++ b/sonic-radiance.love/game/modules/subgames/world/actors/fighters/states/init.lua @@ -0,0 +1,3 @@ +return { + "idle", +} \ No newline at end of file -- 2.30.2 From 4598b25e05dc10bde51f432b8912b3f2b626c96b Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sat, 28 May 2022 11:55:21 +0200 Subject: [PATCH 21/23] feat: add hit combo --- .../world/actors/fighters/player/controls.lua | 21 ++++++++++++------- .../world/actors/fighters/player/init.lua | 4 ---- .../world/actors/fighters/states/hit1.lua | 20 ++++++++++++++++++ .../world/actors/fighters/states/hit2.lua | 20 ++++++++++++++++++ .../world/actors/fighters/states/hit3.lua | 16 ++++++++++++++ .../world/actors/fighters/states/idle.lua | 7 +++++++ .../world/actors/fighters/states/init.lua | 3 +++ 7 files changed, 80 insertions(+), 11 deletions(-) create mode 100644 sonic-radiance.love/game/modules/subgames/world/actors/fighters/states/hit1.lua create mode 100644 sonic-radiance.love/game/modules/subgames/world/actors/fighters/states/hit2.lua create mode 100644 sonic-radiance.love/game/modules/subgames/world/actors/fighters/states/hit3.lua diff --git a/sonic-radiance.love/game/modules/subgames/world/actors/fighters/player/controls.lua b/sonic-radiance.love/game/modules/subgames/world/actors/fighters/player/controls.lua index ed110af..d455990 100644 --- a/sonic-radiance.love/game/modules/subgames/world/actors/fighters/player/controls.lua +++ b/sonic-radiance.love/game/modules/subgames/world/actors/fighters/player/controls.lua @@ -1,17 +1,23 @@ local PlayerControls = Object:extend() function PlayerControls:applyInputs() - if (self.world.autorun == true) then - self:applyAutorunInput() - else - self:applyMoveInput() - end + self:applyMoveInput() self:applyJumpInput() self:applyActionsInputs() self:applySwitchInputs() end function PlayerControls:applyMoveInput() + if (self:getStateVar("canMove", false)) then + if (self.world.autorun == true) then + self:applyAutorunInput() + else + self:applyFreemoveInput() + end + end +end + +function PlayerControls:applyFreemoveInput() local angle, strenght = self:dpadToAngle() if (strenght ~= 0) then self:goTowardDir(angle, strenght) @@ -62,8 +68,9 @@ end function PlayerControls:applyActionsInputs() - if self.keys["B"].isPressed and (self.onGround) then - -- Nothing for the moment + if self.keys["B"].isPressed then + --self:setState("hit1") + self:playStateFunc("bAction") end end 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 33c43cf..dad14f3 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 @@ -38,10 +38,6 @@ function Player:timerResponse(response) end end -function Player:animationEnded(name) - -end - function Player:getViewCenter() local x, y = Player.super.getViewCenter(self) return x, y-16 diff --git a/sonic-radiance.love/game/modules/subgames/world/actors/fighters/states/hit1.lua b/sonic-radiance.love/game/modules/subgames/world/actors/fighters/states/hit1.lua new file mode 100644 index 0000000..b4bd926 --- /dev/null +++ b/sonic-radiance.love/game/modules/subgames/world/actors/fighters/states/hit1.lua @@ -0,0 +1,20 @@ +local hit1state = {} + +hit1state.canSwitch = false +hit1state.canJump = false +hit1state.defaultAnim = false +hit1state.canMove = false + +function hit1state:start() + self.sprite:changeAnimation("hit1", true) +end + +function hit1state:bAction() + self:setState("hit2") +end + +function hit1state:animationEnded() + self:setState("idle") +end + +return hit1state \ No newline at end of file diff --git a/sonic-radiance.love/game/modules/subgames/world/actors/fighters/states/hit2.lua b/sonic-radiance.love/game/modules/subgames/world/actors/fighters/states/hit2.lua new file mode 100644 index 0000000..d3e9d12 --- /dev/null +++ b/sonic-radiance.love/game/modules/subgames/world/actors/fighters/states/hit2.lua @@ -0,0 +1,20 @@ +local hit1state = {} + +hit1state.canSwitch = false +hit1state.canJump = false +hit1state.defaultAnim = false +hit1state.canMove = false + +function hit1state:start() + self.sprite:changeAnimation("hit2", true) +end + +function hit1state:bAction() + self:setState("hit3") +end + +function hit1state:animationEnded() + self:setState("idle") +end + +return hit1state \ No newline at end of file diff --git a/sonic-radiance.love/game/modules/subgames/world/actors/fighters/states/hit3.lua b/sonic-radiance.love/game/modules/subgames/world/actors/fighters/states/hit3.lua new file mode 100644 index 0000000..712ee4a --- /dev/null +++ b/sonic-radiance.love/game/modules/subgames/world/actors/fighters/states/hit3.lua @@ -0,0 +1,16 @@ +local hit1state = {} + +hit1state.canSwitch = false +hit1state.canJump = false +hit1state.defaultAnim = false +hit1state.canMove = false + +function hit1state:start() + self.sprite:changeAnimation("hit3", true) +end + +function hit1state:animationEnded() + self:setState("idle") +end + +return hit1state \ No newline at end of file diff --git a/sonic-radiance.love/game/modules/subgames/world/actors/fighters/states/idle.lua b/sonic-radiance.love/game/modules/subgames/world/actors/fighters/states/idle.lua index 525e969..6e2a9c7 100644 --- a/sonic-radiance.love/game/modules/subgames/world/actors/fighters/states/idle.lua +++ b/sonic-radiance.love/game/modules/subgames/world/actors/fighters/states/idle.lua @@ -3,5 +3,12 @@ local idleState = {} idleState.canSwitch = true idleState.canJump = true idleState.defaultAnim = true +idleState.canMove = true + +function idleState:bAction() + if (self.onGround) then + self:setState("hit1") + end +end return idleState \ No newline at end of file diff --git a/sonic-radiance.love/game/modules/subgames/world/actors/fighters/states/init.lua b/sonic-radiance.love/game/modules/subgames/world/actors/fighters/states/init.lua index 92e78a1..16c2ab1 100644 --- a/sonic-radiance.love/game/modules/subgames/world/actors/fighters/states/init.lua +++ b/sonic-radiance.love/game/modules/subgames/world/actors/fighters/states/init.lua @@ -1,3 +1,6 @@ return { "idle", + "hit1", + "hit2", + "hit3", } \ No newline at end of file -- 2.30.2 From 2f8ffc42400407989e5b2b097ca669e06959f5c0 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sat, 28 May 2022 11:55:34 +0200 Subject: [PATCH 22/23] fix: add hit combo to sprites --- .../datas/gamedata/characters/amy/sprites.lua | 33 ++++--------------- .../gamedata/characters/sonic/sprites.lua | 33 ++++--------------- 2 files changed, 12 insertions(+), 54 deletions(-) diff --git a/sonic-radiance.love/datas/gamedata/characters/amy/sprites.lua b/sonic-radiance.love/datas/gamedata/characters/amy/sprites.lua index d42c4e0..1f35a38 100644 --- a/sonic-radiance.love/datas/gamedata/characters/amy/sprites.lua +++ b/sonic-radiance.love/datas/gamedata/characters/amy/sprites.lua @@ -35,46 +35,25 @@ return { speed = 10, pauseAtEnd = true, }, - ["hit1start"] = { + ["hit1"] = { startAt = 29, - endAt = 32, - loop = 32, - speed = 25, - pauseAtEnd = true, - }, - ["hit1end"] = { - startAt = 33, endAt = 34, loop = 34, - speed = 25, + speed = 20, pauseAtEnd = true, }, - ["hit2start"] = { + ["hit2"] = { startAt = 35, - endAt = 37, - loop = 37, - speed = 25, - pauseAtEnd = true, - }, - ["hit2end"] = { - startAt = 38, endAt = 39, loop = 39, - speed = 25, + speed = 20, pauseAtEnd = true, }, - ["hit3start"] = { + ["hit3"] = { startAt = 40, - endAt = 44, - loop = 44, - speed = 25, - pauseAtEnd = true, - }, - ["hit3end"] = { - startAt = 45, endAt = 46, loop = 46, - speed = 25, + speed = 20, pauseAtEnd = true, }, ["spindash"] = { diff --git a/sonic-radiance.love/datas/gamedata/characters/sonic/sprites.lua b/sonic-radiance.love/datas/gamedata/characters/sonic/sprites.lua index 7b7cc4b..0456fa4 100644 --- a/sonic-radiance.love/datas/gamedata/characters/sonic/sprites.lua +++ b/sonic-radiance.love/datas/gamedata/characters/sonic/sprites.lua @@ -35,46 +35,25 @@ return { speed = 10, pauseAtEnd = true, }, - ["hit1start"] = { + ["hit1"] = { startAt = 22, - endAt = 24, - loop = 24, - speed = 25, - pauseAtEnd = true, - }, - ["hit1end"] = { - startAt = 24, endAt = 26, loop = 26, - speed = 25, + speed = 20, pauseAtEnd = true, }, - ["hit2start"] = { + ["hit2"] = { startAt = 28, - endAt = 30, - loop = 30, - speed = 25, - pauseAtEnd = true, - }, - ["hit2end"] = { - startAt = 30, endAt = 32, loop = 32, - speed = 25, + speed = 20, pauseAtEnd = true, }, - ["hit3start"] = { + ["hit3"] = { startAt = 33, - endAt = 35, - loop = 35, - speed = 25, - pauseAtEnd = true, - }, - ["hit3end"] = { - startAt = 36, endAt = 36, loop = 36, - speed = 25, + speed = 20, pauseAtEnd = true, }, ["spindash"] = { -- 2.30.2 From 0710086b25fa7055d892343849ab41bf78162751 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sat, 28 May 2022 11:55:40 +0200 Subject: [PATCH 23/23] feat: add ennemies --- .../game/modules/subgames/ennemies.lua | 52 +++++++++++++++++++ .../game/modules/subgames/init.lua | 3 ++ .../world/actors/fighters/ennemies/init.lua | 33 ++++++++++++ .../subgames/world/actors/fighters/parent.lua | 2 +- .../modules/subgames/world/actors/init.lua | 3 ++ .../game/modules/subgames/world/parent.lua | 12 +++++ sonic-radiance.love/scenes/battles/init.lua | 1 + 7 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 sonic-radiance.love/game/modules/subgames/ennemies.lua create mode 100644 sonic-radiance.love/game/modules/subgames/world/actors/fighters/ennemies/init.lua diff --git a/sonic-radiance.love/game/modules/subgames/ennemies.lua b/sonic-radiance.love/game/modules/subgames/ennemies.lua new file mode 100644 index 0000000..faaa0a6 --- /dev/null +++ b/sonic-radiance.love/game/modules/subgames/ennemies.lua @@ -0,0 +1,52 @@ +local EnnemyController = Object:extend() + +local Villain = require "scenes.battlesystem.fighters.ennemy" +local STATS = require "datas.consts.stats" + +function EnnemyController:new(scene) + self.super.new(self) + self.scene = scene + self.list = {} +end + +function EnnemyController:addAll(ennemies) + local count = self:countList(ennemies) + for i, ennemyBaseData in ipairs(ennemies) do + local ennData = core.datas:parse("ennemytype", ennemyBaseData) + local nbr = ennData.number or 1 + for i=1, nbr do + self:add(ennData, count) + end + end +end + +function EnnemyController:countList(ennemies) + local count = 0 + for i, ennemyBaseData in ipairs(ennemies) do + local ennData = core.datas:parse("ennemytype", ennemyBaseData) + local nbr = ennData.number or 1 + count = count + nbr + end + return count +end + +function EnnemyController:getEnnemyArchetype(ennData) + if (ennData.archetype ~= nil) then + return ennData.archetype + end + return ennData.name +end + +function EnnemyController:add(ennData, count) + local ennemy = {} + ennemy.type = ennData.type + ennemy.name = ennData.name + ennemy.category = ennData.category + ennemy.actor = nil + ennemy.isAlive = true + ennemy.data = ennData + table.insert(self.list, ennemy) + self.scene.world:spawnEnnemy(self:getEnnemyArchetype(ennData), ennemy, count) +end + +return EnnemyController diff --git a/sonic-radiance.love/game/modules/subgames/init.lua b/sonic-radiance.love/game/modules/subgames/init.lua index eb1192b..ac4ae1c 100644 --- a/sonic-radiance.love/game/modules/subgames/init.lua +++ b/sonic-radiance.love/game/modules/subgames/init.lua @@ -6,6 +6,8 @@ local PauseScreen = require("game.modules.subgames.pause") local HUD = require("game.modules.subgames.hud") local TestWorld = require("game.modules.subgames.world.parent") +local EnnemyController = require "game.modules.subgames.ennemies" + function PlayStyle:new(supportedLevels, missionfile) PlayStyle.super.new(self, false, false) self.timer = 0 @@ -22,6 +24,7 @@ function PlayStyle:new(supportedLevels, missionfile) self.haveStarted = false self.canPause = true + self.ennemies = EnnemyController(self) end function PlayStyle:loadMissionFile(supportedLevels, missionfile) diff --git a/sonic-radiance.love/game/modules/subgames/world/actors/fighters/ennemies/init.lua b/sonic-radiance.love/game/modules/subgames/world/actors/fighters/ennemies/init.lua new file mode 100644 index 0000000..d0dfa14 --- /dev/null +++ b/sonic-radiance.love/game/modules/subgames/world/actors/fighters/ennemies/init.lua @@ -0,0 +1,33 @@ +local Parent = require("game.modules.subgames.world.actors.fighters.parent") +local Ennemy = Parent:extend() + +function Ennemy:new(world, x, y, owner) + self.defaultDir = -1 + self.owner = owner + self.data = self.owner.data + + Ennemy.super.new(self, world, x, y, self.owner.name) + self:changeSprite(self.owner.name) +end + +function Ennemy:getAbstract() + return game.ennemies:getEnnemyData(self.owner.category, self.owner.name) +end + +function Ennemy:getFighterHitbox() + return 16, 12, self.abstract.data.hudHeight +end + +function Ennemy:isAerial() + return self.abstract.data.isAerial +end + +function Ennemy:getCustomSpeed() + return 16 +end + +function Ennemy:getSpritePath() + return "datas/gamedata/ennemies/" .. self.owner.category .. "/" .. self.owner.name .. "/sprites" +end + +return Ennemy \ No newline at end of file diff --git a/sonic-radiance.love/game/modules/subgames/world/actors/fighters/parent.lua b/sonic-radiance.love/game/modules/subgames/world/actors/fighters/parent.lua index e0e5819..d19da29 100644 --- a/sonic-radiance.love/game/modules/subgames/world/actors/fighters/parent.lua +++ b/sonic-radiance.love/game/modules/subgames/world/actors/fighters/parent.lua @@ -39,7 +39,7 @@ function FighterParent:updateEnd(dt) end function FighterParent:animationEnded(name) - + self:playStateFunc("animationEnded", name) end return FighterParent diff --git a/sonic-radiance.love/game/modules/subgames/world/actors/init.lua b/sonic-radiance.love/game/modules/subgames/world/actors/init.lua index 484af22..9bebf60 100644 --- a/sonic-radiance.love/game/modules/subgames/world/actors/init.lua +++ b/sonic-radiance.love/game/modules/subgames/world/actors/init.lua @@ -19,4 +19,7 @@ Obj.index = {} Obj.index[01] = Obj.Ring Obj.index[02] = Obj.Ring +Obj.ennemies = {} +Obj.ennemies["basic"] = require "game.modules.subgames.world.actors.fighters.ennemies" + return Obj diff --git a/sonic-radiance.love/game/modules/subgames/world/parent.lua b/sonic-radiance.love/game/modules/subgames/world/parent.lua index 3bf246f..64796a2 100644 --- a/sonic-radiance.love/game/modules/subgames/world/parent.lua +++ b/sonic-radiance.love/game/modules/subgames/world/parent.lua @@ -11,6 +11,7 @@ function ParentWorld:new(scene, maptype, mapname) self.mapname = mapname self.autorun = false + self.i = 0 end function ParentWorld:createMapController() @@ -22,6 +23,17 @@ function ParentWorld:loadMapObjects() self:addInvisibleWalls() end +function ParentWorld:spawnEnnemy(name, owner, count) + local EnnemyObj = self.obj.ennemies[name] + if (EnnemyObj == nil) then + EnnemyObj = self.obj.ennemies["basic"] + end + local x = math.random(240, 424) + local y = (120 / count) * (self.i) + self.i = self.i + 1 + EnnemyObj(self, 240, y, owner) +end + function ParentWorld:newObjFromIndex(id, x, y, z) self.obj.index[id](self, x, y, z) end diff --git a/sonic-radiance.love/scenes/battles/init.lua b/sonic-radiance.love/scenes/battles/init.lua index 2be5e90..df60569 100644 --- a/sonic-radiance.love/scenes/battles/init.lua +++ b/sonic-radiance.love/scenes/battles/init.lua @@ -30,6 +30,7 @@ function CBS:new(battleData) CBS.super.new(self, {"shoot", "test", "battle"}, "testmissions", {"sonic"}) self.assets:batchImport("assets.battle") self:playMusic(battleData.music) + self.ennemies:addAll(battleData.ennemies) end function CBS:playMusic(music) -- 2.30.2