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
main.cpp
- Committer:
- Dogstopper
- Date:
- 2016-03-12
- Revision:
- 3:27889fffc2f7
- Parent:
- 2:623f29bad35c
- Child:
- 4:5c7d990d79ac
File content as of revision 3:27889fffc2f7:
#include "mbed.h" #include "InputHandler.h" #include "Invader.h" #include "Player.h" #include "SDFileSystem.h" #include <wave_player.h> #include <vector> #define SIGNAL_KILL 200 #define WIDTH 128 #define HEIGHT 128 #define NUM_INVADERS 2 DigitalOut led(LED1); AnalogOut DACout(p18); SDFileSystem sd(p5, p6, p7, p8, "sd"); // the pinout on the mbed Cool Components workshop board void updatePlayer(const void* player) { while(true) { Player *p = (Player*)player; p->update(WIDTH, HEIGHT); Thread::wait(30); } } void updateInvader(const void* invaders) { std::vector<Invader*> invaderVector = *((std::vector<Invader*>*)invaders); while(true) { for (std::vector<Invader*>::iterator it = invaderVector.begin(); it != invaderVector.end(); ++it) { (*it)->update(); } Thread::wait(30); } } FILE *wave_file; void playBackgroundMusic(const void* waver) { wave_player* playMe = (wave_player*)waver; playMe->play(wave_file); Thread::wait(50); } 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); bool alive = false; while(true) { if (!alive) { // Display the starting image while(!input.getPushed()) {} alive = true; } Thread* playerThread = new Thread(updatePlayer, &player); Thread* invaderThread = new Thread(updateInvader, &invaders); while (alive) { player.draw(); for (std::vector<Invader*>::iterator it = invaders.begin(); it != invaders.end(); ++it) { (*it)->draw(); alive = !(*it)->intersects(player.getX(), player.getY(), player.getWidth(), player.getHeight()); led = alive; } wait_ms(32); } playerThread->terminate(); invaderThread->terminate(); wavplayerThread->terminate(); wave_file=fopen("/sd/blowup.wav","r"); waver.play(wave_file); } }