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:
Sat Jun 08 16:44:54 2013 +0000
Revision:
7:e72691603fd3
Now have grunts wandering around on level 1. They follow the player but since no collision detection logic yet nobody ever gets killed.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
RichardE 7:e72691603fd3 1 /*
RichardE 7:e72691603fd3 2 * SOURCE FILE : HumanObject.cpp
RichardE 7:e72691603fd3 3 *
RichardE 7:e72691603fd3 4 * Represents a wandering human.
RichardE 7:e72691603fd3 5 *
RichardE 7:e72691603fd3 6 */
RichardE 7:e72691603fd3 7
RichardE 7:e72691603fd3 8 #include "HumanObject.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 // Index of next animation to use when constructing.
RichardE 7:e72691603fd3 16 UInt8 HumanObject::nextAnimationIndex = 0;
RichardE 7:e72691603fd3 17
RichardE 7:e72691603fd3 18 /***************/
RichardE 7:e72691603fd3 19 /* CONSTRUCTOR */
RichardE 7:e72691603fd3 20 /***************/
RichardE 7:e72691603fd3 21 // Pass number of sprite to use in sn.
RichardE 7:e72691603fd3 22 // Pass address of animation data in ad.
RichardE 7:e72691603fd3 23 // Animation data must consist of AnimationStages bytes which gives the sprite
RichardE 7:e72691603fd3 24 // image numbers used for each state of the animation.
RichardE 7:e72691603fd3 25 HumanObject::HumanObject() :
RichardE 7:e72691603fd3 26 CurrentState( WalkingAbout ),
RichardE 7:e72691603fd3 27 animationData( Animations::HumanAnimations[ nextAnimationIndex++ ] ),
RichardE 7:e72691603fd3 28 countdown( 100 )
RichardE 7:e72691603fd3 29 {
RichardE 7:e72691603fd3 30 // Wrap around animation index.
RichardE 7:e72691603fd3 31 nextAnimationIndex %= Animations::HumanAnimationCount;
RichardE 7:e72691603fd3 32 // Initialise horizontal and vertical speeds.
RichardE 7:e72691603fd3 33 Walker::InitialiseVelocities( &hSpeed, &vSpeed );
RichardE 7:e72691603fd3 34 // Movement is always restricted (property of GameObject).
RichardE 7:e72691603fd3 35 MovementRestricted = true;
RichardE 7:e72691603fd3 36 // Restrict to boundary of arena.
RichardE 7:e72691603fd3 37 Bounds = &ArenaRectangle;
RichardE 7:e72691603fd3 38 }
RichardE 7:e72691603fd3 39
RichardE 7:e72691603fd3 40 /**************/
RichardE 7:e72691603fd3 41 /* DESTRUCTOR */
RichardE 7:e72691603fd3 42 /**************/
RichardE 7:e72691603fd3 43 HumanObject::~HumanObject() {
RichardE 7:e72691603fd3 44 }
RichardE 7:e72691603fd3 45
RichardE 7:e72691603fd3 46 /*****************************/
RichardE 7:e72691603fd3 47 /* GET TYPE OF HUMAN THIS IS */
RichardE 7:e72691603fd3 48 /*****************************/
RichardE 7:e72691603fd3 49 // Returns type of human.
RichardE 7:e72691603fd3 50 HumanObject::HumanType HumanObject::GetHumanType( void ) {
RichardE 7:e72691603fd3 51 return ( animationData == Animations::WomanAnimation ) ? Woman : Man;
RichardE 7:e72691603fd3 52 }
RichardE 7:e72691603fd3 53
RichardE 7:e72691603fd3 54 /************************/
RichardE 7:e72691603fd3 55 /* MOVE THE GAME OBJECT */
RichardE 7:e72691603fd3 56 /************************/
RichardE 7:e72691603fd3 57 void HumanObject::ProtectedMove( void ) {
RichardE 7:e72691603fd3 58 switch( CurrentState ) {
RichardE 7:e72691603fd3 59 case WalkingAbout :
RichardE 7:e72691603fd3 60 // Make human bounce of edges of restriction area.
RichardE 7:e72691603fd3 61 Walker::Walk( &Xco, &Yco, &hSpeed, &vSpeed, RestrictionFlags );
RichardE 7:e72691603fd3 62 break;
RichardE 7:e72691603fd3 63 case Rescued :
RichardE 7:e72691603fd3 64 case Dead :
RichardE 7:e72691603fd3 65 // Count down and when count reaches zero make human invisible.
RichardE 7:e72691603fd3 66 if( countdown > 0 ) {
RichardE 7:e72691603fd3 67 countdown--;
RichardE 7:e72691603fd3 68 }
RichardE 7:e72691603fd3 69 Visible = ( countdown > 0 );
RichardE 7:e72691603fd3 70 break;
RichardE 7:e72691603fd3 71 }
RichardE 7:e72691603fd3 72 }
RichardE 7:e72691603fd3 73
RichardE 7:e72691603fd3 74 /************************/
RichardE 7:e72691603fd3 75 /* DRAW THE GAME OBJECT */
RichardE 7:e72691603fd3 76 /************************/
RichardE 7:e72691603fd3 77 // Pass pointer to a Gameduino to draw on in gd.
RichardE 7:e72691603fd3 78 // This is only called after it has been established that the
RichardE 7:e72691603fd3 79 // game object is visible.
RichardE 7:e72691603fd3 80 void HumanObject::Draw( Gameduino *gd ) {
RichardE 7:e72691603fd3 81 switch( CurrentState ) {
RichardE 7:e72691603fd3 82 case WalkingAbout :
RichardE 7:e72691603fd3 83 Walker::Draw( gd, SpriteNumber, Xco, Yco, hSpeed, FrameCounter >> 3, animationData );
RichardE 7:e72691603fd3 84 break;
RichardE 7:e72691603fd3 85 case Rescued :
RichardE 7:e72691603fd3 86 gd->sprite( SpriteNumber, ToPixel( Xco ), ToPixel( Yco ), FiftyImage, 0, Gameduino::None, GoodGuy );
RichardE 7:e72691603fd3 87 break;
RichardE 7:e72691603fd3 88 case Dead :
RichardE 7:e72691603fd3 89 gd->sprite( SpriteNumber, ToPixel( Xco ), ToPixel( Yco ), SkullImage, 0, Gameduino::None, GoodGuy );
RichardE 7:e72691603fd3 90 break;
RichardE 7:e72691603fd3 91 }
RichardE 7:e72691603fd3 92 }