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: GameEngine/GameEngine.cpp
- Revision:
- 41:5959256f4aab
- Parent:
- 40:71f947254fda
- Child:
- 42:3aed75338272
diff -r 71f947254fda -r 5959256f4aab GameEngine/GameEngine.cpp
--- a/GameEngine/GameEngine.cpp Sun May 17 21:12:34 2020 +0000
+++ b/GameEngine/GameEngine.cpp Sun May 17 23:40:34 2020 +0000
@@ -31,21 +31,78 @@
points = 0;
smart_bomb_timer = 0;
bullet_timer = 0;
+ current_menu_part_= menu.get_current_menu_part();
}
void GameEngine::gameplay_loop() {
+
// clear screen and set contrast
lcd.setContrast(pad.read_pot1());
lcd.clear();
- read_joystick_direction();
- menu.menu_scroll(pad, d_);
- menu.draw_part(lcd);
+ // creat objects
+ create_weapons_bullets();
+ create_weapons_smart_bomb();
+ spawn_aliens();
+ spawn_people();
+
+ //If spaceship is destroyed stop joystick input, dont draw spaceship sprite
+ if (!spaceship_destroyed){
+ read_joystick_direction();
+ spaceship.movement(d_);
+ spaceship.draw(lcd);
+ }
+
+ // Draws objects
+ map.draw_map(lcd, d_);
+ draw_aliens();
+ draw_bullets();
+ draw_explosions();
+ draw_people();
+ hud.draw_HUD(lcd, spaceship_lives, points, smart_bomb_counter);
+ spaceship_lives_leds();
+
+ reset_map_timer();
// refresh's screen
lcd.refresh();
}
+// Menu Control-----------------------------------------------------------------
+void GameEngine::game_select_part(){
+ switch (current_menu_part_) {
+ case main_menu: run_menu(); break;
+ case play: run_play(); break;
+ case settings: run_settings(); break;
+ case saved_games: run_saved_games(); break;
+ }
+}
+
+void GameEngine::run_menu(){
+ lcd.setContrast(pad.read_pot1());
+ lcd.clear();
+
+ // Scrolls, draws and selcts menu parts
+ read_joystick_direction();
+ menu.menu_scroll(pad, d_);
+ menu.draw_part(lcd);
+ menu.select_part(lcd, pad);
+
+ lcd.refresh();
+}
+
+void GameEngine::run_play(){
+ gameplay_loop();
+}
+
+void GameEngine::run_settings(){
+
+}
+
+void GameEngine::run_saved_games(){
+
+}
+
//Spaceship control ------------------------------------------------------------
void GameEngine::read_joystick_direction(){