For Nikhil

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

Fork of 2035_Tanks_Shell by ECE2035 Spring 2015 TA

Committer:
jford38
Date:
Thu Oct 22 08:02:28 2015 +0000
Revision:
6:3be57cf4bd33
Parent:
5:cfec780c935b
Child:
7:9506f2d84162
Split game synchronization code into separate .h and .cpp files. Also renamed to "game_synchronizer.h" and "game_synchronizer.cpp"

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jford38 6:3be57cf4bd33 1 // Student Side.
jford38 0:899c85cd266f 2
jford38 0:899c85cd266f 3 #include "mbed.h"
jford38 6:3be57cf4bd33 4 #include "game_synchronizer.h"
jford38 6:3be57cf4bd33 5
jford38 6:3be57cf4bd33 6 DigitalOut led1(LED1);
jford38 6:3be57cf4bd33 7 DigitalOut led2(LED2);
jford38 6:3be57cf4bd33 8 DigitalOut led3(LED3);
jford38 6:3be57cf4bd33 9 DigitalOut led4(LED4);
jford38 0:899c85cd266f 10
jford38 6:3be57cf4bd33 11 DigitalIn pb_l(p24); // left button
jford38 6:3be57cf4bd33 12 DigitalIn pb_r(p21); // right button
jford38 6:3be57cf4bd33 13 DigitalIn pb_u(p22); // up button
jford38 6:3be57cf4bd33 14 DigitalIn pb_d(p23); // down button
jford38 6:3be57cf4bd33 15
jford38 6:3be57cf4bd33 16 Game_Synchronizer sync(p9,p10,p11, PLAYER1); // (tx, rx, rst, player mode)
jford38 0:899c85cd266f 17
jford38 6:3be57cf4bd33 18 // For debug only. Don't use in production code. It will slow your game down a lot.
jford38 6:3be57cf4bd33 19 Serial pc(USBTX, USBRX);
jford38 0:899c85cd266f 20
jford38 6:3be57cf4bd33 21 void game_init(void) {
jford38 6:3be57cf4bd33 22
jford38 6:3be57cf4bd33 23 led1 = 0; led2 = 0; led3 = 0; led4 = 0;
jford38 6:3be57cf4bd33 24
jford38 6:3be57cf4bd33 25 pb_l.mode(PullUp);
jford38 6:3be57cf4bd33 26 pb_r.mode(PullUp);
jford38 6:3be57cf4bd33 27 pb_u.mode(PullUp);
jford38 6:3be57cf4bd33 28 pb_d.mode(PullUp);
jford38 6:3be57cf4bd33 29
jford38 6:3be57cf4bd33 30 pc.printf("\033[2J\033[0;0H"); // Clear the terminal screen.
jford38 6:3be57cf4bd33 31 pc.printf("I'm alive! Player 1\n"); // Let us know you made it this far.
jford38 6:3be57cf4bd33 32 sync.init(); // Connect to the other player.
jford38 6:3be57cf4bd33 33 pc.printf("Initialized...\n"); // Let us know you finished initializing.
jford38 6:3be57cf4bd33 34 }
jford38 6:3be57cf4bd33 35
jford38 0:899c85cd266f 36 int main (void) {
jford38 1:0589ea36661b 37 int* buttons;
jford38 0:899c85cd266f 38
jford38 6:3be57cf4bd33 39 game_init();
jford38 5:cfec780c935b 40
jford38 5:cfec780c935b 41 float theta = 0;
jford38 0:899c85cd266f 42 while(1) {
jford38 3:3ddefff03cb2 43
jford38 6:3be57cf4bd33 44 sync.line(64,64,64+50*cos(theta),64+50*sin(theta), BLACK);
jford38 5:cfec780c935b 45 theta += 0.05;
jford38 6:3be57cf4bd33 46 sync.line(64,64,64+50*cos(theta),64+50*sin(theta), RED);
jford38 6:3be57cf4bd33 47 sync.circle(10,10,100, GREEN);
jford38 6:3be57cf4bd33 48 sync.filled_circle(4,4,10, 0xAB);
jford38 6:3be57cf4bd33 49 sync.triangle(10,10, 20,20, 20,40, 0xAB);
jford38 6:3be57cf4bd33 50 sync.rectangle(100,100, 90,90, GREEN);
jford38 6:3be57cf4bd33 51 sync.filled_rectangle(100,100, 110,110, 0xAB);
jford38 6:3be57cf4bd33 52 sync.pixel(40, 40, WHITE);
jford38 3:3ddefff03cb2 53
jford38 6:3be57cf4bd33 54 sync.update();
jford38 6:3be57cf4bd33 55 buttons = sync.get_button_state();
jford38 6:3be57cf4bd33 56 led1 = buttons[0];
jford38 6:3be57cf4bd33 57 led2 = buttons[1];
jford38 6:3be57cf4bd33 58 led3 = buttons[2];
jford38 6:3be57cf4bd33 59 led4 = buttons[3];
jford38 5:cfec780c935b 60 //pc.printf("Button State: %x %x %x %x %x\n", buttons[0], buttons[1], buttons[2], buttons[3], buttons[4]);
jford38 5:cfec780c935b 61 //pc.printf("\033[2J\033[0;0H");
jford38 3:3ddefff03cb2 62 }
jford38 0:899c85cd266f 63 }