Ok. Imagine a level like this:


We are looking at this level from a top view. The white lines are the walls in the level. The green dot is the start point. The red lines form the X and Y axis and meet at the origin, a bright red dot. What I want to do is put another level at the end of the hallway to the east.

So, I start making a new level. It includes part of the hallway from the previous level. It isn't in the same spot (relative to the origin point) but it doesn't have to be. In fact, it can be anywhere you want; more on that later.


So, how do we join these two levels together? First, we add a marker between the two levels that is in the same position relative to the hallway. Here's the two levels again, with the markers (represented as purple dots):



Now we add a trigger in the hallway on each of the levels that will move the player between them (represented as blue lines):



Now when the player touches these triggers, first we need to change the level:

Code:
// load the level
level_load(newlevel);


Then, we set the player's position like this:

Code:
// load the level
level_load(newlevel);

// set player's position
player.x = marker_from_new_level.x - ( marker_from_old_level.x - player.x );
player.y = marker_from_new_level.y - ( marker_from_old_level.y - player.y );
player.z = marker_from_new_level.z - ( marker_from_old_level.z - player.z );



That's just untested pseudo-code by the way. I'm not sure it will work as it is.

Some miscellenaneous things to keep in mind when implementing this:

-The markers have to be in the same position relative to the space you want the player to move to, or else when you change levels the player could be anywhere! Look at my examples levels. The purple dots are in the exact same space relative to the wall below them. That's how your levels should look with the markers in place.

-When you switch levels, the old marker entity will be dumped by the engine. You will probably have to retain it's position in a global VECTOR before using level_load:
Code:
// save the marker from the old level
vec_set( saved_vector, marker_from_old_level );

// load the level
level_load(newlevel);

// set player's position
player.x = marker_from_new_level.x - ( saved_vector.x - player.x );
player.y = marker_from_new_level.y - ( saved_vector.y - player.y );
player.z = marker_from_new_level.z - ( saved_vector.z - player.z );



-To create multiple exits in one level, you will have to link each trigger to its own marker. I would suggest that you use handles for this.

-To move other enemies and objects between the levels and create a truly seamless level load like Half-Life, you will have to do more coding that checks the area surrounding the trigger and re-spawns all the old enemies from the last level in their proper places. This will be tricky and possibly memory consuming, since you will have to keep track of all of the objects within all of the levels accessible from the player's current location. For long games you will have to create several points in the game where the player cannot backtrack anymore so that you can offload all of the entity information you have accumulated from the last several levels. Ugh...

Ok... That's about it I think. That was a bit of a brain dump, but it's getting late where I live and I'm tired and I seem to have lost the ability to form long strings of coherent sentences, especially ones that convey complex ideas such as these. Blug.


Eats commas for breakfast.

Play Barony: Cursed Edition!