Kern Fowler / Mbed 2 deprecated Donkey_Kong_Game

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Options.cpp Source File

Options.cpp

00001 /*
00002 ELEC2645 Project
00003 Options.cpp
00004 Class file for Options in Donkey Kong game.
00005 */
00006 
00007 #include "Options.h"
00008 
00009 // Constructor - Doesn't require any setup.
00010 Options::Options()
00011 {
00012 
00013 }
00014 
00015 // Deconstructor - Doesn't require any setup.
00016 Options::~Options()
00017 {
00018 
00019 }
00020 
00021 // External variables to be used inside and out of the class.
00022 float opt_brightness = 0.5;
00023 float opt_contrast = 0.396;
00024 int opt_volume = 1;
00025 
00026 // Runs and controls all the options functions.
00027 void Options::options_run(Gamepad &pad, N5110 &lcd) {
00028     wait_ms(250);
00029     while (pad.check_event(Gamepad::BACK_PRESSED) == false) { // Continues to show this screen until BACK button pressed.
00030         //printf("Options State");
00031         lcd.clear();
00032         lcd.printString("Options",21,0);
00033         options_brightness(pad, lcd); // Calls brightness function within class.
00034         options_contrast(pad, lcd); // Calls contrast function within class.
00035         options_volume(pad, lcd); // Calls volume function within class.
00036         lcd.refresh(); // Reloads screen on every cycle, controlled by fps. Default set to 24.
00037         wait_ms(1.0f/24);
00038     }
00039 }
00040 
00041 // Toggles the backlight on LCD screen, ON/OFF based on button inputs. 
00042 void Options::options_brightness(Gamepad &pad, N5110 &lcd) {
00043     if (pad.check_event(Gamepad::B_PRESSED) == true) { // If B is pressed, will turn off backlight.
00044         opt_brightness = 0;
00045     }
00046     if (pad.check_event(Gamepad::A_PRESSED) == true) { // If A is pressed, will turn on backlight.
00047         opt_brightness = 0.5;
00048     }
00049     lcd.setBrightness(opt_brightness);
00050     lcd.printString("A/B = BackLite",0,2);
00051 }
00052 
00053 // Controls the LCD screen contrast based on gamepad potentiometer value.
00054 void Options::options_contrast(Gamepad &pad, N5110 &lcd) {
00055     opt_contrast = pad.read_pot(); // Gets potentiometer value from gamepad and assigns it to a value.
00056     lcd.setContrast(opt_contrast); // Uses set value to change actual LCD contrast.
00057     lcd.printString("Pot = Contrast",0,3);
00058     printf("Contrast = %f", opt_contrast);
00059 }
00060 
00061 // Toggles the volume for the game, ON/OFF based on button inputs.
00062 void Options::options_volume(Gamepad &pad, N5110 &lcd) {
00063     if (pad.check_event(Gamepad::Y_PRESSED) == true) { // If Y is pressed, will disable volume.
00064         opt_volume = 0;
00065     }
00066     if (pad.check_event(Gamepad::X_PRESSED) == true) { // If X is press, will enable volume.
00067         opt_volume = 1;
00068         pad.tone(2400, 0.2); // Plays a set of beeps to confirm the volume is on. 
00069         wait_ms(200);
00070         pad.tone(2400, 0.2);
00071         wait_ms(200);
00072         pad.tone(2400, 0.2);
00073     }
00074     lcd.printString("X/Y = Volume",0,4);
00075     if (opt_volume == 0) { // Shows on screen the current volume state.
00076         lcd.printString("Off",36,5);
00077     } else {
00078         lcd.printString("On",36,5);
00079     }
00080 }