![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
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:
- 12:22aedb2598b1
- Parent:
- 11:cdea2c9ec531
- Child:
- 13:36cc024dcf6b
--- a/main.cpp Sun Apr 18 16:04:18 2021 +0000 +++ b/main.cpp Mon Apr 19 19:35:11 2021 +0000 @@ -405,7 +405,7 @@ enemy_14.enemy_blk_y += enemy_14.enemy_height+4; enemy_15.enemy_blk_y += enemy_15.enemy_height+4; } - +/* // thread that plays sounds during game void playstart(void const *args)//Th { //Depending on the state of the game, @@ -455,6 +455,7 @@ } } } +*/ // thread that adds RGB LED Lighting Effects that coincide with the game -- Brice void ledEffects(void const *args)//Th @@ -626,14 +627,16 @@ void mbedSlave(void const *args) { char rx; while(1) { - while(numPlayers == 1) Thread::yield(); + //while(numPlayers == 1) Thread::yield(); rx = '0'; if (secondMbed.readable()) { rx = secondMbed.getc(); if (!begin_game2 && rx == 'S') { + while (!secondMbed.writeable()) wait(0.5); secondMbed.putc(rx); first_player_ready = true; second_player_ready = true; + numPlayers = 2; } else if (begin_game2 && rx == 'W') { secondMbed.putc(rx); first_player_ready = false; @@ -664,14 +667,26 @@ while(numPlayers == 1) Thread::yield(); rx = '0'; if (!begin_game2) { + while(!secondMbed.writeable()) { + pc.printf("not writeable"); + wait(0.5); + } secondMbed.putc('S'); - while(!secondMbed.readable()) wait(0.5); // okay to lock up until can confirm game is ready. --Brice + while(!secondMbed.readable()) { + pc.printf("no read\n\r"); + wait(0.5); // okay to lock up until can confirm game is ready. --Brice + } rx = secondMbed.getc(); + pc.printf("rx = %c", rx); if (rx == 'S') { first_player_ready = true; second_player_ready = true; + pc.printf("both players ready"); } - } else { + } + //} else { + while (first_player_ready && second_player_ready) { + rx = '0'; if (secondMbed.readable()) { rx = secondMbed.getc(); if (rx == 'W') { @@ -691,8 +706,9 @@ second_player_ready = false; } } + Thread::wait(1000); } - Thread::wait(1000); + //Thread::wait(1000); } } @@ -708,6 +724,7 @@ //Thread thread2(mbedSlave); // uncommented if second player -- Brice Thread thread3(mbedMaster); // uncommented if first player -- Brice Thread thread4(ledEffects); // thread added for LED lighting effects -- Brice + secondMbed.baud(9600); uLCD.baudrate(500000); // set to 500000 to increase smooth gameplay // Initialization of Game Menu variables