The classic dueling tanks game for mbed.
Dependencies: 4DGL-uLCD-SE DRV2605 EthernetInterface Game_Synchronizer MMA8452 SDFileSystem SparkfunAnalogJoystick mbed-rtos mbed wave_player
Fork of 2035_Tanks_Shell by
Diff: main.cpp
- Revision:
- 6:3be57cf4bd33
- Parent:
- 5:cfec780c935b
- Child:
- 7:9506f2d84162
--- a/main.cpp Thu Oct 15 22:07:40 2015 +0000
+++ b/main.cpp Thu Oct 22 08:02:28 2015 +0000
@@ -1,37 +1,62 @@
-// THIS GUY LISTENS AND REPEATS. CLIENT. MASTER.
-// (It doesn't make sense, I know.)
+// Student Side.
#include "mbed.h"
-#include "two_player.h"
+#include "game_synchronizer.h"
+
+DigitalOut led1(LED1);
+DigitalOut led2(LED2);
+DigitalOut led3(LED3);
+DigitalOut led4(LED4);
+DigitalIn pb_l(p24); // left button
+DigitalIn pb_r(p21); // right button
+DigitalIn pb_u(p22); // up button
+DigitalIn pb_d(p23); // down button
+
+Game_Synchronizer sync(p9,p10,p11, PLAYER1); // (tx, rx, rst, player mode)
-uLCD_2P uLCD(p28,p27,p26, PLAYER1); // serial tx, serial rx, reset pin;
+// For debug only. Don't use in production code. It will slow your game down a lot.
+Serial pc(USBTX, USBRX);
-
+void game_init(void) {
+
+ led1 = 0; led2 = 0; led3 = 0; led4 = 0;
+
+ pb_l.mode(PullUp);
+ pb_r.mode(PullUp);
+ pb_u.mode(PullUp);
+ pb_d.mode(PullUp);
+
+ pc.printf("\033[2J\033[0;0H"); // Clear the terminal screen.
+ pc.printf("I'm alive! Player 1\n"); // Let us know you made it this far.
+ sync.init(); // Connect to the other player.
+ pc.printf("Initialized...\n"); // Let us know you finished initializing.
+}
+
int main (void) {
int* buttons;
-
- pc.printf("\033[2J\033[0;0H");
- pc.printf("I'm alive! Player 1\n");
- uLCD.init();
- pc.printf("Initialized...\n");
+ game_init();
float theta = 0;
while(1) {
- uLCD.line(64,64,64+50*cos(theta),64+50*sin(theta), BLACK);
+ sync.line(64,64,64+50*cos(theta),64+50*sin(theta), BLACK);
theta += 0.05;
- uLCD.line(64,64,64+50*cos(theta),64+50*sin(theta), RED);
- uLCD.circle(10,10,100, GREEN);
- uLCD.filled_circle(4,4,10, 0xAB);
- uLCD.triangle(10,10, 20,20, 20,40, 0xAB);
- uLCD.rectangle(100,100, 90,90, GREEN);
- uLCD.filled_rectangle(100,100, 110,110, 0xAB);
- uLCD.pixel(40, 40, WHITE);
+ 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, 0xAB);
+ sync.triangle(10,10, 20,20, 20,40, 0xAB);
+ sync.rectangle(100,100, 90,90, GREEN);
+ sync.filled_rectangle(100,100, 110,110, 0xAB);
+ sync.pixel(40, 40, WHITE);
- uLCD.update();
- buttons = uLCD.get_button_state();
+ sync.update();
+ buttons = sync.get_button_state();
+ led1 = buttons[0];
+ led2 = buttons[1];
+ led3 = buttons[2];
+ led4 = buttons[3];
//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");
}
