Updated Space Invaders on the mbed. Improved upon Michael Son's "Mbed Space Invaders" at https://os.mbed.com/users/michaeljson/notebook/mbed-space-invaders/.
Dependencies: mbed wave_player mbed-rtos 4DGL-uLCD-SE SparkfunAnalogJoystick SDFileSystem LSM9DS1_Library_cal_updated
Fork of Two-PlayerSpaceInvaders by
test
Diff: main.cpp
- Revision:
- 4:739f6e0dd8af
- Parent:
- 3:e6c081c7f6f1
- Child:
- 5:b7934866b264
diff -r e6c081c7f6f1 -r 739f6e0dd8af main.cpp --- a/main.cpp Fri Apr 16 14:49:18 2021 +0000 +++ b/main.cpp Fri Apr 16 15:22:31 2021 +0000 @@ -105,6 +105,8 @@ volatile bool begin_game = false; volatile bool gameover = false; volatile int numPlayers = 1; +volatile bool first_player_ready = false; +volatile bool second_player_ready = false; // Initialize global player object player_t player; @@ -446,8 +448,25 @@ } } -//void mbedComm(void const *args) { - +// Thread added for mbed communication, which allows two-player +void mbedComm(void const *args) { + while(1) { + while(numPlayers == 1) Thread::yield(); + while(!first_player_ready || !second_player_ready) { + //if (!first_player_ready || !second_player_ready) { + secondMbed.putc('S'); + first_player_ready = true; + //} + if (secondMbed.readable()) { + if (secondMbed.getc() == 'S') { + second_player_ready = true; + } + } + Thread::wait(1000); + } + } +} + int main() { // Initialization of Setup variables @@ -455,7 +474,7 @@ pb.mode(PullUp); Thread thread(playstart); // intializes the thread to play sound - + Thread thread2(mbedComm); // initialized thread to start mbed communication between players -- Brice uLCD.baudrate(500000); // set to 500000 to increase smooth gameplay // Initialization of Game Menu variables @@ -532,7 +551,7 @@ Thread::wait(500); // changed this to Thread::wait ... originally wait(0.5); } } - + while(numPlayers != 1 && (!first_player_ready || !second_player_ready)) Thread::yield(); // added to force wait with two-player and one player not ready. -- added by Brice begin_game = true; // defaults begin_game to true uLCD.cls();