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
BlueMeanyObject.cpp@8:82d88f9381f3, 2013-06-08 (annotated)
- Committer:
- RichardE
- Date:
- Sat Jun 08 17:51:33 2013 +0000
- Revision:
- 8:82d88f9381f3
Enemies, humans, explosions, collisions all working now. Sound is still missing and there are only 2 levels.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
RichardE | 8:82d88f9381f3 | 1 | /* |
RichardE | 8:82d88f9381f3 | 2 | * SOURCE FILE : BlueMeanyObject.cpp |
RichardE | 8:82d88f9381f3 | 3 | * |
RichardE | 8:82d88f9381f3 | 4 | * Represents the BlueMeany enemy object. |
RichardE | 8:82d88f9381f3 | 5 | * |
RichardE | 8:82d88f9381f3 | 6 | */ |
RichardE | 8:82d88f9381f3 | 7 | |
RichardE | 8:82d88f9381f3 | 8 | #include "BlueMeanyObject.h" |
RichardE | 8:82d88f9381f3 | 9 | #include "MathFuncs.h" |
RichardE | 8:82d88f9381f3 | 10 | |
RichardE | 8:82d88f9381f3 | 11 | /************************/ |
RichardE | 8:82d88f9381f3 | 12 | /* MOVE THE GAME OBJECT */ |
RichardE | 8:82d88f9381f3 | 13 | /************************/ |
RichardE | 8:82d88f9381f3 | 14 | void BlueMeanyObject::ProtectedMove( void ) { |
RichardE | 8:82d88f9381f3 | 15 | // If being restricted horizontally then make horizontal velocity zero. |
RichardE | 8:82d88f9381f3 | 16 | if( RestrictionFlags & ( LeftRestriction | RightRestriction ) ) { |
RichardE | 8:82d88f9381f3 | 17 | hVelocity = 0; |
RichardE | 8:82d88f9381f3 | 18 | } |
RichardE | 8:82d88f9381f3 | 19 | // If being restricted vertically then make vertical velocity zero. |
RichardE | 8:82d88f9381f3 | 20 | if( RestrictionFlags & ( UpRestriction | DownRestriction ) ) { |
RichardE | 8:82d88f9381f3 | 21 | vVelocity = 0; |
RichardE | 8:82d88f9381f3 | 22 | } |
RichardE | 8:82d88f9381f3 | 23 | // Update coordinates by adding velocities. |
RichardE | 8:82d88f9381f3 | 24 | Xco += hVelocity; |
RichardE | 8:82d88f9381f3 | 25 | Yco += vVelocity; |
RichardE | 8:82d88f9381f3 | 26 | // Accelerate towards chase object horizontally. |
RichardE | 8:82d88f9381f3 | 27 | if( Xco > chaseObject->Xco ) { |
RichardE | 8:82d88f9381f3 | 28 | hVelocity--; |
RichardE | 8:82d88f9381f3 | 29 | } |
RichardE | 8:82d88f9381f3 | 30 | else { |
RichardE | 8:82d88f9381f3 | 31 | hVelocity++; |
RichardE | 8:82d88f9381f3 | 32 | } |
RichardE | 8:82d88f9381f3 | 33 | // Accelerate towards chase object vertically. |
RichardE | 8:82d88f9381f3 | 34 | if( Yco > chaseObject->Yco ) { |
RichardE | 8:82d88f9381f3 | 35 | vVelocity--; |
RichardE | 8:82d88f9381f3 | 36 | } |
RichardE | 8:82d88f9381f3 | 37 | else { |
RichardE | 8:82d88f9381f3 | 38 | vVelocity++; |
RichardE | 8:82d88f9381f3 | 39 | } |
RichardE | 8:82d88f9381f3 | 40 | // Don't let speed get too fast. |
RichardE | 8:82d88f9381f3 | 41 | hVelocity = MathFuncs::Constrain( hVelocity, -MaxBlueMeanyVelocity, MaxBlueMeanyVelocity ); |
RichardE | 8:82d88f9381f3 | 42 | vVelocity = MathFuncs::Constrain( vVelocity, -MaxBlueMeanyVelocity, MaxBlueMeanyVelocity ); |
RichardE | 8:82d88f9381f3 | 43 | } |