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:
- 8:27c4345be3db
- Parent:
- 7:9a826617be92
- Child:
- 9:c22613b0007a
--- a/main.cpp Fri Apr 16 17:27:30 2021 +0000 +++ b/main.cpp Fri Apr 16 17:28:52 2021 +0000 @@ -111,7 +111,7 @@ volatile int numWins = 0; volatile bool two_player_win = false; volatile bool two_player_lose = false; -Mutex mbed; +Mutex mbedLock; // Initialize global player object player_t player; @@ -459,9 +459,9 @@ while(numPlayers == 1) Thread::yield(); // with one player, thread is unneeded and should yield. while(!first_player_ready || !second_player_ready) { // while either player isn't ready, send a start code, and become ready //if (!first_player_ready || !second_player_ready) { - mbed.lock(); + mbedLock.lock(); secondMbed.putc('S'); - mbed.unlock(); + mbedLock.unlock(); first_player_ready = true; //pc.printf("first player ready"); Thread::wait(1000); @@ -475,9 +475,9 @@ // Thread::wait(1000); // run once a second } if (two_player_win) { // if this player wins, notify the other mbed/player that they lost. - mbed.lock(); + mbedLock.lock(); secondMbed.putc('W'); - mbed.unlock(); + mbedLock.unlock(); } //if (secondMbed.readable()) { // if (secondMbed.getc() == 'W') { @@ -491,14 +491,14 @@ void mbedReceive(void const *args) { char rx; while(1) { - mbed.lock(); + mbedLock.lock(); while(numPlayers == 1 || !secondMbed.readable()) { mbed.unlock(); //pc.printf("yielding"); Thread::yield(); // with one player, thread is unneeded and should yield. } rx = secondMbed.getc(); - mbed.unlock(); + mbedLock.unlock(); if (rx == 'S') { second_player_ready = true; //pc.printf("second play ready");