Revenge of the Mouse

Dependencies:   4DGL-uLCD-SE EthernetInterface Game_Synchronizer LCD_fonts MMA8452 SDFileSystem mbed-rtos mbed wave_player

Fork of 2035_Tanks_Shell by ECE2035 Spring 2015 TA

Files at this revision

API Documentation at this revision

Comitter:
jford38
Date:
Thu Oct 29 02:21:11 2015 +0000
Parent:
19:7aa3af04d6a8
Child:
21:edfeb289b21f
Commit message:
Updated to use separate functions to get button data and accelerometer data separately.

Changed in this revision

Bullet/bullet.cpp Show annotated file Show diff for this revision Revisions of this file
Game_Synchronizer.lib Show annotated file Show diff for this revision Revisions of this file
Tank/tank.cpp Show annotated file Show diff for this revision Revisions of this file
globals/globals.cpp Show diff for this revision Revisions of this file
globals/globals.h Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
misc/misc.cpp Show annotated file Show diff for this revision Revisions of this file
misc/misc.h Show annotated file Show diff for this revision Revisions of this file
--- a/Bullet/bullet.cpp	Wed Oct 28 08:40:55 2015 +0000
+++ b/Bullet/bullet.cpp	Thu Oct 29 02:21:11 2015 +0000
@@ -1,7 +1,7 @@
 #include "uLCD_4DGL.h"
 #include "bullet.h"
 #include "game_synchronizer.h"
-#include "globals.h"
+#include "misc.h"
 #include "math.h"
 
 extern Game_Synchronizer sync;
--- a/Game_Synchronizer.lib	Wed Oct 28 08:40:55 2015 +0000
+++ b/Game_Synchronizer.lib	Thu Oct 29 02:21:11 2015 +0000
@@ -1,1 +1,1 @@
-http://developer.mbed.org/teams/ECE2035-Spring-2015-TA/code/Game_Synchronizer/#8cad51d2f763
+http://developer.mbed.org/teams/ECE2035-Spring-2015-TA/code/Game_Synchronizer/#5807272c35b5
--- a/Tank/tank.cpp	Wed Oct 28 08:40:55 2015 +0000
+++ b/Tank/tank.cpp	Thu Oct 29 02:21:11 2015 +0000
@@ -5,7 +5,10 @@
 
 extern Game_Synchronizer sync;
 
