Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: 4DGL-uLCD-SE LSM9DS1_Library SDFileSystem mbed-rtos mbed wave_player
Diff: main.cpp
- Revision:
- 4:5c7d990d79ac
- Parent:
- 3:27889fffc2f7
diff -r 27889fffc2f7 -r 5c7d990d79ac main.cpp --- a/main.cpp Sat Mar 12 19:59:00 2016 +0000 +++ b/main.cpp Mon Mar 14 18:53:11 2016 +0000 @@ -23,7 +23,7 @@ while(true) { Player *p = (Player*)player; p->update(WIDTH, HEIGHT); - Thread::wait(30); + Thread::wait(45); } } @@ -33,7 +33,7 @@ for (std::vector<Invader*>::iterator it = invaderVector.begin(); it != invaderVector.end(); ++it) { (*it)->update(); } - Thread::wait(30); + Thread::wait(45); } } @@ -48,44 +48,55 @@ int main() { InputHandler input(p9, p10, 0xD6, 0x3C, p15); uLCD_4DGL uLCD(p28,p27,p30); // serial tx, serial rx, reset pin; - - Player player(&uLCD, &input, WIDTH/2, HEIGHT/2); - - std::vector<Invader *> invaders; - for (int i = 0; i < NUM_INVADERS; i++) { - invaders.push_back(new Invader(&uLCD, WIDTH, HEIGHT)); - } wave_player waver(&DACout); wave_file=fopen("/sd/beethoven.wav","r"); Thread* inputThread = input.start(); - Thread* wavplayerThread = new Thread(playBackgroundMusic, &waver); uLCD.background_color(BLACK); + uLCD.baudrate(300000); bool alive = false; while(true) { - if (!alive) { - // Display the starting image - while(!input.getPushed()) {} - alive = true; + uLCD.media_init(); + uLCD.set_sector_address(0x003B, 0x5001); + uLCD.display_image(0,0); + while(!input.getPushed()) {} + + Player player(&uLCD, &input, WIDTH/2, HEIGHT/2); + + std::vector<Invader *> invaders; + for (int i = 0; i < NUM_INVADERS; i++) { + invaders.push_back(new Invader(&uLCD, WIDTH, HEIGHT)); } + + alive = true; + uLCD.cls(); + uLCD.background_color(BLACK); + + // Start the music and the two updater threads (different speeds) Thread* playerThread = new Thread(updatePlayer, &player); Thread* invaderThread = new Thread(updateInvader, &invaders); + Thread* wavplayerThread = new Thread(playBackgroundMusic, &waver); + while (alive) { player.draw(); + int count = 1; for (std::vector<Invader*>::iterator it = invaders.begin(); it != invaders.end(); ++it) { + printf("count: %d", count); (*it)->draw(); alive = !(*it)->intersects(player.getX(), player.getY(), player.getWidth(), player.getHeight()); led = alive; + count++; } - wait_ms(32); + wait_ms(40); } + uLCD.locate(2, 2); + uLCD.printf("GAME OVER! >:)"); + playerThread->terminate(); invaderThread->terminate(); - wavplayerThread->terminate(); - - wave_file=fopen("/sd/blowup.wav","r"); - waver.play(wave_file); + wait_ms(5000); + break; } }