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.
Diff: main.cpp
- Revision:
- 8:21b6d4dbce44
- Parent:
- 7:68e06dda79f7
- Child:
- 9:96969b1c6bde
--- a/main.cpp Wed Apr 17 12:39:46 2019 +0000 +++ b/main.cpp Fri Apr 19 17:54:09 2019 +0000 @@ -20,8 +20,10 @@ #include "Game.h" #include "Music.h" #include "SoundData.h" - -Timer processedTime; +#include "SplashScreen.h" +#include "MenuScreen.h" +Timer game_timer; +Timer music_timer; ////// Constants ////// @@ -44,27 +46,26 @@ void init() { - - // need to initialise LCD and Gamepad + + // need to initialise LCD and Gamepad lcd.init(); lcd.setContrast(0.4); pad.init(); - processedTime.reset(); + play.init(data1,NUM_ELEMENTS); game.init(); - play.init(data1,NUM_ELEMENTS); - + } // simple splash screen displayed on start-up -void welcome() { - - - lcd.printString(" WOo2 ",0,1); - lcd.printString(" Press Start ",0,4); +void welcome() +{ + + + lcd.drawSprite(0,0,48,84, (int *) splashScreen); lcd.refresh(); - - // wait flashing LEDs until start button is pressed + + // wait flashing LEDs until start button is pressed while ( pad.check_event(Gamepad::START_PRESSED) == false) { pad.leds_on(); wait(0.1); @@ -75,40 +76,73 @@ } -int tick = 0.000125; +void how_to_play() +{ + + +} + +void menu() +{ + int menu_option = 1; + + + while ( !pad.check_event(Gamepad::A_PRESSED) ) { + + if (pad.get_coord().y> 0.7f) { + menu_option = 1; + } + if (pad.get_coord().y < -0.7f) { + menu_option = 0; + } + lcd.drawSprite(0,0,48,84, (int *) menuScreen); + if (menu_option == 1) { + lcd.drawSprite(40,10,7,4, (int *) arrow); + } else { + lcd.drawSprite(40,25,7,4, (int *) arrow); + } + lcd.refresh(); + + } + if (menu_option == 1) { + how_to_play(); + } +} + int main() { - - + init(); // initialise and then display welcome screen... welcome(); // waiting for the user to start - lcd.clear(); - lcd.refresh(); - printf("MAIN\n"); - - + menu(); // main menu // game loop - read input, update the game state and render the display game.init(); - while (1) { - processedTime.start(); - printf("TIME: %i\n",processedTime.read_ms()); + + game_timer.reset(); + music_timer.reset(); + game_timer.start(); + music_timer.start(); - - game.read_input(pad); - game.update(pad); - game.draw(lcd); - wait(0.1); - - -// if (processedTime.read_us() > 125) { -// player.play_next(); -// processedTime.reset(); -// } + const int MUSIC_TICK_TIME = 100; //125 microseconds + const int GAME_TICK_TIME = 100; // 100 millieconds + + while (1) { + if (game_timer.read_ms() > GAME_TICK_TIME) { + game.read_input(pad); + game.update(pad); + game.draw(lcd); + game_timer.reset(); + } - + if (music_timer.read_us() > MUSIC_TICK_TIME) { + play.play_next(); + music_timer.reset(); + } - } -} \ No newline at end of file + + + } + } \ No newline at end of file