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:49:45 2020 +0000
Revision:
74:6827b43c689d
Parent:
72:e7492591307e
Child:
75:643a509cf9ed
Added music on/off setting which is fully integrated and works.

Who changed what in which revision?

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