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/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 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 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 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"] = { 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", +} 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/hud.lua b/sonic-radiance.love/game/modules/subgames/hud.lua new file mode 100644 index 0000000..d986430 --- /dev/null +++ b/sonic-radiance.love/game/modules/subgames/hud.lua @@ -0,0 +1,64 @@ +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 StatusBar = require "scenes.battlesystem.gui.hudelements.statutbar" + +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), + StatusBar(), + -- 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..ac4ae1c 100644 --- a/sonic-radiance.love/game/modules/subgames/init.lua +++ b/sonic-radiance.love/game/modules/subgames/init.lua @@ -3,8 +3,11 @@ 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") +local EnnemyController = require "game.modules.subgames.ennemies" + function PlayStyle:new(supportedLevels, missionfile) PlayStyle.super.new(self, false, false) self.timer = 0 @@ -17,9 +20,11 @@ function PlayStyle:new(supportedLevels, missionfile) self.tweens = TweenManager(self) PauseScreen() + HUD() 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/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/mixins/movements.lua b/sonic-radiance.love/game/modules/subgames/world/actors/fighters/mixins/movements.lua new file mode 100644 index 0000000..19c4f6d --- /dev/null +++ b/sonic-radiance.love/game/modules/subgames/world/actors/fighters/mixins/movements.lua @@ -0,0 +1,54 @@ +local PlayerMovement = Object:extend() + +local SPEED = 160 + +function PlayerMovement:initMovements() + if (not self:isAerial()) then + self:setGravity(480 * 2) + end +end + +function PlayerMovement:updateMovements() + self:setFrc() +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() + self.zsp = 280 * 1.33 +end + +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 new file mode 100644 index 0000000..180b364 --- /dev/null +++ b/sonic-radiance.love/game/modules/subgames/world/actors/fighters/mixins/sprites.lua @@ -0,0 +1,59 @@ +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) + 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) + 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 + 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 new file mode 100644 index 0000000..d19da29 --- /dev/null +++ b/sonic-radiance.love/game/modules/subgames/world/actors/fighters/parent.lua @@ -0,0 +1,45 @@ +local Parent = require("game.modules.subgames.world.actors.parent") +local FighterParent = Parent:extend() + +local TweenManager = require "birb.classes.time" + +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(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() + + local w, h, d = self:getFighterHitbox() + local z = self:getStartZ() + + FighterParent.super.new(self, world, fighterType, x, y, z, w, h, d, false) + self.defaultDir = self.defaultDir or -1 + self:initMovements() + + self.tweens = TweenManager(self) +end + +function FighterParent:update(dt) + self:updateMovements(dt) + FighterParent.super.update(self, dt) + self.tweens:update(dt) +end + +function FighterParent:updateEnd(dt) + self:updateSprites() +end + +function FighterParent:animationEnded(name) + self:playStateFunc("animationEnded", name) +end + +return FighterParent 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 new file mode 100644 index 0000000..d455990 --- /dev/null +++ b/sonic-radiance.love/game/modules/subgames/world/actors/fighters/player/controls.lua @@ -0,0 +1,88 @@ +local PlayerControls = Object:extend() + +function PlayerControls:applyInputs() + 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) + 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() and self:getStateVar("canJump", false)) then + self:jump() + end +end + + +function PlayerControls:applyActionsInputs() + if self.keys["B"].isPressed then + --self:setState("hit1") + self:playStateFunc("bAction") + end +end + +function PlayerControls:applySwitchInputs() + 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 + +return PlayerControls \ No newline at end of file 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 new file mode 100644 index 0000000..dad14f3 --- /dev/null +++ b/sonic-radiance.love/game/modules/subgames/world/actors/fighters/player/init.lua @@ -0,0 +1,46 @@ +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 Identity = require "game.modules.subgames.world.actors.fighters.player.identity" + +local Team = require "scenes.overworld.actors.player.team" + +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 + Player.super.new(self, world, x, y, "player") + self:updateCurrentCharset() + 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: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/player/score.lua b/sonic-radiance.love/game/modules/subgames/world/actors/fighters/player/score.lua new file mode 100644 index 0000000..bccfc8a --- /dev/null +++ b/sonic-radiance.love/game/modules/subgames/world/actors/fighters/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/fighters/player/sprites.lua b/sonic-radiance.love/game/modules/subgames/world/actors/fighters/player/sprites.lua new file mode 100644 index 0000000..99fff27 --- /dev/null +++ b/sonic-radiance.love/game/modules/subgames/world/actors/fighters/player/sprites.lua @@ -0,0 +1,18 @@ +local SpritedPlayer = Object:extend() + +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:updateCurrentCharset() + self.charName = game.characters:getActiveCharacter() + self:initAbstract() + self:changeSprite(self.charName) +end + +return SpritedPlayer 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 new file mode 100644 index 0000000..6e2a9c7 --- /dev/null +++ b/sonic-radiance.love/game/modules/subgames/world/actors/fighters/states/idle.lua @@ -0,0 +1,14 @@ +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 new file mode 100644 index 0000000..16c2ab1 --- /dev/null +++ b/sonic-radiance.love/game/modules/subgames/world/actors/fighters/states/init.lua @@ -0,0 +1,6 @@ +return { + "idle", + "hit1", + "hit2", + "hit3", +} \ No newline at end of file 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..9bebf60 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 = {} @@ -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/actors/player/init.lua b/sonic-radiance.love/game/modules/subgames/world/actors/player/init.lua deleted file mode 100644 index 9a33c9e..0000000 --- a/sonic-radiance.love/game/modules/subgames/world/actors/player/init.lua +++ /dev/null @@ -1,127 +0,0 @@ -local cwd = (...):gsub('%.player$', '') .. "." -local Parent = require(cwd .. "parent") -local Player = Parent:extend() - -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) -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 - -end - -function Player:collisionResponse(collision) - if collision.other.type == "collectible" then - collision.other.owner:getPicked(self) - end -end - -function Player:animationEnded(name) - -end - -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 -end - -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/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 new file mode 100644 index 0000000..df60569 --- /dev/null +++ b/sonic-radiance.love/scenes/battles/init.lua @@ -0,0 +1,45 @@ +-- 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) + self.ennemies:addAll(battleData.ennemies) +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/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) 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" } 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")