Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Menus.cpp
00001 /* Menus.cpp 00002 Governs all the Menus 00003 and outside-of-game articles. 00004 13.4.19 00005 */ 00006 #include "Menus.h" 00007 00008 Menus::Menus() 00009 { 00010 _health = 6; 00011 _mute = false; 00012 _contrast = 0.4; 00013 } 00014 00015 Menus::~Menus() 00016 { 00017 00018 } 00019 00020 void Menus::start_up_screen(Graphics &graphics, N5110 &lcd, Gamepad &pad) 00021 { 00022 while(pad.check_event(Gamepad::START_PRESSED) == false) { 00023 _read_inputs(pad); 00024 lcd.clear(); 00025 graphics.draw_start_up_screen(lcd); 00026 lcd.printString(" Press Start ",0,3); 00027 _start_up_visuals(graphics, lcd, pad); 00028 lcd.drawRect(0, 0, 84 , 48, FILL_TRANSPARENT); 00029 lcd.drawRect(1, 1, 82 , 46, FILL_TRANSPARENT); 00030 lcd.refresh(); 00031 } 00032 } 00033 00034 void Menus::main_menu(Graphics &graphics, N5110 &lcd, Gamepad &pad, 00035 Scores &scores) 00036 { 00037 while(pad.check_event(Gamepad::Y_PRESSED) == false) { 00038 pad.leds_off(); 00039 lcd.clear(); 00040 _main_menu_controls(lcd, pad, scores); 00041 lcd.printString(" (Y) Play",0,1); 00042 lcd.printString(" (X) Controls",0,2); 00043 lcd.printString(" (A) Settings",0,3); 00044 lcd.printString(" (B) Scores",0,4); 00045 lcd.drawRect(0, 0, 84 , 48, FILL_TRANSPARENT); 00046 lcd.drawRect(1, 1, 82 , 46, FILL_TRANSPARENT); 00047 lcd.refresh(); 00048 wait_ms(1000/60); 00049 } 00050 } 00051 00052 void Menus::_main_menu_controls(N5110 &lcd, Gamepad &pad, Scores &scores) 00053 { 00054 pad.check_event(Gamepad::BACK_PRESSED); 00055 if (pad.check_event(Gamepad::X_PRESSED) == true) { 00056 _controls_screen(lcd, pad); 00057 } 00058 else if (pad.check_event(Gamepad::A_PRESSED) == true) { 00059 _settings_screen(lcd, pad); 00060 } 00061 else if (pad.check_event(Gamepad::B_PRESSED) == true) { 00062 _scores_screen(lcd, pad, scores); 00063 } 00064 } 00065 00066 void Menus::_start_up_visuals(Graphics &graphics, N5110 &lcd, Gamepad &pad) // Draw start up visuals 00067 { 00068 if (_counter >= 0) { 00069 graphics.start_up(1, pad); 00070 graphics.draw_tank_l(10, 5, lcd); 00071 graphics.draw_turret_l(10, 5, 10, lcd); 00072 graphics.draw_tank_r(64, 5, lcd); 00073 graphics.draw_turret_r(64, 5, 180, lcd); 00074 } else { 00075 graphics.start_up(0, pad); 00076 graphics.draw_tank_l(10, 5, lcd); 00077 graphics.draw_turret_l(10, 5, 180, lcd); 00078 graphics.draw_tank_r(64, 5, lcd); 00079 graphics.draw_turret_r(64, 5, 340, lcd); 00080 } 00081 if (_counter >= 199) { 00082 _counter = -200; 00083 } 00084 _counter++; 00085 } 00086 00087 void Menus::_read_inputs(Gamepad &pad) // Clear the triggers 00088 { 00089 pad.check_event(Gamepad::Y_PRESSED); 00090 pad.check_event(Gamepad::X_PRESSED); 00091 pad.check_event(Gamepad::A_PRESSED); 00092 pad.check_event(Gamepad::B_PRESSED); 00093 } 00094 00095 void Menus::_controls_screen(N5110 &lcd, Gamepad &pad) 00096 { 00097 while(pad.check_event(Gamepad::BACK_PRESSED) == false) { 00098 _read_inputs(pad); 00099 lcd.clear(); 00100 lcd.printString(" Stick: Aim",0,1); 00101 lcd.printString(" A : Fire",0,2); 00102 lcd.printString(" L/R : Move",0,3); 00103 lcd.printString(" Pot : Power",0,4); 00104 lcd.drawRect(0, 0, 84 , 48, FILL_TRANSPARENT); 00105 lcd.drawRect(1, 1, 82 , 46, FILL_TRANSPARENT); 00106 lcd.refresh(); 00107 wait_ms(1000/60); 00108 } 00109 } 00110 00111 void Menus::_settings_screen(N5110 &lcd, Gamepad &pad) 00112 { 00113 while(pad.check_event(Gamepad::BACK_PRESSED) == false) { 00114 lcd.clear(); 00115 _mute_brightness_lives(lcd, pad); 00116 _read_inputs(pad); 00117 lcd.printString("(O) Health:",4,1); 00118 lcd.printString("(A) Mute:",4,2); 00119 lcd.printString("(B) Brightness",4,3); 00120 lcd.printString("tune with pot",4,4); 00121 lcd.drawRect(0, 0, 84 , 48, FILL_TRANSPARENT); 00122 lcd.drawRect(1, 1, 82 , 46, FILL_TRANSPARENT); 00123 if (_mute == true ) { 00124 lcd.drawRect(70, 17, 7 , 7, FILL_BLACK); 00125 } else { 00126 lcd.drawRect(70, 17, 7 , 7, FILL_TRANSPARENT); 00127 } 00128 lcd.refresh(); 00129 wait_ms(1000/60); 00130 } 00131 } 00132 00133 void Menus::_mute_brightness_lives(N5110 &lcd, Gamepad &pad) 00134 { 00135 _counter--; 00136 if (_counter < 0) { // counter stops multiple consecutive button clicks 00137 _counter = 10; 00138 if (pad.get_direction() == W && _health > 1) { 00139 _health-- ; 00140 } else if (pad.get_direction() == E && _health < 6) { 00141 _health++ ; 00142 } else if (pad.check_event(Gamepad::A_PRESSED) == true) { 00143 _mute = !_mute; 00144 } else if (pad.check_event(Gamepad::B_PRESSED) == true) { 00145 lcd.setBrightness(pad.read_pot()); 00146 } else { 00147 _counter = -1; //reset counter 00148 } 00149 } 00150 char buffer[14]; 00151 sprintf(buffer,"%d",_health); 00152 lcd.printString(buffer, 74, 1); 00153 } 00154 00155 void Menus::_scores_screen(N5110 &lcd, Gamepad &pad, Scores &scores) 00156 { 00157 while(pad.check_event(Gamepad::BACK_PRESSED) == false) { 00158 lcd.clear(); 00159 scores.display_top_scores(lcd); 00160 lcd.printString("High Scores", 10, 1); 00161 lcd.drawRect(0, 0, 84 , 48, FILL_TRANSPARENT); 00162 lcd.drawRect(1, 1, 82 , 46, FILL_TRANSPARENT); 00163 _read_inputs(pad); 00164 lcd.refresh(); 00165 wait_ms(1000/60); 00166 } 00167 } 00168 00169 bool Menus::get_mute() 00170 { 00171 return _mute; 00172 } 00173 00174 int Menus::get_health() 00175 { 00176 return _health; 00177 }
Generated on Thu Jul 14 2022 01:14:35 by
1.7.2