From 9b16ae44293ca6c1669ab0ce79841dbc55eccd92 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sat, 28 Dec 2019 14:13:19 +0100 Subject: [PATCH] chore: separate world types --- .../game/modules/world/battle.lua | 17 +++++++++ .../modules/world/{init.lua => parent.lua} | 35 ++++++++----------- .../game/modules/world/shoot.lua | 18 ++++++++++ .../scenes/test_scene/init.lua | 8 +++-- 4 files changed, 55 insertions(+), 23 deletions(-) create mode 100644 sonic-bluestreak.love/game/modules/world/battle.lua rename sonic-bluestreak.love/game/modules/world/{init.lua => parent.lua} (54%) create mode 100644 sonic-bluestreak.love/game/modules/world/shoot.lua diff --git a/sonic-bluestreak.love/game/modules/world/battle.lua b/sonic-bluestreak.love/game/modules/world/battle.lua new file mode 100644 index 0000000..183f74a --- /dev/null +++ b/sonic-bluestreak.love/game/modules/world/battle.lua @@ -0,0 +1,17 @@ +local ParentWorld = require "game.modules.world.parent" +local BattleWorld = ParentWorld:extend() + +local customMap = require "game.modules.world.maps" + +function BattleWorld:new(scene, mapname) + local mappath = game.utils.getMapPath("battle", mapname) + BattleWorld.super.new(self, scene, "battle", mapname) + + self.mapname = mapname +end + +function BattleWorld:createMapController() + customMap.Battle(self, self.maptype, self.mapname) +end + +return BattleWorld diff --git a/sonic-bluestreak.love/game/modules/world/init.lua b/sonic-bluestreak.love/game/modules/world/parent.lua similarity index 54% rename from sonic-bluestreak.love/game/modules/world/init.lua rename to sonic-bluestreak.love/game/modules/world/parent.lua index 920f0b8..368ded7 100644 --- a/sonic-bluestreak.love/game/modules/world/init.lua +++ b/sonic-bluestreak.love/game/modules/world/parent.lua @@ -1,34 +1,27 @@ local World3D = require "core.modules.world.world3D" -local RadianceWorld = World3D:extend() +local ParentWorld = World3D:extend() local customMap = require "game.modules.world.maps" -function RadianceWorld:new(scene, maptype, mapname) - local mappath = game.utils.getMapPath(maptype, mapname) - RadianceWorld.super.new(self, scene, "game.modules.world.actors", mappath, maptype) +function ParentWorld:new(scene, maptype, mapname) + local mappath = game.utils.getMapPath("test", "test") + self.customMap = customMap + + ParentWorld.super.new(self, scene, "game.modules.world.actors", mappath, maptype) self.mapname = mapname end -function RadianceWorld:createMapController() - if (self.maptype == "test") then - customMap.Test(self) - elseif (self.maptype == "battle") then - customMap.Battle(self, self.maptype, self.mapname) - elseif (self.maptype == "shoot") then - customMap.Shoot(self, self.maptype, self.mapname) - self.cameras:lockY(10) - else - RadianceWorld.super.createMapController(self) - end +function ParentWorld:createMapController() + customMap.Test(self) end -function RadianceWorld:loadMapObjects() - RadianceWorld.super.loadMapObjects(self) +function ParentWorld:loadMapObjects() + ParentWorld.super.loadMapObjects(self) self:addInvisibleWalls() end -function RadianceWorld:addInvisibleWalls() +function ParentWorld:addInvisibleWalls() local w, h = self:getDimensions() print(w, h) self.obj.collisions["invisible"](self, 0, -16, 0, w, 16, 1000) @@ -37,7 +30,7 @@ function RadianceWorld:addInvisibleWalls() self.obj.collisions["invisible"](self, -16, 0, 0, 16, h, 1000) end -function RadianceWorld:draw(dt) +function ParentWorld:draw(dt) self:drawBackgroundColor() local camNumber = self.cameras:getViewNumber() @@ -55,11 +48,11 @@ function RadianceWorld:draw(dt) end end -function RadianceWorld:drawParallax(i) +function ParentWorld:drawParallax(i) local x, y, w, h = self.cameras:getViewCoordinate(i) if (self.map ~= nil) and (self.maptype ~= "sti") then self.map:drawParallax(x, y, w, h) end end -return RadianceWorld +return ParentWorld diff --git a/sonic-bluestreak.love/game/modules/world/shoot.lua b/sonic-bluestreak.love/game/modules/world/shoot.lua new file mode 100644 index 0000000..6039269 --- /dev/null +++ b/sonic-bluestreak.love/game/modules/world/shoot.lua @@ -0,0 +1,18 @@ +local ParentWorld = require "game.modules.world.parent" +local ShootWorld = ParentWorld:extend() + +local customMap = require "game.modules.world.maps" + +function ShootWorld:new(scene, mapname) + local mappath = game.utils.getMapPath("shoot", mapname) + ShootWorld.super.new(self, scene, "shoot", mapname) + + self.mapname = mapname +end + +function ShootWorld:createMapController() + self.customMap.Shoot(self, self.maptype, self.mapname) + self.cameras:lockY(10) +end + +return ShootWorld diff --git a/sonic-bluestreak.love/scenes/test_scene/init.lua b/sonic-bluestreak.love/scenes/test_scene/init.lua index 09298de..efb7df4 100644 --- a/sonic-bluestreak.love/scenes/test_scene/init.lua +++ b/sonic-bluestreak.love/scenes/test_scene/init.lua @@ -24,7 +24,9 @@ local Scene = require "core.modules.scenes" local MovePlayer = Scene:extend() -local World = require "game.modules.world" +local TestWorld = require "game.modules.world.parent" +local ShootWorld = require "game.modules.world.shoot" +local BattleWorld = require "game.modules.world.battle" function MovePlayer:new(playerNumber, cameraMode) local playerNumber = playerNumber or 1 @@ -33,7 +35,9 @@ function MovePlayer:new(playerNumber, cameraMode) MovePlayer.super.new(self) self.assets:batchImport("scenes.test_scene.assets") - World(self, "shoot", "coast") + --ShootWorld(self, "coast") + --BattleWorld(self, "ebeach") + TestWorld(self) self.world:setPlayerNumber(playerNumber) self.world.cameras:setMode(cameraMode)