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:
Fri Oct 23 03:33:35 2015 +0000
Parent:
9:ee330b1ba394
Child:
11:f455e907baba
Commit message:
Draws tanks! And terrain and junk. Idk. I'm tired.

Changed in this revision

Game_Synchronizer.lib Show annotated file Show diff for this revision Revisions of this file
globals.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
map/map.cpp Show annotated file Show diff for this revision Revisions of this file
map/map.h Show annotated file Show diff for this revision Revisions of this file
--- a/Game_Synchronizer.lib	Thu Oct 22 21:34:00 2015 +0000
+++ b/Game_Synchronizer.lib	Fri Oct 23 03:33:35 2015 +0000
@@ -1,1 +1,1 @@
-http://developer.mbed.org/teams/ECE2035-Spring-2015-TA/code/Game_Synchronizer/#0d1343bfbfda
+http://developer.mbed.org/teams/ECE2035-Spring-2015-TA/code/Game_Synchronizer/#b1fcf9bddc40
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/globals.h	Fri Oct 23 03:33:35 2015 +0000
@@ -0,0 +1,25 @@
+#ifndef GLOBAL_H
+#define GLOBAL_H
+
+#ifndef ULCD_4DGL_H_
+#define ULCD_4DGL_H_
+#include "uLCD_4DGL.h"
+#endif
+
+// === [global object] ===
+extern uLCD_4DGL uLCD;
+
+
+// === [global settings] ===
+#define BACKGROUND_COLOR 0x000000
+#define GRID_RADIUS 3
+//I changed this
+#define GRID_SIZE 8     //(GRID_RADIUS*2+1)
+#define NUM_GRID_X 15
+#define NUM_GRID_Y 14
+#define NUM_GRID 210    //(NUM_GRID_X*NUM_GRID_Y)
+//end of change
+
+
+
+#endif //GLOBAL_H
\ No newline at end of file
--- a/main.cpp	Thu Oct 22 21:34:00 2015 +0000
+++ b/main.cpp	Fri Oct 23 03:33:35 2015 +0000
@@ -2,6 +2,13 @@
 
 #include "mbed.h"
 #include "game_synchronizer.h"
+#include "math.h"
+
+#define SKY_COLOR  0x7EC0EE
+#define GND_COLOR  0x66CD00
+#define TANK_RED   0xCD0000
+#define TANK_BLUE  0x000080
+#define PI  3.1415926535797
 
 DigitalOut led1(LED1);
 DigitalOut led2(LED2);
@@ -13,6 +20,7 @@
 DigitalIn pb_u(p22);  // up button
 DigitalIn pb_d(p23);  // down button
 
+
 uLCD_4DGL uLCD(p9,p10,p11); // LCD (serial tx, serial rx, reset pin;)
 Game_Synchronizer sync(PLAYER1); // (tx, rx, rst, player mode)
 
@@ -24,6 +32,7 @@
     
     // Figure out what mode the game will be run in.
     
+    uLCD.current_orientation = IS_LANDSCAPE;
     uLCD.locate(0,1);
     uLCD.puts("Select Mode:");
     uLCD.locate(0,3);
@@ -42,6 +51,52 @@
     }
 }
 
