Ben Evans University Second Year Project. Game Called Defender.
Hello, soldier, you have been specially selected as the defender of planet earth.
Your mission, if you choose to accept it. Fly around the planet and pulverise invading alien ships for as long as you can. Stop the aliens abducting the innocent people on the ground. Be warned if an alien ship manages to abduct a person and take them to top of the screen, they will no longer move randomly and will begin to hunt you down. This sounds like a challenge you were trained for.
But don’t worry soldier you’re not going into battle empty-handed. Your ship is equipped with a state of the art laser beam that has unlimited ammo and four smart bombs that will destroy anything on the screen. The ship also has three lives so use them wisely.
As time goes on more alien ships will arrive on planet earth increasing the difficulty of your mission. And remember the landscape bellow loops around so if you continually fly in the same direction you go to your original position. Good luck soldier.
Diff: GameEngine/GameEngine.cpp
- Revision:
- 84:f61c85a5f13a
- Parent:
- 82:3211b31e9421
- Child:
- 85:87bc28b151d8
--- a/GameEngine/GameEngine.cpp Mon May 25 22:18:11 2020 +0000 +++ b/GameEngine/GameEngine.cpp Tue May 26 14:39:45 2020 +0000 @@ -85,8 +85,8 @@ // printf("sound%d\n",sound_fx_ ); // Stops double button press - if(pad.A_pressed()) { - wait(0.3); + if (pad.A_pressed()) { + wait(0.3); } // Inititialise the game if play @@ -97,15 +97,34 @@ lcd.refresh(); } +void GameEngine::loading_screen(){ + lcd.clear(); + + // Draws adding dots 3 times + for(int x = 0; x <= 2; x++) { + lcd.printString("Loading",15,3); + lcd.refresh(); + + // Adds loading dots + for(int i = 0; i <= 3; i++) { + wait(0.25); + lcd.printString(".",57+(i*6),3); + lcd.refresh(); + } + lcd.clear(); + } +} // Menu Play ------------------------------------------------------------------- void GameEngine::run_play() { + loading_screen(); + // Stops melody playing pad.play_melody(2, melody_off, melody_off_note_time, 1, false); - int paused_flag = false; + bool paused_flag = false; // Main gameplay loop to run plable part of game, pause and save screens while (1) { @@ -114,31 +133,18 @@ // Resets ISR flag lcd_frame_time_flag_ = 0; - // Pause button pressed - if (pad.start_pressed() && paused_counter_ > 10 ) { - paused_flag = !paused_flag; - paused_counter_ = 0 ; - } - - // Stoped double press of pause button - paused_counter_++; - - // Draws pause screen if paused button presed - if (paused_flag) { - run_paused_game(); - - // Otherwise draw gameplay screen - }else{ - gameplay_loop(); - } + // Selects the differnt parts of the game + play_select(paused_flag); // Break out of run play loop when lives = 0 or exite flag set - if(!spaceship_lives_||exit_flag_) { - draw_game_over_screen(); + if (!spaceship_lives_||exit_flag_) { + if (!spaceship_lives_) { + draw_game_over_screen(); + } reset_map(); pad.leds_off(); break; - } + } } // MCU put to sleep between each frame to save power @@ -150,15 +156,38 @@ play_music(); } +void GameEngine::play_select(bool paused_flag){ + // Pause button pressed + if (pad.start_pressed() && paused_counter_ > 10 ) { + paused_flag = !paused_flag; + paused_counter_ = 0 ; + run_save_a_game_flag_ = false; + } + + // Stoped double press of pause button + paused_counter_++; + + // Draws pause screen if paused button presed + if (paused_flag) { + run_paused_game(); + + // Otherwise draw gameplay screen + }else{ + gameplay_loop(); + } + + +} + void GameEngine::play_music() { - if(music_fx_ == music_on) { + if (music_fx_ == music_on) { pad.play_melody(88, star_wars, star_wars_note_time, 108, true); } } void GameEngine::stop_music() { - if(music_fx_ == music_off) { + if (music_fx_ == music_off) { pad.play_melody(1, melody_off, melody_off_note_time, 1, false); } } @@ -216,7 +245,7 @@ if (!spaceship_destroyed_) { // Changes the control method depedning whats selected in the setting - if(setting.get_control_method() == joy ) { + if (setting.get_control_method() == joy ) { read_joystick_direction(); }else { read_accelerometer_direction(accelerometer.get_roll_angle(), @@ -243,14 +272,14 @@ h_score.set_error(false); // Prints new high score if a high score and no error - if(calculate_new_score()&& !h_score.get_error()) { + if (calculate_new_score()&& !h_score.get_error()) { lcd.printString("NEW HIGH SCORE",0,4); - if(music_fx_ == music_on) { + if (music_fx_ == music_on) { pad.play_melody(61, take_on_me, take_on_me_note_time, 140, false); } - }else if(music_fx_ == music_on) { + }else if (music_fx_ == music_on) { pad.play_melody(23, god_farther, god_farther_note_time, 80, false); } @@ -360,11 +389,11 @@ current_menu_part_ = main_menu; } - // Load save, if no file press go back to main menu + // Press A to load save, if no file press go back to main menu if (pad.A_pressed()) { wait(0.035); saved_games_overide_init(); - if(saved.get_error()) { + if (saved.get_error()) { saved.set_error(false); current_menu_part_ = main_menu; }else{