Ben Evans University Second Year Project. Game Called Defender.

Dependencies:   mbed

https://os.mbed.com/media/uploads/evanso/84bc1a30759fd6a1e3f1fd1fae3e97c2.png

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.

Committer:
evanso
Date:
Tue May 19 18:32:18 2020 +0000
Revision:
54:d46459104dea
Parent:
43:d43759dbddb9
Child:
65:daa792a09e1f
Added display_saved_games function and scroll_saved_games function to SavedGames class.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
evanso 40:71f947254fda 1 #include "Menu.h"
evanso 40:71f947254fda 2
evanso 40:71f947254fda 3 const int arrow_up[3][5] = {
evanso 40:71f947254fda 4 { 0, 0, 1, 0, 0 },
evanso 40:71f947254fda 5 { 0, 1, 1, 1, 0 },
evanso 40:71f947254fda 6 { 1, 1, 1, 1, 1 },
evanso 40:71f947254fda 7 };
evanso 40:71f947254fda 8
evanso 40:71f947254fda 9 const int arrow_down[3][5] = {
evanso 40:71f947254fda 10 { 1, 1, 1, 1, 1 },
evanso 40:71f947254fda 11 { 0, 1, 1, 1, 0 },
evanso 40:71f947254fda 12 { 0, 0, 1, 0, 0 },
evanso 40:71f947254fda 13 };
evanso 40:71f947254fda 14
evanso 40:71f947254fda 15 const char menu_part_names[3][12] = {
evanso 40:71f947254fda 16 {"Play"},
evanso 40:71f947254fda 17 {"Settings"},
evanso 40:71f947254fda 18 {"Saved Games"},
evanso 40:71f947254fda 19 };
evanso 40:71f947254fda 20
evanso 40:71f947254fda 21 // Defining scroll_order states for scroll_order FSM
evanso 40:71f947254fda 22 scroll_order menu_fsm[3] = {
evanso 41:5959256f4aab 23 {settings, saved_games},
evanso 41:5959256f4aab 24 {saved_games, play},
evanso 40:71f947254fda 25 {play, settings},
evanso 40:71f947254fda 26 };
evanso 40:71f947254fda 27
evanso 40:71f947254fda 28 Menu::Menu() {
evanso 40:71f947254fda 29
evanso 40:71f947254fda 30 }
evanso 40:71f947254fda 31
evanso 40:71f947254fda 32 Menu::~Menu() {
evanso 40:71f947254fda 33
evanso 40:71f947254fda 34 }
evanso 40:71f947254fda 35
evanso 40:71f947254fda 36 void Menu::init() {
evanso 40:71f947254fda 37 current_menu_part_ = main_menu;
evanso 40:71f947254fda 38 displayed_menu_part_ = play;
evanso 40:71f947254fda 39 }
evanso 40:71f947254fda 40
evanso 40:71f947254fda 41 void Menu::draw_part(N5110 &lcd) {
evanso 40:71f947254fda 42 // Prints the menu part that should be displayed in the centre
evanso 40:71f947254fda 43 if(displayed_menu_part_ == play){
evanso 40:71f947254fda 44 lcd.printString(menu_part_names[displayed_menu_part_],30 ,4);
evanso 40:71f947254fda 45 }else if(displayed_menu_part_ == settings){
evanso 40:71f947254fda 46 lcd.printString(menu_part_names[displayed_menu_part_],18 ,4);
evanso 41:5959256f4aab 47 }else if(displayed_menu_part_ == saved_games){
evanso 40:71f947254fda 48 lcd.printString(menu_part_names[displayed_menu_part_],9 ,4);
evanso 40:71f947254fda 49 }
evanso 40:71f947254fda 50
evanso 40:71f947254fda 51 lcd.drawSprite(39, 26, 3, 5, (int *)arrow_up);
evanso 40:71f947254fda 52 lcd.drawSprite(39, 42, 3, 5, (int *)arrow_down);
evanso 40:71f947254fda 53
evanso 40:71f947254fda 54 #ifdef MENU_DEBUG
evanso 40:71f947254fda 55 printf("displayed_menu_part_ = %d\n",displayed_menu_part_);
evanso 40:71f947254fda 56 printf("current_menu_part_ = %d\n", current_menu_part_);
evanso 40:71f947254fda 57 #endif
evanso 40:71f947254fda 58 }
evanso 40:71f947254fda 59
evanso 40:71f947254fda 60 void Menu::menu_scroll(Gamepad &pad, Direction d_) {
evanso 54:d46459104dea 61 // printf ("d = %d\n",d_);
evanso 40:71f947254fda 62 // Changes displayed manu part depending on joystick input
evanso 40:71f947254fda 63 if (d_ == N || d_ == NE || d_ == NW ) {
evanso 40:71f947254fda 64 displayed_menu_part_ = menu_fsm[displayed_menu_part_].part_next;
evanso 40:71f947254fda 65 } else if (d_ == S || d_ == SW || d_ == SE) {
evanso 40:71f947254fda 66 displayed_menu_part_ = menu_fsm[displayed_menu_part_].part_next;
evanso 40:71f947254fda 67 displayed_menu_part_ = menu_fsm[displayed_menu_part_].part_next;
evanso 40:71f947254fda 68 }
evanso 43:d43759dbddb9 69 wait(0.15);
evanso 40:71f947254fda 70 }
evanso 40:71f947254fda 71
evanso 40:71f947254fda 72 void Menu::select_part(N5110 &lcd, Gamepad &pad) {
evanso 40:71f947254fda 73 if (pad.A_pressed()) {
evanso 40:71f947254fda 74 current_menu_part_ = displayed_menu_part_;
evanso 40:71f947254fda 75 } else {
evanso 40:71f947254fda 76 current_menu_part_ = main_menu;
evanso 40:71f947254fda 77 }
evanso 40:71f947254fda 78 }
evanso 41:5959256f4aab 79
evanso 41:5959256f4aab 80 MenuParts Menu::get_current_menu_part(){
evanso 41:5959256f4aab 81 return current_menu_part_;
evanso 41:5959256f4aab 82 }
evanso 40:71f947254fda 83