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/Menus.cpp
- Committer:
- el17mcd
- Date:
- 2019-04-19
- Revision:
- 15:fa5282fcd134
- Child:
- 16:a2c945279b79
File content as of revision 15:fa5282fcd134:
/* Menus.cpp Governs all the Menus and outside-of-game articles. 13.4.19 */ #include "Menus.h" Menus::Menus() { _lives = 6; _mute = false; _contrast = 0.4; } Menus::~Menus() { } void Menus::start_up_screen(Graphics &graphics, N5110 &lcd, Gamepad &pad) { while(pad.check_event(Gamepad::START_PRESSED) == false) { lcd.clear(); lcd.printString(" TANKS! ",0,1); lcd.printString(" Press Start ",0,3); _start_up_visuals(graphics, lcd, pad); lcd.drawRect(0, 0, 84 , 48, FILL_TRANSPARENT); lcd.drawRect(1, 1, 82 , 46, FILL_TRANSPARENT); lcd.refresh(); } } void Menus::main_menu(Graphics &graphics, N5110 &lcd, Gamepad &pad) { while(pad.check_event(Gamepad::Y_PRESSED) == false) { pad.leds_off(); 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); } 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.drawRect(0, 0, 84 , 48, FILL_TRANSPARENT); lcd.drawRect(1, 1, 82 , 46, FILL_TRANSPARENT); lcd.refresh(); wait_ms(16.666); } } void Menus::_start_up_visuals(Graphics &graphics, N5110 &lcd, Gamepad &pad) { if (_counter >= 0) { graphics.start_up(1, pad); graphics.draw_tank_l(10, 5, lcd); graphics.draw_turret_l(10, 5, 10, lcd); graphics.draw_tank_r(64, 5, lcd); graphics.draw_turret_r(64, 5, 180, lcd); } else { graphics.start_up(0, pad); graphics.draw_tank_l(10, 5, lcd); graphics.draw_turret_l(10, 5, 180, lcd); graphics.draw_tank_r(64, 5, lcd); graphics.draw_turret_r(64, 5, 340, lcd); } if (_counter >= 199) { _counter = -200; } _counter++; } void Menus::_read_inputs(Gamepad &pad) { pad.check_event(Gamepad::Y_PRESSED); pad.check_event(Gamepad::X_PRESSED); pad.check_event(Gamepad::A_PRESSED); pad.check_event(Gamepad::B_PRESSED); } 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); lcd.printString(" A : Fire",0,2); lcd.printString(" L/R : Move",0,3); lcd.printString(" Pot : Power",0,4); 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); } } void Menus::_settings(N5110 &lcd, Gamepad &pad) { while(pad.check_event(Gamepad::BACK_PRESSED) == false) { lcd.clear(); _mute_contrast(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.drawRect(0, 0, 84 , 48, FILL_TRANSPARENT); lcd.drawRect(1, 1, 82 , 46, FILL_TRANSPARENT); lcd.refresh(); wait(0.2); } } void Menus::_mute_contrast(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); } char buffer[14]; sprintf(buffer,"%d",_lives); lcd.printString(buffer, 70, 1); if (_mute == true ) { lcd.drawRect(70, 17, 7 , 7, FILL_BLACK); } else { lcd.drawRect(70, 17, 7 , 7, FILL_TRANSPARENT); } } bool Menus::get_mute() { return _mute; } int Menus::get_lives() { return _lives; }