From 2fe37fe9f2a103b202d82cf678a40ad3118448c8 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sat, 27 Jul 2019 15:11:14 +0200 Subject: [PATCH] feat: add support for Sonic Battle maps --- .../game/modules/world/init.lua | 4 ++ .../game/modules/world/maps/battle.lua | 54 +++++++++++++++++++ .../game/modules/world/maps/init.lua | 3 +- 3 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 sonic-radiance.love/game/modules/world/maps/battle.lua diff --git a/sonic-radiance.love/game/modules/world/init.lua b/sonic-radiance.love/game/modules/world/init.lua index 07622ae..dabba03 100644 --- a/sonic-radiance.love/game/modules/world/init.lua +++ b/sonic-radiance.love/game/modules/world/init.lua @@ -6,11 +6,15 @@ 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) + + 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) else RadianceWorld.super.createMapController(self) end diff --git a/sonic-radiance.love/game/modules/world/maps/battle.lua b/sonic-radiance.love/game/modules/world/maps/battle.lua new file mode 100644 index 0000000..3ba24a7 --- /dev/null +++ b/sonic-radiance.love/game/modules/world/maps/battle.lua @@ -0,0 +1,54 @@ +local BaseMap = require "core.modules.world.maps.parent" +local BattleMap = BaseMap:extend() + +function BattleMap:new(world, maptype, mapname) + BattleMap.super.new(self, world) + self:setPadding(0, 96, 0, 0) + self.directory = game.utils.getMapDirectory(maptype, mapname) + self.mappath = game.utils.getMapPath(maptype, mapname) + + self.background = love.graphics.newImage(self.directory .. "background.png") + self.data = require(self.mappath) + self.assets = world.scene.assets +end + +function BattleMap:loadCollisions() + local w, h = self:getDimensions() + self.world:newCollision("floor", 0, 0, -16, w, h, 16) + for i, block in ipairs(self.data.blocks) do + self:addBlock(block[1], block[2], block[3], block[4], block[5], block[6]) + end +end + +function BattleMap:addBlock(x, y, w, h, top, bottom) + if (self.assets.images[top] == nil) then + self.assets:addImage(top, self.directory .. top .. ".png") + end + if (self.assets.images[bottom] == nil) then + self.assets:addImage(bottom, self.directory .. bottom .. ".png") + end + self.world.obj.collisions["textured"](self.world, x*2, y, 0, w*2, h, 64, top, bottom) +end + +function BattleMap:getDimensions() + local w, h = self.background:getDimensions() + return w, (h/2) +end + +function BattleMap:loadPlayers() + self.world:addPlayer(16, 16, 0, 1) +end + +function BattleMap:loadActors() + -- Empty Placeholder function +end + +function BattleMap:draw() + love.graphics.draw(self.background, 0, 0, 0, 1, 0.5) +end + +function BattleMap:drawParallax(x, y, w, h) + -- Empty Placeholder function +end + +return BattleMap diff --git a/sonic-radiance.love/game/modules/world/maps/init.lua b/sonic-radiance.love/game/modules/world/maps/init.lua index 5148f18..f1eda71 100644 --- a/sonic-radiance.love/game/modules/world/maps/init.lua +++ b/sonic-radiance.love/game/modules/world/maps/init.lua @@ -1,5 +1,6 @@ local customMap = {} -customMap.Test = require "game.modules.world.maps.test" +customMap.Test = require "game.modules.world.maps.test" +customMap.Battle = require "game.modules.world.maps.battle" return customMap