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

LevelCollection.cpp

Committer:
RichardE
Date:
2013-06-09
Revision:
11:2ddaf46e95cb
Parent:
10:bfa1c307c99d
Child:
12:81926431fea7

File content as of revision 11:2ddaf46e95cb:

/*
 * SOURCE FILE : LevelCollection.cpp
 *
 * Definition of class LevelCollection.
 *
 */

#include <stdio.h>
#include "LevelCollection.h"
#include "Level0.h"
#include "LevelNormal.h"
#include "LevelDescriptor.h"

/***************/
/* CONSTRUCTOR */
/***************/
LevelCollection::LevelCollection() {
}

/**************/
/* DESTRUCTOR */
/**************/
LevelCollection::~LevelCollection() {
}

#define LEVELCOUNT 21

/************************/
/* GET NUMBER OF LEVELS */
/************************/
UInt8 LevelCollection::GetLevelCount( void ) const {
  return LEVELCOUNT;
}

// Level 0 which is NOT dynamically allocated.
// Not a real level. This is attract mode.
static Level0 level0;

// Level descriptors.
static const UInt8 ld0[] = { ENDDESCRIPTOR };
static const UInt8 ld1[] = { Grunt, 5, Crusher, 5, ENDDESCRIPTOR };
static const UInt8 ld2[] = { Grunt, 10, Brain, 2, ENDDESCRIPTOR };
static const UInt8 ld3[] = { Grunt, 10, Crusher, 8, ENDDESCRIPTOR };
static const UInt8 ld4[] = { Grunt, 12, Crusher, 6, Brain, 2, ENDDESCRIPTOR };
static const UInt8 ld5[] = { Grunt, 12, Brain, 4, BlueMeany, 2, ENDDESCRIPTOR };
static const UInt8 ld6[] = { Grunt, 5, Crusher, 8, Brain, 1, BlueMeany, 3, ENDDESCRIPTOR };
static const UInt8 ld7[] = { Brain, 15, ENDDESCRIPTOR };
static const UInt8 ld8[] = { Grunt, 3, Brain, 2, BlueMeany, 5, ENDDESCRIPTOR };
static const UInt8 ld9[] = { Grunt, 1, BlueMeany, 10, ENDDESCRIPTOR };
static const UInt8 ld10[] = { Brain, 5, BlueMeany, 10, ENDDESCRIPTOR };
static const UInt8 ld11[] = { Grunt, 5, Crusher, 5, Brain, 10, ENDDESCRIPTOR };
static const UInt8 ld12[] = { Grunt, 10, Brain, 5, BlueMeany, 9, ENDDESCRIPTOR };
static const UInt8 ld13[] = { BlueMeany, 15, ENDDESCRIPTOR };
static const UInt8 ld14[] = { Brain, 20, ENDDESCRIPTOR };
static const UInt8 ld15[] = { Grunt, 32, BlueMeany, 1, ENDDESCRIPTOR };
static const UInt8 ld16[] = { Grunt, 10, Crusher, 30, ENDDESCRIPTOR };
static const UInt8 ld17[] = { Brain, 25, ENDDESCRIPTOR };
static const UInt8 ld18[] = { Grunt, 16, Brain, 16, ENDDESCRIPTOR };
static const UInt8 ld19[] = { Grunt, 16, Brain, 16, BlueMeany, 5, ENDDESCRIPTOR };
static const UInt8 ld20[] = { Brain, 15, BlueMeany, 15, ENDDESCRIPTOR };

// Array pointing to level data for each level.
static const UInt8* const levelDescriptors[ LEVELCOUNT ] = {
    ld0, ld1, ld2, ld3, ld4,
    ld5, ld6, ld7, ld8, ld9,
    ld10, ld11, ld12, ld13, ld14,
    ld15, ld16, ld17, ld18, ld19,
    ld20,
};

/***************/
/* GET A LEVEL */
/***************/
// Pass level number in levelNumber.
// Returns pointer to level or NULL if no such level.
Level *LevelCollection::GetLevel( UInt8 levelNumber ) {
  if( levelNumber >= LEVELCOUNT ) {
    // Level number out of range.
    return (Level*)NULL;
  }
  else if( levelNumber == 0 ) {
    // Level zero is the attract mode and is not dynamically allocated.
    return &level0;
  }
  else {
    // Fetch level descriptor for this level and create a Level from it.
    Level *level = new LevelNormal( levelDescriptors[ levelNumber ] );
    // Tag it with the correct level number before returning it.
    level->LevelNumber = levelNumber;
    return level;
  }
}

/*******************************/
/* FREE MEMORY USED BY A LEVEL */
/*******************************/
// Pass pointer to a level.
// Frees memory used by level.
void LevelCollection::FreeLevel( Level *level ) {
    if( ( level != (Level*)NULL ) && level->IsDynamicallyAllocated ) {
        delete level;
    }
}