From 001c1a3d5aec873ace53c9112e85e5ed8984594d Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Fri, 2 Aug 2019 13:54:04 +0200 Subject: [PATCH] feat(maps): add a Shadow Shoot map loader --- .../datas/gamedata/maps/shoot/zones.lua | 46 ++++++ .../game/modules/utils/init.lua | 2 +- .../game/modules/world/init.lua | 3 + .../game/modules/world/maps/init.lua | 1 + .../game/modules/world/maps/shoot.lua | 133 ++++++++++++++++++ .../scenes/test_scene/init.lua | 2 +- 6 files changed, 185 insertions(+), 2 deletions(-) create mode 100644 sonic-radiance.love/datas/gamedata/maps/shoot/zones.lua create mode 100644 sonic-radiance.love/game/modules/world/maps/shoot.lua diff --git a/sonic-radiance.love/datas/gamedata/maps/shoot/zones.lua b/sonic-radiance.love/datas/gamedata/maps/shoot/zones.lua new file mode 100644 index 0000000..75e10b0 --- /dev/null +++ b/sonic-radiance.love/datas/gamedata/maps/shoot/zones.lua @@ -0,0 +1,46 @@ +return { + ["forest"] = { + name = "Jade Forest", + borders = 0, + tiles = 0, + background = "forest" + }, + ["city"] ={ + name = "Diamond Highway", + borders = 1, + tiles = 1, + background = "city" + }, + ["tunnel"] ={ + name = "Peridot Tunnel", + borders = 2, + tiles = 2, + background = "tunnel", + music = nil + }, + ["mountain"] ={ + name = "Pearl Mountain", + borders = 3, + tiles = 3, + background = "mountain" + }, + ["hills"] ={ + name = "Calcite Hills", + borders = 4, + tiles = 4, + background = "hills" + }, + ["bridge"] ={ + name = "Carnelian Bridge", + borders = 5, + tiles = 5, + background = "bridge" + }, + ["castle"] ={ + name = "Ametist Castle", + borders = 6, + tiles = 6, + background = "castle", + music = nil + }, +} diff --git a/sonic-radiance.love/game/modules/utils/init.lua b/sonic-radiance.love/game/modules/utils/init.lua index 3948045..2c47be2 100644 --- a/sonic-radiance.love/game/modules/utils/init.lua +++ b/sonic-radiance.love/game/modules/utils/init.lua @@ -21,7 +21,7 @@ function gameutils.getMapDirectory(maptype, mapname) end function gameutils.validateMapType(maptype) - local types = {"battle", "sti", "test"} + local types = {"battle", "sti", "test", "shoot"} local validated = false for i, type in ipairs(types) do diff --git a/sonic-radiance.love/game/modules/world/init.lua b/sonic-radiance.love/game/modules/world/init.lua index dabba03..2a87ef8 100644 --- a/sonic-radiance.love/game/modules/world/init.lua +++ b/sonic-radiance.love/game/modules/world/init.lua @@ -15,6 +15,9 @@ function RadianceWorld:createMapController() 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(4) else RadianceWorld.super.createMapController(self) end diff --git a/sonic-radiance.love/game/modules/world/maps/init.lua b/sonic-radiance.love/game/modules/world/maps/init.lua index f1eda71..41f47b0 100644 --- a/sonic-radiance.love/game/modules/world/maps/init.lua +++ b/sonic-radiance.love/game/modules/world/maps/init.lua @@ -2,5 +2,6 @@ local customMap = {} customMap.Test = require "game.modules.world.maps.test" customMap.Battle = require "game.modules.world.maps.battle" +customMap.Shoot = require "game.modules.world.maps.shoot" return customMap diff --git a/sonic-radiance.love/game/modules/world/maps/shoot.lua b/sonic-radiance.love/game/modules/world/maps/shoot.lua new file mode 100644 index 0000000..452d500 --- /dev/null +++ b/sonic-radiance.love/game/modules/world/maps/shoot.lua @@ -0,0 +1,133 @@ +local BaseMap = require "core.modules.world.maps.parent" +local ShootMap = BaseMap:extend() + +local TILESIZE = 31 +local TESTZONE = "forest" + +local zoneDatas = require "datas.gamedata.maps.shoot.zones" + +function ShootMap:new(world, maptype, mapname) + ShootMap.super.new(self, world) + + self:setPadding(0, 0, 0, 0) + self:generateTextures(1) +end + +function ShootMap:loadCollisions() + local w, h = self:getDimensions() + self.world:newCollision("floor", 0, 0, -16, w, h, 16) +end + +function ShootMap:addBlock(x, y, w, h, top, bottom) + -- Empty Placeholder function +end + +function ShootMap:getDimensions() + return 3000, 100 +end + +function ShootMap:loadPlayers() + self.world:addPlayer(16, 50, 0, 1) +end + +function ShootMap:loadActors() + -- Empty Placeholder function +end + +function ShootMap:generateTextures(tile) + + self.texture = {} + self.texture.floor = self:generateFloor(tile) + self.texture.border = love.graphics.newImage("assets/backgrounds/borders.png") + self.quads = {} + local w, h = self.texture.border:getDimensions() + self.quads.borders = love.graphics.newQuad(0, tile*10, 80, 10, w, h) + + self:addParallax("city") +end + +function ShootMap:generateFloor(tile) + local canvas = love.graphics.newCanvas(31*16, 100) + local tile = tile or 1 + + local tileTexture = love.graphics.newImage("assets/backgrounds/normaltile.png") + local tileQuad = {} + local w, h = tileTexture:getDimensions() + tileQuad[1] = love.graphics.newQuad( 0, tile*24, 40, 24, w, h) + tileQuad[2] = love.graphics.newQuad(40, tile*24, 40, 24, w, h) + + love.graphics.setCanvas( canvas ) + + for i=1, 5 do + for j=0, 18 do + local tiley = (i-1)*20 - 4 + local tilex = (j-2)*31 + (i-1)*10 + local variant = 1 + ((i + j) % 2) + love.graphics.draw(tileTexture, tileQuad[variant], tilex, tiley) + end + end + + love.graphics.setCanvas( ) + + local imagedata = canvas:newImageData() + local texture = love.graphics.newImage( imagedata ) + imagedata:release() + canvas:release() + return texture +end + +function ShootMap:draw() + for i=1, 10 do + --love.graphics.draw(self.texture.floor, ((i-1)*31*16), 0) + end +end + +function ShootMap:addParallax(filename) + -- Empty Placeholder function + local filename = filename or "forest" + local backfolder = "assets/backgrounds/parallax/" + filename = backfolder .. filename + self.texture.back1 = love.graphics.newImage(filename .. "-back.png") + self.texture.back2 = love.graphics.newImage(filename .. "-fore.png") +end + +function ShootMap:drawParallax(x, y, w, h) + + self:drawBackground(x, y, w, h) + self:drawForeground(x, y + 10, w, h) + local w2, _ = self.texture.floor:getDimensions() + for i=1, 2 do + local x2 = x % w2 + love.graphics.draw(self.texture.floor, ((i-1)*31*16)-x2, -y) + end + + self:drawBorder(x, y + 10) + self:drawBorder(x, y - 100) +end + +function ShootMap:drawBackground(x, y, w, h) + local w2, h2 = self.texture.back1:getDimensions() + local imax = math.ceil(w / w2) + 1 + for i=1, imax do + local x1 = (x / 5) % w2 + love.graphics.draw(self.texture.back1, (i-1)*w2 - x1, 0, 0, 1, 1, 0, 0) + end +end + +function ShootMap:drawForeground(x, y, w, h) + local w2, h2 = self.texture.back2:getDimensions() + local imax = math.ceil(w / w2) + 1 + for i=1, imax do + local x1 = (x / 2) % w2 + love.graphics.draw(self.texture.back2, (i-1)*w2 - x1, -y, 0, 1, 1, 0, h2) + end +end + +function ShootMap:drawBorder(x, y) + for i=1, 7 do + local x2 = x % 80 + love.graphics.draw(self.texture.border, self.quads.borders, (i-1)*80 - x2, -y, 0, 1, 1) + end +end + +return ShootMap diff --git a/sonic-radiance.love/scenes/test_scene/init.lua b/sonic-radiance.love/scenes/test_scene/init.lua index d91ba85..c5ead8c 100644 --- a/sonic-radiance.love/scenes/test_scene/init.lua +++ b/sonic-radiance.love/scenes/test_scene/init.lua @@ -33,7 +33,7 @@ function MovePlayer:new(playerNumber, cameraMode) MovePlayer.super.new(self) self.assets:batchImport("scenes.test_scene.assets") - World(self, "battle", "ebeach") + World(self, "shoot", "ebeach") self.world:setPlayerNumber(playerNumber) self.world.cameras:setMode(cameraMode)