Silvan Li
/
mbedKart_sp
(notes)
Diff: main.cpp
- Revision:
- 8:92bf0cc337b5
- Parent:
- 7:ee46a1d4227b
- Child:
- 9:6649141315be
--- a/main.cpp Mon Dec 10 01:46:53 2018 +0000 +++ b/main.cpp Mon Dec 10 02:35:13 2018 +0000 @@ -21,10 +21,42 @@ bool collide = false; // Global game actions -bool game_paused = false; -void pause_game() { - game_paused = !game_paused; - // code to tell other mbeds game is paused +bool paused = false; +void check_unpause() { + char bnum=0; + char bhit=0; + while (true) { + if (blue.getc()=='B') { //button data packet + bnum = blue.getc(); //button number + bhit = blue.getc(); //1=hit, 0=release + if (blue.getc()==char(~('!' + 'B' + bnum + bhit))) { //checksum OK? + if (bnum == '1') { //number button 1, pause + if (bhit=='1') paused = false; + } + } + } + } +} + +void game_paused() { + // Cycle through LEDs + Thread pause_thread; + pause_thread.start(check_unpause); + while (paused) { + int num = 1; + for (int i = 0; i < 3; i++) { + num *= 2; + myled = num; + ThisThread::sleep_for(100); + } + ThisThread::sleep_for(500); + for (int i = 3; i > 0; i--) { + num /= 2; + myled = num; + ThisThread::sleep_for(100); + } + ThisThread::sleep_for(500); + } } // Thread for detecting item boxes @@ -98,12 +130,13 @@ case '1': //number button 1, pause if (bhit=='1') { //myled = bnum - '0'; //current button number will appear on LEDs - //pause_game(); + paused = true; + game_paused(); } break; case '2': //number button 2, accelerate if (bhit=='1') { - //myled = bnum - '0'; //current button number will appear on LEDs + myled = bnum - '0'; //current button number will appear on LEDs left.speed(1.0); right.speed(1.0); } else { @@ -138,7 +171,7 @@ break; case '6': //button 6 down arrow if (bhit=='1') { - //myled = bnum - '0'; //current button number will appear on LEDs + myled = bnum - '0'; //current button number will appear on LEDs left.speed(-1.0); right.speed(-1.0); } else {