feat: stop hardcoding position in maps
This commit is contained in:
parent
001ae44eec
commit
fbbe20e225
8 changed files with 58 additions and 21 deletions
|
@ -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
|
||||
|
|
8
sonic-radiance.love/datas/gamedata/startdata.lua
Normal file
8
sonic-radiance.love/datas/gamedata/startdata.lua
Normal file
|
@ -0,0 +1,8 @@
|
|||
return {
|
||||
position = {
|
||||
x = 10,
|
||||
y = 10,
|
||||
area = "test.plain"
|
||||
},
|
||||
baseteam = {"sonic", "tails", "amy"}
|
||||
}
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -98,6 +98,7 @@ end
|
|||
|
||||
function SaveExitWidget:action()
|
||||
if (self.save) then
|
||||
self.scene.world:savePosition()
|
||||
game:write()
|
||||
end
|
||||
if (self.exit) then
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in a new issue