![](/media/cache/profiles/LinkedIn_0NghoZJ.jpeg.50x50_q85.jpg)
Snake vs Block Game to be run upon K64F.
Settings/Settings.cpp@30:461231877c89, 2019-04-15 (annotated)
- Committer:
- AhmedPlaymaker
- Date:
- Mon Apr 15 06:00:01 2019 +0000
- Revision:
- 30:461231877c89
- Parent:
- 6:3ffab44ed49c
- Child:
- 31:6566026b4c6a
Removed glitches of the pad remembering the buttons pressed too long.
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 | 5:e4df87957a5b | 5 | |
AhmedPlaymaker | 5:e4df87957a5b | 6 | } |
AhmedPlaymaker | 5:e4df87957a5b | 7 | |
AhmedPlaymaker | 5:e4df87957a5b | 8 | Settings::~Settings() |
AhmedPlaymaker | 5:e4df87957a5b | 9 | { |
AhmedPlaymaker | 5:e4df87957a5b | 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 | 30:461231877c89 | 20 | {1,1,0,0,0,0,0,0}, |
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 | 30:461231877c89 | 36 | {0,0,0,0,0,0,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 | 30:461231877c89 | 45 | float * Settings::Implement(N5110 &lcd, Gamepad &pad, int st, float cs) |
AhmedPlaymaker | 30:461231877c89 | 46 | { |
AhmedPlaymaker | 30:461231877c89 | 47 | Settings::info(lcd, pad); |
AhmedPlaymaker | 30:461231877c89 | 48 | while (pad.check_event(Gamepad::BACK_PRESSED) == false) { //if button pressed. |
AhmedPlaymaker | 30:461231877c89 | 49 | Direction d = pad.get_direction(); |
AhmedPlaymaker | 30:461231877c89 | 50 | wait(1/cs); |
AhmedPlaymaker | 30:461231877c89 | 51 | lcd.clear(); |
AhmedPlaymaker | 30:461231877c89 | 52 | |
AhmedPlaymaker | 30:461231877c89 | 53 | if((d==E)&&(st==5)) { |
AhmedPlaymaker | 30:461231877c89 | 54 | st=1; |
AhmedPlaymaker | 30:461231877c89 | 55 | } |
AhmedPlaymaker | 30:461231877c89 | 56 | else if((d==W)&&(st==1)) { |
AhmedPlaymaker | 30:461231877c89 | 57 | st=5; |
AhmedPlaymaker | 30:461231877c89 | 58 | } |
AhmedPlaymaker | 30:461231877c89 | 59 | else if((d==E)&&(1<=st<=4)) { |
AhmedPlaymaker | 30:461231877c89 | 60 | st=st+1; |
AhmedPlaymaker | 30:461231877c89 | 61 | } |
AhmedPlaymaker | 30:461231877c89 | 62 | else if((d==W)&&(2<=st<=5)) { |
AhmedPlaymaker | 30:461231877c89 | 63 | st=st-1; |
AhmedPlaymaker | 30:461231877c89 | 64 | } |
AhmedPlaymaker | 30:461231877c89 | 65 | lcd.drawSprite(5,22,13,8,(int *)naviL); //Function used to draw the sprite. |
AhmedPlaymaker | 30:461231877c89 | 66 | lcd.drawSprite(71,22,13,8,(int *)naviR); //Function used to draw the sprite. |
AhmedPlaymaker | 30:461231877c89 | 67 | if(st==1) { |
AhmedPlaymaker | 30:461231877c89 | 68 | cs = Settings::controlSensitivity(lcd, pad); |
AhmedPlaymaker | 30:461231877c89 | 69 | } |
AhmedPlaymaker | 30:461231877c89 | 70 | if(st==2) { |
AhmedPlaymaker | 30:461231877c89 | 71 | Settings::brigntness(lcd, pad); |
AhmedPlaymaker | 30:461231877c89 | 72 | } |
AhmedPlaymaker | 30:461231877c89 | 73 | if(st==3) { |
AhmedPlaymaker | 30:461231877c89 | 74 | Settings::contrast(lcd, pad); |
AhmedPlaymaker | 30:461231877c89 | 75 | } |
AhmedPlaymaker | 30:461231877c89 | 76 | if(st==4) { |
AhmedPlaymaker | 30:461231877c89 | 77 | Settings::volume(lcd, pad); |
AhmedPlaymaker | 30:461231877c89 | 78 | } |
AhmedPlaymaker | 30:461231877c89 | 79 | if(st==5) { |
AhmedPlaymaker | 30:461231877c89 | 80 | cs_sc[1] = Settings::showCredits(lcd, pad); |
AhmedPlaymaker | 30:461231877c89 | 81 | } |
AhmedPlaymaker | 30:461231877c89 | 82 | lcd.refresh(); |
AhmedPlaymaker | 30:461231877c89 | 83 | } |
AhmedPlaymaker | 30:461231877c89 | 84 | cs_sc[0] = cs; |
AhmedPlaymaker | 30:461231877c89 | 85 | return cs_sc; |
AhmedPlaymaker | 30:461231877c89 | 86 | } |
AhmedPlaymaker | 30:461231877c89 | 87 | |
AhmedPlaymaker | 5:e4df87957a5b | 88 | void Settings::info(N5110 &lcd, Gamepad &pad) |
AhmedPlaymaker | 5:e4df87957a5b | 89 | { |
AhmedPlaymaker | 5:e4df87957a5b | 90 | lcd.clear(); |
AhmedPlaymaker | 5:e4df87957a5b | 91 | pad.leds_on(); |
AhmedPlaymaker | 5:e4df87957a5b | 92 | lcd.printString("For selecting",0,0);//Function used to promt the user to how to use settings. |
AhmedPlaymaker | 5:e4df87957a5b | 93 | lcd.printString("from settings",0,1); |
AhmedPlaymaker | 5:e4df87957a5b | 94 | lcd.printString("available, use",0,2); |
AhmedPlaymaker | 5:e4df87957a5b | 95 | lcd.printString("Joystick in <>",0,3); |
AhmedPlaymaker | 5:e4df87957a5b | 96 | lcd.printString("directions",0,4); |
AhmedPlaymaker | 5:e4df87957a5b | 97 | lcd.refresh(); |
AhmedPlaymaker | 5:e4df87957a5b | 98 | wait(2); |
AhmedPlaymaker | 5:e4df87957a5b | 99 | lcd.clear(); |
AhmedPlaymaker | 5:e4df87957a5b | 100 | lcd.printString("For adjusting",0,0); |
AhmedPlaymaker | 5:e4df87957a5b | 101 | lcd.printString("the parameters,",0,1); |
AhmedPlaymaker | 5:e4df87957a5b | 102 | lcd.printString("use the pot",0,2); |
AhmedPlaymaker | 5:e4df87957a5b | 103 | lcd.printString("by rotating",0,3); |
AhmedPlaymaker | 5:e4df87957a5b | 104 | lcd.printString("Press Back",0,4); |
AhmedPlaymaker | 5:e4df87957a5b | 105 | lcd.printString("to confirm",0,5); |
AhmedPlaymaker | 5:e4df87957a5b | 106 | lcd.refresh(); |
AhmedPlaymaker | 5:e4df87957a5b | 107 | wait(2); |
AhmedPlaymaker | 5:e4df87957a5b | 108 | pad.leds_off(); |
AhmedPlaymaker | 5:e4df87957a5b | 109 | lcd.clear(); |
AhmedPlaymaker | 5:e4df87957a5b | 110 | } |
AhmedPlaymaker | 5:e4df87957a5b | 111 | |
AhmedPlaymaker | 5:e4df87957a5b | 112 | float Settings::controlSensitivity(N5110 &lcd, Gamepad &pad) |
AhmedPlaymaker | 5:e4df87957a5b | 113 | { |
AhmedPlaymaker | 5:e4df87957a5b | 114 | lcd.printString("Control Speeds",0,0); |
AhmedPlaymaker | 5:e4df87957a5b | 115 | float cs; |
AhmedPlaymaker | 6:3ffab44ed49c | 116 | cs = pad.read_pot()*5+1; |
AhmedPlaymaker | 5:e4df87957a5b | 117 | lcd.drawRect(15,22,54,13,FILL_TRANSPARENT); |
AhmedPlaymaker | 5:e4df87957a5b | 118 | lcd.drawRect(15,22,pad.read_pot()*54,13,FILL_BLACK); |
AhmedPlaymaker | 5:e4df87957a5b | 119 | pad.leds_on(); |
AhmedPlaymaker | 5:e4df87957a5b | 120 | return cs; |
AhmedPlaymaker | 5:e4df87957a5b | 121 | } |
AhmedPlaymaker | 5:e4df87957a5b | 122 | |
AhmedPlaymaker | 5:e4df87957a5b | 123 | void Settings::brigntness(N5110 &lcd, Gamepad &pad) |
AhmedPlaymaker | 5:e4df87957a5b | 124 | { |
AhmedPlaymaker | 5:e4df87957a5b | 125 | lcd.printString("Brigntness",9,0); |
AhmedPlaymaker | 5:e4df87957a5b | 126 | float pot; |
AhmedPlaymaker | 5:e4df87957a5b | 127 | pot = pad.read_pot(); |
AhmedPlaymaker | 5:e4df87957a5b | 128 | lcd.drawRect(15,22,54,13,FILL_TRANSPARENT); |
AhmedPlaymaker | 5:e4df87957a5b | 129 | lcd.drawRect(15,22,pad.read_pot()*54,13,FILL_BLACK); |
AhmedPlaymaker | 5:e4df87957a5b | 130 | lcd.setBrightness(pot); |
AhmedPlaymaker | 5:e4df87957a5b | 131 | pad.leds_on(); |
AhmedPlaymaker | 5:e4df87957a5b | 132 | } |
AhmedPlaymaker | 5:e4df87957a5b | 133 | |
AhmedPlaymaker | 5:e4df87957a5b | 134 | void Settings::contrast(N5110 &lcd, Gamepad &pad) |
AhmedPlaymaker | 5:e4df87957a5b | 135 | { |
AhmedPlaymaker | 5:e4df87957a5b | 136 | lcd.printString("Contrast",16,0); |
AhmedPlaymaker | 5:e4df87957a5b | 137 | float pot; |
AhmedPlaymaker | 6:3ffab44ed49c | 138 | pot = ((pad.read_pot()+3.5)/8); |
AhmedPlaymaker | 5:e4df87957a5b | 139 | lcd.drawRect(15,22,54,13,FILL_TRANSPARENT); |
AhmedPlaymaker | 5:e4df87957a5b | 140 | lcd.drawRect(15,22,pad.read_pot()*54,13,FILL_BLACK); |
AhmedPlaymaker | 5:e4df87957a5b | 141 | lcd.setContrast(pot); |
AhmedPlaymaker | 5:e4df87957a5b | 142 | pad.leds_on(); |
AhmedPlaymaker | 5:e4df87957a5b | 143 | } |
AhmedPlaymaker | 5:e4df87957a5b | 144 | |
AhmedPlaymaker | 5:e4df87957a5b | 145 | void Settings::volume(N5110 &lcd, Gamepad &pad) |
AhmedPlaymaker | 5:e4df87957a5b | 146 | { |
AhmedPlaymaker | 5:e4df87957a5b | 147 | lcd.printString("Volume",20,0); |
AhmedPlaymaker | 5:e4df87957a5b | 148 | float pot; |
AhmedPlaymaker | 5:e4df87957a5b | 149 | pot = pad.read_pot(); |
AhmedPlaymaker | 5:e4df87957a5b | 150 | lcd.drawRect(15,22,54,13,FILL_TRANSPARENT); |
AhmedPlaymaker | 5:e4df87957a5b | 151 | lcd.drawRect(15,22,pot*54,13,FILL_BLACK); |
AhmedPlaymaker | 5:e4df87957a5b | 152 | pad.leds_on(); |
AhmedPlaymaker | 5:e4df87957a5b | 153 | } |
AhmedPlaymaker | 5:e4df87957a5b | 154 | |
AhmedPlaymaker | 5:e4df87957a5b | 155 | int Settings::showCredits(N5110 &lcd, Gamepad &pad) |
AhmedPlaymaker | 5:e4df87957a5b | 156 | { |
AhmedPlaymaker | 5:e4df87957a5b | 157 | lcd.printString("Show Credits?",5,0); |
AhmedPlaymaker | 5:e4df87957a5b | 158 | float pot; |
AhmedPlaymaker | 5:e4df87957a5b | 159 | int show = 1; |
AhmedPlaymaker | 5:e4df87957a5b | 160 | pot = pad.read_pot(); |
AhmedPlaymaker | 5:e4df87957a5b | 161 | |
AhmedPlaymaker | 6:3ffab44ed49c | 162 | 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 | 5:e4df87957a5b | 163 | lcd.printString("NO",36,3); |
AhmedPlaymaker | 5:e4df87957a5b | 164 | show = 0; |
AhmedPlaymaker | 5:e4df87957a5b | 165 | } |
AhmedPlaymaker | 5:e4df87957a5b | 166 | |
AhmedPlaymaker | 6:3ffab44ed49c | 167 | else { |
AhmedPlaymaker | 5:e4df87957a5b | 168 | lcd.printString("YES",33,3); |
AhmedPlaymaker | 5:e4df87957a5b | 169 | show = 1; |
AhmedPlaymaker | 5:e4df87957a5b | 170 | } |
AhmedPlaymaker | 6:3ffab44ed49c | 171 | |
AhmedPlaymaker | 5:e4df87957a5b | 172 | pad.leds_on(); |
AhmedPlaymaker | 5:e4df87957a5b | 173 | return show; |
AhmedPlaymaker | 5:e4df87957a5b | 174 | } |