Ben Evans University Second Year Project. Game Called Defender.

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Settings.cpp Source File

Settings.cpp

00001 #include "Settings.h"
00002 
00003 const char settings_part_names[4][9] = {
00004     {"Contrast"},
00005     {"Controls"},
00006     {"Sound FX"}, 
00007     {"  Music "}, 
00008 };
00009 
00010 const char controls_part_names[2][4] = {
00011     {"Joy"},
00012     {"Acc"},
00013 };
00014 
00015 const char sound_part_names[2][4] = {
00016     {"On"},
00017     {"Off"},
00018 };
00019 
00020 const char music_part_names[2][4] = {
00021     {"On"},
00022     {"Off"},
00023 };
00024 
00025 // Defining scroll_order_settings states for scroll_order_settings FSM
00026 scroll_order_setting settings_fsm[4] = { 
00027     {music, contrast, controls}, 
00028     {contrast, controls, sound_fx},
00029     {controls, sound_fx, music},
00030     {sound_fx, music, contrast}, 
00031 }; 
00032 
00033 // Defining on_off_order states for _on_off FSM
00034 on_off_order settings_on_off_fsm[2] = {
00035     {off, on},
00036     {on, off}, 
00037 };
00038 
00039 // Defining on_off_order states for music_on_off FSM
00040 music_on_off_order music_on_off_fsm[2] = {
00041     {music_off, music_on},
00042     {music_on, music_off}, 
00043 };  
00044 
00045 // Defining control_order states for settings_joy_acc FSM
00046 control_order settings_joy_acc_fsm[2] = {
00047     {acc, joy}, 
00048     {joy, acc},
00049 }; 
00050 
00051 Settings::Settings() {
00052     
00053 }
00054  
00055 Settings::~Settings() {
00056     
00057 }
00058 
00059 void Settings::init() {
00060     control_method_ = joy;
00061     sound_method_ = on;
00062     displayed_settings_part_ = controls;
00063     music_method_ = music_on;
00064 }
00065 
00066 ControlsParts Settings::get_control_method() {
00067     return control_method_;
00068 }
00069 
00070 
00071 SoundParts Settings::get_sound_method() {
00072     return sound_method_;
00073 }
00074 
00075 MusicParts Settings::get_music_method() {
00076     return music_method_;
00077 }
00078 
00079 SettingsParts Settings::get_displayed_settings_part() {
00080     return displayed_settings_part_;
00081 }
00082 
00083 void Settings::display_settings_screen(N5110 &lcd, float pot_read) {
00084     // Prints different settings parts
00085     if(displayed_settings_part_ == controls) {
00086         lcd.printString(settings_part_names[displayed_settings_part_],6 ,3);
00087         lcd.printString(controls_part_names[control_method_],60 ,3);
00088     }else if(displayed_settings_part_ == sound_fx) {
00089         lcd.printString(settings_part_names[displayed_settings_part_],6 ,3);
00090         lcd.printString(sound_part_names[sound_method_],60 ,3);
00091     }else if(displayed_settings_part_ == music) {
00092         lcd.printString(settings_part_names[displayed_settings_part_],6 ,3);
00093         lcd.printString(music_part_names[music_method_],60 ,3);
00094     }else if(displayed_settings_part_ == contrast) {
00095         lcd.printString(settings_part_names[displayed_settings_part_],6 ,3);
00096         char buffer[2]; 
00097         sprintf(buffer,"%.2f",pot_read);
00098         lcd.printString(buffer,58,3);
00099     }
00100     
00101     // prints setting title and button instructions and arrows
00102     lcd.printString("Settings",18,0);
00103     lcd.drawSprite(39, 18, 3, 5, (int *)arrow_up);
00104     lcd.drawSprite(39, 34, 3, 5, (int *)arrow_down);
00105     lcd.printString("Back(B)Alt(A)",3,5);
00106 }
00107 
00108 void Settings::change_setting(bool pressed) {
00109     // When a is pressed changes the settings for the displayed setting part
00110     if (pressed) { 
00111         if (displayed_settings_part_ == sound_fx) { 
00112         sound_method_ = settings_on_off_fsm[sound_method_].part_next;  
00113         }else if(displayed_settings_part_ == controls) {
00114             control_method_ = settings_joy_acc_fsm[control_method_].part_next;  
00115         }else if(displayed_settings_part_ == music) {
00116             music_method_ =  music_on_off_fsm[music_method_].part_next; 
00117         }   
00118     wait(0.3);   
00119     }
00120     
00121 }
00122 
00123 void Settings::settings_scroll(Direction d_) {
00124     // Changes displayed settings part depending on joystick input
00125     if (d_ == N || d_ == NE || d_ == NW ) {  
00126         // printf(" displayed_settings_part_ %d\n",displayed_settings_part_);
00127         displayed_settings_part_ = 
00128         settings_fsm[displayed_settings_part_].part_next;   
00129     } else if (d_ == S || d_ == SW || d_ == SE) {
00130         displayed_settings_part_= 
00131         settings_fsm[displayed_settings_part_].part_previous; 
00132     }
00133     wait(0.15);
00134 }