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:
Mon Jun 17 15:10:43 2013 +0000
Revision:
18:70190f956a24
Parent:
7:e72691603fd3
Improved response to button 1 when entering high scores (HighScoreEntry.cpp).

Who changed what in which revision?

UserRevisionLine numberNew contents of line
RichardE 7:e72691603fd3 1 /*
RichardE 7:e72691603fd3 2 * SOURCE FILE : CrusherObject.cpp
RichardE 7:e72691603fd3 3 *
RichardE 7:e72691603fd3 4 * Represents a big square robot that crushes humans.
RichardE 7:e72691603fd3 5 *
RichardE 7:e72691603fd3 6 */
RichardE 7:e72691603fd3 7
RichardE 7:e72691603fd3 8 #include "CrusherObject.h"
RichardE 7:e72691603fd3 9 #include "Gameduino.h"
RichardE 7:e72691603fd3 10 #include "FrameCounter.h"
RichardE 7:e72691603fd3 11 #include "ArenaConst.h"
RichardE 7:e72691603fd3 12 #include "Animations.h"
RichardE 7:e72691603fd3 13 #include "Walker.h"
RichardE 7:e72691603fd3 14
RichardE 7:e72691603fd3 15 /***************/
RichardE 7:e72691603fd3 16 /* CONSTRUCTOR */
RichardE 7:e72691603fd3 17 /***************/
RichardE 7:e72691603fd3 18 CrusherObject::CrusherObject() :
RichardE 7:e72691603fd3 19 animationData( Animations::CrusherAnimation ),
RichardE 7:e72691603fd3 20 stunCountdown( 0 ),
RichardE 7:e72691603fd3 21 stunFrameCount( 0 )
RichardE 7:e72691603fd3 22 {
RichardE 7:e72691603fd3 23 // Initialise horizontal and vertical speeds.
RichardE 7:e72691603fd3 24 Walker::InitialiseVelocities( &hSpeed, &vSpeed );
RichardE 7:e72691603fd3 25 // Movement is always restricted (property of GameObject).
RichardE 7:e72691603fd3 26 MovementRestricted = true;
RichardE 7:e72691603fd3 27 // Restrict to boundary of arena.
RichardE 7:e72691603fd3 28 Bounds = &ArenaRectangle;
RichardE 7:e72691603fd3 29 // Crushers are indestructable.
RichardE 7:e72691603fd3 30 HitPoints = Indestructable;
RichardE 7:e72691603fd3 31 // Crushers squash humans.
RichardE 7:e72691603fd3 32 SquashesHumans = true;
RichardE 7:e72691603fd3 33 }
RichardE 7:e72691603fd3 34
RichardE 7:e72691603fd3 35 /**************/
RichardE 7:e72691603fd3 36 /* DESTRUCTOR */
RichardE 7:e72691603fd3 37 /**************/
RichardE 7:e72691603fd3 38 CrusherObject::~CrusherObject() {
RichardE 7:e72691603fd3 39 }
RichardE 7:e72691603fd3 40
RichardE 7:e72691603fd3 41 /************************/
RichardE 7:e72691603fd3 42 /* MOVE THE GAME OBJECT */
RichardE 7:e72691603fd3 43 /************************/
RichardE 7:e72691603fd3 44 void CrusherObject::ProtectedMove( void ) {
RichardE 7:e72691603fd3 45 if( stunCountdown > 0 ) {
RichardE 7:e72691603fd3 46 stunCountdown--;
RichardE 7:e72691603fd3 47 }
RichardE 7:e72691603fd3 48 else {
RichardE 7:e72691603fd3 49 Walker::Walk( &Xco, &Yco, &hSpeed, &vSpeed, RestrictionFlags );
RichardE 7:e72691603fd3 50 }
RichardE 7:e72691603fd3 51 }
RichardE 7:e72691603fd3 52
RichardE 7:e72691603fd3 53 /************************/
RichardE 7:e72691603fd3 54 /* DRAW THE GAME OBJECT */
RichardE 7:e72691603fd3 55 /************************/
RichardE 7:e72691603fd3 56 // Pass pointer to Gameduino to draw on in gd.
RichardE 7:e72691603fd3 57 // This is only called after it has been established that the
RichardE 7:e72691603fd3 58 // game object is visible.
RichardE 7:e72691603fd3 59 void CrusherObject::Draw( Gameduino *gd ) {
RichardE 7:e72691603fd3 60 // Only update stunFrameCount when not stunned.
RichardE 7:e72691603fd3 61 // This halts animation when in stunned state.
RichardE 7:e72691603fd3 62 if( stunCountdown == 0 ) {
RichardE 7:e72691603fd3 63 stunFrameCount = FrameCounter >> 3;
RichardE 7:e72691603fd3 64 }
RichardE 7:e72691603fd3 65 Walker::Draw( gd, SpriteNumber, Xco, Yco, hSpeed, stunFrameCount, animationData );
RichardE 7:e72691603fd3 66 }
RichardE 7:e72691603fd3 67
RichardE 7:e72691603fd3 68 /********************************************/
RichardE 7:e72691603fd3 69 /* INFORM ENEMY IT HAS BEEN HIT BY A BULLET */
RichardE 7:e72691603fd3 70 /********************************************/
RichardE 7:e72691603fd3 71 // Default implementation does nothing but if special behaviour
RichardE 7:e72691603fd3 72 // is required in a derived class then this should be overridden.
RichardE 7:e72691603fd3 73 // Note that this does NOT deal with determining if the enemy is dead or not.
RichardE 7:e72691603fd3 74 // An enemy ALWAYS dies if HitPoints reaches zero.
RichardE 7:e72691603fd3 75 void CrusherObject::RegisterHitByBullet( void ) {
RichardE 7:e72691603fd3 76 stunCountdown = 10;
RichardE 7:e72691603fd3 77 }