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.
Diff: Options_Engine/OptionsEngine.cpp
- Revision:
- 23:61fa82f76808
- Parent:
- 22:4e305ff8a050
- Child:
- 24:c6415cc74b17
--- a/Options_Engine/OptionsEngine.cpp Thu Apr 18 11:50:53 2019 +0000
+++ b/Options_Engine/OptionsEngine.cpp Thu Apr 18 22:56:34 2019 +0000
@@ -12,7 +12,7 @@
}
-void OptionsEngine::options_menu(Gamepad &gamepad, N5110 &lcd){
+void OptionsEngine::options_menu(Gamepad &gamepad, N5110 &lcd, Ball &ball){
Option choice = BRIGHTNESS;
while(!(gamepad.check_event(gamepad.A_PRESSED))){
lcd.clear();
@@ -22,7 +22,7 @@
wait(0.2);
}
if(choice == BRIGHTNESS){ change_brightness(gamepad, lcd); }
- if(choice == BALL_SPEED){ /*change_ball_speed(gamepad, lcd);*/ }
+ if(choice == BALL_SPEED){ change_ball_speed(gamepad, lcd, ball); }
if(choice == HIGH_SCORES){ /*view_high_scores(gamepad, lcd);*/ }
}
@@ -55,10 +55,10 @@
lcd.printString("Use L and R to", 0, 3);
lcd.printString("change", 24, 4);
lcd.printString("A = confirm", 9, 5);
- lcd.drawRect(10, 16, 63, 8, FILL_TRANSPARENT);
+ lcd.drawRect(10, 12, 63, 8, FILL_TRANSPARENT);
read_brightness_input(gamepad);
for(int i = 0; i < _brightness*10; i ++){
- lcd.drawRect(12+6*i, 18, 5, 4, FILL_BLACK);
+ lcd.drawRect(12+6*i, 14, 5, 4, FILL_BLACK);
}
lcd.setBrightness(_brightness);
lcd.refresh();
@@ -67,9 +67,34 @@
}
void OptionsEngine::read_brightness_input(Gamepad &gamepad){
- if(gamepad.check_event(gamepad.L_PRESSED)){ _brightness -= 0.1f; } //Use of f to explicitly convert to a float (to fit declaration type in header file.
+ if(gamepad.check_event(gamepad.L_PRESSED)){ _brightness -= 0.1f; } //Use of f to explicitly convert to a float (to fit declaration type in header file).
if(gamepad.check_event(gamepad.R_PRESSED)){ _brightness += 0.1f; } //Otherwise 0.1 is implicitly converted to a double (giving warning messages).
if(_brightness < 0){ _brightness = 0; }
if(_brightness > 1){ _brightness = 1; }
+ /*printf("Brightness = %f\n", _brightness);*/
}
-
\ No newline at end of file
+
+void OptionsEngine::change_ball_speed(Gamepad &gamepad, N5110 &lcd, Ball &ball){
+ while(!(gamepad.check_event(gamepad.A_PRESSED))){
+ lcd.clear();
+ lcd.printString("Ball Speed", 12, 0);
+ lcd.printString("Use L and R to", 0, 3);
+ lcd.printString("change", 24, 4);
+ lcd.printString("A = confirm", 9, 5);
+ lcd.drawRect(10, 12, 63, 8, FILL_TRANSPARENT);
+ read_ball_speed_input(gamepad);
+ for(int i = 0; i < _ball_speed; i ++){
+ lcd.drawRect(12+6*i, 14, 5, 4, FILL_BLACK);
+ }
+ ball.set_ball_speed(_ball_speed);
+ lcd.refresh();
+ wait(0.2);
+ }
+}
+
+void OptionsEngine::read_ball_speed_input(Gamepad &gamepad){
+ if(gamepad.check_event(gamepad.L_PRESSED)){ _ball_speed -= 1; }
+ if(gamepad.check_event(gamepad.R_PRESSED)){ _ball_speed += 1; }
+ if(_ball_speed < 0){ _ball_speed = 0; }
+ if(_ball_speed > 10){ _ball_speed = 10; }
+}
\ No newline at end of file