Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Multiple levels

Author
Message
kuwagata
12
Years of Service
User Offline
Joined: 10th Feb 2012
Location:
Posted: 14th Feb 2012 18:20
How can I make multiple levels in a game? Thanks!

Hello!
Hodgey
14
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 15th Feb 2012 00:38
Have a look at this thread.

Millenium7
19
Years of Service
User Offline
Joined: 13th Dec 2004
Location:
Posted: 18th Feb 2012 16:21
first you need a function used to set up a new level. it could be as simple as some for-next loops that check if any images/sounds/objects exist and delete them, ready to load new data. Or you could make it a bit more elaborate and use classes rather than numbers when referencing objects, check what will be required for the next level and delete the rest

then you need another function that loads data and sets up the layout. there's a few ways to do this but ultimately boil down to 2 methods
Hard coding:
is where you write the level layout within your game code. i.e.
if level=1
position object player,50,0,50
etc etc
endif
if level=2
position object player 450,70,0
etc etc
endif
this method is the easiest but far less flexible, and requires time consuming and mundane tweaking of code to get everything set up right

Scripting:
is where you use external files to tell your program how to set up a level. this method requires a thorough understanding of functions and how to handle file loading/reading/sorting. It takes longer to initially set up the code required to do it effectively
decide how large your project will be. if its only a couple small levels its probably a lot faster to jaust hard code it in. if you will be using lots of levels, want more flexibility (such as the ability to use a 3d editor to position units and export that data), or want the ability to add/modify levels without recoding then its the only way to go
MrValentine
AGK Backer
13
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 20th Feb 2012 21:56
hmm this got me thinking...

will check out that other thread too

I like the idea of individual files to manage loading and possibly deleting too...

the question there would be... do you also delete the textures too?

I am considering synced and unsynced loading methods too...

Millenium7
19
Years of Service
User Offline
Joined: 13th Dec 2004
Location:
Posted: 21st Feb 2012 05:10 Edited at: 21st Feb 2012 05:11
You should clear all data before loading a level if you are unsure. You can make it a bit smarter by instead using UDT's and defining 'pre-loaded data'. It's a little difficult to explain but basically I have a scripting engine. It loads everything to do with units, particles, textures, sounds, music, objects and so on from configuration files. These are stored in temporary 'preload' arrays. When my game wants to load another unit, it will check these 'preload' arrays to see if the unit has already been loaded. Then it will simply find an empty object number and clone the preloaded data across. Or load it fresh (depending on the object classification) but it already has the required parameters in memory and does not have to reload the scripting engine to pull out the configuration data again

So if I load map1 and it has a unit class called 'barrel' within the map, it will find that it hasn't already been loaded, so start fresh and load all the relevant data. If I go to map2 which also has a 'barrel', it will see that it's already loaded into memory, so will just clone it into a free object number
Make sense?

edit: now sure why you'd want to use unsync'd loading? i've never used anything other than sync and have no problems. It's much faster
MrValentine
AGK Backer
13
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 21st Feb 2012 06:08
oh unsynced was live loading a form of streaming media...

Yeah I agree with your post there Millenium7

I am thinking to use ini files which you use? .dat?

Millenium7
19
Years of Service
User Offline
Joined: 13th Dec 2004
Location:
Posted: 21st Feb 2012 08:46
I use my own format in the form of
[HEADING]
parameter=string,string,string,string

There can be an unlimited number of strings/values for each parameter, and multiple headings with common parameter names
i.e

[MAP] // global map variables, loaded regardless of game type
marines.spawn=25,70
music=music1.mp3,music2.mp3,music3.mp3
spawnunit=barrel,40,40
[ASSAULT] // gametype specific parameters
marines.spawn=33,10
music=assault.mp3
spawnunit=barrel,41,40

the above example would use the parameters listed under [MAP] always, but is overriden by [ASSAULT] when that gametype is used, so in this case the music and spawn positions will change. But a
'barrel' will always be spawned at 40x40 regardless of game type chosen. And a second 'barrel' will be spawned if using the assault gametype
Additionally, 'barrel' is not hardcoded into my game. So the game will recognise a new type of unit and will go looking for a barrel.cfg file and use that to load the object, scale, rotation, animations, particle effects, health, unit type etc. I have infinite branching within configuration files. So I may want to barrel to have a particle that rotates around it, and a blinking light source under it. So the barrel.cfg file also points to another configuration file containing the particle effect and what it does, as well as a .cfg file pertaining to a blinking light

It's quite complex, yet simple to use. Also allows for a lot of user created content and mods
Ramon156
12
Years of Service
User Offline
Joined: 13th Jul 2011
Location: Netherlands
Posted: 16th Apr 2012 16:13 Edited at: 16th Apr 2012 16:19
What I did a while ago.
Make a main loop.
A variable that checks what level you are in, let's say -

Global Levelstatus as integer = 0



Apart from your "main loop" you can also make a loop in the gosub.




Remember if you gosub to a new level, do not use the "return" command.

Keep in mind to unload everything you dont need and load everything you need for the second level.

Login to post a reply

Server time is: 2024-05-17 05:53:39
Your offset time is: 2024-05-17 05:53:39