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

Committer:
RichardE
Date:
Sun Jun 09 19:58:49 2013 +0000
Revision:
11:2ddaf46e95cb
Parent:
10:bfa1c307c99d
Child:
12:81926431fea7
Ported over all 20 levels from the Maple version of the game. Looks good. No memory leaks so far.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
RichardE 0:5fa232ee5fdf 1 /*
RichardE 0:5fa232ee5fdf 2 * SOURCE FILE : LevelCollection.cpp
RichardE 0:5fa232ee5fdf 3 *
RichardE 0:5fa232ee5fdf 4 * Definition of class LevelCollection.
RichardE 0:5fa232ee5fdf 5 *
RichardE 0:5fa232ee5fdf 6 */
RichardE 0:5fa232ee5fdf 7
RichardE 0:5fa232ee5fdf 8 #include <stdio.h>
RichardE 0:5fa232ee5fdf 9 #include "LevelCollection.h"
RichardE 0:5fa232ee5fdf 10 #include "Level0.h"
RichardE 10:bfa1c307c99d 11 #include "LevelNormal.h"
RichardE 10:bfa1c307c99d 12 #include "LevelDescriptor.h"
RichardE 0:5fa232ee5fdf 13
RichardE 0:5fa232ee5fdf 14 /***************/
RichardE 0:5fa232ee5fdf 15 /* CONSTRUCTOR */
RichardE 0:5fa232ee5fdf 16 /***************/
RichardE 0:5fa232ee5fdf 17 LevelCollection::LevelCollection() {
RichardE 0:5fa232ee5fdf 18 }
RichardE 0:5fa232ee5fdf 19
RichardE 0:5fa232ee5fdf 20 /**************/
RichardE 0:5fa232ee5fdf 21 /* DESTRUCTOR */
RichardE 0:5fa232ee5fdf 22 /**************/
RichardE 0:5fa232ee5fdf 23 LevelCollection::~LevelCollection() {
RichardE 0:5fa232ee5fdf 24 }
RichardE 0:5fa232ee5fdf 25
RichardE 11:2ddaf46e95cb 26 #define LEVELCOUNT 21
RichardE 0:5fa232ee5fdf 27
RichardE 0:5fa232ee5fdf 28 /************************/
RichardE 0:5fa232ee5fdf 29 /* GET NUMBER OF LEVELS */
RichardE 0:5fa232ee5fdf 30 /************************/
RichardE 0:5fa232ee5fdf 31 UInt8 LevelCollection::GetLevelCount( void ) const {
RichardE 0:5fa232ee5fdf 32 return LEVELCOUNT;
RichardE 0:5fa232ee5fdf 33 }
RichardE 0:5fa232ee5fdf 34
RichardE 10:bfa1c307c99d 35 // Level 0 which is NOT dynamically allocated.
RichardE 10:bfa1c307c99d 36 // Not a real level. This is attract mode.
RichardE 10:bfa1c307c99d 37 static Level0 level0;
RichardE 0:5fa232ee5fdf 38
RichardE 10:bfa1c307c99d 39 // Level descriptors.
RichardE 10:bfa1c307c99d 40 static const UInt8 ld0[] = { ENDDESCRIPTOR };
RichardE 10:bfa1c307c99d 41 static const UInt8 ld1[] = { Grunt, 5, Crusher, 5, ENDDESCRIPTOR };
RichardE 10:bfa1c307c99d 42 static const UInt8 ld2[] = { Grunt, 10, Brain, 2, ENDDESCRIPTOR };
RichardE 11:2ddaf46e95cb 43 static const UInt8 ld3[] = { Grunt, 10, Crusher, 8, ENDDESCRIPTOR };
RichardE 11:2ddaf46e95cb 44 static const UInt8 ld4[] = { Grunt, 12, Crusher, 6, Brain, 2, ENDDESCRIPTOR };
RichardE 11:2ddaf46e95cb 45 static const UInt8 ld5[] = { Grunt, 12, Brain, 4, BlueMeany, 2, ENDDESCRIPTOR };
RichardE 11:2ddaf46e95cb 46 static const UInt8 ld6[] = { Grunt, 5, Crusher, 8, Brain, 1, BlueMeany, 3, ENDDESCRIPTOR };
RichardE 11:2ddaf46e95cb 47 static const UInt8 ld7[] = { Brain, 15, ENDDESCRIPTOR };
RichardE 11:2ddaf46e95cb 48 static const UInt8 ld8[] = { Grunt, 3, Brain, 2, BlueMeany, 5, ENDDESCRIPTOR };
RichardE 11:2ddaf46e95cb 49 static const UInt8 ld9[] = { Grunt, 1, BlueMeany, 10, ENDDESCRIPTOR };
RichardE 11:2ddaf46e95cb 50 static const UInt8 ld10[] = { Brain, 5, BlueMeany, 10, ENDDESCRIPTOR };
RichardE 11:2ddaf46e95cb 51 static const UInt8 ld11[] = { Grunt, 5, Crusher, 5, Brain, 10, ENDDESCRIPTOR };
RichardE 11:2ddaf46e95cb 52 static const UInt8 ld12[] = { Grunt, 10, Brain, 5, BlueMeany, 9, ENDDESCRIPTOR };
RichardE 11:2ddaf46e95cb 53 static const UInt8 ld13[] = { BlueMeany, 15, ENDDESCRIPTOR };
RichardE 11:2ddaf46e95cb 54 static const UInt8 ld14[] = { Brain, 20, ENDDESCRIPTOR };
RichardE 11:2ddaf46e95cb 55 static const UInt8 ld15[] = { Grunt, 32, BlueMeany, 1, ENDDESCRIPTOR };
RichardE 11:2ddaf46e95cb 56 static const UInt8 ld16[] = { Grunt, 10, Crusher, 30, ENDDESCRIPTOR };
RichardE 11:2ddaf46e95cb 57 static const UInt8 ld17[] = { Brain, 25, ENDDESCRIPTOR };
RichardE 11:2ddaf46e95cb 58 static const UInt8 ld18[] = { Grunt, 16, Brain, 16, ENDDESCRIPTOR };
RichardE 11:2ddaf46e95cb 59 static const UInt8 ld19[] = { Grunt, 16, Brain, 16, BlueMeany, 5, ENDDESCRIPTOR };
RichardE 11:2ddaf46e95cb 60 static const UInt8 ld20[] = { Brain, 15, BlueMeany, 15, ENDDESCRIPTOR };
RichardE 10:bfa1c307c99d 61
RichardE 10:bfa1c307c99d 62 // Array pointing to level data for each level.
RichardE 10:bfa1c307c99d 63 static const UInt8* const levelDescriptors[ LEVELCOUNT ] = {
RichardE 11:2ddaf46e95cb 64 ld0, ld1, ld2, ld3, ld4,
RichardE 11:2ddaf46e95cb 65 ld5, ld6, ld7, ld8, ld9,
RichardE 11:2ddaf46e95cb 66 ld10, ld11, ld12, ld13, ld14,
RichardE 11:2ddaf46e95cb 67 ld15, ld16, ld17, ld18, ld19,
RichardE 11:2ddaf46e95cb 68 ld20,
RichardE 0:5fa232ee5fdf 69 };
RichardE 0:5fa232ee5fdf 70
RichardE 0:5fa232ee5fdf 71 /***************/
RichardE 0:5fa232ee5fdf 72 /* GET A LEVEL */
RichardE 0:5fa232ee5fdf 73 /***************/
RichardE 0:5fa232ee5fdf 74 // Pass level number in levelNumber.
RichardE 0:5fa232ee5fdf 75 // Returns pointer to level or NULL if no such level.
RichardE 0:5fa232ee5fdf 76 Level *LevelCollection::GetLevel( UInt8 levelNumber ) {
RichardE 0:5fa232ee5fdf 77 if( levelNumber >= LEVELCOUNT ) {
RichardE 10:bfa1c307c99d 78 // Level number out of range.
RichardE 0:5fa232ee5fdf 79 return (Level*)NULL;
RichardE 0:5fa232ee5fdf 80 }
RichardE 10:bfa1c307c99d 81 else if( levelNumber == 0 ) {
RichardE 10:bfa1c307c99d 82 // Level zero is the attract mode and is not dynamically allocated.
RichardE 10:bfa1c307c99d 83 return &level0;
RichardE 10:bfa1c307c99d 84 }
RichardE 0:5fa232ee5fdf 85 else {
RichardE 10:bfa1c307c99d 86 // Fetch level descriptor for this level and create a Level from it.
RichardE 10:bfa1c307c99d 87 Level *level = new LevelNormal( levelDescriptors[ levelNumber ] );
RichardE 10:bfa1c307c99d 88 // Tag it with the correct level number before returning it.
RichardE 0:5fa232ee5fdf 89 level->LevelNumber = levelNumber;
RichardE 0:5fa232ee5fdf 90 return level;
RichardE 0:5fa232ee5fdf 91 }
RichardE 0:5fa232ee5fdf 92 }
RichardE 0:5fa232ee5fdf 93
RichardE 10:bfa1c307c99d 94 /*******************************/
RichardE 10:bfa1c307c99d 95 /* FREE MEMORY USED BY A LEVEL */
RichardE 10:bfa1c307c99d 96 /*******************************/
RichardE 10:bfa1c307c99d 97 // Pass pointer to a level.
RichardE 10:bfa1c307c99d 98 // Frees memory used by level.
RichardE 10:bfa1c307c99d 99 void LevelCollection::FreeLevel( Level *level ) {
RichardE 10:bfa1c307c99d 100 if( ( level != (Level*)NULL ) && level->IsDynamicallyAllocated ) {
RichardE 10:bfa1c307c99d 101 delete level;
RichardE 10:bfa1c307c99d 102 }
RichardE 10:bfa1c307c99d 103 }