Monday, August 2, 2010


This function is called from the main, and it is the very core of the game.
It consists of a big while which keeps running until
(a) you leave the current room
(b) you happen to win
or (c) you happen to... die.

Let's have a look:
roomLoop() { /*C_00C0*/
newRoomFlag = 0;
while(gameState == GS_OK && newRoomFlag == 0) {
C_014C(); /* update objects'list */
if(gameState == GS_OK && newRoomFlag == 0) {
/* info display */
/* update screen */

Except for C_014C (didn't find a descent name yet), all the other function calls are related to the display. So as you may have already guessed, the game management, the REAL one, is inside the almighty C_014C().

Let's check it:
/* update objects'list */
C_014C() {
unsigned char bp_04, bp_05;

for(bp_04 = 0; newRoomFlag == 0 && (pObject1 = mGameObjectsU[bp_04]); bp_04++) {
hitWallFlag = 0;
curMove[COORD_Z] = 0;
curMove[COORD_Y] = 0;
curMove[COORD_X] = 0;
if(pObject1->_status & STATE_VISIBLE) {
pushFlag = 1;
bp_05 = (*(D_2543[pObject1->_type]))();
while(pushFlag && bp_05 == 0 && newRoomFlag == 0) {
if(newRoomFlag == 0) { /* update sprite's pos */
pObject1->_x += curMove[COORD_X];
pObject1->_y += curMove[COORD_Y];
pObject1->_z += curMove[COORD_Z];

First, you may have notices how my naming convention sucks for the local variables too. I used that while disassembling the code and ... well, kept it until now. Let's put that on the TODO list, it's not such a problem after all.

The main part of this function is a for block which task is to browse through the list of all the current objects (tank, fire, enemies, gates, ... ) and update their states.
D_2543 is the more obscure part of this code; in fact it is just a table of functions indexed with the current object's type. In a word, you could achieve the same logic with a switch(pObject1->_type).
The tank has its own callback, and actually, it is inside this callback that the input (joystick+keyboard) management is done.
C_020F() is the collision management function, and that is a big piece so ... let's keep it for another post, if you don't mind.

Well I hope you're having fun so far.

No comments: