Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
verilog
Citizen
Posts: 97
Joined: Thu Nov 03, 2011 3:15 am
Contact:

Hey guys!

This post is just for seeking general info about level management. I’m working on a platform game, and right now I’m outlining a general scheme for a level management system (select level, load resources, unload resources) what I have right now is a couple of files describing some tables for level geometry (collision paths), some helper functions, and resources instances.

The first file is just pretty much a collection of tables and functions, it is something like this:

Code: Select all

--File: level0-A.lua

level0 = {}
local levelGeometry = {some stuff…}

function level0:someFunction()
stuff…
end
…
In another file I’ve got some graphics and resources instances, this file is described as a (SECS) class, and is structured a little bit like this:

Code: Select all

--File: level0-B.lua

level = class:new()

function level:init()
end

function level:update()
--update level state
end

function level:draw()
--draw all images
end
The reason of having two files is pretty much direct result of me testing stuff and building/debugging it as I was experimenting. Both of these files are loaded right away when the game starts. What I’m looking for is a flexible scheme for level selection that just depends on one, current, level file (leve0.lua, level1.lua, …., leveln.lua).

What I’m thinking right off the bat is to merge all my level stuff in a one file, structured as a class, eventually I’ll end up with n level files and I could require them with a state machine-like structure in my main game file, but I honestly haven’t tested that idea yet and I’m unsure of its effectiveness. What do you think?

If you’ve got any suggestions for me, please feel free to comment! Thanks for your time

ivan
Party member
Posts: 1619
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

Hello verilog.
Hope you don't mind me sharing my opinions here. Others may have better ideas and I'd be interested in seeing other approaches to level formats/management as well.
In my experience, it's better not to have code in your level files. Levels are supposed to be content that your game loads. Suppose you have functions like "level3_load ( )", "level4_load ( )", etc which depend on functions in the "core" of your game. Then you decide to change how a function works which your levels are depending on. Now you have to manually edit all of those level files. What I'm saying is, it's probably better to represent the levels purely as data (not code). Each level file could have a list of images and sounds and then the "core" of your game could simply iterate and load those assets.
Loading the levels dynamically can also be pretty handy. I usually like to be able to swap and re-order levels without changing any of the code. Something like:

Code: Select all

local level = {}
level.images = { "player.png", "enemy.png", etc }
level.sounds = { "shoot.wav", "explode.wav", etc }
-- maps and other level data

return level
Basically, you save this as "level1.lua" or something then you can load it from the game, perhaps like:

Code: Select all

levels = {}
for i = 1, numberoflevels do
levels[i] = require("level" .. i)
end
Hope this helps.

verilog
Citizen
Posts: 97
Joined: Thu Nov 03, 2011 3:15 am
Contact: