Ben Evans / Mbed 2 deprecated Defender_Game

Dependencies:   mbed

Revision:
69:753ba27325ce
Parent:
44:2d957de3bce3
Child:
70:8c4572d17441
--- a/Settings/Settings.cpp	Thu May 21 22:46:23 2020 +0000
+++ b/Settings/Settings.cpp	Fri May 22 13:02:26 2020 +0000
@@ -1,5 +1,40 @@
 #include "Settings.h"
 
+const char settings_part_names[3][9] = {
+    {"Contrast"},
+    {"Controls"},
+    {"Sound FX"}, 
+};
+
+const char controls_part_names[2][4] = {
+    {"Joy"},
+    {"Acc"},
+};
+
+const char sound_part_names[2][4] = {
+    {"On"},
+    {"Off"},
+};
+
+// Defining scroll_order_settings states for scroll_order_settings FSM
+scroll_order_setting settings_fsm[3] = {
+    {controls, sound_fx},
+    {sound_fx, contrast},
+    {contrast, controls}, 
+}; 
+
+// Defining on_off_order states for settings_on_off FSM
+on_off_order settings_on_off_fsm[2] = {
+    {off, on},
+    {on, off}, 
+}; 
+
+// Defining control_order states for settings_joy_acc FSM
+control_order settings_joy_acc_fsm[2] = {
+    {acc, joy}, 
+    {joy, acc},
+}; 
+
 Settings::Settings() {
     
 }
@@ -9,6 +44,61 @@
 }
 
 void Settings::init(){
-    lcd_contrast = 4;
-    control_method = false;
+    control_method_ = joy;
+    sound_method_ = on;
+    displayed_settings_part_ = contrast;
+}
+
+ControlsParts Settings::get_control_method(){
+    return control_method_;
+}
+
+void Settings::display_settings_screen(N5110 &lcd, float pot_read){
+    //Pirnts differnt settings parts
+    if(displayed_settings_part_ == controls){
+        lcd.printString(settings_part_names[displayed_settings_part_],6 ,3);
+        lcd.printString(controls_part_names[control_method_],60 ,3);
+    }else if(displayed_settings_part_ == sound_fx){
+        lcd.printString(settings_part_names[displayed_settings_part_],6 ,3);
+        lcd.printString(sound_part_names[sound_method_],60 ,3);
+    }else if(displayed_settings_part_ == contrast){
+        lcd.printString(settings_part_names[displayed_settings_part_],6 ,3);
+        char buffer[2]; 
+        sprintf(buffer,"%.2f",pot_read);
+        lcd.printString(buffer,58,3);
+    }
+    
+    //prints setting title and button instructions and arrows
+    lcd.printString("Settings",18,0);
+    lcd.drawSprite(39, 18, 3, 5, (int *)arrow_up);
+    lcd.drawSprite(39, 34, 3, 5, (int *)arrow_down);
+    lcd.printString("Back(B)Alt(A)",3,5);
+}
+
+void Settings::change_setting(bool pressed) {
+    // When a is pressed changes the settings for the displayed setting part
+    if (pressed) { 
+        if (displayed_settings_part_ == sound_fx){ 
+        sound_method_ = settings_on_off_fsm[sound_method_].part_next;  
+        }else if(displayed_settings_part_ == controls){
+            control_method_ = settings_joy_acc_fsm[control_method_].part_next;  
+        }  
+    wait(0.15);   
+    }
+    
+}
+
+
+void Settings::settings_scroll(Direction d_) {
+    // Changes displayed settings part depending on joystick input
+    if (d_ == N || d_ == NE || d_ == NW ) {   
+        displayed_settings_part_ = 
+        settings_fsm[displayed_settings_part_].part_next;   
+    } else if (d_ == S || d_ == SW || d_ == SE) {
+        displayed_settings_part_= 
+        settings_fsm[displayed_settings_part_].part_next; 
+        displayed_settings_part_ = 
+        settings_fsm[displayed_settings_part_].part_next; 
+    }
+    wait(0.15);
 }
\ No newline at end of file