Internal Game Logic

-Anirban Chatterjee-

Introduction | Implementation | Responsibilities | Functions

Introduction

Internal Game Logic (IGL) is responsible for coordinating all the various elements of the game (Graphics, Input, Sound, AI) in order to create what we hope will be a faithful recreation of the classic Legend of Zelda, spiced up in many areas by our originality.  It keeps track of all game-object-related data that any of the four game elements could possibly need, and triggers all the actions (moves, attacks, hits) that the player will see on the game screen.

Implementation

In order to properly keep track of all the data involved, IGL will make use of two data structures: the 'GameRoom' and the 'GameObject'.

A 'GameObject' is our way of representing any object in the game that isn't merely scenery.  This includes enemies and projectile weapons like fireballs.  A GameObject will hold any and all data associated with an object, including current position and speed, hit points, status, animation state, etc.  IGL will be responsible for updating any data fields in a GameObject as appropriate.  Further information about this structure is available on the project's main page.

Every room in the dungeon has a 'GameRoom' structure associated with it.  The portion of GameRoom that is useful to IGL is an array of the GameObjects that are currently in that room. IGL will use these structures to keep track of enemies all over the dungeon, and will delete an enemy from a room if it is killed.  Again, further information about this structure is available on the project's main page.

IGL will also have it's own 'global' array that follows the game from room to room.   It initially contains Link's GameObject.  As Link or enemies fire projectile weapons, IGL will instantiate these GameObjects and place them into this array.  When Link walks into a different room, the portion of this array that contains active weapons is wiped.

The primary IGL function will be a loop (or 'action frame') that iterates through all the objects (Link, enemies, projectile weapons, etc.) in a given room and updates their states.  An AI routine is called to determine the object's next action, and a collision routine is called to determine collisions.  The following pseudocode (which is, of course, a very simple representation of what the main loop does) illustrates this:

   while(still_in_game)
    {
        for(i = 0, i < NUM_OBJECTS, i++)
            {
                call AI_Obj(obj_array[i])
                if(attack)
                    call IGL_Linkattack
                call IGL_CollDetect
                if(no_collision)
                    update obj_array[i]
            }
        call GFX_RefreshScreen
    }

Most other IGL functions will be helper functions for this main looping function.

The first and last two events in the list in the 'Responsibilities' section below are processed at the beginning of every loop, and all other events are processed for every GameObject in the current room.

Responsibilities

Responsibilities of IGL include...

Current Room

All dungeon information, including graphic tile assignments, walkability indices, and default objects, will be loaded into system memory upon startup.  IGL will maintain a pointer that indicates the current active room at all times.

Location/Status of Link

IGL will read state variables written by Input to determine what Link's next action should be.  This will be done through a 'pseudo-AI' routine that will be placed in the AI module.  This routine will calculate Link's new position based on input direction and speed.  If Link takes an action (such as attack), IGL will process it.   In both cases, IGL will set Link's location coordinates and the appropriate bits in Link's status byte.  After processing Link, IGL will clear these state variables in preparation for the next loop.

Location/Status of Enemies

IGL will call routines from the AI module, which will decide an enemy's new direction and action.  IGL will process these actions, run collision detection, save new coordinates, and set the appropriate status bits.

Location of Projectile Weapons

IGL will use other 'pseudo-AI' routines to determine the next position of a weapon.   A flying fireball, for example, would have a simple routine because it always flies in the direction in which it was launched, at a constant speed.  IGL would, as usual, run collision detection and save new coordinates and status bits.

Instantiating Projectile Weapons

IGL will have to create a new fireball every time a GameObject decides to use one, and store the GameObjects for these weapons in the global array discussed earlier.  IGL will be responsible for removing these objects once they hit something, or if Link decides to leave the room.

Checking Collisions (Units)

For each GameObject in a room, IGL would call a collision detection routine immediately after calling the AI routine.  This routine would have two return values: a code giving IGL the type of collision, and a pointer indicating the object collided with (if applicable).

Here are the possibilities for the return code:

In the cases where both of the involved objects in a collision are an enemy, a weapon, or Link, IGL would need a pointer. It would use this pointer to 'reach out' to the object that the current object collided with and set a variable as a pointer to the 'current' object.

Say, for example, that Link is somewhere on the game screen (hmmm...) and an enemy is immediately below him.  Link is feeling a tiny bit suicidal, and decides to head down towards the enemy.  A collision naturally results.  Appropriate damage is subtracted from Link's and the enemy's health, movement by Link is intercepted and halted, and the pointer in the enemy object that was hit is set to point to Link.

We continue iterating through the array and finally get to the unfortunate enemy that Link ran into earlier (realize that this is still the same 'action' frame). This enemy decides to go up towards our hero.  Once again, a collision results, and the collision routine returns a pointer to Link.  IGL will compare this pointer to the current object's internal pointer and realize that Link has already run into this enemy earlier in this frame, and will thus do no more damage to either object.  It will, however, prevent the enemy from moving where it wanted to go.

If however, this enemy had instead decided to go down, IGL would allow it to do so unmolested (provided there was nothing else already there).

If an enemy is stopped from moving by another enemy, IGL throws out the move (as before) but does not subtract any hit points.

When a projectile weapon hits a unit, the weapon is destroyed and the unit takes damage.

Checking Collisions (Other)

As stated previously (in the section regarding collisions between units), IGL runs a collision detection routine after the unit's AI decides where it wants to go.  For the return codes of this function, see this section.

Usually, in cases of collisions with inactive objects, IGL throws out the move and deals no damage.  If a weapon is involved, the weapon is destroyed.

In the event that Link walks through an open door or passage, IGL will determine what room Link walked into, load the information from the new room and update the room pointer it maintains.  It will also update Link's screen coordinates so that Link correctly appears on the other side of the door.

Triggering Sound/Music

IGL is responsible for triggering special music at points in the game where it is required (i.e. main boss death, etc.) using functions provided by Sound.  See the section for Sound and Music for a list of sound effects and music tracks.

Refreshing the Screen

At the end of every action frame, IGL will call a GFX routine which will read through the global and object array and draw the new object positions and sprites to the screen.

Functions

^ Top

Back to Main Page