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
Diff: BrainObject.cpp
- Revision:
- 10:bfa1c307c99d
- Parent:
- 7:e72691603fd3
--- a/BrainObject.cpp Sun Jun 09 14:28:53 2013 +0000 +++ b/BrainObject.cpp Sun Jun 09 19:34:56 2013 +0000 @@ -15,6 +15,7 @@ #include "BulletVelocityCalculator.h" #include "HumanObject.h" #include "Random.h" +#include "EnemyFactory.h" /***************/ /* CONSTRUCTOR */ @@ -28,8 +29,6 @@ MovementRestricted = true; // Restrict to boundary of arena. Bounds = &ArenaRectangle; - // Restrict bullet to boundary of arena. - bullet.Bounds = &ArenaRectangle; } /**************/ @@ -52,30 +51,37 @@ /******************/ // Pass sprite number to use in spriteNumber. // Returns pointer to bullet object or NULL on failure. +// Memory is dynamically allocated since Brain bullet is an EnemyObject. BrainBulletObject *BrainObject::StartBullet( UInt8 spriteNumber ) { - // Give bullet same coordinates as the brain that fired it. - bullet.Xco = Xco; - bullet.Yco = Yco; - // Set correct sprite number. - bullet.SpriteNumber = spriteNumber; - // Must make it visible because last time bullet was - // killed off this property may have been set to false. - bullet.Visible = true; - // Similarly hit points may already be at zero. - // If you don't do this then bullet hit points gets decremented to -1 (0xFF) - // and it becomes indestructible. - bullet.HitPoints = 1; - // Calculate bullet velocities. - // Aim for a point somewhere in the vicinity of the chase object. - if( chaseObject != (GameObject*)NULL ) { - UInt16 targetX = chaseObject->Xco + (Int16)Random::Get( -128, +128 ); - UInt16 targetY = chaseObject->Yco + (Int16)Random::Get( -128, +128 ); - BulletVelocityCalculator::CalculateVelocities( - targetX - Xco, targetY - Yco, - 80, &bullet.HVelocity, &bullet.VVelocity - ); + // Create a new bullet. + BrainBulletObject *newBullet = (BrainBulletObject*)EnemyFactory::Instance.MakeEnemy( BrainBullet ); + if( newBullet != (BrainBulletObject*)NULL ) { + // Give bullet same coordinates as the brain that fired it. + newBullet->Xco = Xco; + newBullet->Yco = Yco; + // Restrict bullet to boundary of arena. + newBullet->Bounds = &ArenaRectangle; + // Set correct sprite number. + newBullet->SpriteNumber = spriteNumber; + // Must make it visible because last time bullet was + // killed off this property may have been set to false. + newBullet->Visible = true; + // Similarly hit points may already be at zero. + // If you don't do this then bullet hit points gets decremented to -1 (0xFF) + // and it becomes indestructible. + newBullet->HitPoints = 1; + // Calculate bullet velocities. + // Aim for a point somewhere in the vicinity of the chase object. + if( chaseObject != (GameObject*)NULL ) { + UInt16 targetX = chaseObject->Xco + (Int16)Random::Get( -128, +128 ); + UInt16 targetY = chaseObject->Yco + (Int16)Random::Get( -128, +128 ); + BulletVelocityCalculator::CalculateVelocities( + targetX - Xco, targetY - Yco, + 80, &(newBullet->HVelocity), &(newBullet->VVelocity) + ); + } } - return • + return newBullet; } /************************/