Game Development Community

Implementing game levels

by Michael Young · in Torque Game Engine · 06/06/2007 (6:39 pm) · 5 replies

This seems like a stupidly simple question, but I've been all over the site and forums as well as my Finney book, and I can't stumble across a solution. How do I set up my game to move from one level (which I presume I implement as a mission) and the next (which I presume is implemented as a different mission)? This happens all of the time in various games so it's got to be easy. Perhaps I'm missing some keyword in my searches for info on this site?

Thanks!

About the author

Recent Threads


#1
06/09/2007 (8:45 pm)
I'll try to help out Michael, I just need one piece of information. How do you plan on executing this level transition?
Ex:
1. Single Player Game.
2. Player obtains object/kills boss/walks through door.
3. Cut Scene plays.
4. Next level?

Something along those lines? Your two main steps are to disconnect from the current mission and connect to the second one, and use whatever method you want for covering up the transition. Here's an example:

(assume we have two missions, standard starter.fps folder setup, and a full screen GUI that plays a cut scene)

function levelOneTransition()
{
     // Cover up the game and start playing the movie
     Canvas.setContent(FirstCutScene);
     FirstCutScene.play();

     [b]// Disconnect from the current level[/b]
     [b]disconnect();[/b]

     [b]// Launch the next mission[/b]
     // Create the server and load the mission
     createServer("SinglePlayer", "Starter.fps/data/missions/missionTwo.mis");

     // Make a local connection
     %conn = new GameConnection(ServerConnection);
     RootGroup.add(ServerConnection);
     %conn.setConnectArgs("Player");
     %conn.setJoinPassword("None");
     %conn.connectLocal();
}
That's just one of dozens of ways to transitions to new level, from a design standpoint. From a coding standpoint, you'll want to disconnect and then reconnect to a new level, unless you implement a little extra engine code magic =)
#2
06/20/2007 (12:12 pm)
Thanks, Michael. That helps a lot.

To answer your question, after the single player completes certain tasks, they need to be advanced to the next level to face a new series of tasks. I've now reached the point in my coding where I need to do this, and another question has arisen. I currently have 21 NPCs' behavior coded in aiplayer.cs, and when the PC moves to a new level, I'd like a different set of behaviors for these NPCs. I could, of course, implement this all within the single aiplayer.cs file (and may have to do so). Ideally, I'd like to load a different aiplayer.cs for each mission/level.

I'll keep poking around the documentation and forums to see how this might be done.
#3
06/20/2007 (12:14 pm)
FYI: I'm an experimental psychologist who is creating a platform for studying human decision making. Fortunately, I have a computer science background but it's 15 years out of date. As an aside, people really like being in one of my experiments now that it involves playing a video game!
#4
06/20/2007 (11:53 pm)
Got it working! It got a little tricky because I had some global variables I had to reset before starting the new mission (I at first thought that everything would start from scratch). I also chose an alternative technique for changing the behaviors of my NPCs rather than the proposed "new" aiplayer.cs. Pretty straightforward, actually - I just checked which mission I was in and spawned different types of orcs. For example, to have the orc aim at different locations depending on mission:

%spawnLoc = "414 302 219 1 0 0 0";
$player2 = AIPlayer::spawn("Bork",%spawnLoc);

$player2.mountImage(DudCrossbow,0);
$player2.setInventory(CrossbowAmmo,1000);
if (MissionInfo.name $= "Stronghold")
$player2.setAimObject("Fire3");
else
$player2.setAimObject("Fire2");

The same logic can be used to change the type of weapon mounted (which I'll need to do).

Nothing complex, but I wanted to share anyway.
#5
06/21/2007 (5:18 am)
Good work Michael!