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
Diff: Menus/Menus.cpp
- Revision:
- 16:a2c945279b79
- Parent:
- 15:fa5282fcd134
- Child:
- 17:cb39d9fa08dc
--- a/Menus/Menus.cpp Fri Apr 19 15:58:51 2019 +0000 +++ b/Menus/Menus.cpp Wed Apr 24 13:44:12 2019 +0000 @@ -7,9 +7,10 @@ Menus::Menus() { - _lives = 6; + _health = 6; _mute = false; - _contrast = 0.4; + _contrast = 0.4; + _brightness = 1.0; } Menus::~Menus() @@ -20,6 +21,7 @@ void Menus::start_up_screen(Graphics &graphics, N5110 &lcd, Gamepad &pad) { while(pad.check_event(Gamepad::START_PRESSED) == false) { + _read_inputs(pad); lcd.clear(); lcd.printString(" TANKS! ",0,1); lcd.printString(" Press Start ",0,3); @@ -30,22 +32,24 @@ } } -void Menus::main_menu(Graphics &graphics, N5110 &lcd, Gamepad &pad) +void Menus::main_menu(Graphics &graphics, N5110 &lcd, Gamepad &pad, Scores &scores) { while(pad.check_event(Gamepad::Y_PRESSED) == false) { + pad.leds_off(); + pad.check_event(Gamepad::BACK_PRESSED); lcd.clear(); if (pad.check_event(Gamepad::X_PRESSED) == true) { _controls(lcd, pad); } - else if (pad.check_event(Gamepad::A_PRESSED) == true) { _scores(lcd, pad); } - else if (pad.check_event(Gamepad::B_PRESSED) == true) { _settings(lcd, pad); } + else if (pad.check_event(Gamepad::A_PRESSED) == true) { _settings(lcd, pad); } + else if (pad.check_event(Gamepad::B_PRESSED) == true) { _scores(lcd, pad, scores); } lcd.printString(" (Y) Play",0,1); lcd.printString(" (X) Controls",0,2); - lcd.printString(" (A) Scores",0,3); - lcd.printString(" (B) Settings ",0,4); + lcd.printString(" (A) Settings",0,3); + lcd.printString(" (B) Scores",0,4); lcd.drawRect(0, 0, 84 , 48, FILL_TRANSPARENT); lcd.drawRect(1, 1, 82 , 46, FILL_TRANSPARENT); lcd.refresh(); - wait_ms(16.666); + wait_ms(1000/60); } } @@ -79,6 +83,7 @@ void Menus::_controls(N5110 &lcd, Gamepad &pad) { while(pad.check_event(Gamepad::BACK_PRESSED) == false) { + _read_inputs(pad); lcd.clear(); lcd.printString(" Stick: Aim",0,1); @@ -88,65 +93,72 @@ lcd.drawRect(0, 0, 84 , 48, FILL_TRANSPARENT); lcd.drawRect(1, 1, 82 , 46, FILL_TRANSPARENT); lcd.refresh(); - wait_ms(50); - } -} - -void Menus::_scores(N5110 &lcd, Gamepad &pad) -{ - while(pad.check_event(Gamepad::BACK_PRESSED) == false) { - _read_inputs(pad); - lcd.clear(); - lcd.printString(" Highest",0,1); - lcd.printString(" Score",0,1); - lcd.drawRect(0, 0, 84 , 48, FILL_TRANSPARENT); - lcd.drawRect(1, 1, 82 , 46, FILL_TRANSPARENT); - lcd.refresh(); - wait_ms(50); + wait_ms(1000/60); } } void Menus::_settings(N5110 &lcd, Gamepad &pad) { while(pad.check_event(Gamepad::BACK_PRESSED) == false) { + lcd.clear(); - _mute_contrast(lcd, pad); + _mute_brightness_lives(lcd, pad); _read_inputs(pad); - lcd.printString(" (O) Lives:",0,1); - lcd.printString(" (A) Mute :",0,2); - lcd.printString(" (B) Contrast",0,3); - lcd.printString(" reads off pot",0,4); + lcd.printString("(O) Health:",4,1); + lcd.printString("(A) Mute:",4,2); + lcd.printString("(B) Brightness",4,3); + lcd.printString("tune with pot",4,4); lcd.drawRect(0, 0, 84 , 48, FILL_TRANSPARENT); lcd.drawRect(1, 1, 82 , 46, FILL_TRANSPARENT); lcd.refresh(); - wait(0.2); + wait_ms(1000/60); } } -void Menus::_mute_contrast(N5110 &lcd, Gamepad &pad) +void Menus::_mute_brightness_lives(N5110 &lcd, Gamepad &pad) { - pad.check_event(Gamepad::Y_PRESSED); - pad.check_event(Gamepad::X_PRESSED); - if (pad.get_direction() == W && _lives > 1) { _lives-- ; } - else if (pad.get_direction() == E && _lives < 6) { _lives++ ; } - else if (pad.check_event(Gamepad::A_PRESSED) == true) { _mute = !_mute; } - else if (pad.check_event(Gamepad::B_PRESSED) == true) { - _contrast = pad.read_pot(); - lcd.setContrast(_contrast); + _counter--; + if (_counter < 0) { // counter stops multiple consecutive button clicks + _counter = 10; + if (pad.get_direction() == W && _health > 1) { _health-- ; } + else if (pad.get_direction() == E && _health < 6) { _health++ ; } + else if (pad.check_event(Gamepad::A_PRESSED) == true) { _mute = !_mute; } + else if (pad.check_event(Gamepad::B_PRESSED) == true) { + _brightness = pad.read_pot(); + lcd.setBrightness(_brightness); + } + else { _counter = -1; } } char buffer[14]; - sprintf(buffer,"%d",_lives); - lcd.printString(buffer, 70, 1); + sprintf(buffer,"%d",_health); + lcd.printString(buffer, 74, 1); if (_mute == true ) { lcd.drawRect(70, 17, 7 , 7, FILL_BLACK); } else { lcd.drawRect(70, 17, 7 , 7, FILL_TRANSPARENT); } } +void Menus::_scores(N5110 &lcd, Gamepad &pad, Scores &scores) +{ + while(pad.check_event(Gamepad::BACK_PRESSED) == false) { + + lcd.clear(); + // if (pad.check_event(Gamepad::A_PRESSED) == true) { scores.read_sd_scores() } + // else if (pad.check_event(Gamepad::B_PRESSED) == true) { scores.write_sd_scores() } + scores.display_top_scores(lcd); + lcd.printString("High Scores", 10, 1); + lcd.drawRect(0, 0, 84 , 48, FILL_TRANSPARENT); + lcd.drawRect(1, 1, 82 , 46, FILL_TRANSPARENT); + _read_inputs(pad); + lcd.refresh(); + wait_ms(1000/60); + } +} + bool Menus::get_mute() { return _mute; } -int Menus::get_lives() +int Menus::get_health() { - return _lives; + return _health; } \ No newline at end of file