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@18:70190f956a24, 2013-06-17 (annotated)
- Committer:
- RichardE
- Date:
- Mon Jun 17 15:10:43 2013 +0000
- Revision:
- 18:70190f956a24
- Parent:
- 12:81926431fea7
Improved response to button 1 when entering high scores (HighScoreEntry.cpp).
Who changed what in which revision?
User | Revision | Line number | New 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 | 12:81926431fea7 | 39 | // Data for enemies on each level. |
RichardE | 12:81926431fea7 | 40 | static const UInt8 e0 [] = { ENDDESCRIPTOR }; |
RichardE | 12:81926431fea7 | 41 | static const UInt8 e1 [] = { Grunt, 5, Crusher, 5, ENDDESCRIPTOR }; |
RichardE | 12:81926431fea7 | 42 | static const UInt8 e2 [] = { Grunt, 10, Brain, 2, ENDDESCRIPTOR }; |
RichardE | 12:81926431fea7 | 43 | static const UInt8 e3 [] = { Grunt, 10, Crusher, 8, ENDDESCRIPTOR }; |
RichardE | 12:81926431fea7 | 44 | static const UInt8 e4 [] = { Grunt, 12, Crusher, 6, Brain, 2, ENDDESCRIPTOR }; |
RichardE | 12:81926431fea7 | 45 | static const UInt8 e5 [] = { Grunt, 12, Brain, 4, BlueMeany, 2, ENDDESCRIPTOR }; |
RichardE | 12:81926431fea7 | 46 | static const UInt8 e6 [] = { Grunt, 5, Crusher, 8, Brain, 1, BlueMeany, 3, ENDDESCRIPTOR }; |
RichardE | 12:81926431fea7 | 47 | static const UInt8 e7 [] = { Brain, 15, ENDDESCRIPTOR }; |
RichardE | 12:81926431fea7 | 48 | static const UInt8 e8 [] = { Grunt, 3, Brain, 2, BlueMeany, 5, ENDDESCRIPTOR }; |
RichardE | 12:81926431fea7 | 49 | static const UInt8 e9 [] = { Grunt, 1, BlueMeany, 10, ENDDESCRIPTOR }; |
RichardE | 12:81926431fea7 | 50 | static const UInt8 e10 [] = { Brain, 5, BlueMeany, 10, ENDDESCRIPTOR }; |
RichardE | 12:81926431fea7 | 51 | static const UInt8 e11 [] = { Grunt, 5, Crusher, 5, Brain, 10, ENDDESCRIPTOR }; |
RichardE | 12:81926431fea7 | 52 | static const UInt8 e12 [] = { Grunt, 10, Brain, 5, BlueMeany, 9, ENDDESCRIPTOR }; |
RichardE | 12:81926431fea7 | 53 | static const UInt8 e13 [] = { BlueMeany, 15, ENDDESCRIPTOR }; |
RichardE | 12:81926431fea7 | 54 | static const UInt8 e14 [] = { Brain, 20, ENDDESCRIPTOR }; |
RichardE | 12:81926431fea7 | 55 | static const UInt8 e15 [] = { Grunt, 32, BlueMeany, 1, ENDDESCRIPTOR }; |
RichardE | 12:81926431fea7 | 56 | static const UInt8 e16 [] = { Grunt, 10, Crusher, 30, ENDDESCRIPTOR }; |
RichardE | 12:81926431fea7 | 57 | static const UInt8 e17 [] = { Brain, 25, ENDDESCRIPTOR }; |
RichardE | 12:81926431fea7 | 58 | static const UInt8 e18 [] = { Grunt, 16, Brain, 16, ENDDESCRIPTOR }; |
RichardE | 12:81926431fea7 | 59 | static const UInt8 e19 [] = { Grunt, 16, Brain, 16, BlueMeany, 5, ENDDESCRIPTOR }; |
RichardE | 12:81926431fea7 | 60 | static const UInt8 e20 [] = { Brain, 15, BlueMeany, 15, ENDDESCRIPTOR }; |
RichardE | 10:bfa1c307c99d | 61 | |
RichardE | 12:81926431fea7 | 62 | // Array containing level data for each level. |
RichardE | 12:81926431fea7 | 63 | // First parameter is number of humans. |
RichardE | 12:81926431fea7 | 64 | // Second parameter points to an array describing enemies on the level. |
RichardE | 12:81926431fea7 | 65 | static const LevelDescriptor levelDescriptors[ LEVELCOUNT ] = { |
RichardE | 12:81926431fea7 | 66 | LevelDescriptor( 0, e0 ), |
RichardE | 12:81926431fea7 | 67 | LevelDescriptor( 5, e1 ), |
RichardE | 12:81926431fea7 | 68 | LevelDescriptor( 6, e2 ), |
RichardE | 12:81926431fea7 | 69 | LevelDescriptor( 5, e3 ), |
RichardE | 12:81926431fea7 | 70 | LevelDescriptor( 6, e4 ), |
RichardE | 12:81926431fea7 | 71 | LevelDescriptor( 8, e5 ), |
RichardE | 12:81926431fea7 | 72 | LevelDescriptor( 8, e6 ), |
RichardE | 12:81926431fea7 | 73 | LevelDescriptor( 8, e7 ), |
RichardE | 12:81926431fea7 | 74 | LevelDescriptor( 8, e8 ), |
RichardE | 12:81926431fea7 | 75 | LevelDescriptor( 8, e9 ), |
RichardE | 12:81926431fea7 | 76 | LevelDescriptor( 8, e10 ), |
RichardE | 12:81926431fea7 | 77 | LevelDescriptor( 8, e11 ), |
RichardE | 12:81926431fea7 | 78 | LevelDescriptor( 8, e12 ), |
RichardE | 12:81926431fea7 | 79 | LevelDescriptor( 12, e13 ), |
RichardE | 12:81926431fea7 | 80 | LevelDescriptor( 8, e14 ), |
RichardE | 12:81926431fea7 | 81 | LevelDescriptor( 16, e15 ), |
RichardE | 12:81926431fea7 | 82 | LevelDescriptor( 16, e16 ), |
RichardE | 12:81926431fea7 | 83 | LevelDescriptor( 16, e17 ), |
RichardE | 12:81926431fea7 | 84 | LevelDescriptor( 16, e18 ), |
RichardE | 12:81926431fea7 | 85 | LevelDescriptor( 16, e19 ), |
RichardE | 12:81926431fea7 | 86 | LevelDescriptor( 24, e20 ), |
RichardE | 0:5fa232ee5fdf | 87 | }; |
RichardE | 0:5fa232ee5fdf | 88 | |
RichardE | 0:5fa232ee5fdf | 89 | /***************/ |
RichardE | 0:5fa232ee5fdf | 90 | /* GET A LEVEL */ |
RichardE | 0:5fa232ee5fdf | 91 | /***************/ |
RichardE | 0:5fa232ee5fdf | 92 | // Pass level number in levelNumber. |
RichardE | 0:5fa232ee5fdf | 93 | // Returns pointer to level or NULL if no such level. |
RichardE | 0:5fa232ee5fdf | 94 | Level *LevelCollection::GetLevel( UInt8 levelNumber ) { |
RichardE | 0:5fa232ee5fdf | 95 | if( levelNumber >= LEVELCOUNT ) { |
RichardE | 10:bfa1c307c99d | 96 | // Level number out of range. |
RichardE | 0:5fa232ee5fdf | 97 | return (Level*)NULL; |
RichardE | 0:5fa232ee5fdf | 98 | } |
RichardE | 10:bfa1c307c99d | 99 | else if( levelNumber == 0 ) { |
RichardE | 10:bfa1c307c99d | 100 | // Level zero is the attract mode and is not dynamically allocated. |
RichardE | 10:bfa1c307c99d | 101 | return &level0; |
RichardE | 10:bfa1c307c99d | 102 | } |
RichardE | 0:5fa232ee5fdf | 103 | else { |
RichardE | 10:bfa1c307c99d | 104 | // Fetch level descriptor for this level and create a Level from it. |
RichardE | 12:81926431fea7 | 105 | Level *level = new LevelNormal( levelDescriptors + levelNumber ); |
RichardE | 10:bfa1c307c99d | 106 | // Tag it with the correct level number before returning it. |
RichardE | 0:5fa232ee5fdf | 107 | level->LevelNumber = levelNumber; |
RichardE | 0:5fa232ee5fdf | 108 | return level; |
RichardE | 0:5fa232ee5fdf | 109 | } |
RichardE | 0:5fa232ee5fdf | 110 | } |
RichardE | 0:5fa232ee5fdf | 111 | |
RichardE | 10:bfa1c307c99d | 112 | /*******************************/ |
RichardE | 10:bfa1c307c99d | 113 | /* FREE MEMORY USED BY A LEVEL */ |
RichardE | 10:bfa1c307c99d | 114 | /*******************************/ |
RichardE | 10:bfa1c307c99d | 115 | // Pass pointer to a level. |
RichardE | 10:bfa1c307c99d | 116 | // Frees memory used by level. |
RichardE | 10:bfa1c307c99d | 117 | void LevelCollection::FreeLevel( Level *level ) { |
RichardE | 10:bfa1c307c99d | 118 | if( ( level != (Level*)NULL ) && level->IsDynamicallyAllocated ) { |
RichardE | 10:bfa1c307c99d | 119 | delete level; |
RichardE | 10:bfa1c307c99d | 120 | } |
RichardE | 10:bfa1c307c99d | 121 | } |