![](/media/cache/profiles/LinkedIn_0NghoZJ.jpeg.50x50_q85.jpg)
Snake vs Block Game to be run upon K64F.
Diff: MenuClasses/Settings/Settings.cpp
- Revision:
- 83:329da564799a
- Parent:
- 76:7fa91122907f
- Child:
- 89:8fbb0405a916
--- a/MenuClasses/Settings/Settings.cpp Mon May 06 10:49:50 2019 +0000 +++ b/MenuClasses/Settings/Settings.cpp Mon May 06 14:28:35 2019 +0000 @@ -76,18 +76,24 @@ {0,0,0,1,0,0,0,1,0,0,0,1,0,0,0}, }; -float * Settings::Implement(N5110 &lcd, Gamepad &pad, float cs) +void Settings::init(N5110 *lcd, Gamepad *pad) { - Settings::info(lcd, pad); + _lcd = lcd; + _pad = pad; +} + +float * Settings::Implement(float cs) +{ + Settings::info(); cs_sc[0] = 4; //to initialise the control speeds cs_sc[1] = 1; //to set show credits to a default of 1. int st = 1; //an index for settings wait(1/cs); //to avoid a race condition of the following while loop being skipped. - //pad.init(); - while (pad.check_event(Gamepad::BACK_PRESSED) == false) { //if button pressed. - Direction d = pad.get_direction(); + //_pad->init(); + while (_pad->check_event(Gamepad::BACK_PRESSED) == false) { //if button pressed. + Direction d = _pad->get_direction(); wait(1/cs); - lcd.clear(); + _lcd->clear(); if((d==E)&&(st==4)) { st=1; @@ -105,103 +111,103 @@ st=st-1; } - Settings::CallFunctions(lcd, pad, st); + Settings::CallFunctions(st); } - pad.tone(1000.0,0.1); + _pad->tone(1000.0,0.1); return cs_sc; } -void Settings::info(N5110 &lcd, Gamepad &pad) +void Settings::info() { - lcd.clear(); - pad.leds_on(); - lcd.printString("For selecting",0,0);//Function used to promt the user to how to use settings. - lcd.printString("from settings",0,1); - lcd.printString("available, use",0,2); - lcd.printString("Joystick in <>",0,3); - lcd.printString("directions",0,4); - lcd.refresh(); + _lcd->clear(); + _pad->leds_on(); + _lcd->printString("For selecting",0,0);//Function used to promt the user to how to use settings. + _lcd->printString("from settings",0,1); + _lcd->printString("available, use",0,2); + _lcd->printString("Joystick in <>",0,3); + _lcd->printString("directions",0,4); + _lcd->refresh(); wait(2); - lcd.clear(); - lcd.printString("For adjusting",0,0); - lcd.printString("the parameters,",0,1); - lcd.printString("use the pot",0,2); - lcd.printString("by rotating",0,3); - lcd.printString("Press Back",0,4); - lcd.printString("to confirm",0,5); - lcd.refresh(); + _lcd->clear(); + _lcd->printString("For adjusting",0,0); + _lcd->printString("the parameters,",0,1); + _lcd->printString("use the pot",0,2); + _lcd->printString("by rotating",0,3); + _lcd->printString("Press Back",0,4); + _lcd->printString("to confirm",0,5); + _lcd->refresh(); wait(2); - pad.leds_off(); + _pad->leds_off(); } -void Settings::CallFunctions(N5110 &lcd, Gamepad &pad, int st) +void Settings::CallFunctions(int st) { - lcd.clear(); - lcd.drawSprite(5,22,13,8,(int *)naviL); //Function used to draw the sprite. - lcd.drawSprite(71,22,13,8,(int *)naviR); //Function used to draw the sprite. + _lcd->clear(); + _lcd->drawSprite(5,22,13,8,(int *)naviL); //Function used to draw the sprite. + _lcd->drawSprite(71,22,13,8,(int *)naviR); //Function used to draw the sprite. switch (st) { case 1: - Settings::controlSensitivity(lcd, pad); + Settings::controlSensitivity(); break; case 2: - Settings::brigntness(lcd, pad); + Settings::brigntness(); break; case 3: - Settings::contrast(lcd, pad); + Settings::contrast(); break; case 4: - Settings::showCredits(lcd, pad); + Settings::showCredits(); break; } - lcd.refresh(); + _lcd->refresh(); } -void Settings::controlSensitivity(N5110 &lcd, Gamepad &pad) +void Settings::controlSensitivity() { - lcd.printString("Control Speeds",0,0); - cs_sc[0] = pad.read_pot()*5+1; - lcd.drawRect(15,22,54,13,FILL_TRANSPARENT); - lcd.drawRect(15,22,pad.read_pot()*54,13,FILL_BLACK); - pad.leds_on(); + _lcd->printString("Control Speeds",0,0); + cs_sc[0] = _pad->read_pot()*5+1; + _lcd->drawRect(15,22,54,13,FILL_TRANSPARENT); + _lcd->drawRect(15,22,_pad->read_pot()*54,13,FILL_BLACK); + _pad->leds_on(); } -void Settings::brigntness(N5110 &lcd, Gamepad &pad) +void Settings::brigntness() { - lcd.drawSprite(35,2,15,15,(int *)brightness); //Function used to draw the sprite. + _lcd->drawSprite(35,2,15,15,(int *)brightness); //Function used to draw the sprite. float pot; - pot = pad.read_pot(); - lcd.drawRect(15,22,54,13,FILL_TRANSPARENT); - lcd.drawRect(15,22,pad.read_pot()*54,13,FILL_BLACK); - lcd.setBrightness(pot); - pad.leds_on(); + pot = _pad->read_pot(); + _lcd->drawRect(15,22,54,13,FILL_TRANSPARENT); + _lcd->drawRect(15,22,_pad->read_pot()*54,13,FILL_BLACK); + _lcd->setBrightness(pot); + _pad->leds_on(); } -void Settings::contrast(N5110 &lcd, Gamepad &pad) +void Settings::contrast() { - lcd.drawSprite(36,3,13,13,(int *)screenContrast); //Function used to draw the sprite. + _lcd->drawSprite(36,3,13,13,(int *)screenContrast); //Function used to draw the sprite. float pot; - pot = ((pad.read_pot()+3.8)/8); - lcd.drawRect(15,22,54,13,FILL_TRANSPARENT); - lcd.drawRect(15,22,pad.read_pot()*54,13,FILL_BLACK); - lcd.setContrast(pot); - pad.leds_on(); + pot = ((_pad->read_pot()+3.8)/8); + _lcd->drawRect(15,22,54,13,FILL_TRANSPARENT); + _lcd->drawRect(15,22,_pad->read_pot()*54,13,FILL_BLACK); + _lcd->setContrast(pot); + _pad->leds_on(); } -void Settings::showCredits(N5110 &lcd, Gamepad &pad) +void Settings::showCredits() { - lcd.printString("Show Credits?",5,0); + _lcd->printString("Show Credits?",5,0); float pot; - pot = pad.read_pot(); + pot = _pad->read_pot(); 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))) { - lcd.printString("NO",36,3); + _lcd->printString("NO",36,3); cs_sc[1] = 0; } else { - lcd.printString("YES",33,3); + _lcd->printString("YES",33,3); cs_sc[1] = 1; } - pad.leds_on(); + _pad->leds_on(); } \ No newline at end of file