-
+// sx is the x-coord of the bottom left corner of the tank
+// sy is the y-coord of the same corner
+// width is the width of the tank
+// height is the height of the tank
 Tank::Tank(int sx, int sy, int width, int height, int color) {
     x = sx; y = sy;
     w = width; h = height;
--- a/globals/globals.cpp	Wed Oct 28 08:40:55 2015 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,13 +0,0 @@
-#include "globals.h"
-
-int CONVERT_24_TO_16_BPP(int col_24) {
-    int b = col_24 & 0xFF;
-    int g = (col_24 >> 8) & 0xFF;
-    int r = (col_24 >> 16)& 0xFF;
-    
-    r >>= 3;
-    g >>= 2;
-    b >>= 3;
-    
-    return r<<11 | g<<5 | b;
-}
\ No newline at end of file
--- a/globals/globals.h	Wed Oct 28 08:40:55 2015 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,25 +0,0 @@
-#ifndef GLOBAL_H__
-#define GLOBAL_H__
-
-#define SKY_COLOR  0x7EC0EE
-#define GND_COLOR  0x66CD00
-#define TANK_RED   0xCD0000
-#define TANK_BLUE  0x000080
-
-#define U_BUTTON 0
-#define R_BUTTON 1
-#define D_BUTTON 2
-#define L_BUTTON 3
-
-#define TURN_P1 0
-#define TURN_P2 1
-
-
-
-#define ACC_THRESHOLD 0.25
-
-#define PI  3.1415926535797
-
-int CONVERT_24_TO_16_BPP(int col_24);
-
-#endif //GLOBAL_H__
\ No newline at end of file
--- a/main.cpp	Wed Oct 28 08:40:55 2015 +0000
+++ b/main.cpp	Thu Oct 29 02:21:11 2015 +0000
@@ -7,7 +7,7 @@
 #include "game_synchronizer.h"
 #include "tank.h"
 #include "bullet.h"
-#include "globals.h"
+#include "misc.h"
 
 
 DigitalOut led1(LED1);
@@ -29,9 +29,12 @@
 Game_Synchronizer sync(PLAYER1);            // Game_Synchronizer (PLAYER)
 Timer frame_timer;                          // Timer
 
+// Global variables go here.
 int winner = -1;
 int whose_turn = PLAYER1;
 
+
+
 // Ask the user whether to run the game in Single- or Multi-Player mode.
 // Note that this function uses uLCD instead of sync because it is only 
 // writing to the local (Player1) lcd. Sync hasn't been initialized yet,
@@ -84,7 +87,9 @@
     // Before you write text on the screens, tell the LCD where to put it.
     sync.locate(0,15);
     
+    // Set the text background color to match the sky. Just for looks.
     sync.textbackground_color(SKY_COLOR);
+    // Display the game title.
     char title[] = "  ECE 2035 Tanks";
     sync.puts(title, sizeof(title));
     sync.update();
@@ -126,8 +131,12 @@
 }
 
 int main (void) {
-    int* p1_inputs;
-    int* p2_inputs;
+    
+    int* p1_buttons;
+    int* p2_buttons;
+    
+    float ax1, ay1, az1;
+    float ax2, ay2, az2;
     
     game_init();
     
@@ -138,28 +147,21 @@
     
     
     frame_timer.start();
-    while(1) {
+    while(true) {
         
         sync.set_p1_inputs();
         
-        p1_inputs = sync.get_p1_inputs();
-        p2_inputs = sync.get_p2_inputs();
-        
-        
-        led1 = p2_inputs[0] ^ p1_inputs[0];
-        led2 = p2_inputs[1] ^ p1_inputs[1];
-        led3 = p2_inputs[2] ^ p1_inputs[2];
-        led4 = p2_inputs[3] ^ p1_inputs[3];
+        p1_buttons = sync.get_p1_buttons();
+        p2_buttons = sync.get_p2_buttons();
+
+        sync.get_p1_accel_data(ax1, ay1, az1);
+        sync.get_p1_accel_data(ax2, ay2, az2);
         
-        float ax1 = (float) p1_inputs[4] / 65536.0;
-        float ay1 = (float) p1_inputs[5] / 65536.0;
-        float az1 = (float) p1_inputs[6] / 65536.0;
-        //pc.printf("P1 X: %f\tY: %f\tZ: %f\n", ax1, ay1, az1);
-        
-        float ax2 = (float) p2_inputs[4] / 65536.0;
-        float ay2 = (float) p2_inputs[5] / 65536.0;
-        float az2 = (float) p2_inputs[6] / 65536.0;
-        //pc.printf("P2 X: %f\tY: %f\tZ: %f\n", ax2, ay2, az2);
+        led1 = p2_buttons[0] ^ p2_buttons[0];
+        led2 = p2_buttons[1] ^ p2_buttons[1];
+        led3 = p2_buttons[2] ^ p2_buttons[2];
+        led4 = p2_buttons[3] ^ p2_buttons[3];
+
         
         if(whose_turn == PLAYER1) {
             if(ax1 >  ACC_THRESHOLD) { t1.reposition(-1, 0, 0); }
@@ -168,12 +170,12 @@
             if(ay1 >  ACC_THRESHOLD) { t1.reposition(0, 0, +PI/30.0); }
             if(ay1 < -ACC_THRESHOLD) { t1.reposition(0, 0, -PI/30.0); }
             
-            if(p1_inputs[D_BUTTON]) { 
+            if(p1_buttons[D_BUTTON]) { 
                 b1.shoot(); 
             }
             
-            float time = frame_timer.read();
-            int pix_color = b1.time_step(time);
+            float dt = frame_timer.read();
+            int pix_color = b1.time_step(dt);
             if(pix_color != CONVERT_24_TO_16_BPP(SKY_COLOR)) { pc.printf("Now it's P1's turn!\n"); whose_turn = PLAYER2; }
             if(pix_color == CONVERT_24_TO_16_BPP(t1.tank_color) || pix_color == CONVERT_24_TO_16_BPP(t2.tank_color)) { 
                 sync.update();
@@ -195,12 +197,12 @@
             if((sync.play_mode == MULTI_PLAYER && ay2 < -ACC_THRESHOLD) || (sync.play_mode == SINGLE_PLAYER && ay1 < -ACC_THRESHOLD)) { 
                 t2.reposition(0, 0, +PI/30.0);
             }
-            if((sync.play_mode == MULTI_PLAYER && p2_inputs[D_BUTTON]) || (sync.play_mode == SINGLE_PLAYER && p1_inputs[D_BUTTON])) { 
+            if((sync.play_mode == MULTI_PLAYER && p2_buttons[D_BUTTON]) || (sync.play_mode == SINGLE_PLAYER && p1_buttons[D_BUTTON])) { 
                 b2.shoot(); 
             }
                 
-            float time = frame_timer.read();
-            int pix_color = b2.time_step(time);
+            float dt = frame_timer.read();
+            int pix_color = b2.time_step(dt);
             if(pix_color != CONVERT_24_TO_16_BPP(SKY_COLOR)) { pc.printf("Now it's P1's turn!\n"); whose_turn = PLAYER1; }
             if(pix_color == CONVERT_24_TO_16_BPP(t1.tank_color) || pix_color == CONVERT_24_TO_16_BPP(t2.tank_color)) { 
                 sync.update();
@@ -214,7 +216,7 @@
         sync.update();
     } 
     
-    playSound("/sd/BUZZER.wav");
+    playSound("/sd/wavfiles/BUZZER.wav");
         
     // This dies after a while, and I have NO IDEA WHY.
     int i = 0;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/misc/misc.cpp	Thu Oct 29 02:21:11 2015 +0000
@@ -0,0 +1,13 @@
+#include "misc.h"
+
+int CONVERT_24_TO_16_BPP(int col_24) {
+    int b = col_24 & 0xFF;
+    int g = (col_24 >> 8) & 0xFF;
+    int r = (col_24 >> 16)& 0xFF;
+    
+    r >>= 3;
+    g >>= 2;
+    b >>= 3;
+    
+    return r<<11 | g<<5 | b;
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/misc/misc.h	Thu Oct 29 02:21:11 2015 +0000
@@ -0,0 +1,25 @@
+#ifndef GLOBAL_H__
+#define GLOBAL_H__
+
+#define SKY_COLOR  0x7EC0EE
+#define GND_COLOR  0x66CD00
+#define TANK_RED   0xCD0000
+#define TANK_BLUE  0x000080
+
+#define U_BUTTON 0
+#define R_BUTTON 1
+#define D_BUTTON 2
+#define L_BUTTON 3
+
+#define TURN_P1 0
+#define TURN_P2 1
+
+
+
+#define ACC_THRESHOLD 0.25
+
+#define PI  3.1415926535797
+
+int CONVERT_24_TO_16_BPP(int col_24);
+
+#endif //GLOBAL_H__
\ No newline at end of file