TGB Level Loader

So working with a new board selection class for La Box and I came across a nice little piece of code for loading levels. This is not my code and I don’t remember whose it is but it works wonders for me.

function loadNewLevel(%levelFile, %delay)
{
// Prevents a crash ;)
if (%delay $= “”) %delay = 100;

// If you haven’t included a directory then we’ll use the default
if (!isFile(%levelFile))
%levelFile = “game/data/levels/” @ %levelFile;

// Add on the extension if needed
%fileExtn = “.t2d”;
if (getSubStr(%levelFile, strlen(%levelFile) – strlen(%fileExtn), strlen(%fileExtn)) !$= %fileExtn)
%levelFile = %levelFile @ %fileExtn;

// Load the file if possible
$gameRunning=true;
$levelName=%levelFile;
if (isFile(%levelFile))
schedule(%delay, 0, “startGame”, %levelFile, %empty);
else
warn(”Level not found: ” @ %levelFile);
}

This always works nicely if you want to play some kind of particle effect or animation before you load a new level. just call it like this loadNewLevel(%scene, 5000);

Comments are closed.