Ahmed Adamjee
/
SnakeVSBlock
Snake vs Block Game to be run upon K64F.
MenuClasses/Settings/Settings.cpp@76:7fa91122907f, 2019-05-05 (annotated)
- Committer:
- AhmedPlaymaker
- Date:
- Sun May 05 15:00:34 2019 +0000
- Revision:
- 76:7fa91122907f
- Parent:
- 64:540aa1602372
- Child:
- 83:329da564799a
Fixed a problem i did not know i had about block sides collision, where i added the x axis coordinates of the block to the collision loop.
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 | 49:441c32f6603e | 79 | float * Settings::Implement(N5110 &lcd, Gamepad &pad, float cs) |
AhmedPlaymaker | 30:461231877c89 | 80 | { |
AhmedPlaymaker | 30:461231877c89 | 81 | Settings::info(lcd, pad); |
AhmedPlaymaker | 64:540aa1602372 | 82 | cs_sc[0] = 4; //to initialise the control speeds |
AhmedPlaymaker | 64:540aa1602372 | 83 | cs_sc[1] = 1; //to set show credits to a default of 1. |
AhmedPlaymaker | 63:205f0ca48473 | 84 | int st = 1; //an index for settings |
AhmedPlaymaker | 63:205f0ca48473 | 85 | wait(1/cs); //to avoid a race condition of the following while loop being skipped. |
AhmedPlaymaker | 61:f3c402bc2ad0 | 86 | //pad.init(); |
AhmedPlaymaker | 30:461231877c89 | 87 | while (pad.check_event(Gamepad::BACK_PRESSED) == false) { //if button pressed. |
AhmedPlaymaker | 30:461231877c89 | 88 | Direction d = pad.get_direction(); |
AhmedPlaymaker | 30:461231877c89 | 89 | wait(1/cs); |
AhmedPlaymaker | 30:461231877c89 | 90 | lcd.clear(); |
AhmedPlaymaker | 63:205f0ca48473 | 91 | |
AhmedPlaymaker | 63:205f0ca48473 | 92 | if((d==E)&&(st==4)) { |
AhmedPlaymaker | 63:205f0ca48473 | 93 | st=1; |
AhmedPlaymaker | 63:205f0ca48473 | 94 | } |
AhmedPlaymaker | 63:205f0ca48473 | 95 | |
AhmedPlaymaker | 63:205f0ca48473 | 96 | else if((d==W)&&(st==1)) { |
AhmedPlaymaker | 63:205f0ca48473 | 97 | st=4; |
AhmedPlaymaker | 63:205f0ca48473 | 98 | } |
AhmedPlaymaker | 63:205f0ca48473 | 99 | |
AhmedPlaymaker | 63:205f0ca48473 | 100 | else if((d==E)&&(1<=st<=3)) { |
AhmedPlaymaker | 63:205f0ca48473 | 101 | st=st+1; |
AhmedPlaymaker | 63:205f0ca48473 | 102 | } |
AhmedPlaymaker | 63:205f0ca48473 | 103 | |
AhmedPlaymaker | 63:205f0ca48473 | 104 | else if((d==W)&&(2<=st<=4)) { |
AhmedPlaymaker | 63:205f0ca48473 | 105 | st=st-1; |
AhmedPlaymaker | 63:205f0ca48473 | 106 | } |
AhmedPlaymaker | 63:205f0ca48473 | 107 | |
AhmedPlaymaker | 55:df0825049171 | 108 | Settings::CallFunctions(lcd, pad, st); |
AhmedPlaymaker | 30:461231877c89 | 109 | } |
AhmedPlaymaker | 55:df0825049171 | 110 | pad.tone(1000.0,0.1); |
AhmedPlaymaker | 30:461231877c89 | 111 | return cs_sc; |
AhmedPlaymaker | 30:461231877c89 | 112 | } |
AhmedPlaymaker | 30:461231877c89 | 113 | |
AhmedPlaymaker | 5:e4df87957a5b | 114 | void Settings::info(N5110 &lcd, Gamepad &pad) |
AhmedPlaymaker | 5:e4df87957a5b | 115 | { |
AhmedPlaymaker | 5:e4df87957a5b | 116 | lcd.clear(); |
AhmedPlaymaker | 5:e4df87957a5b | 117 | pad.leds_on(); |
AhmedPlaymaker | 5:e4df87957a5b | 118 | lcd.printString("For selecting",0,0);//Function used to promt the user to how to use settings. |
AhmedPlaymaker | 5:e4df87957a5b | 119 | lcd.printString("from settings",0,1); |
AhmedPlaymaker | 5:e4df87957a5b | 120 | lcd.printString("available, use",0,2); |
AhmedPlaymaker | 5:e4df87957a5b | 121 | lcd.printString("Joystick in <>",0,3); |
AhmedPlaymaker | 5:e4df87957a5b | 122 | lcd.printString("directions",0,4); |
AhmedPlaymaker | 5:e4df87957a5b | 123 | lcd.refresh(); |
AhmedPlaymaker | 5:e4df87957a5b | 124 | wait(2); |
AhmedPlaymaker | 5:e4df87957a5b | 125 | lcd.clear(); |
AhmedPlaymaker | 5:e4df87957a5b | 126 | lcd.printString("For adjusting",0,0); |
AhmedPlaymaker | 5:e4df87957a5b | 127 | lcd.printString("the parameters,",0,1); |
AhmedPlaymaker | 5:e4df87957a5b | 128 | lcd.printString("use the pot",0,2); |
AhmedPlaymaker | 5:e4df87957a5b | 129 | lcd.printString("by rotating",0,3); |
AhmedPlaymaker | 5:e4df87957a5b | 130 | lcd.printString("Press Back",0,4); |
AhmedPlaymaker | 5:e4df87957a5b | 131 | lcd.printString("to confirm",0,5); |
AhmedPlaymaker | 5:e4df87957a5b | 132 | lcd.refresh(); |
AhmedPlaymaker | 5:e4df87957a5b | 133 | wait(2); |
AhmedPlaymaker | 5:e4df87957a5b | 134 | pad.leds_off(); |
AhmedPlaymaker | 5:e4df87957a5b | 135 | } |
AhmedPlaymaker | 5:e4df87957a5b | 136 | |
AhmedPlaymaker | 63:205f0ca48473 | 137 | void Settings::CallFunctions(N5110 &lcd, Gamepad &pad, int st) |
AhmedPlaymaker | 63:205f0ca48473 | 138 | { |
AhmedPlaymaker | 76:7fa91122907f | 139 | lcd.clear(); |
AhmedPlaymaker | 63:205f0ca48473 | 140 | lcd.drawSprite(5,22,13,8,(int *)naviL); //Function used to draw the sprite. |
AhmedPlaymaker | 63:205f0ca48473 | 141 | lcd.drawSprite(71,22,13,8,(int *)naviR); //Function used to draw the sprite. |
AhmedPlaymaker | 63:205f0ca48473 | 142 | switch (st) { |
AhmedPlaymaker | 63:205f0ca48473 | 143 | case 1: |
AhmedPlaymaker | 63:205f0ca48473 | 144 | Settings::controlSensitivity(lcd, pad); |
AhmedPlaymaker | 63:205f0ca48473 | 145 | break; |
AhmedPlaymaker | 63:205f0ca48473 | 146 | case 2: |
AhmedPlaymaker | 63:205f0ca48473 | 147 | Settings::brigntness(lcd, pad); |
AhmedPlaymaker | 63:205f0ca48473 | 148 | break; |
AhmedPlaymaker | 63:205f0ca48473 | 149 | case 3: |
AhmedPlaymaker | 63:205f0ca48473 | 150 | Settings::contrast(lcd, pad); |
AhmedPlaymaker | 63:205f0ca48473 | 151 | break; |
AhmedPlaymaker | 63:205f0ca48473 | 152 | case 4: |
AhmedPlaymaker | 63:205f0ca48473 | 153 | Settings::showCredits(lcd, pad); |
AhmedPlaymaker | 63:205f0ca48473 | 154 | break; |
AhmedPlaymaker | 63:205f0ca48473 | 155 | } |
AhmedPlaymaker | 63:205f0ca48473 | 156 | lcd.refresh(); |
AhmedPlaymaker | 63:205f0ca48473 | 157 | } |
AhmedPlaymaker | 63:205f0ca48473 | 158 | |
AhmedPlaymaker | 49:441c32f6603e | 159 | void Settings::controlSensitivity(N5110 &lcd, Gamepad &pad) |
AhmedPlaymaker | 5:e4df87957a5b | 160 | { |
AhmedPlaymaker | 5:e4df87957a5b | 161 | lcd.printString("Control Speeds",0,0); |
AhmedPlaymaker | 49:441c32f6603e | 162 | cs_sc[0] = pad.read_pot()*5+1; |
AhmedPlaymaker | 5:e4df87957a5b | 163 | lcd.drawRect(15,22,54,13,FILL_TRANSPARENT); |
AhmedPlaymaker | 5:e4df87957a5b | 164 | lcd.drawRect(15,22,pad.read_pot()*54,13,FILL_BLACK); |
AhmedPlaymaker | 5:e4df87957a5b | 165 | pad.leds_on(); |
AhmedPlaymaker | 5:e4df87957a5b | 166 | } |
AhmedPlaymaker | 5:e4df87957a5b | 167 | |
AhmedPlaymaker | 5:e4df87957a5b | 168 | void Settings::brigntness(N5110 &lcd, Gamepad &pad) |
AhmedPlaymaker | 5:e4df87957a5b | 169 | { |
AhmedPlaymaker | 57:845781aea5ec | 170 | lcd.drawSprite(35,2,15,15,(int *)brightness); //Function used to draw the sprite. |
AhmedPlaymaker | 5:e4df87957a5b | 171 | float pot; |
AhmedPlaymaker | 5:e4df87957a5b | 172 | pot = pad.read_pot(); |
AhmedPlaymaker | 5:e4df87957a5b | 173 | lcd.drawRect(15,22,54,13,FILL_TRANSPARENT); |
AhmedPlaymaker | 5:e4df87957a5b | 174 | lcd.drawRect(15,22,pad.read_pot()*54,13,FILL_BLACK); |
AhmedPlaymaker | 5:e4df87957a5b | 175 | lcd.setBrightness(pot); |
AhmedPlaymaker | 5:e4df87957a5b | 176 | pad.leds_on(); |
AhmedPlaymaker | 5:e4df87957a5b | 177 | } |
AhmedPlaymaker | 5:e4df87957a5b | 178 | |
AhmedPlaymaker | 5:e4df87957a5b | 179 | void Settings::contrast(N5110 &lcd, Gamepad &pad) |
AhmedPlaymaker | 5:e4df87957a5b | 180 | { |
AhmedPlaymaker | 57:845781aea5ec | 181 | lcd.drawSprite(36,3,13,13,(int *)screenContrast); //Function used to draw the sprite. |
AhmedPlaymaker | 5:e4df87957a5b | 182 | float pot; |
AhmedPlaymaker | 43:233f93860d08 | 183 | pot = ((pad.read_pot()+3.8)/8); |
AhmedPlaymaker | 5:e4df87957a5b | 184 | lcd.drawRect(15,22,54,13,FILL_TRANSPARENT); |
AhmedPlaymaker | 5:e4df87957a5b | 185 | lcd.drawRect(15,22,pad.read_pot()*54,13,FILL_BLACK); |
AhmedPlaymaker | 5:e4df87957a5b | 186 | lcd.setContrast(pot); |
AhmedPlaymaker | 5:e4df87957a5b | 187 | pad.leds_on(); |
AhmedPlaymaker | 5:e4df87957a5b | 188 | } |
AhmedPlaymaker | 5:e4df87957a5b | 189 | |
AhmedPlaymaker | 49:441c32f6603e | 190 | void Settings::showCredits(N5110 &lcd, Gamepad &pad) |
AhmedPlaymaker | 5:e4df87957a5b | 191 | { |
AhmedPlaymaker | 5:e4df87957a5b | 192 | lcd.printString("Show Credits?",5,0); |
AhmedPlaymaker | 5:e4df87957a5b | 193 | float pot; |
AhmedPlaymaker | 5:e4df87957a5b | 194 | pot = pad.read_pot(); |
AhmedPlaymaker | 63:205f0ca48473 | 195 | |
AhmedPlaymaker | 6:3ffab44ed49c | 196 | 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 | 63:205f0ca48473 | 197 | lcd.printString("NO",36,3); |
AhmedPlaymaker | 63:205f0ca48473 | 198 | cs_sc[1] = 0; |
AhmedPlaymaker | 5:e4df87957a5b | 199 | } |
AhmedPlaymaker | 63:205f0ca48473 | 200 | |
AhmedPlaymaker | 6:3ffab44ed49c | 201 | else { |
AhmedPlaymaker | 63:205f0ca48473 | 202 | lcd.printString("YES",33,3); |
AhmedPlaymaker | 63:205f0ca48473 | 203 | cs_sc[1] = 1; |
AhmedPlaymaker | 5:e4df87957a5b | 204 | } |
AhmedPlaymaker | 63:205f0ca48473 | 205 | |
AhmedPlaymaker | 5:e4df87957a5b | 206 | pad.leds_on(); |
AhmedPlaymaker | 5:e4df87957a5b | 207 | } |