![](/media/cache/profiles/LinkedIn_0NghoZJ.jpeg.50x50_q85.jpg)
Snake vs Block Game to be run upon K64F.
MenuClasses/Settings/Settings.cpp@104:17040265b7b4, 2019-05-09 (annotated)
- Committer:
- AhmedPlaymaker
- Date:
- Thu May 09 14:52:19 2019 +0000
- Revision:
- 104:17040265b7b4
- Parent:
- 89:8fbb0405a916
Final Submission. I have read and agreed with Statement of Academic Integrity.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
AhmedPlaymaker | 5:e4df87957a5b | 1 | #include "Settings.h" |
AhmedPlaymaker | 5:e4df87957a5b | 2 | |
AhmedPlaymaker | 5:e4df87957a5b | 3 | Settings::Settings() |
AhmedPlaymaker | 5:e4df87957a5b | 4 | { |
AhmedPlaymaker | 63:205f0ca48473 | 5 | |
AhmedPlaymaker | 5:e4df87957a5b | 6 | } |
AhmedPlaymaker | 5:e4df87957a5b | 7 | |
AhmedPlaymaker | 5:e4df87957a5b | 8 | Settings::~Settings() |
AhmedPlaymaker | 5:e4df87957a5b | 9 | { |
AhmedPlaymaker | 63:205f0ca48473 | 10 | |
AhmedPlaymaker | 5:e4df87957a5b | 11 | } |
AhmedPlaymaker | 5:e4df87957a5b | 12 | |
AhmedPlaymaker | 30:461231877c89 | 13 | int naviL[13][8] = { |
AhmedPlaymaker | 30:461231877c89 | 14 | {0,0,0,0,0,0,1,1}, |
AhmedPlaymaker | 30:461231877c89 | 15 | {0,0,0,0,0,1,1,0}, |
AhmedPlaymaker | 30:461231877c89 | 16 | {0,0,0,0,1,1,0,0}, |
AhmedPlaymaker | 30:461231877c89 | 17 | {0,0,0,1,1,0,0,0}, |
AhmedPlaymaker | 30:461231877c89 | 18 | {0,0,1,1,0,0,0,0}, |
AhmedPlaymaker | 30:461231877c89 | 19 | {0,1,1,0,0,0,0,0}, |
AhmedPlaymaker | 56:142e9fdb77a8 | 20 | {1,1,1,1,1,1,1,1}, |
AhmedPlaymaker | 30:461231877c89 | 21 | {0,1,1,0,0,0,0,0}, |
AhmedPlaymaker | 30:461231877c89 | 22 | {0,0,1,1,0,0,0,0}, |
AhmedPlaymaker | 30:461231877c89 | 23 | {0,0,0,1,1,0,0,0}, |
AhmedPlaymaker | 30:461231877c89 | 24 | {0,0,0,0,1,1,0,0}, |
AhmedPlaymaker | 30:461231877c89 | 25 | {0,0,0,0,0,1,1,0}, |
AhmedPlaymaker | 30:461231877c89 | 26 | {0,0,0,0,0,0,1,1}, |
AhmedPlaymaker | 30:461231877c89 | 27 | }; |
AhmedPlaymaker | 30:461231877c89 | 28 | |
AhmedPlaymaker | 30:461231877c89 | 29 | int naviR[13][8] = { |
AhmedPlaymaker | 30:461231877c89 | 30 | {1,1,0,0,0,0,0,0}, |
AhmedPlaymaker | 30:461231877c89 | 31 | {0,1,1,0,0,0,0,0}, |
AhmedPlaymaker | 30:461231877c89 | 32 | {0,0,1,1,0,0,0,0}, |
AhmedPlaymaker | 30:461231877c89 | 33 | {0,0,0,1,1,0,0,0}, |
AhmedPlaymaker | 30:461231877c89 | 34 | {0,0,0,0,1,1,0,0}, |
AhmedPlaymaker | 30:461231877c89 | 35 | {0,0,0,0,0,1,1,0}, |
AhmedPlaymaker | 56:142e9fdb77a8 | 36 | {1,1,1,1,1,1,1,1}, |
AhmedPlaymaker | 30:461231877c89 | 37 | {0,0,0,0,0,1,1,0}, |
AhmedPlaymaker | 30:461231877c89 | 38 | {0,0,0,0,1,1,0,0}, |
AhmedPlaymaker | 30:461231877c89 | 39 | {0,0,0,1,1,0,0,0}, |
AhmedPlaymaker | 30:461231877c89 | 40 | {0,0,1,1,0,0,0,0}, |
AhmedPlaymaker | 30:461231877c89 | 41 | {0,1,1,0,0,0,0,0}, |
AhmedPlaymaker | 30:461231877c89 | 42 | {1,1,0,0,0,0,0,0}, |
AhmedPlaymaker | 30:461231877c89 | 43 | }; |
AhmedPlaymaker | 30:461231877c89 | 44 | |
AhmedPlaymaker | 57:845781aea5ec | 45 | int screenContrast[13][13] = { |
AhmedPlaymaker | 57:845781aea5ec | 46 | {0,0,0,0,1,1,1,1,1,0,0,0,0}, |
AhmedPlaymaker | 57:845781aea5ec | 47 | {0,0,0,1,0,0,0,0,0,1,0,0,0}, |
AhmedPlaymaker | 57:845781aea5ec | 48 | {0,0,1,0,0,1,1,1,0,0,1,0,0}, |
AhmedPlaymaker | 57:845781aea5ec | 49 | {0,1,0,1,1,0,0,1,1,1,0,1,0}, |
AhmedPlaymaker | 57:845781aea5ec | 50 | {1,0,0,1,0,0,0,1,1,1,0,0,1}, |
AhmedPlaymaker | 57:845781aea5ec | 51 | {1,0,1,1,0,0,0,1,1,1,1,0,1}, |
AhmedPlaymaker | 57:845781aea5ec | 52 | {1,0,1,0,0,0,0,1,1,1,1,0,1}, |
AhmedPlaymaker | 57:845781aea5ec | 53 | {1,0,1,0,0,0,0,1,1,1,1,0,1}, |
AhmedPlaymaker | 57:845781aea5ec | 54 | {1,0,0,1,0,0,0,1,1,1,0,0,1}, |
AhmedPlaymaker | 57:845781aea5ec | 55 | {0,1,0,1,1,0,0,1,1,1,0,1,0}, |
AhmedPlaymaker | 57:845781aea5ec | 56 | {0,0,1,0,0,1,1,1,0,0,1,0,0}, |
AhmedPlaymaker | 57:845781aea5ec | 57 | {0,0,0,1,0,0,0,0,0,1,0,0,0}, |
AhmedPlaymaker | 57:845781aea5ec | 58 | {0,0,0,0,1,1,1,1,1,0,0,0,0}, |
AhmedPlaymaker | 57:845781aea5ec | 59 | }; |
AhmedPlaymaker | 57:845781aea5ec | 60 | |
AhmedPlaymaker | 57:845781aea5ec | 61 | int brightness[15][15] = { |
AhmedPlaymaker | 57:845781aea5ec | 62 | {0,0,0,1,0,0,0,1,0,0,0,1,0,0,0}, |
AhmedPlaymaker | 57:845781aea5ec | 63 | {0,1,0,0,1,0,0,1,0,0,1,0,0,1,0}, |
AhmedPlaymaker | 57:845781aea5ec | 64 | {0,0,1,0,0,1,0,1,0,1,0,0,1,0,0}, |
AhmedPlaymaker | 57:845781aea5ec | 65 | {1,0,0,1,0,0,1,1,1,0,0,1,0,0,1}, |
AhmedPlaymaker | 57:845781aea5ec | 66 | {0,1,0,0,1,1,0,0,0,1,1,0,0,1,0}, |
AhmedPlaymaker | 57:845781aea5ec | 67 | {0,0,1,0,1,0,0,0,0,0,1,0,1,0,0}, |
AhmedPlaymaker | 57:845781aea5ec | 68 | {0,0,0,1,0,0,0,0,0,0,0,1,0,0,0}, |
AhmedPlaymaker | 57:845781aea5ec | 69 | {1,1,1,1,0,0,0,0,0,0,0,1,1,1,1}, |
AhmedPlaymaker | 57:845781aea5ec | 70 | {0,0,0,1,0,0,0,0,0,0,0,1,0,0,0}, |
AhmedPlaymaker | 57:845781aea5ec | 71 | {0,0,1,0,1,0,0,0,0,0,1,0,1,0,0}, |
AhmedPlaymaker | 57:845781aea5ec | 72 | {0,1,0,0,1,1,0,0,0,1,1,0,0,1,0}, |
AhmedPlaymaker | 57:845781aea5ec | 73 | {1,0,0,1,0,0,1,1,1,0,0,1,0,0,1}, |
AhmedPlaymaker | 57:845781aea5ec | 74 | {0,0,1,0,0,1,0,1,0,1,0,0,1,0,0}, |
AhmedPlaymaker | 57:845781aea5ec | 75 | {0,1,0,0,1,0,0,1,0,0,1,0,0,1,0}, |
AhmedPlaymaker | 57:845781aea5ec | 76 | {0,0,0,1,0,0,0,1,0,0,0,1,0,0,0}, |
AhmedPlaymaker | 57:845781aea5ec | 77 | }; |
AhmedPlaymaker | 57:845781aea5ec | 78 | |
AhmedPlaymaker | 83:329da564799a | 79 | void Settings::init(N5110 *lcd, Gamepad *pad) |
AhmedPlaymaker | 30:461231877c89 | 80 | { |
AhmedPlaymaker | 83:329da564799a | 81 | _lcd = lcd; |
AhmedPlaymaker | 83:329da564799a | 82 | _pad = pad; |
AhmedPlaymaker | 89:8fbb0405a916 | 83 | cs_sc[0] = 4; //to initialise the control speeds |
AhmedPlaymaker | 89:8fbb0405a916 | 84 | cs_sc[1] = 1; //to set show credits to a default of 1. |
AhmedPlaymaker | 89:8fbb0405a916 | 85 | settingsIndex = 1; //an index for settings |
AhmedPlaymaker | 83:329da564799a | 86 | } |
AhmedPlaymaker | 83:329da564799a | 87 | |
AhmedPlaymaker | 89:8fbb0405a916 | 88 | float * Settings::Implement(float controlSensitivity) |
AhmedPlaymaker | 83:329da564799a | 89 | { |
AhmedPlaymaker | 83:329da564799a | 90 | Settings::info(); |
AhmedPlaymaker | 89:8fbb0405a916 | 91 | wait(1/controlSensitivity); //to avoid a race condition of the following while loop being skipped. |
AhmedPlaymaker | 83:329da564799a | 92 | //_pad->init(); |
AhmedPlaymaker | 83:329da564799a | 93 | while (_pad->check_event(Gamepad::BACK_PRESSED) == false) { //if button pressed. |
AhmedPlaymaker | 83:329da564799a | 94 | Direction d = _pad->get_direction(); |
AhmedPlaymaker | 89:8fbb0405a916 | 95 | wait(1/controlSensitivity); |
AhmedPlaymaker | 83:329da564799a | 96 | _lcd->clear(); |
AhmedPlaymaker | 63:205f0ca48473 | 97 | |
AhmedPlaymaker | 89:8fbb0405a916 | 98 | if((d==E)&&(settingsIndex==4)) { |
AhmedPlaymaker | 89:8fbb0405a916 | 99 | settingsIndex=1; |
AhmedPlaymaker | 63:205f0ca48473 | 100 | } |
AhmedPlaymaker | 63:205f0ca48473 | 101 | |
AhmedPlaymaker | 89:8fbb0405a916 | 102 | else if((d==W)&&(settingsIndex==1)) { |
AhmedPlaymaker | 89:8fbb0405a916 | 103 | settingsIndex=4; |
AhmedPlaymaker | 63:205f0ca48473 | 104 | } |
AhmedPlaymaker | 63:205f0ca48473 | 105 | |
AhmedPlaymaker | 89:8fbb0405a916 | 106 | else if((d==E)&&(1<=settingsIndex<=3)) { |
AhmedPlaymaker | 89:8fbb0405a916 | 107 | settingsIndex=settingsIndex+1; |
AhmedPlaymaker | 63:205f0ca48473 | 108 | } |
AhmedPlaymaker | 63:205f0ca48473 | 109 | |
AhmedPlaymaker | 89:8fbb0405a916 | 110 | else if((d==W)&&(2<=settingsIndex<=4)) { |
AhmedPlaymaker | 89:8fbb0405a916 | 111 | settingsIndex=settingsIndex-1; |
AhmedPlaymaker | 63:205f0ca48473 | 112 | } |
AhmedPlaymaker | 63:205f0ca48473 | 113 | |
AhmedPlaymaker | 89:8fbb0405a916 | 114 | Settings::CallFunctions(settingsIndex); |
AhmedPlaymaker | 30:461231877c89 | 115 | } |
AhmedPlaymaker | 83:329da564799a | 116 | _pad->tone(1000.0,0.1); |
AhmedPlaymaker | 30:461231877c89 | 117 | return cs_sc; |
AhmedPlaymaker | 30:461231877c89 | 118 | } |
AhmedPlaymaker | 30:461231877c89 | 119 | |
AhmedPlaymaker | 83:329da564799a | 120 | void Settings::info() |
AhmedPlaymaker | 5:e4df87957a5b | 121 | { |
AhmedPlaymaker | 83:329da564799a | 122 | _lcd->clear(); |
AhmedPlaymaker | 83:329da564799a | 123 | _pad->leds_on(); |
AhmedPlaymaker | 83:329da564799a | 124 | _lcd->printString("For selecting",0,0);//Function used to promt the user to how to use settings. |
AhmedPlaymaker | 83:329da564799a | 125 | _lcd->printString("from settings",0,1); |
AhmedPlaymaker | 83:329da564799a | 126 | _lcd->printString("available, use",0,2); |
AhmedPlaymaker | 83:329da564799a | 127 | _lcd->printString("Joystick in <>",0,3); |
AhmedPlaymaker | 83:329da564799a | 128 | _lcd->printString("directions",0,4); |
AhmedPlaymaker | 83:329da564799a | 129 | _lcd->refresh(); |
AhmedPlaymaker | 5:e4df87957a5b | 130 | wait(2); |
AhmedPlaymaker | 83:329da564799a | 131 | _lcd->clear(); |
AhmedPlaymaker | 83:329da564799a | 132 | _lcd->printString("For adjusting",0,0); |
AhmedPlaymaker | 83:329da564799a | 133 | _lcd->printString("the parameters,",0,1); |
AhmedPlaymaker | 83:329da564799a | 134 | _lcd->printString("use the pot",0,2); |
AhmedPlaymaker | 83:329da564799a | 135 | _lcd->printString("by rotating",0,3); |
AhmedPlaymaker | 83:329da564799a | 136 | _lcd->printString("Press Back",0,4); |
AhmedPlaymaker | 83:329da564799a | 137 | _lcd->printString("to confirm",0,5); |
AhmedPlaymaker | 83:329da564799a | 138 | _lcd->refresh(); |
AhmedPlaymaker | 5:e4df87957a5b | 139 | wait(2); |
AhmedPlaymaker | 83:329da564799a | 140 | _pad->leds_off(); |
AhmedPlaymaker | 5:e4df87957a5b | 141 | } |
AhmedPlaymaker | 5:e4df87957a5b | 142 | |
AhmedPlaymaker | 89:8fbb0405a916 | 143 | void Settings::CallFunctions(int settingsIndex) |
AhmedPlaymaker | 63:205f0ca48473 | 144 | { |
AhmedPlaymaker | 83:329da564799a | 145 | _lcd->clear(); |
AhmedPlaymaker | 83:329da564799a | 146 | _lcd->drawSprite(5,22,13,8,(int *)naviL); //Function used to draw the sprite. |
AhmedPlaymaker | 83:329da564799a | 147 | _lcd->drawSprite(71,22,13,8,(int *)naviR); //Function used to draw the sprite. |
AhmedPlaymaker | 89:8fbb0405a916 | 148 | switch (settingsIndex) { |
AhmedPlaymaker | 63:205f0ca48473 | 149 | case 1: |
AhmedPlaymaker | 83:329da564799a | 150 | Settings::controlSensitivity(); |
AhmedPlaymaker | 63:205f0ca48473 | 151 | break; |
AhmedPlaymaker | 63:205f0ca48473 | 152 | case 2: |
AhmedPlaymaker | 83:329da564799a | 153 | Settings::brigntness(); |
AhmedPlaymaker | 63:205f0ca48473 | 154 | break; |
AhmedPlaymaker | 63:205f0ca48473 | 155 | case 3: |
AhmedPlaymaker | 83:329da564799a | 156 | Settings::contrast(); |
AhmedPlaymaker | 63:205f0ca48473 | 157 | break; |
AhmedPlaymaker | 63:205f0ca48473 | 158 | case 4: |
AhmedPlaymaker | 83:329da564799a | 159 | Settings::showCredits(); |
AhmedPlaymaker | 63:205f0ca48473 | 160 | break; |
AhmedPlaymaker | 63:205f0ca48473 | 161 | } |
AhmedPlaymaker | 83:329da564799a | 162 | _lcd->refresh(); |
AhmedPlaymaker | 63:205f0ca48473 | 163 | } |
AhmedPlaymaker | 63:205f0ca48473 | 164 | |
AhmedPlaymaker | 83:329da564799a | 165 | void Settings::controlSensitivity() |
AhmedPlaymaker | 5:e4df87957a5b | 166 | { |
AhmedPlaymaker | 83:329da564799a | 167 | _lcd->printString("Control Speeds",0,0); |
AhmedPlaymaker | 83:329da564799a | 168 | cs_sc[0] = _pad->read_pot()*5+1; |
AhmedPlaymaker | 83:329da564799a | 169 | _lcd->drawRect(15,22,54,13,FILL_TRANSPARENT); |
AhmedPlaymaker | 83:329da564799a | 170 | _lcd->drawRect(15,22,_pad->read_pot()*54,13,FILL_BLACK); |
AhmedPlaymaker | 83:329da564799a | 171 | _pad->leds_on(); |
AhmedPlaymaker | 5:e4df87957a5b | 172 | } |
AhmedPlaymaker | 5:e4df87957a5b | 173 | |
AhmedPlaymaker | 83:329da564799a | 174 | void Settings::brigntness() |
AhmedPlaymaker | 5:e4df87957a5b | 175 | { |
AhmedPlaymaker | 83:329da564799a | 176 | _lcd->drawSprite(35,2,15,15,(int *)brightness); //Function used to draw the sprite. |
AhmedPlaymaker | 5:e4df87957a5b | 177 | float pot; |
AhmedPlaymaker | 83:329da564799a | 178 | pot = _pad->read_pot(); |
AhmedPlaymaker | 83:329da564799a | 179 | _lcd->drawRect(15,22,54,13,FILL_TRANSPARENT); |
AhmedPlaymaker | 83:329da564799a | 180 | _lcd->drawRect(15,22,_pad->read_pot()*54,13,FILL_BLACK); |
AhmedPlaymaker | 83:329da564799a | 181 | _lcd->setBrightness(pot); |
AhmedPlaymaker | 83:329da564799a | 182 | _pad->leds_on(); |
AhmedPlaymaker | 5:e4df87957a5b | 183 | } |
AhmedPlaymaker | 5:e4df87957a5b | 184 | |
AhmedPlaymaker | 83:329da564799a | 185 | void Settings::contrast() |
AhmedPlaymaker | 5:e4df87957a5b | 186 | { |
AhmedPlaymaker | 83:329da564799a | 187 | _lcd->drawSprite(36,3,13,13,(int *)screenContrast); //Function used to draw the sprite. |
AhmedPlaymaker | 5:e4df87957a5b | 188 | float pot; |
AhmedPlaymaker | 83:329da564799a | 189 | pot = ((_pad->read_pot()+3.8)/8); |
AhmedPlaymaker | 83:329da564799a | 190 | _lcd->drawRect(15,22,54,13,FILL_TRANSPARENT); |
AhmedPlaymaker | 83:329da564799a | 191 | _lcd->drawRect(15,22,_pad->read_pot()*54,13,FILL_BLACK); |
AhmedPlaymaker | 83:329da564799a | 192 | _lcd->setContrast(pot); |
AhmedPlaymaker | 83:329da564799a | 193 | _pad->leds_on(); |
AhmedPlaymaker | 5:e4df87957a5b | 194 | } |
AhmedPlaymaker | 5:e4df87957a5b | 195 | |
AhmedPlaymaker | 83:329da564799a | 196 | void Settings::showCredits() |
AhmedPlaymaker | 5:e4df87957a5b | 197 | { |
AhmedPlaymaker | 83:329da564799a | 198 | _lcd->printString("Show Credits?",5,0); |
AhmedPlaymaker | 5:e4df87957a5b | 199 | float pot; |
AhmedPlaymaker | 83:329da564799a | 200 | pot = _pad->read_pot(); |
AhmedPlaymaker | 63:205f0ca48473 | 201 | |
AhmedPlaymaker | 6:3ffab44ed49c | 202 | if(((0.1<=pot)&&(pot<=0.2))||((0.3<=pot)&&(pot<=0.4))||((0.5<=pot)&&(pot<=0.6))||((0.7<=pot)&&(pot<=0.8))||((0.9<=pot)&&(pot<=1))) { |
AhmedPlaymaker | 83:329da564799a | 203 | _lcd->printString("NO",36,3); |
AhmedPlaymaker | 63:205f0ca48473 | 204 | cs_sc[1] = 0; |
AhmedPlaymaker | 5:e4df87957a5b | 205 | } |
AhmedPlaymaker | 63:205f0ca48473 | 206 | |
AhmedPlaymaker | 6:3ffab44ed49c | 207 | else { |
AhmedPlaymaker | 83:329da564799a | 208 | _lcd->printString("YES",33,3); |
AhmedPlaymaker | 63:205f0ca48473 | 209 | cs_sc[1] = 1; |
AhmedPlaymaker | 5:e4df87957a5b | 210 | } |
AhmedPlaymaker | 63:205f0ca48473 | 211 | |
AhmedPlaymaker | 83:329da564799a | 212 | _pad->leds_on(); |
AhmedPlaymaker | 5:e4df87957a5b | 213 | } |