diff --git a/sonic-radiance.love/core/modules/world/maps/tiled/stiwrapper.lua b/sonic-radiance.love/core/modules/world/maps/tiled/stiwrapper.lua index 6e2c828..f2ee979 100644 --- a/sonic-radiance.love/core/modules/world/maps/tiled/stiwrapper.lua +++ b/sonic-radiance.love/core/modules/world/maps/tiled/stiwrapper.lua @@ -1,11 +1,12 @@ local StiWrapper = Object:extend() local STI = require "core.modules.world.maps.tiled.libs.sti" -function StiWrapper:new(owner, mapfile, x, y) +function StiWrapper:new(owner, mapfile, x, y, canLoadPlayer) self.sti = STI(mapfile) self.owner = owner self.x = x or 0 self.y = y or 0 + self.canLoadPlayer = (canLoadPlayer ~= false) self.objectlayer = 0 self.isLoaded = false @@ -84,13 +85,15 @@ end function StiWrapper:loadPlayers() for k, objectlayer in pairs(self.sti.layers) do if (objectlayer.name == "player") then - local debugstring = - "loading at most " .. #objectlayer.objects .. " actors in " .. objectlayer.name .. " actor layer" - core.debug:print("map/sti", debugstring) - local i = 1 - for k, object in pairs(objectlayer.objects) do - self.owner:newPlayer(object, i, self.x, self.y) - i = i + 1 + if (self.canLoadPlayer) then + local debugstring = + "loading at most " .. #objectlayer.objects .. " actors in " .. objectlayer.name .. " actor layer" + core.debug:print("map/sti", debugstring) + local i = 1 + for k, object in pairs(objectlayer.objects) do + self.owner:newPlayer(object, i, self.x, self.y) + i = i + 1 + end end self.sti:removeLayer(objectlayer.name) end diff --git a/sonic-radiance.love/datas/gamedata/startdata.lua b/sonic-radiance.love/datas/gamedata/startdata.lua new file mode 100644 index 0000000..0883566 --- /dev/null +++ b/sonic-radiance.love/datas/gamedata/startdata.lua @@ -0,0 +1,8 @@ +return { + position = { + x = 10, + y = 10, + area = "test.plain" + }, + baseteam = {"sonic", "tails", "amy"} +} \ No newline at end of file diff --git a/sonic-radiance.love/game/characters.lua b/sonic-radiance.love/game/characters.lua index a0a60d5..e752bce 100644 --- a/sonic-radiance.love/game/characters.lua +++ b/sonic-radiance.love/game/characters.lua @@ -26,12 +26,13 @@ local CharacterManager = Object:extend() local charutils = require "game.utils.characters" local AbstractCharacter = require "game.abstractmobs.character" +local startdata = require "datas.gamedata.startdata" function CharacterManager:new(controller) self.controller = controller self.namelist = require "datas.gamedata.characters" self.list = {} - self.team = require "datas.gamedata.characters.baseteam" + self.team = startdata.baseteam self.active = 1 self:init() end diff --git a/sonic-radiance.love/game/init.lua b/sonic-radiance.love/game/init.lua index 66599d1..7a37335 100644 --- a/sonic-radiance.love/game/init.lua +++ b/sonic-radiance.love/game/init.lua @@ -32,6 +32,8 @@ local CBSCore = require "game.battle" local binser = require "core.modules.gamesystem.libs.binser" +local startdata = require "datas.gamedata.startdata" + Game.utils = require "game.modules.utils" Game.gui = require "game.modules.gui" @@ -46,6 +48,8 @@ function Game:new() self.loot = Loot(self) self.cbs = CBSCore(self) + self:initPosition() + self.flags = {} self.destroyedGizmo = {} self.variables = {} @@ -53,12 +57,20 @@ function Game:new() self.version = "0.0.0" end +function Game:initPosition() + self.position = {} + self.position.x = startdata.position.x + self.position.y = startdata.position.y + self.position.area = startdata.position.area +end + function Game:setData(data) local data = data self.gametime = data.gametime self.destroyedGizmo = data.destroyedGizmo self.variables = data.variables self.flags = data.flags + self.position = data.position self.characters:setData(data.characters) end @@ -69,6 +81,7 @@ function Game:getData() data.flags = self.flags data.destroyedGizmo = self.destroyedGizmo data.variables = self.variables + data.position = self.position return data end diff --git a/sonic-radiance.love/scenes/overworld/init.lua b/sonic-radiance.love/scenes/overworld/init.lua index cf57e0a..734bffb 100644 --- a/sonic-radiance.love/scenes/overworld/init.lua +++ b/sonic-radiance.love/scenes/overworld/init.lua @@ -36,7 +36,7 @@ local EventManager = require "game.events" local PLAYER_MESSAGE = 240 - 32 -function OverWorld:new() +function OverWorld:new(area, playerx, playery) OverWorld.super.new(self) self.charsetManager = CharsetManager(self) self.assets:batchImport("game.modules.gui.assets") @@ -45,7 +45,7 @@ function OverWorld:new() self.tweens = TweenManager(self) self.screens = screens - World(self, "test", "plain") + World(self, area, playerx, playery) self.world:setPlayerNumber(1) self.world:loadMap() diff --git a/sonic-radiance.love/scenes/overworld/map.lua b/sonic-radiance.love/scenes/overworld/map.lua index f94ec9a..d270203 100644 --- a/sonic-radiance.love/scenes/overworld/map.lua +++ b/sonic-radiance.love/scenes/overworld/map.lua @@ -8,10 +8,11 @@ TiledMultiMap:implement(TiledMixins) local mapFolder = "datas/gamedata/maps/sti/" local areaFolder = "datas.gamedata.maps.area." -function TiledMultiMap:new(world, subworld, file) +function TiledMultiMap:new(world, area, playerx, playery) self.wrappers = {} - self.data = require(areaFolder .. subworld .. "." .. file) + self.data = require(areaFolder .. area) self.w, self.h = 0, 0 + self.playerx, self.playery = playerx * 16, playery * 16 self:loadMaps() TiledMultiMap.super.new(self, world) self.supportTileCollision = true @@ -32,6 +33,11 @@ function TiledMultiMap:loadObjects() for i, wrapper in ipairs(self.wrappers) do wrapper:loadObjects() end + self:loadPlayer() +end + +function TiledMultiMap:loadPlayer() + self.world:addPlayer(self.playerx, self.playery, 0, 1) end -- MAP HANDLING FUNCTIONS @@ -46,7 +52,7 @@ end function TiledMultiMap:addMap(id, mapData) print("Loading map " .. mapData.name) local mapFile = mapFolder .. mapData.folder .. "/" .. mapData.map .. ".lua" - local wrapper = StiWrapper(self, mapFile, mapData.x, mapData.y) + local wrapper = StiWrapper(self, mapFile, mapData.x, mapData.y, false) wrapper.id = id wrapper.music = mapData.music wrapper.name = mapData.name diff --git a/sonic-radiance.love/scenes/overworld/screens/mainmenu/pause.lua b/sonic-radiance.love/scenes/overworld/screens/mainmenu/pause.lua index 8479085..9b27bb8 100644 --- a/sonic-radiance.love/scenes/overworld/screens/mainmenu/pause.lua +++ b/sonic-radiance.love/scenes/overworld/screens/mainmenu/pause.lua @@ -98,6 +98,7 @@ end function SaveExitWidget:action() if (self.save) then + self.scene.world:savePosition() game:write() end if (self.exit) then diff --git a/sonic-radiance.love/scenes/overworld/world.lua b/sonic-radiance.love/scenes/overworld/world.lua index 2dff5b8..bec1dc4 100644 --- a/sonic-radiance.love/scenes/overworld/world.lua +++ b/sonic-radiance.love/scenes/overworld/world.lua @@ -1,19 +1,24 @@ local World = require "core.modules.world.world2D" local RPGWorld = World:extend() local objFile = "scenes.overworld.actors" -local mapFolder = "datas/gamedata/maps/sti/" local RPGMap = require "scenes.overworld.map" -function RPGWorld:new(scene, folder, area, playerx, playery) - --local mapFile = mapFolder .. folder .. "/" .. map .. ".lua" - self.folder = folder - self.area = area +function RPGWorld:new(scene, area, playerx, playery) + self.area = area or game.position.area + self.playerx = playerx or game.position.x + self.playery = playery or game.position.y RPGWorld.super.new(self, scene, objFile, nil, nil) end - function RPGWorld:createMapController() - RPGMap(self, self.folder, self.area) + RPGMap(self, self.area, self.playerx, self.playery) +end + +function RPGWorld:savePosition() + local x, y = self.players[1].actor.x, self.players[1].actor.y + game.position.x = math.floor(x / 16) + game.position.y = math.floor(y / 16) + game.position.area = self.area end function RPGWorld:restoreActions()