Home | AGI Documentation | AGI Tutorials | AGI Tools | AGI Wiki | Community

Basic structure of a room

 �

Each room in a game has it's own individual logic (except in special cases which I won't go into here). Room 2 of the template game gives you an example of the basic structure of a room, which I will go through in detail here. Note that these sections are not required in each room - but it is recommended that you follow this structure. Once you get more experience with AGI you might like to experiment with this a bit.

The header

This section doesn't actually do anything for the room, as it's all commented out - it's just to remind you what the room is. You might like to put a description of what happens in the room or something.

Code:
 
// ****************************************************************************
//
// Logic 2: First room
//
// ****************************************************************************

Defines

All your defines should be placed together at the top of the logic. There aren't any actual defines in this room, but it does include the defines.txt file so the include statement goes here.

For more info on defines and include statements, click here.

Code:
 
#include "defines.txt"
 

The initialization section

When the player first enters the room, there are some things that need to be set up. The background picture needs be loaded, drawn, and discarded from memory. The horizon is set to the appropriate value, and ego is positioned on screen at the desired location. Objects such as background animations, props and other characters are also set up here.

Since the interpreter operates in cycles (and the logic for the current room is executed on each cycle), we only want to do the initialization on the first cycle in the room. This is done by testing for the new_room flag. If this is set, then it means that this is the first cycle in this room. Otherwise, the initialization section is skipped over.

Code:
 
if (new_room) {
  load.pic(room_no);
  draw.pic(room_no);
  discard.pic(room_no);
  set.horizon(50);

  // The next 6 lines need only be in the first room of the game
  if ((prev_room_no == 1 ||    // just come from intro screen
      prev_room_no == 0)) {    // or just started game
    position(ego,120,140);
    status.line.on();
    accept.input();
  }

// Check what room the player came from and position them on the
// screen accordingly here, e.g:
// if (prev_room_no == 5) {
//   position(ego,12,140);
// }

  draw(ego);
  show.pic();
}
 

The main bit

This is where the code goes that controls all the things that happen in the room. In room 2 of the template game, it just consists of a simple text response to the "look" command and a test for ego touching the edge of the screen to switch to the next room (this room just loops back on itself).

Code:
 
if (said("look")) {
  print("This is an empty room.");
}

if (ego_edge_code == horizon_edge) {  // ego touching horizon
  new.room(2);
}

if (ego_edge_code == right_edge) {    // ego touching right edge of screen
  new.room(2);
}

if (ego_edge_code == bottom_edge) {   // ego touching bottom edge of screen
  new.room(2);
}

if (ego_edge_code == left_edge) {     // ego touching left edge of screen
  new.room(2);
}
 

The return command

The return command must be present at the end of every logic. In the case of a room, it returns execution to logic 0 (which calls the room's logic on every cycle). In the case of logic 0 (the main logic), it tells the interpreter to go on to the next cycle.

Code:
 
return();
 


by helping to defray some of the costs of hosting this site. If it has been of help to you, please consider contributing to help keep it online.
Thank you.
pixe
Top

© 2013 to present The Sierra Help Pages. All rights reserved. All Sierra games, artwork and music © Sierra.