Article Index
Introduction
Game Engine
Game Logic
Bitmap Font
Sprites
The CCavern Method
Level Files
Sound And Input
Class Summary
Modding

The CCavern Method

The method CCavern::Play() is responsible for the game loop. Every game frame lasts 60 miliseconds.

Timing is based on the GetTickCount() API function. Every game frame, the hero situation is checked.

// check whether hero is standing on the falling floor block
CheckForFallingFloor(); 
 
// check whether hero is standing on the moving floor block
CheckForMovingFloor();
     
// check if hero touched pick item
CheckIfHeroPickItem();
 
// check if user moves hero (left or right)
CheckIfHeroMoves();

// if hero is falling or not
if (!CheckIfHeroFalls()) {
  // if hero is not falling, maybe is he jumping?
  if (!CheckIfHeroJumps()) {
   // if hero is not jumping, maybe user just makes him jump?
   CheckIfHeroCanJump();
  }
}


After that collision detection routines are called with the guardians. First bounding rectangles are checked, then pixel level based tests are done.  

// hero-guardian collision detection
for (int i=0;i<_nGuardians;i++) {
  _hero.CollideTest(&_guardians[i]);
}

// hero-killing item collision detection
for (int y=0;y<_nCavernHeight;y++) {
  for (int x=0;x<_nCavernWidth;x++) {
   if (GetMapBlockType(x,y) == 'X') {
    _hero.CollideTest( &_wallLethal, GetMapBlockSubtype(x,y), x*TILE_SIZE, y*TILE_SIZE );
   }
  }


After coliision detection, it is calculated whether the graphics should be shifted during display. That is required for 240x320 device resolutions, and sometimes for 320x240 device resolutions.

The game map is 27 tiles wide and 18 tiles high, and that gives a level size of 324x216 pixels.

First THE background image is drawn, then all tiles, all sprites, items, and finally the hero.

This is executed every game frame (60 ms).




DDJ