diff --git a/sonic-bluestreak.love/datas/gamedata/maps/shoot/testlevel/test1.lua b/sonic-bluestreak.love/datas/gamedata/maps/shoot/testlevel/test1.lua index 0fa87f6..bb6b6ea 100644 --- a/sonic-bluestreak.love/datas/gamedata/maps/shoot/testlevel/test1.lua +++ b/sonic-bluestreak.love/datas/gamedata/maps/shoot/testlevel/test1.lua @@ -9,6 +9,6 @@ return { }, layout = {{"self", {00}}, {"basics", {00, 00}},}, parts = { - [0] = {{"basics", {01}}, {"basics", {00}}} + [0] = { {"basics", {01}}, {"basics", {00}}, } } } diff --git a/sonic-bluestreak.love/game/modules/playstyle/assets.lua b/sonic-bluestreak.love/game/modules/playstyle/assets.lua index c13d485..8813876 100644 --- a/sonic-bluestreak.love/game/modules/playstyle/assets.lua +++ b/sonic-bluestreak.love/game/modules/playstyle/assets.lua @@ -21,6 +21,7 @@ return { {"cancel", "assets/sfx/menu/cancel.wav"}, }, ["tilesets"] = { - {"weapons", "assets/gui/status/weapons"} + {"weapons", "assets/gui/status/weapons"}, + {"sptiles", "assets/backgrounds/specialtile"} } } diff --git a/sonic-bluestreak.love/game/modules/world/maps/shoot.lua b/sonic-bluestreak.love/game/modules/world/maps/shoot.lua index 7fb89f4..6bcfc10 100644 --- a/sonic-bluestreak.love/game/modules/world/maps/shoot.lua +++ b/sonic-bluestreak.love/game/modules/world/maps/shoot.lua @@ -6,12 +6,22 @@ local TESTZONE = "forest" local zoneDatas = require "datas.gamedata.maps.shoot.zones" +local Chunk = require "game.modules.world.maps.tools.chunk" + function ShootMap:new(world, maptype, mapname) ShootMap.super.new(self, world) self:setPadding(0, 0, 0, 0) self:getLevelData(mapname) self:generateTextures(self.datas.tiles, self.datas.background) + self.layout = {} + + self.width = 0 +end + +function ShootMap:updateWidth() + self.size = #self.layout * 8 + self.width = self.size * 31 end function ShootMap:getLevelData(mapname) @@ -32,19 +42,86 @@ function ShootMap:getLevelData(mapname) self.datas = currentZone_datas end + self.datas.layout = level.layout + self.datas.parts = level.parts end function ShootMap:loadCollisions() + self:loadLayout(); local w, h = self:getDimensions() self.world:newCollision("floor", 0, 0, -16, w, h, 16) end +function ShootMap:loadLayout() + self.layout = {} + -- [ShootMap].datas.layout est un tableau composée d'une série de tableau, + -- chacuns en deux partie : le premier (part[1]) contient le nom du fichier + -- où se trouve des partie de niveau, et la seconde partie (part[2]) une liste + -- d'identifiant de partie de niveau à rajouter. + + -- Ce format permet de simplifier l'écriture de layout, si on a besoin de + -- plusieur partie de niveau se trouvant dans le même fichier. + for i, partContainer in ipairs(self.datas.layout) do + for j, part in ipairs(partContainer[2]) do + self:addPart(partContainer[1], part) + end + end +end + +function ShootMap:addPart(source, partId) + local source = source or "self" + local partdata = {} + + -- On recupère les données de chunks + + -- Si le nom est "self", cela veut dire que fichier est le même que celui ou + -- se trouve le layout, qui est forcément le fichier du niveau. Cela veut dire + -- qu'il faut utiliser les parties de niveau du niveau actuel, localisée dans + -- self.controller.parts + if (source == "self") or (source == "") then + partdata = self.datas.parts + else + -- Si c'est un autre nom, on charge dans "partdata" la liste des partie de niveau + -- du fichier qu'on réfère. + local chunkfile = require("datas.gamedata.maps.shoot.chunks." .. source) + partdata = chunkfile.parts + end + + local chunklist = partdata[partId] + + -- chunklist fonctionne de la même manière que partlist. + -- chaque entrée dans la liste (chunkContainer) contient deux partie : + -- chunkContainer[1]: l'identifiant du fichier où se trouve le chunk voulu + -- chunkContainer[2]: la liste de chunks voulu. chaque entrée dedans est + -- un nombre correspondant à un chunk + for i, chunkContainer in ipairs(chunklist) do + for j, chunk in ipairs(chunkContainer[2]) do + self:addChunk(source, chunkContainer[1], chunk) + end + end + +end + +function ShootMap:addChunk(source, filename, chunkid) + local filename = filename or "self" + if (filename == "self") or (filename == "") then + filename = source + end + + local chunkfile = require("datas.gamedata.maps.shoot.chunks." .. filename) + local chunkdata = chunkfile.chunks + local chunkpos = #self.layout + local chunk = Chunk(self, chunkdata[chunkid]) + table.insert(self.layout, chunk) + self:updateWidth() +end + function ShootMap:addBlock(x, y, w, h, top, bottom) -- Empty Placeholder function end function ShootMap:getDimensions() - return 3000, 100 + return self.width, 100 end function ShootMap:loadPlayers() @@ -97,10 +174,8 @@ function ShootMap:generateFloor(tile) return texture end -function ShootMap:draw() - for i=1, 10 do - --love.graphics.draw(self.texture.floor, ((i-1)*31*16), 0) - end +function ShootMap:draw(x, y, w, h) + self:drawChunks(x) end function ShootMap:addParallax(filename) @@ -160,5 +235,17 @@ function ShootMap:drawCliff(x, y, w, h) end end +function ShootMap:drawChunks(x) + local x = x or 0 + local firstChunk = math.floor(x / (8*31)) - 2 + print(firstChunk) + + for i=1, 6 do + local chunkID = firstChunk + i + if (self.layout[chunkID] ~= nil) then + self.layout[chunkID]:draw(chunkID * (8*31)) + end + end +end return ShootMap diff --git a/sonic-bluestreak.love/game/modules/world/maps/tools/chunk.lua b/sonic-bluestreak.love/game/modules/world/maps/tools/chunk.lua new file mode 100644 index 0000000..2bafeb9 --- /dev/null +++ b/sonic-bluestreak.love/game/modules/world/maps/tools/chunk.lua @@ -0,0 +1,40 @@ +local Chunk = Object:extend() + +function Chunk:new(map, data) + self.map = map + self.data = data +end + +function Chunk:getFakeData() + local fakedata = {} + local emptyline = {00, 00, 00, 00, 00, 00, 00, 00} + fakedata.objects = {emptyline, emptyline, emptyline, emptyline, emptyline} + fakedata.terrain = {emptyline, emptyline, emptyline, emptyline, emptyline} + fakedata.grind = {emptyline, emptyline, emptyline, emptyline, emptyline} + + return fakedata, false +end + +function Chunk:update(dt) + +end + +function Chunk:draw(x) + for i=1, 5 do + for j=1, 8 do + if (self.data.terrain[i][j] ~= 0) then + local tiley = (i-1)*20 + local tilex = x + (j-1)*31 + (i-1)*10 + local tileid = self.data.terrain[i][j] + + self:drawTile(tilex, tiley, tileid) + end + end + end +end + +function Chunk:drawTile(x, y, type) + self.map.world.scene.assets.tileset["sptiles"]:drawTile(type, x, y) +end + +return Chunk diff --git a/sonic-bluestreak.love/game/modules/world/parent.lua b/sonic-bluestreak.love/game/modules/world/parent.lua index 0fb7b3b..85ae9d5 100644 --- a/sonic-bluestreak.love/game/modules/world/parent.lua +++ b/sonic-bluestreak.love/game/modules/world/parent.lua @@ -52,6 +52,13 @@ function ParentWorld:draw(dt) end end +function ParentWorld:drawMap(i) + local x, y, w, h = self.cameras:getViewCoordinate(i) + if (self.map ~= nil) then + self.map:draw(x, y, w, h) + end +end + function ParentWorld:drawParallax(i) local x, y, w, h = self.cameras:getViewCoordinate(i) if (self.map ~= nil) and (self.maptype ~= "sti") then