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:
Sat May 23 22:59:15 2020 +0000
Revision:
75:643a509cf9ed
Parent:
74:6827b43c689d
Child:
82:3211b31e9421
Created high score menu and added it to the menu.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
evanso 40:71f947254fda 1 #include "Menu.h"
evanso 40:71f947254fda 2
evanso 75:643a509cf9ed 3 const char menu_part_names[4][12] = {
evanso 40:71f947254fda 4 {"Play"},
evanso 40:71f947254fda 5 {"Settings"},
evanso 40:71f947254fda 6 {"Saved Games"},
evanso 75:643a509cf9ed 7 {"High Score"},
evanso 40:71f947254fda 8 };
evanso 40:71f947254fda 9
evanso 40:71f947254fda 10 // Defining scroll_order states for scroll_order FSM
evanso 75:643a509cf9ed 11 scroll_order menu_fsm[4] = {
evanso 75:643a509cf9ed 12 {high_score, play, settings},
evanso 74:6827b43c689d 13 {play, settings, saved_games},
evanso 75:643a509cf9ed 14 {settings, saved_games, high_score},
evanso 75:643a509cf9ed 15 {saved_games, high_score, play},
evanso 40:71f947254fda 16 };
evanso 40:71f947254fda 17
evanso 40:71f947254fda 18 Menu::Menu() {
evanso 40:71f947254fda 19
evanso 40:71f947254fda 20 }
evanso 40:71f947254fda 21
evanso 40:71f947254fda 22 Menu::~Menu() {
evanso 40:71f947254fda 23
evanso 40:71f947254fda 24 }
evanso 40:71f947254fda 25
evanso 40:71f947254fda 26 void Menu::init() {
evanso 40:71f947254fda 27 current_menu_part_ = main_menu;
evanso 40:71f947254fda 28 displayed_menu_part_ = play;
evanso 72:e7492591307e 29 //attach ticker to isr
evanso 72:e7492591307e 30 ticker_title.attach(callback(this, &Menu::title_screen_isr), 0.9 );
evanso 72:e7492591307e 31 title_screen_flag_ = true;
evanso 40:71f947254fda 32 }
evanso 40:71f947254fda 33
evanso 72:e7492591307e 34 void Menu::title_screen_isr(){
evanso 72:e7492591307e 35 // set ISR flag
evanso 72:e7492591307e 36 title_screen_flag_ = !title_screen_flag_;
evanso 72:e7492591307e 37 }
evanso 72:e7492591307e 38
evanso 40:71f947254fda 39 void Menu::draw_part(N5110 &lcd) {
evanso 40:71f947254fda 40 // Prints the menu part that should be displayed in the centre
evanso 40:71f947254fda 41 if(displayed_menu_part_ == play){
evanso 40:71f947254fda 42 lcd.printString(menu_part_names[displayed_menu_part_],30 ,4);
evanso 40:71f947254fda 43 }else if(displayed_menu_part_ == settings){
evanso 40:71f947254fda 44 lcd.printString(menu_part_names[displayed_menu_part_],18 ,4);
evanso 41:5959256f4aab 45 }else if(displayed_menu_part_ == saved_games){
evanso 40:71f947254fda 46 lcd.printString(menu_part_names[displayed_menu_part_],9 ,4);
evanso 40:71f947254fda 47 }
evanso 75:643a509cf9ed 48 else if(displayed_menu_part_ == high_score){
evanso 75:643a509cf9ed 49 lcd.printString(menu_part_names[displayed_menu_part_],12 ,4);
evanso 75:643a509cf9ed 50 }
evanso 40:71f947254fda 51
evanso 40:71f947254fda 52 lcd.drawSprite(39, 26, 3, 5, (int *)arrow_up);
evanso 40:71f947254fda 53 lcd.drawSprite(39, 42, 3, 5, (int *)arrow_down);
evanso 72:e7492591307e 54
evanso 72:e7492591307e 55 //flashes title screen
evanso 72:e7492591307e 56 if(title_screen_flag_){
evanso 72:e7492591307e 57 title_screen(lcd);
evanso 72:e7492591307e 58 }else{
evanso 72:e7492591307e 59 lcd.printString("DEFENDER",18,1);
evanso 72:e7492591307e 60 }
evanso 40:71f947254fda 61
evanso 40:71f947254fda 62 #ifdef MENU_DEBUG
evanso 40:71f947254fda 63 printf("displayed_menu_part_ = %d\n",displayed_menu_part_);
evanso 40:71f947254fda 64 printf("current_menu_part_ = %d\n", current_menu_part_);
evanso 40:71f947254fda 65 #endif
evanso 40:71f947254fda 66 }
evanso 40:71f947254fda 67
evanso 65:daa792a09e1f 68 void Menu::menu_scroll(Direction d_) {
evanso 69:753ba27325ce 69 //printf("displayed_menu_part_ %d\n",displayed_menu_part_);
evanso 69:753ba27325ce 70 //printf("d = %d\n",d_);
evanso 40:71f947254fda 71 // Changes displayed manu part depending on joystick input
evanso 72:e7492591307e 72 if (d_ == N || d_ == NE || d_ == NW ) {
evanso 40:71f947254fda 73 displayed_menu_part_ = menu_fsm[displayed_menu_part_].part_next;
evanso 40:71f947254fda 74 } else if (d_ == S || d_ == SW || d_ == SE) {
evanso 74:6827b43c689d 75 displayed_menu_part_ = menu_fsm[displayed_menu_part_].part_previous;
evanso 40:71f947254fda 76 }
evanso 43:d43759dbddb9 77 wait(0.15);
evanso 40:71f947254fda 78 }
evanso 40:71f947254fda 79
evanso 65:daa792a09e1f 80 void Menu::select_part(bool pressed) {
evanso 65:daa792a09e1f 81 if (pressed) {
evanso 40:71f947254fda 82 current_menu_part_ = displayed_menu_part_;
evanso 40:71f947254fda 83 } else {
evanso 40:71f947254fda 84 current_menu_part_ = main_menu;
evanso 40:71f947254fda 85 }
evanso 65:daa792a09e1f 86 wait(0.035);
evanso 40:71f947254fda 87 }
evanso 41:5959256f4aab 88
evanso 41:5959256f4aab 89 MenuParts Menu::get_current_menu_part(){
evanso 41:5959256f4aab 90 return current_menu_part_;
evanso 41:5959256f4aab 91 }
evanso 68:bb1650c657ef 92
evanso 68:bb1650c657ef 93 void Menu::title_screen(N5110 &lcd) {
evanso 68:bb1650c657ef 94 lcd.drawSprite(5, 8, 10, 8, (int *)title_screen_d); //D
evanso 68:bb1650c657ef 95 lcd.drawSprite(15, 8, 10, 7, (int *)title_screen_e); //E
evanso 68:bb1650c657ef 96 lcd.drawSprite(24, 8, 10, 7, (int *)title_screen_f); //F
evanso 68:bb1650c657ef 97 lcd.drawSprite(33, 8, 10, 7, (int *)title_screen_e); //E
evanso 68:bb1650c657ef 98 lcd.drawSprite(42, 8, 10, 7, (int *)title_screen_n); //N
evanso 68:bb1650c657ef 99 lcd.drawSprite(51, 8, 10, 8, (int *)title_screen_d); //D
evanso 68:bb1650c657ef 100 lcd.drawSprite(61, 8, 10, 7, (int *)title_screen_e); //E
evanso 68:bb1650c657ef 101 lcd.drawSprite(70, 8, 10, 8, (int *)title_screen_r); //R
evanso 68:bb1650c657ef 102 }
evanso 40:71f947254fda 103