+void map_init() {
+    sync.background_color(SKY_COLOR);
+    sync.cls();
+    sync.filled_rectangle(0,0,128,20, GND_COLOR);
+    sync.filled_rectangle(59, 20, 69, 60, BLACK);
+    sync.update();
+}
+
+class Tank {
+    public:
+        int x, y;
+        int w;
+        int h;
+        int tank_color;
+        float barrel_theta;
+        int barrel_length;
+        int wheel_rad;
+        
+        Tank(int sx, int sy, int width, int height, int color) {
+            x = sx; y = sy;
+            w = width; h = height;
+            tank_color = color;
+            barrel_theta = PI/4.0;
+            barrel_length = w;
+            wheel_rad = 2.0;
+            draw();
+        }
+        int min_x(void) { return x; }
+        int min_y(void) { return y; }
+        int max_x(void) { return x + w; }
+        int max_y(void) { return y + h + wheel_rad + ceil(barrel_length*sin(barrel_theta)); }
+        
+        void reposition(int new_x, int new_y, int new_theta) {
+            sync.filled_rectangle(min_x(), min_y(), max_x(), max_y(), SKY_COLOR);
+            sync.line(x + w/2.0, y+h+wheel_rad, x + w/2.0 + barrel_length*cos(barrel_theta), y+h + barrel_length*sin(barrel_theta), SKY_COLOR);
+            x = new_x; y = new_y; barrel_theta = new_theta;
+            draw();
+        }
+        void draw() {
+            sync.line(x + w/2.0, y+h+wheel_rad, x + w/2.0 + barrel_length*cos(barrel_theta), y+h+wheel_rad + barrel_length*sin(barrel_theta), BLACK);
+            sync.filled_rectangle(x, y+wheel_rad, x+w, y+h+wheel_rad, tank_color);
+            sync.filled_circle(x+wheel_rad, y+wheel_rad, wheel_rad, BLACK);
+            sync.filled_circle(x+w-wheel_rad, y+wheel_rad, wheel_rad, BLACK);
+        }
+};
+
 void game_init(void) {
     
     led1 = 0; led2 = 0; led3 = 0; led4 = 0;
@@ -55,7 +110,7 @@
     pc.printf("I'm alive! Player 1\n");         // Let us know you made it this far.
     int mode = game_menu();
     sync.init(&uLCD, mode);                     // Connect to the other player.
-    //sync.cls();
+    map_init();
     pc.printf("Initialized...\n");              // Let us know you finished initializing.
 }
 
@@ -64,30 +119,11 @@
     
     game_init();
     
-    float theta = 0;
-    bool first = true;
+    Tank t1(4, 20, 12, 8, TANK_RED);
+    Tank t2(111, 20, 12, 8, TANK_BLUE);
     
     while(1) {
-        
-        char howdy[] = "Howdy!";
-        if(first) {
-            sync.background_color(BLUE);
-            sync.cls();
-            
-            sync.locate(5,0);
-            sync.puts(howdy, sizeof(howdy));
-            first = false;
-        }
-        sync.line(64,64,64+50*cos(theta),64+50*sin(theta), BLUE);
-        theta += 0.05;
-        sync.line(64,64,64+50*cos(theta),64+50*sin(theta), RED);
-        sync.circle(10,10,100, GREEN);
-        sync.filled_circle(4,4,10, RED);
-        sync.triangle(10,10, 20,20, 20,40, RED);
-        sync.rectangle(100,100, 90,90, GREEN);
-        sync.filled_rectangle(100,100, 110,110, RED);
-        sync.pixel(40, 40, WHITE);
-        
+        sync.line(0,0, 5,5, BLACK);
         sync.update();
         
         p2_buttons = sync.get_button_state();
@@ -96,8 +132,5 @@
         led2 = p2_buttons[1] ^ !pb_r;
         led3 = p2_buttons[2] ^ !pb_d;
         led4 = p2_buttons[3] ^ !pb_l;
-        
-        //pc.printf("Button State: %x %x %x %x %x\n", buttons[0], buttons[1], buttons[2], buttons[3], buttons[4]);
-        //pc.printf("\033[2J\033[0;0H");
     } 
 }
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/map/map.h	Fri Oct 23 03:33:35 2015 +0000
@@ -0,0 +1,24 @@
+#ifndef MAP_H__
+#define MAP_H__
+
+#define MAP_WIDTH  128
+#define MAP_HEIGHT 128
+
+#define GROUND_VAL   0
+#define SKY_VAL      1
+#define OBSTACLE_VAL 2
+
+int terrain[MAP_WIDTH][MAP_HEIGHT];
+
+void map_init() {
+    for(int x = 0; x < MAP_WIDTH; x++) {
+        for(int y = 0; y < MAP_HEIGHT; y++) {
+           if(x < 20) {terrain[x][y] = GROUND_VAL; }
+           else if( 50 < y && 78 > y) { terrain[x][y] = OBSTACLE_VAL; }
+        }
+    }
+}
+
+
+
+#endif
\ No newline at end of file