Dynamic Level Loading
Posted by jetstarforever on March 27, 2008
Probably one of the biggest challenges of Zonerunners is the fact that the game is one big level, meaning very little load times and little to no hiccups that normal games usally have upon loading the next section or level. For those familiar with Game Maker, there’s a handy script called instance_deactivate(), which takes the object out of the main game loop without deleting it. Meaning you can delete it, but bring it back with all it’s stats intact. Cool, huh?
Well, for Zonerunners I found that doing this would basically ruin the game code-wise. You see, for the game to work I have to have control over everything all of the time, because the A.I. itself must have the same control. Putting it simply: Deactivating the enviorment (which also plays a major role in speed) would render the A.I. useless since it can’t read what’s around it. The reason the game was coming to a hault on large maps was due to the intensive A.I. script running for every character EVERY frame. As you can imagine, this would slow the game down to a near 10fps on a large map, let alone a small one. I had to fix this fast, for the future of the game depended on it.
I was fully prepared for a one-hour coding spree when I somehow managed to make a simple script in under five minutes that solved the problem:
if x>level.xa and x<level.xb{return true}else{return false}
“What?” Yes, this solved my problem. What it does is check to see if the calling object is in the currently set level boundaries. If the object is not in the area, it’s not drawn to the screen, it’s STEP event does not run, but it’s still “there”. This way, depending on what I set the current boundaries as I can make small levels inside one big level.