void PlayLayer::onPause() { if (game_stoped) { return; } game_stoped = true; //stopMusic(); this->unschedule(schedule_selector(PlayLayer::step)); this->unschedule(schedule_selector(PlayLayer::gameProc)); this->unschedule(schedule_selector(PlayLayer::procLostStone)); this->unschedule(schedule_selector(PlayLayer::lookWheel)); this->unschedule(schedule_selector(PlayLayer::onTruckTimer)); DoodleTruck *doodleTruck = DoodleTruck::sharedDoodleTruck(); if (doodleTruck->getMode()) game_time = getLimitTime(doodleTruck->getMapIndex()); else game_time = 0; showPauseMenu(); }
//main game loop extern void showGame(MI0283QT9 lcd){ //setup seed uint16_t seed = (rand() % 65534) + 1; srand(seed); //setup car uint8_t x = 2; uint8_t movCounter = 0; uint8_t colored[] = {red,green,blue}; uint16_t score = 0; uint8_t pSensitivity = 0; initGenObjects(); //objects preGenObjects[128]; if (sLow == 1) { pSensitivity = 5; } else if (sMedium == 1) { pSensitivity = 4; } else if (sHigh == 1){ pSensitivity = 3; } //Draw game road showDefaultLayout(lcd); nun.nunchuck_init(); posYobj1 = 0; posYobj2 = 0; posYobj3 = 0; prevposXobj1 = 0; prevposXobj2 = 0; prevposXobj3 = 0; keepObj2Alive = 0; keepObj3Alive = 0; uint8_t carHitMax = 15; uint8_t truckHitmax = 18; uint8_t countDown = 3; //start game loop while(1){ if(returnToMain){ returnToMain = 0; lcd.fillScreen(BACKGROUND); break; } if(restartGame){ posYobj1 = 0; posYobj2 = 0; posYobj3 = 0; prevposXobj1 = 0; prevposXobj2 = 0; prevposXobj3 = 0; keepObj2Alive = 0; keepObj3Alive = 0; //Draw game road initGenObjects(); x = 2; movCounter = 0; colored[0] = red; colored[1] = green; colored[2] = blue; score = 0; pSensitivity = 0; if (sLow == 1) { pSensitivity = 5; } else if (sMedium == 1) { pSensitivity = 4; } else if (sHigh == 1) { pSensitivity = 3; } showDefaultLayout(lcd); onBeginB = 0; restartGame = 0; countDown = 3; } //countdown before game start while(countDown != 0){ lcd.drawInteger(centerText(" ", 3), 150, countDown, DEC, OBJECTCOLOR, BACKGROUND, 3); _delay_ms(1000); lcd.drawInteger(centerText(" ", 3), 150, countDown, DEC, BACKGROUND, BACKGROUND, 3); if(countDown == 1){ lcd.drawText(centerText("START" , 3), 150, "START", OBJECTCOLOR, BACKGROUND, 3); _delay_ms(1000); lcd.drawText(centerText("START" , 3), 150, "START", BACKGROUND, BACKGROUND, 3); } countDown--; } //shows the enemy cars showGenObjects(lcd); //Draw player car at start location drawCar(lcd, x, 12,colored); //If obj1 is at you y location, check if objectx = playerx if((object[0].type == 1 && object[0].posY >= 12 && object[0].posY <= carHitMax ) || (object[0].type == 2 && object[0].posY >= 12 && object[0].posY <= truckHitmax)){ if (object[0].posX == x ) { showGameOverMenu(lcd, score); }else{ if(object[0].posY == carHitMax || object[0].posY == truckHitmax){ score = object[0].type + score; } } }else if((object[1].type == 1 && object[1].posY >= 12 && object[1].posY <= carHitMax ) || (object[1].type == 2 && object[1].posY >= 12 && object[1].posY <= truckHitmax)){ //If obj2 is at player y location, check if objectx = playerx if (object[1].posX == x) { showGameOverMenu(lcd,score); }else{ if(object[1].posY == carHitMax || object[1].posY == truckHitmax){ score = object[1].type + score; } } } else if((object[2].type == 1 && object[2].posY >= 12 && object[2].posY <= carHitMax ) || (object[2].type == 2 && object[2].posY >= 12 && object[2].posY <= truckHitmax)){ //If obj3 is at player y location, check if objectx = playerx if (object[2].posX == x) { showGameOverMenu(lcd,score); }else{ if(object[2].posY == carHitMax || object[2].posY == truckHitmax){ score = object[2].type + score; } } } //draws car at x depending on tilt, and y = 12 (front of car), y = 15 end of car if(nun.retreive_data()){ if (nun.getC() ==1) { showPauseMenu(lcd); } //if nunchuck is tilted right, increment x if(nun.getAccX() > 148 || nun.getJoyX() > 150){ if(movCounter == 0){ removeCar(lcd, x, 12); if(x<4){ x++; } movCounter++; }else{ movCounter++; if(movCounter>=pSensitivity){ movCounter = 0; } } drawCar(lcd, x, 12, colored); } //draw car at x location //if nunchuck is tilted left, substract 1 from x else if((nun.getAccX() > 70 && nun.getAccX() < 108) || nun.getJoyX() < 90){ if(movCounter==0){ removeCar(lcd, x, 12); if(x>0){ x--; } movCounter++; }else{ movCounter++; if(movCounter>=pSensitivity){ movCounter = 0; } } //draw car at x location drawCar(lcd, x, 12, colored); //if nunchuck is in middle, movCounter = 0 }else if(nun.getAccX() > 120 && nun.getAccX() < 136){ movCounter = 0; } lcd.drawInteger(22, 2, score, DEC, GRASSCOLOR, BACKGROUND, 1); } } }