Version of Robotron arcade game using LPC1768, a Gameduino shield, a serial EEPROM (for high scores), two microswitch joysticks and two buttons plus a box to put it in. 20 levels of mayhem.

Dependencies:   25LCxxx_SPI CommonTypes Gameduino mbed

ExplosionManager.cpp

Committer:
RichardE
Date:
2013-06-08
Revision:
8:82d88f9381f3

File content as of revision 8:82d88f9381f3:

/*
 * SOURCE FILE : ExplosionManager.cpp
 *
 * Responsible for managing a collection of explosions.
 *
 */

#include "ExplosionManager.h"
#include "SpriteNumber.h"

// An instance of this class.
ExplosionManager ExplosionManager::Instance( FirstExplosionSprite );

/***************/
/* CONSTRUCTOR */
/***************/
// Pass index of first sprite used for explosions in fsn.
ExplosionManager::ExplosionManager( UInt8 fsn ) :
    firstSpriteNumber( fsn )
{
  KillAllExplosions();
}
    
/**************/
/* DESTRUCTOR */
/**************/
ExplosionManager::~ExplosionManager() {
}

/**************************/
/* START AN EXPLOSION OFF */
/**************************/
// Pass start coordinates in x and y (NOT pixel coordinates).
// Returns pointer to an ExplosionObject if it was started successfully or NULL if
// no more explosions are available at the moment.
ExplosionObject *ExplosionManager::StartExplosion( Int16 x, Int16 y ) {
  // Find a free explosion slot.
  UInt8 i = 0;
  ExplosionObject *explosion = (ExplosionObject*)NULL;
  while( ( i < MaxExplosions ) && ( explosion == (ExplosionObject*)NULL ) ) {
    if( explosionPointers[ i ] == (GameObject*)NULL ) {
      explosion = explosions + i;
      explosionPointers[ i ] = explosion;
      explosion->SpriteNumber = firstSpriteNumber + i;
      explosion->Xco = x;
      explosion->Yco = y;
      explosion->Restart();
    }
    i++;
  }
  return explosion;
}

/***********************/
/* KILL ALL EXPLOSIONS */
/***********************/
void ExplosionManager::KillAllExplosions( void ) {
  for( UInt8 i = 0; i < MaxExplosions; ++i ) {
    explosionPointers[ i ] = (GameObject*)NULL;
  }
}