void win() { fillPalette(startScreen_palette, 0, STARTSCREEN_PALETTE_SIZE); drawImage4(0, 0, 240, 160, start); drawString4(90, 130, "YOU WIN!", PALETTE[2]); drawString4(60, 145, "PRESS <START> TO RESTART", PALETTE[2]); state = 2; }
void lose() { fillPalette(gameOverScreen_palette, 0, GAMEOVERSCREEN_PALETTE_SIZE); drawImage4(0, 0, 240, 160, gameOver); drawString4(90, 130, "TRY AGAIN?", PALETTE[2]); drawString4(60, 145, "PRESS <START> TO RESTART", PALETTE[2]); state = 2; }
//draw discription information such as lives and score void drawDiscription(){ drawString4( 1, 1, "SCORE:", YELLOWIDX); writeNum(0, 1, 55, 35, 10, YELLOWIDX); drawRect(1, 90, 10, 10, BLACKIDX); drawString4( 1, 90, "LIVES:", YELLOWIDX); writeNum(3, 1, 140, 35, 10, YELLOWIDX); drawRect(1, 175, 10, 10, BLACKIDX); }
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 draw() { drawPacman(pacman.row, pacman.col); drawString4(SCREENHEIGHT-TEXT_HEIGHT, 0, string, WHITEINDEX); for (int i = 0; i < NUMDOTS; i++) drawDot(i); }
void drawLives(megaman* X) { drawHollowRect4(20,1,53,15,5); drawRect4(21,2,52,14,202); drawRect4(23,4,41,10,5); for(int i=0; i<(X->lives); i++) { drawRect4(2*i+24+(20-X->lives)*2,6,1,6,254); } char string[5]; sprintf(string,"x"); drawString4(64,6,string,149); }
static void loseLife() { numOfLives--; if (numOfLives >= 0) { drawString4(95, 75, "LIVES -1", PALETTE[1]); flipPage(); delay(20); loadAvatar(); } else { lose(); } }
void writeNum(short s, u16 row, u16 col, u16 width, u16 height, u8 ci){ // FlipPage(); drawRect(row, col, height, width, BLACKIDX); // FlipPage(); // drawRect(row, col, height, width, BLACKIDX); char num[4] ="000\0"; short i = 2; while (s && i>=0) { num[i--] = (s%10+'0'); s/=10; } // FlipPage(); // drawString4(row, col, num, ci); // FlipPage(); drawString4(row, col, num, ci); }
int main() { REG_DISPCTL = MODE4 | BG2_ENABLE | BUFFER1FLAG; loadPalette(pics_palette, PICS_PALETTE_SIZE, 0); int state = BEGIN; while(1) { switch(state) { case BEGIN: // loadPalette(pics_palette, PICS_PALETTE_SIZE, 0); drawImage4(0, 0, 240, 160, (u16*)screen); waitForVblank(); FlipPage(); while(!KEY_DOWN_NOW(BUTTON_START)); state = GAME; break; case GAME: state = play(); break; case WIN: loadPalette(pics_palette, PICS_PALETTE_SIZE, 0); drawImage4(0, 0, 240, 160, (u16*)win); drawString4(5, 8, "Press Select", PALETTE[0]); waitForVblank(); FlipPage(); while(!KEY_DOWN_NOW(BUTTON_SELECT)); state = BEGIN; break; case LOSE: // loadPalette(pics_palette, PICS_PALETTE_SIZE, 0); drawImage4(0, 0, 240, 160, (u16*)die); waitForVblank(); FlipPage(); while(!KEY_DOWN_NOW(BUTTON_SELECT)); state = BEGIN; break; default: break; } } return 0; }
int main() { //create obj //X megaman megamanX; megamanX.r = 62; megamanX.c = 30; megamanX.mapX = megamanX.c; megamanX.mapY = megamanX.r; megamanX.inAir = 0; megamanX.lives = 20; //blast Blast blast;; blast.r = 0; blast.c = megamanX.c; blast.fired = 0; blast.speed = 8; //drlight Drlight drlight; drlight.r = 0; drlight.c = 0; //minion Minion minion; minion.r = 0; minion.c = 0; minion.lives = 5; //turret Turret turret; turret.r = 0; turret.c = 0; turret.lives = 10; //bullet Bullet bullet; bullet.r = 0; bullet.c = 0; //worldMap ground set up WorldMap worldmap[1688]; for(int x=0; x<535; x++) { worldmap[x].y = 94; } for(int x=545; x<905; x++) { worldmap[x].y = 74; } for(int x=921; x<1688; x++) { worldmap[x].y = 84; } // 1. Set up REG_DISPCNT // Enable objects (sprites) (by setting bit 10) and set the sprite dimension type (given to you by nin10kit) // 2. Copy the palette given to into the sprite palette (SPRITEPAL) // 3 Copy the sprite tile graphics to character block 5 // 4. For each of the 128 sprites set its attribute 0 to hide them (ATTR0_HIDE) // 5. When you want to use a sprite pick a OamEntry. // a. Modify its attribute 0 with its x and or this with the palette type (from nin10kit) and shape (nin10kit) // b. Modify its attribute 1 with its y and size (nin10kit) // c. Modify its attribute 2 with the sprite id (nin10kit) REG_DISPCTL = MODE4 | BG2_ENABLE | OBJ_ENABLE | X_DIMENSION_TYPE; DMA[3].src = X_palette; DMA[3].dst = SPRITEPAL; DMA[3].cnt = DMA_ON | X_PALETTE_SIZE; DMA[3].src = X; DMA[3].dst = SPRITEDATA; DMA[3].cnt = DMA_ON | X_SIZE; //copy OamEntry shadow[128]; //make all sprites transparent for(int i=0; i<128; i++) { shadow[i].attr0 = ATTR0_HIDE; } //helper //((SPRITEMEM[0].attr0 &~ 0x00FF)|(20)) //((SPRITEMEM[1].attr0 &~ 0x01FF)|(0)) int state=0; int hold=0; while(1) { if(gameState==0) { DMA[3].src = title_palette; DMA[3].dst = PALETTE; DMA[3].cnt = DMA_ON | TITLE_PALETTE_SIZE; stage_stop(); megaman_play(); } while(gameState==0) { drawImage4(0,0,240,160,title); if(KEY_DOWN_NOW(BUTTON_A) || KEY_DOWN_NOW(BUTTON_START)) { gameState=1; megaman_stop(); break; } waitForVblank(); flipPage(); } if(gameState==1) { //setup stage palette DMA[3].src = stage_palette; DMA[3].dst = PALETTE; DMA[3].cnt = DMA_ON | STAGE_PALETTE_SIZE; //music stage_play(); } while(gameState==1) { if(KEY_DOWN_NOW(BUTTON_SELECT)) { for(int i=0; i<128; i++) { shadow[i].attr0 = ATTR0_HIDE; } hurting=0; minionSpawn=0; turretSpawn=0; turretFired=0; megamanX.r = 62; megamanX.c = 30; megamanX.mapX = megamanX.c; megamanX.mapY = megamanX.r; megamanX.inAir = 0; megamanX.lives = 20; started=0; telCount=0; gameState=0; } //conversation if(started==0) { drawStage(30,STAGE_WIDTH,STAGE_HEIGHT,stage); switch (state) { case 0: drawHollowRect4(100,0,59,239,0); drawRect4(102,2,56,236,140); char buffer[50]; sprintf(buffer, "X:"); drawString4(105,5,buffer,0); sprintf(buffer, "What happened here?"); drawString4(120,5,buffer,0); if(KEY_DOWN_NOW(BUTTON_A) && hold==0) { state=1; hold=1; } break; case 1: drawHollowRect4(100,0,59,239,0); drawRect4(102,2,56,236,140); char buffer2[50]; sprintf(buffer2, "X:"); drawString4(105,5,buffer2,0); sprintf(buffer2, "The highway is destroyed!"); drawString4(120,5,buffer2,0); if(KEY_DOWN_NOW(BUTTON_A) && hold==0) { state=2; hold=1; } break; case 2: drawHollowRect4(100,0,59,239,0); drawRect4(102,2,56,236,140); char buffer3[50]; sprintf(buffer3, "X:"); drawString4(105,5,buffer3,0); sprintf(buffer3, "I need to turn in my CS2110 homework!"); drawString4(120,5,buffer3,0); if(KEY_DOWN_NOW(BUTTON_A) && hold==0) { state=3; hold=1; } break; case 3: drawHollowRect4(100,0,59,239,0); drawRect4(102,2,56,236,140); char buffer4[50]; sprintf(buffer4, "Press Right to walk, Up to jump,"); drawString4(105,5,buffer4,0); char buffer5[50]; sprintf(buffer5, "B to dash, A to fire."); drawString4(120,5,buffer5,0); if(KEY_DOWN_NOW(BUTTON_A) && hold==0) { started=1; state=0; hold=1; } break; } if(!KEY_DOWN_NOW(BUTTON_A)) { hold=0; } } //teleports if(started==1) { drawStage(30,STAGE_WIDTH,STAGE_HEIGHT,stage); if(telCount<80) { drawRect4(telCount,megamanX.c-1+14,30,6,149); drawRect4(telCount+1,megamanX.c+14,26,2,0); telCount+=8; } else if(telCount>=80 && telCount<=120) { shadow[2].attr0 = megamanX.r | X_PALETTE_TYPE | X_SPRITE_SHAPE; shadow[2].attr1 = megamanX.c | X_SPRITE_SIZE; shadow[2].attr2 = CHARGES_ID; telCount+=8; } else { shadow[2].attr0 = ATTR0_HIDE; //draw megaman shadow[0].attr0 = megamanX.r | X_PALETTE_TYPE | X_SPRITE_SHAPE; shadow[0].attr1 = megamanX.c | X_SPRITE_SIZE; shadow[0].attr2 = X_ID; started=2; telCount=0; } } //in Game if(started==2) { //update background moveScreen(megamanX.mapX); //status check if(!borderCheck(megamanX.r, megamanX.c)) { megamanX.lives-=1; hurting=1; } if(!checkHealth(&megamanX)) { //need delay here // for(int i=0; i<160;i++) { // hurt(&megamanX, shadow); // } for(int i=0; i<128; i++) { shadow[i].attr0 = ATTR0_HIDE; } refreshBlast(&megamanX, &blast, shadow, 1); hurting=0; minionSpawn=0; turretSpawn=0; turretFired=0; started=0; gameState=3; } //buttons if(KEY_DOWN_NOW(BUTTON_A) && hurting==0) { if(charge<102) charge++; if(charge>20) { drawCharges(&megamanX, shadow); } } if(!KEY_DOWN_NOW(BUTTON_A) && charge<=20 && charge>0 && hurting==0) { blast.fired = 1; blast.r = megamanX.r; charge = 0; blastType = 0; } else if(!KEY_DOWN_NOW(BUTTON_A) && charge<=100 && charge>20 && hurting==0) { blast.fired = 1; blast.r = megamanX.r; charge = 0; blastType = 1; shadow[2].attr0 = ATTR0_HIDE; chargesDelay = 0; } else if(!KEY_DOWN_NOW(BUTTON_A) && charge<=102 && charge>100 && hurting==0) { blast.fired = 1; blast.r = megamanX.r; charge = 0; blastType = 2; shadow[2].attr0 = ATTR0_HIDE; chargesDelay = 0; } if((KEY_DOWN_NOW(BUTTON_B) || (KEY_DOWN_NOW(BUTTON_B) && KEY_DOWN_NOW(BUTTON_RIGHT))) && stopMove==0 && hurting==0) { dash(&megamanX, shadow); moving = 2; } if(KEY_DOWN_NOW(BUTTON_RIGHT) && !KEY_DOWN_NOW(BUTTON_UP) && !KEY_DOWN_NOW(BUTTON_LEFT) && !KEY_DOWN_NOW(BUTTON_B) && megamanX.inAir==0 && hurting==0) { stopMove = 0; dashCounter = 0; megamanX.mapX++; walk(&megamanX, shadow); moving = 1; } if(KEY_DOWN_NOW(BUTTON_LEFT) && !KEY_DOWN_NOW(BUTTON_UP) && !KEY_DOWN_NOW(BUTTON_RIGHT) && !KEY_DOWN_NOW(BUTTON_B) && megamanX.inAir==0 && hurting==0) { stopMove = 0; dashCounter = 0; if(megamanX.mapX-25>0) megamanX.mapX--; walk(&megamanX, shadow); moving = -1; } if(KEY_DOWN_NOW(BUTTON_RIGHT) && KEY_DOWN_NOW(BUTTON_UP) && megamanX.inAir==0 && hurting==0) { megamanX.inAir = 1; jumpForward = 1; moving = 1; } if(KEY_DOWN_NOW(BUTTON_UP) && megamanX.inAir==0 && hurting==0) { megamanX.inAir = 1; moving = 0; } //default position if(!KEY_DOWN_NOW(BUTTON_START) && !KEY_DOWN_NOW(BUTTON_SELECT) && !KEY_DOWN_NOW(BUTTON_B) && !KEY_DOWN_NOW(BUTTON_R) && !KEY_DOWN_NOW(BUTTON_L) && !KEY_DOWN_NOW(BUTTON_LEFT) && !KEY_DOWN_NOW(BUTTON_RIGHT) && !KEY_DOWN_NOW(BUTTON_DOWN) && !KEY_DOWN_NOW(BUTTON_UP) && megamanX.inAir==0 && hurting==0) { stopMove = 0; jumpCounter = 0; dashCounter = 0; shadow[0].attr2 = X_ID; moving = 0; } //draw blast drawBlast(&blast, &megamanX, shadow); //gap check when walking if(((megamanX.mapX>=535 && megamanX.mapX<=545) || (megamanX.mapX>=905 && megamanX.mapX<=921))) { if(megamanX.inAir==0) { megamanX.inAir=1; falling=1; jumpCounter=4; } } if(megamanX.inAir==1) { jump(&megamanX, shadow); } if(falling==1) { groundCheck(&megamanX, worldmap); } geoCheck(&megamanX); drawLives(&megamanX); //restore if(hurtTime<=0) { restore(shadow); } blastCollision(&megamanX, &blast, &minion, &turret,shadow); if(explosionDelay==0) { shadow[2].attr0 = ATTR0_HIDE; explosionDelay=12; } else { explosionDelay--; } //player collision if(hurting==0) { playerCollision(&megamanX, &minion, &turret, &bullet, shadow); } //check hurt is second priority if(hurting==1) { hurt(&megamanX, shadow); } // for testing // char string[50]; // char string2[50]; // sprintf(string, "world x: %d, y: %d", megamanX.mapX, worldmap[megamanX.mapX].y-32); // sprintf(string2, "I am x: %d, y: %d", megamanX.mapX, megamanX.r); // drawString4(10,0,string,5); // drawString4(20,0,string2,5); //Enemy if(((megamanX.mapX>=50 && megamanX.mapX<=250) || (megamanX.mapX>=922 && megamanX.mapX<=1122) || (megamanX.mapX>=1200 && megamanX.mapX<=1300)) && minionSpawn==0) { //more condition here to spawn in area minionSpawn = 1; minion.lives=5; minion.c = megamanX.mapX%240+240; if(megamanX.mapX>=50 && megamanX.mapX<=250) { minion.r = 67; //it's short } else { minion.r = 57; } } if(minionSpawn==1) { drawMinion(&minion, shadow); if(!borderCheck(minion.r,minion.c)) { minionSpawn=0; shadow[3].attr0 = ATTR0_HIDE; } if(moving!=0 && hurting==0) { minion.c-=moving; } } //turret if(((megamanX.mapX>=300 && megamanX.mapX<=650) || (megamanX.mapX>=950 && megamanX.mapX<=1050)) && turretSpawn==0) { turretSpawn = 1; turret.lives = 10; turret.c = megamanX.mapX%240+240; if(megamanX.mapX>=300 && megamanX.mapX<=650) { turret.r = 36; //it's short } else { turret.r = 46; } } if(turretSpawn==1) { drawTurret(&turret, shadow); if(!borderCheck(turret.r,turret.c)) { turretSpawn=0; shadow[4].attr0 = ATTR0_HIDE; } else if(turretFired==0) { bullet.c = turret.c-10; if(megamanX.mapX>=300 && megamanX.mapX<=650) { bullet.r = 45; //it's short } else { bullet.r = 55; } } if(moving!=0 && hurting==0) { bullet.c-=moving; } } //fire if(turretFired==1) { bulletAnimate(&bullet, shadow); } if(!borderCheck(bullet.r,bullet.c)) { turretFired=0; shadow[5].attr0 = ATTR0_HIDE; } else if(turretSpawn==1) { if(bulletDelay<=0) { turretFired=1; bulletDelay=100; } else { bulletDelay--; } } if(moving!=0 && hurting==0) { turret.c-=moving; } //spawn drlight when reach end if(megamanX.mapX>=STAGE_WIDTH-270) { //more condition here to spawn in area started=3; } } if(started==3) { for(int i=0; i<128; i++) { shadow[i].attr0 = ATTR0_HIDE; } drawStage(STAGE_WIDTH-270,STAGE_WIDTH,STAGE_HEIGHT,stage); shadow[0].attr0 = 52 | X_PALETTE_TYPE | X_SPRITE_SHAPE; shadow[0].attr1 = 30 | X_SPRITE_SIZE; shadow[0].attr2 = X_ID; drlight.c = megamanX.c+160; drlight.r = megamanX.r; shadow[6].attr0 = drlight.r | X_PALETTE_TYPE | X_SPRITE_SHAPE; shadow[6].attr1 = drlight.c | X_SPRITE_SIZE; shadow[6].attr2 = DRLIGHT_ID; switch (state) { case 0: drawHollowRect4(100,0,59,239,0); drawRect4(102,2,56,236,140); char buffer[50]; sprintf(buffer, "X:"); drawString4(105,5,buffer,0); sprintf(buffer, "Professor!"); drawString4(120,5,buffer,0); if(KEY_DOWN_NOW(BUTTON_A) && hold==0) { state=1; hold=1; } break; case 1: drawHollowRect4(100,0,59,239,0); drawRect4(102,2,56,236,140); char buffer2[50]; sprintf(buffer2, "Professor Light:"); drawString4(105,5,buffer2,0); sprintf(buffer2, "Finally, you have come."); drawString4(120,5,buffer2,0); if(KEY_DOWN_NOW(BUTTON_A) && hold==0) { state=2; hold=1; } break; case 2: drawHollowRect4(100,0,59,239,0); drawRect4(102,2,56,236,140); char buffer3[50]; sprintf(buffer3, "X:"); drawString4(105,5,buffer3,0); sprintf(buffer3, "Here's my assignment"); drawString4(120,5,buffer3,0); if(KEY_DOWN_NOW(BUTTON_A) && hold==0) { state=3; hold=1; } break; case 3: drawHollowRect4(100,0,59,239,0); drawRect4(102,2,56,236,140); char buffer4[50]; sprintf(buffer4, "Professor Light:"); drawString4(105,5,buffer4,0); char buffer5[50]; sprintf(buffer5, "Goodjob X."); drawString4(120,5,buffer5,0); if(KEY_DOWN_NOW(BUTTON_A) && hold==0) { started=4; state=0; hold=1; break; } break; } if(!KEY_DOWN_NOW(BUTTON_A)) { hold=0; } } if(started==4) { drawStage(STAGE_WIDTH-270,STAGE_WIDTH,STAGE_HEIGHT,stage); if(telCount<40) { //hide megaman shadow[0].attr0 = ATTR0_HIDE; shadow[2].attr0 = megamanX.r | X_PALETTE_TYPE | X_SPRITE_SHAPE; shadow[2].attr1 = megamanX.c | X_SPRITE_SIZE; shadow[2].attr2 = CHARGES_ID; telCount+=8; } else if(telCount>=40 && telCount<=120) { shadow[2].attr0 = ATTR0_HIDE; drawRect4(121-telCount,megamanX.c-1+14,30,6,149); drawRect4(121-telCount+1,megamanX.c+14,26,2,0); telCount+=8; } else { for(int i=0; i<128; i++) { shadow[i].attr0 = ATTR0_HIDE; } megamanX.r = 62; megamanX.c = 30; megamanX.mapX = megamanX.c; megamanX.mapY = megamanX.r; megamanX.inAir = 0; megamanX.lives = 20; started=0; telCount=0; gameState=2; } } waitForVblank(); flipPage(); //update spritememory DMA[3].src = shadow; DMA[3].dst = SPRITEMEM; DMA[3].cnt = 128 * 4 | DMA_ON; } if(gameState==2) { stage_stop(); DMA[3].src = win_palette; DMA[3].dst = PALETTE; DMA[3].cnt = DMA_ON | WIN_PALETTE_SIZE; } while(gameState==2) { drawImage4(0,0,240,160,win); if(KEY_DOWN_NOW(BUTTON_A) || KEY_DOWN_NOW(BUTTON_START) || KEY_DOWN_NOW(BUTTON_SELECT)) { gameState=0; break; } waitForVblank(); flipPage(); } if(gameState==3) { stage_stop(); DMA[3].src = lost_palette; DMA[3].dst = PALETTE; DMA[3].cnt = DMA_ON | LOST_PALETTE_SIZE; } while(gameState==3) { drawImage4(0,0,240,160,lost); if(KEY_DOWN_NOW(BUTTON_A) || KEY_DOWN_NOW(BUTTON_START)) { hurting=0; megamanX.r = 62; megamanX.c = 30; megamanX.mapX = megamanX.c; megamanX.mapY = megamanX.r; megamanX.inAir = 0; megamanX.lives = 20; started=0; telCount=0; gameState=1; break; } if(KEY_DOWN_NOW(BUTTON_SELECT)) { megamanX.r = 62; megamanX.c = 30; megamanX.mapX = megamanX.c; megamanX.mapY = megamanX.r; megamanX.inAir = 0; megamanX.lives = 20; started=0; telCount=0; gameState=0; break; } waitForVblank(); flipPage(); } } }
int play() { int score = 0; int speed = 1; int life = 1; int timer = 10; int pT = 0; char lifes[15]; char scores[15]; BIRD bird; bird.r = 70; bird.c = BIRD_C; // loadPalette(pics_palette, PICS_PALETTE_SIZE, 0); drawImage4(0, 0, 240, 160, (u16*)background); FlipPage(); drawImage4(0, 0, 240, 160, (u16*)background); PIPE pp[4]; for(int i = 0; i < 4; i++) { pp[i].r = 10; pp[i].c = 219 - i*60; pp[i].hole = 25 + rand() / (RAND_MAX / (145 - HOLE_L - 25 + 1) + 1); pp[i].on = 0; if(i == 0) { pp[i].on = 1; } } int frame = 0; while(1) { if(KEY_DOWN_NOW(BUTTON_SELECT)) { return 0; } if(KEY_DOWN_NOW(BUTTON_A)) { speed = -5; } if(timer == 0) { bird.r += speed; speed++; timer = 3; } timer--; if(pT == 0) { pp[0].on = 1; } else { pT--; } if(bird.r < 10) { bird.r = 10; } if(bird.r > 149) { life--; if (life < 0) { return LOSE; } bird.r = 70; speed = 1; timer = 2; } for(int i = 1; i < 4; i++) { if(pp[0].c < 220 - i*60 && !pp[i].on) { pp[i].c = 219; pp[i].on = 1; } } for(int i = 0; i < 4; i++) { if(pp[i].on) { pp[i].c -= 1; if(bird.c == (pp[i].c + PIPE_W / 2) && pp[i].on) { score++; if(score == 5) { return WIN; } } if(pp[i].c < 0) { pp[i].c = 219; pp[i].hole = 25 + rand() / (RAND_MAX / (145 - HOLE_L - 25 + 1) + 1); pT = 20; pp[i].on = 0; } //collision if(bird.c + 14 > pp[i].c && bird.c < pp[i].c + 20 && ((bird.r < pp[i].hole) | (bird.r + 10 > pp[i].hole + HOLE_L)) && pp[i].on) { life--; if (life < 0) { return LOSE; } bird.r = pp[i].hole + 2; speed = 1; timer = 2; } } } drawImage4(0, 0, 240, 160, (u16*)background); delay(3); //draw pipe for(int i = 0; i < 4; i++) { if(pp[i].on) { drawPipe(pp[i].r, pp[i].c, pp[i].hole, (u16*)pipes); } } //draw bird if(frame % 9 == 0) { drawImage4(bird.r, bird.c, BIRD_W, BIRD_H, (u16*)flappy0); } else if(frame % 9 == 1) { drawImage4(bird.r, bird.c, BIRD_W, BIRD_H, (u16*)flappy1); } else if(frame % 9 == 2) { drawImage4(bird.r, bird.c, BIRD_W, BIRD_H, (u16*)flappy2); } else if(frame % 9 == 3) { drawImage4(bird.r, bird.c, BIRD_W, BIRD_H, (u16*)flappy3); } else if(frame % 9 == 4) { drawImage4(bird.r, bird.c, BIRD_W, BIRD_H, (u16*)flappy4); } else if(frame % 9 == 5) { drawImage4(bird.r, bird.c, BIRD_W, BIRD_H, (u16*)flappy5); } else if(frame % 9 == 6) { drawImage4(bird.r, bird.c, BIRD_W, BIRD_H, (u16*)flappy6); } else if(frame % 9 == 7) { drawImage4(bird.r, bird.c, BIRD_W, BIRD_H, (u16*)flappy7); } else { drawImage4(bird.r, bird.c, BIRD_W, BIRD_H, (u16*)flappy8); } // drawImage4(bird.r, bird.c, BIRD_W, BIRD_H, (u16*)flappy0); // drawImage4(bird.r, bird.c, BIRD_W, BIRD_H, (u16*)flappy1); // drawImage4(bird.r, bird.c, BIRD_W, BIRD_H, (u16*)flappy2); // drawImage4(bird.r, bird.c, BIRD_W, BIRD_H, (u16*)flappy3); // drawImage4(bird.r, bird.c, BIRD_W, BIRD_H, (u16*)flappy4); // drawImage4(bird.r, bird.c, BIRD_W, BIRD_H, (u16*)flappy5); // drawImage4(bird.r, bird.c, BIRD_W, BIRD_H, (u16*)flappy6); // drawImage4(bird.r, bird.c, BIRD_W, BIRD_H, (u16*)flappy7); sprintf(lifes, "Life: %d", life); drawString4(0, 10, lifes, PALETTE[0]); sprintf(scores, "Score: %d", score); drawString4(0, 170, scores, PALETTE[0]); waitForVblank(); frame++; FlipPage(); } return 1; }
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; }
static int gotHome(int isSafe) { if (homeFlags[0] == 0 && frog.y >= 10 && frog.y <= 30 && frog.x >= 10 && frog.x <= 25) { drawString4(95, 75, "YOU ARE SAVE NOW!", PALETTE[1]); flipPage(); homeFlags[0] = 1; loadAvatar(); isSafe = 1; delay(20); } if (homeFlags[0]) { drawImage4(18, 15, 14, 14, frog.imgU1); } if (homeFlags[1] == 0 && frog.y >= 10 && frog.y <= 30 && frog.x >= 60 && frog.x <= 70) { drawString4(95, 75, "YOU ARE SAVE NOW!", PALETTE[1]); flipPage(); homeFlags[1] = 1; loadAvatar(); isSafe = 1; delay(20); } if (homeFlags[1]) { drawImage4(66, 15, 14, 14, frog.imgU1); } if (homeFlags[2] == 0 && frog.y >= 10 && frog.y <= 30 && frog.x >= 108 && frog.x <= 118) { drawString4(95, 75, "YOU ARE SAVE NOW!", PALETTE[1]); flipPage(); homeFlags[2] = 1; loadAvatar(); isSafe = 1; delay(20); } if (homeFlags[2]) { drawImage4(114, 15, 14, 14, frog.imgU1); } if (homeFlags[3] == 0 && frog.y >= 10 && frog.y <= 30 && frog.x >= 155 && frog.x <= 165) { drawString4(95, 75, "YOU ARE SAVE NOW!", PALETTE[1]); flipPage(); homeFlags[3] = 1; loadAvatar(); isSafe = 1; delay(20); } if (homeFlags[3]) { drawImage4(160, 15, 14, 14, frog.imgU1); } if (homeFlags[4] == 0 && frog.y >= 10 && frog.y <= 30 && frog.x >= 195 && frog.x <= 210) { drawString4(95, 75, "YOU ARE SAVE NOW!", PALETTE[1]); flipPage(); homeFlags[4] = 1; loadAvatar(); isSafe = 1; delay(20); } if (homeFlags[4]) { drawImage4(208, 15, 14, 14, frog.imgU1); } if (homeFlags[0] && homeFlags[1] && homeFlags[2] && homeFlags[3] && homeFlags[4]) { win(); } return isSafe; }
void startGame() { fillPalette(startScreen_palette, 0, STARTSCREEN_PALETTE_SIZE); drawImage4(0, 0, 240, 160, start); drawString4(30, 140, "PRESS <START> TO PLAY", PALETTE[3]); }