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:
Wed May 27 02:06:05 2020 +0000
Revision:
87:832ca78426b5
Parent:
85:87bc28b151d8
Final Submission. I have read and agreed with Statement of Academic Integrity.

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 85:87bc28b151d8 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 82:3211b31e9421 34 void Menu::title_screen_isr() {
evanso 82:3211b31e9421 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 85:87bc28b151d8 41 if (displayed_menu_part_ == play) {
evanso 40:71f947254fda 42 lcd.printString(menu_part_names[displayed_menu_part_],30 ,4);
evanso 85:87bc28b151d8 43 }else if (displayed_menu_part_ == settings) {
evanso 40:71f947254fda 44 lcd.printString(menu_part_names[displayed_menu_part_],18 ,4);
evanso 85:87bc28b151d8 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 85:87bc28b151d8 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 82:3211b31e9421 55 // Flashes title screen
evanso 85:87bc28b151d8 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 82:3211b31e9421 69 // printf("displayed_menu_part_ %d\n",displayed_menu_part_);
evanso 82:3211b31e9421 70 // printf("d = %d\n",d_);
evanso 82:3211b31e9421 71
evanso 85:87bc28b151d8 72 // Changes displayed menu part depending on joystick input
evanso 72:e7492591307e 73 if (d_ == N || d_ == NE || d_ == NW ) {
evanso 40:71f947254fda 74 displayed_menu_part_ = menu_fsm[displayed_menu_part_].part_next;
evanso 40:71f947254fda 75 } else if (d_ == S || d_ == SW || d_ == SE) {
evanso 74:6827b43c689d 76 displayed_menu_part_ = menu_fsm[displayed_menu_part_].part_previous;
evanso 40:71f947254fda 77 }
evanso 43:d43759dbddb9 78 wait(0.15);
evanso 40:71f947254fda 79 }
evanso 40:71f947254fda 80
evanso 65:daa792a09e1f 81 void Menu::select_part(bool pressed) {
evanso 65:daa792a09e1f 82 if (pressed) {
evanso 40:71f947254fda 83 current_menu_part_ = displayed_menu_part_;
evanso 85:87bc28b151d8 84 wait(0.3);
evanso 40:71f947254fda 85 } else {
evanso 40:71f947254fda 86 current_menu_part_ = main_menu;
evanso 85:87bc28b151d8 87 }
evanso 40:71f947254fda 88 }
evanso 41:5959256f4aab 89
evanso 82:3211b31e9421 90 MenuParts Menu::get_current_menu_part() {
evanso 41:5959256f4aab 91 return current_menu_part_;
evanso 41:5959256f4aab 92 }
evanso 68:bb1650c657ef 93
evanso 68:bb1650c657ef 94 void Menu::title_screen(N5110 &lcd) {
evanso 68:bb1650c657ef 95 lcd.drawSprite(5, 8, 10, 8, (int *)title_screen_d); //D
evanso 85:87bc28b151d8 96 lcd.drawSprite(15, 8, 10, 7, (int *)title_screen_e); // E
evanso 85:87bc28b151d8 97 lcd.drawSprite(24, 8, 10, 7, (int *)title_screen_f); // F
evanso 85:87bc28b151d8 98 lcd.drawSprite(33, 8, 10, 7, (int *)title_screen_e); // E
evanso 85:87bc28b151d8 99 lcd.drawSprite(42, 8, 10, 7, (int *)title_screen_n); // N
evanso 85:87bc28b151d8 100 lcd.drawSprite(51, 8, 10, 8, (int *)title_screen_d); // D
evanso 85:87bc28b151d8 101 lcd.drawSprite(61, 8, 10, 7, (int *)title_screen_e); // E
evanso 85:87bc28b151d8 102 lcd.drawSprite(70, 8, 10, 8, (int *)title_screen_r); // R
evanso 68:bb1650c657ef 103 }
evanso 85:87bc28b151d8 104