From 0710086b25fa7055d892343849ab41bf78162751 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sat, 28 May 2022 11:55:40 +0200 Subject: [PATCH] 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)