<< Previous

Next >>

indy_logo.gif (3362 bytes)

Step 3: doors

Only one room was created in the previous steps. An adventure needs several rooms, and virtual doors have to be introduced to go from one room to another.

In this case, all the magic takes place in the EVENT block. EVENT blocks are triggers. They are very similar to the COMMAND blocks, except that they are tested and executed all the time, even when the player is idle.

A door, from the point of view of the Indyjava language, is a normal ITEM with just an EVENT block that makes it react like a door, by detecting when the player steps on it.
The item "plant 2" from the previous listing was renamed "way out" to give the player a clue about its function. The mechanism is simple: as soon as the player's character bumps into that item, the COLLISION condition becomes true and the player is transfered to the other room with the PLACE instruction. But, putting the player there is not enough. The GOTO instruction is needed to switch the view to the second room.
A symetric EVENT mechanism is used in the second room, to go back to the first room.


ROOM main	// Starting room
{
	BGSOUND { "snd/indysong.mid" }	// A bit of music
	IMAGE
	{
		"gr/idol.jpg"		// Backdrop picture
	}
	WALK
	{
		"gr/idol_bm.gif"	// Walking area
	}
	ITEM Indy	// My hero   :)
	{
		ANIMATION
		{
			// --- standby images ---
			0  0  "gr/indy_d.gif"  1 // Looking South
			0  1  "gr/indy_r.gif"  1 // Looking West
			0  2  "gr/indy_u.gif"  1 // Looking North
			0  3  "gr/indy_l.gif"  1 // Looking East
			// --- walking animation ---
			1  0  "gr/indy_wd.gif" 4 // Looking South
			1  1  "gr/indy_wr.gif" 6 // Looking West
			1  2  "gr/indy_wu.gif" 4 // Looking North
			1  3  "gr/indy_wl.gif" 6 // Looking East
			// --- talking animation ---
			2  0  "gr/indy_td.gif" 7 // Looking South
			2  1  "gr/indy_tr.gif" 4 // Looking West
			2  2  "gr/indy_tu.gif" 1 // Looking North
			2  3  "gr/indy_tl.gif" 4 // Looking East
		}
		POSITION { 170 170 0 }
		ITEM whip
		{
			SENTENCE { 2 }	// this item needs another object with the verb "use"
			ICON { "gr/whip.gif" }
			/* local triggers */
			COMMAND Look whip
			{
				SAY indy "I never get out without it!"
			}
			COMMAND * whip
			{
				SAY indy "I don't want to do that with my whip."
			}
		}
	}

	ITEM idol
	{
		IMAGE { 0  0  "gr/blank.gif" }
		POSITION { 155 135 0 }
	}
	ITEM plant_1
	{
		IMAGE { 0  0  "gr/plant_1.gif" }
		POSITION { 0 183 0 }
	}
	ITEM wayout	// This will play the role of "door"
	{
		IMAGE { 0  0  "gr/plant_2.gif" }
		POSITION { 256 183 38 }
	}
	ITEM plant_3
	{
		IMAGE { 0  0  "gr/plant_3.gif" }
		POSITION { 190 183 0 }
	}

	EVENT	// Trigger for this room
	{
		IF
		{
			COLLISION indy wayout	// When player steps on the door...
		}
		THEN
		{
			GOTO outside		// ...jump to the other room
			PLACE indy outside	// Move player there.
			LOCATE indy 140 140 0	// Make sure he is inside a walkable area.
		}
	}
}

ROOM outside	// The other room
{
	BGSOUND { "snd/indysong.mid" }		// Background music for this room.
	IMAGE { "gr/street_2.gif" }
	WALK { "gr/street_2_bm.gif" }

	ITEM entrance
	{
		IMAGE { 0  0  "gr/blank2.gif" }
		POSITION { 32  142  0 }
	}

	EVENT	// Trigger for this room
	{
		IF
		{
			COLLISION indy entrance	// When player steps on the door...
		}
		THEN
		{
			GOTO main		// ...jump to the initial room.
			PLACE indy main		// Move item there.
			LOCATE indy 220 140 0	// Make sure it is inside a walkable area.
		}
	}
}

/* global triggers */

COMMAND look *
{
	SAY indy "Nothing special"
}
COMMAND * *	// Will match any sentence (verb+object) not handled by previous command blocks.
{
	SAY indy "I can't do that"
}
COMMAND * * *	// Will match any sentence (verb+obj1+obj2) not handled by previous command blocks.
{
	SAY indy "I can't do this"
}

Trigger blocks (COMMAND and EVENT) can be declared inside any room and any item, as well as globally. As you would expect, inner local triggers are tested first.

Notice that one of the rooms is called "main". The engine detects this conventional name to know where to start when there are several rooms in the game.

For each item, you can specifiy if it can be "used" alone or if it requires another object, with the keyword SENTENCE. For example, the Whip always has to be used against something else.

Not surprisingly, a different background music is played in every room.

<< Previous

Next >>

Back to the main page

1