int main() { setMode(MODE_4 | BG2_ENABLE); startGame(); while(1) { if (KEY_DOWN_NOW(KEY_START) && state == 0) { state = 1; numOfLives = 3; loadAvatar(); fillPalette(GPalette_palette, 0, GPALETTE_PALETTE_SIZE); PALETTE[200] = BLACK; PALETTE[201] = WHITE; PALETTE[202] = RED; PALETTE[203] = GREEN; PALETTE[204] = BLUE; for (int i = 0; i < 5; i++) { homeFlags[i] = 0; } } if (state == 1) { drawBG(); char liveStr[7]; if (numOfLives >= 0) { sprintf(liveStr, "%d", numOfLives); drawString4(10, 147, "LIVES LEFT: ", PALETTE[1]); drawString4(80, 147, liveStr, PALETTE[1]); } drawTrucks(); drawCars(); drawCrocodiles(); drawWoods(); drawFrog(); collision(); reset(); delay(2); waitForVblank(); flipPage(); } if (state == 2) { while (1) { if (KEY_DOWN_NOW(KEY_START)) { state = 0; break; } } } } return 0; }
void Helper::paint(QPainter *painter, QPaintEvent *event, int elapsed, bool timerStopped) { painter->fillRect(event->rect(), background); for (int i = 0; i < b->lights.length(); i++) { glm::vec2 position = b->lights.at(i)->getPosition(); drawLight(painter, position.x, position.y, b->lights.at(i)->radius); drawTrail(painter, b->lights.at(i)->trail, b->lights.at(i)->trailColor); } for (int j = 0; j < b->mosquitoes.length(); j++) { if (!b->mosquitoes.at(j)->isEaten) { drawMosquito(painter, b->mosquitoes.at(j)->position.x, b->mosquitoes.at(j)->position.y); } } for (int k = 0; k < b->walls.length(); k++) { drawWall(painter, b->walls.at(k)->point1.x, b->walls.at(k)->point1.y, b->walls.at(k)->point2.x, b->walls.at(k)->point2.y); } drawFrog(painter, b->frog->position.x, b->frog->position.y, b->frog->radius); }
int play() { drawFrog(); while(1) { drawImage4(0, 0, BACKGROUND_WIDTH, BACKGROUND_HEIGHT, background); // if(life < 61 && life >= 45) { // lifeCount = 3; // } else if (life < 45 && life >= 30){ // lifeCount = 2; // } else if (life < 30 && life > 10) { // lifeCount = 1; // } char str[15]; drawString4 (4, 8, "Your life: ", PALETTE[11]); sprintf (str, "%d", life); drawString4 (4, 70, str, PALETTE[11]); if(KEY_DOWN_NOW(BUTTON_RIGHT)) { frog.y = frog.y + 1; drawFrog(); flipPage(); } else if (KEY_DOWN_NOW(BUTTON_LEFT)) { frog.y = frog.y - 1; drawFrog(); flipPage(); } else if (KEY_DOWN_NOW(BUTTON_UP)) { frog.x = frog.x - 1; // drawImage4(frog.x, frog.y, FROG1_WIDTH, FROG1_HEIGHT, frog1); // drawImage4(frog.x, frog.y, FROG1_WIDTH, FROG1_HEIGHT, frog2); // drawImage4(frog.x, frog.y, FROG1_WIDTH, FROG1_HEIGHT, frog3); // drawImage4(frog.x, frog.y, FROG1_WIDTH, FROG1_HEIGHT, frog4); // drawImage4(frog.x, frog.y, FROG1_WIDTH, FROG1_HEIGHT, frog1); drawFrog(); flipPage(); } else if (KEY_DOWN_NOW(BUTTON_DOWN)) { frog.x = frog.x + 1; drawFrog(); flipPage(); } if (KEY_DOWN_NOW(BUTTON_SELECT)) { return START; } waitForVblank(); if ((frog.x == 0)) { return GAMEWIN; } drawOther(); redcar1.x %= 160; yellowcar1.x %= 160; bluecar1.x %= 160; flower1.x %= 160; tree1.x %= 160; flower2.x %= 160; tree2.x %= 160; redcar1.y %= 240; yellowcar1.y %= 240; bluecar1.y %= 240; flower1.y %= 240; tree1.y %= 240; flower2.y %= 240; tree2.y %= 240;; if(((((frog.x >= redcar1.x - 7)&&(frog.x <= redcar1.x +7)) && ((frog.y >= redcar1.y-7) && (frog.y <= redcar1.y + 7)))) || ((((frog.x >= yellowcar1.x - 7)&&(frog.x <= yellowcar1.x +7)) && ((frog.y >= yellowcar1.y-7) && (frog.y <= yellowcar1.y + 7)))) || ((((frog.x >= bluecar1.x - 7)&&(frog.x <= bluecar1.x +7)) && ((frog.y >= bluecar1.y-7) && (frog.y <= bluecar1.y + 7)))) || ((((frog.x >= flower1.x - 7)&&(frog.x <= flower1.x +7)) && ((frog.y >= flower1.y-7) && (frog.y <= flower1.y + 7)))) || ((((frog.x >= tree1.x - 7)&&(frog.x <= tree1.x +7)) && ((frog.y >= tree1.y-7) && (frog.y <= tree1.y + 7)))) || ((((frog.x >= flower2.x - 7)&&(frog.x <= flower2.x +7)) && ((frog.y >= flower2.y-7) && (frog.y <= flower2.y + 7)))) || ((((frog.x >= tree2.x - 7)&&(frog.x <= tree2.x +7)) && ((frog.y >= tree2.y-7) && (frog.y <= tree2.y + 7))))) { frog.x = 146; frog.y = 120; drawFrog(); life -= 1; if (life == 0) { return GAMELOSE; } if (frog.x == 0) { return GAMEWIN; } } } return 0; }