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 : BulletVelocityCalculator.cpp
RichardE 7:e72691603fd3 3 *
RichardE 7:e72691603fd3 4 * Definition of class BulletVelocityCalculator.
RichardE 7:e72691603fd3 5 *
RichardE 7:e72691603fd3 6 */
RichardE 7:e72691603fd3 7
RichardE 7:e72691603fd3 8 #include <stdlib.h> // for abs
RichardE 7:e72691603fd3 9 #include "BulletVelocityCalculator.h"
RichardE 7:e72691603fd3 10
RichardE 7:e72691603fd3 11 // A few constants.
RichardE 7:e72691603fd3 12 #define COS11_25 0.980785
RichardE 7:e72691603fd3 13 #define SIN11_25 0.195090
RichardE 7:e72691603fd3 14 #define COS33_75 0.831470
RichardE 7:e72691603fd3 15 #define SIN33_75 0.555570
RichardE 7:e72691603fd3 16 #define COS56_25 0.555570
RichardE 7:e72691603fd3 17 #define SIN56_25 0.831470
RichardE 7:e72691603fd3 18 #define COS78_75 0.195090
RichardE 7:e72691603fd3 19 #define SIN78_75 0.980785
RichardE 7:e72691603fd3 20
RichardE 7:e72691603fd3 21 /*******************************/
RichardE 7:e72691603fd3 22 /* CALCULATE BULLET VELOCITIES */
RichardE 7:e72691603fd3 23 /*******************************/
RichardE 7:e72691603fd3 24 // Pass distances to target in dx and dy.
RichardE 7:e72691603fd3 25 // Pass velocity at which bullet moves in v.
RichardE 7:e72691603fd3 26 // Horizontal and vertical velocities returned in variables pointed to by hv and vv.
RichardE 7:e72691603fd3 27 void BulletVelocityCalculator::CalculateVelocities( Int16 dx, Int16 dy, Int16 v, Int16 *hv, Int16 *vv ) {
RichardE 7:e72691603fd3 28 Int16 ax = abs( dx );
RichardE 7:e72691603fd3 29 Int16 ay = abs( dy );
RichardE 7:e72691603fd3 30 if( ax < 8 ) {
RichardE 7:e72691603fd3 31 *hv = 0;
RichardE 7:e72691603fd3 32 *vv = v;
RichardE 7:e72691603fd3 33 }
RichardE 7:e72691603fd3 34 else if( ay < 8 ) {
RichardE 7:e72691603fd3 35 *hv = v;
RichardE 7:e72691603fd3 36 *vv = 0;
RichardE 7:e72691603fd3 37 }
RichardE 7:e72691603fd3 38 else {
RichardE 7:e72691603fd3 39 float ratio = (float)ay / (float)ax;
RichardE 7:e72691603fd3 40 if( ratio < 0.5f ) {
RichardE 7:e72691603fd3 41 *hv = v * COS11_25;
RichardE 7:e72691603fd3 42 *vv = v * SIN11_25;
RichardE 7:e72691603fd3 43 }
RichardE 7:e72691603fd3 44 else if( ratio < 1.0f ) {
RichardE 7:e72691603fd3 45 *hv = v * COS33_75;
RichardE 7:e72691603fd3 46 *vv = v * SIN33_75;
RichardE 7:e72691603fd3 47 }
RichardE 7:e72691603fd3 48 else if( ratio < 2.0f ) {
RichardE 7:e72691603fd3 49 *hv = v * COS56_25;
RichardE 7:e72691603fd3 50 *vv = v * SIN56_25;
RichardE 7:e72691603fd3 51 }
RichardE 7:e72691603fd3 52 else {
RichardE 7:e72691603fd3 53 *hv = v * COS78_75;
RichardE 7:e72691603fd3 54 *vv = v * SIN78_75;
RichardE 7:e72691603fd3 55 }
RichardE 7:e72691603fd3 56 }
RichardE 7:e72691603fd3 57 if( dx < 0 ) {
RichardE 7:e72691603fd3 58 *hv = -(*hv);
RichardE 7:e72691603fd3 59 }
RichardE 7:e72691603fd3 60 if( dy < 0 ) {
RichardE 7:e72691603fd3 61 *vv = -(*vv);
RichardE 7:e72691603fd3 62 }
RichardE 7:e72691603fd3 63 }