void firmware() { display_init(); gfx_init_ctxt(&gfx_ctxt, display_init_framebuffer(), 720, 1280, 768); gfx_clear_color(&gfx_ctxt, 0xFF000000); gfx_con_init(&gfx_con, &gfx_ctxt); gfx_con_setcol(&gfx_con, DEFAULT_TEXT_COL, 0, 0); while (!sdMount()) { error("Failed to init SD card!\n"); print("Press POWER to power off, any other key to retry\n"); if (btn_wait() & BTN_POWER) i2c_send_byte(I2C_5, 0x3C, MAX77620_REG_ONOFFCNFG1, MAX77620_ONOFFCNFG1_PWR_OFF); btn_wait(); } if(PMC(APBDEV_PMC_SCRATCH49) != 69 && fopen("/ReiNX.bin", "rb")) { fread((void*)PAYLOAD_ADDR, fsize(), 1); fclose(); sdUnmount(); display_end(); CLOCK(CLK_RST_CONTROLLER_CLK_OUT_ENB_V) |= 0x400; // Enable AHUB clock. CLOCK(CLK_RST_CONTROLLER_CLK_OUT_ENB_Y) |= 0x40; // Enable APE clock. PMC(APBDEV_PMC_SCRATCH49) = 69; ((void (*)())PAYLOAD_ADDR)(); } SYSREG(AHB_AHB_SPARE_REG) = (volatile vu32)0xFFFFFF9F; PMC(APBDEV_PMC_SCRATCH49) = 0; print("Welcome to ReiNX %s!\n", VERSION); loadFirm(); drawSplash(); launch(); }
int main() { char fractal; int x=width/2,y=height/2,radius=width/3; int margin=20; int x1=margin,x2=width-margin,x3=width/2,y1=margin,y2=margin,y3=height-margin; gfx_open(width,height,"Fractals"); gfx_clear_color(0,0,0); gfx_clear(); gfx_color(255,255,255); printf("Which fractal would you like to see?\n1: Sierpinski Triangles\n2: Shrinking Squares\n3: Spiral Squares\n4: Circular Lace\n5: Snowflake\n6: Tree\n7: Fern\n8: Spiral of Spirals\n\n"); while(fractal!='q'){ fractal=gfx_wait(); gfx_clear(); switch(fractal){ case 'q': return 0; break; case '1': printf("Sierpinski Triangles\n\n"); sierpTriangles(x1,y1,x2,y2,x3,y3); break; case '2': printf("Shrinking Squares\n\n"); shrinkSquares(x,y,width/4); break; case '3': printf("Spiral Squares\n\n"); spiralSquares(x,y,-M_PI/4,width*2/3); break; case '4': printf("Circular Lace\n\n"); circularLace(x,y,width); break; case '5': printf("Snowflake\n\n"); snowflake(x,y,radius); break; case '6': printf("Tree\n\n"); tree(x,height,x,height*3/4,0,height/4); break; case '7': printf("Fern\n\n"); fern(width/2,height-margin,2*height/3,0); break; case '8': printf("Spiral of Spirals\n\n"); spiralSpirals(x,y,0,width); break; default: printf("Please enter a valid option\n\n"); break; } } }
int main() { int width = 400; int height = 550; int gameLoop = 1; int highScore = 0; gfx_open(width, height, "Flappy Bird"); //create two pipes to be recycled Pipe* leadPipe = (Pipe*)malloc(sizeof(Pipe)); Pipe* trailPipe = (Pipe*)malloc(sizeof(Pipe)); while (gameLoop) { //initialize each pipe initializePipe(leadPipe, width, height); initializePipe(trailPipe, width, height); //set background color gfx_clear_color(85, 203, 217); gfx_clear(); //present game home screen char c; int flap = 0; double birdX = 150, birdY = 275, birdR = 12, degrees = 0; while (1) { gfx_clear(); if(gfx_event_waiting()){ if(gfx_wait()==' ') break; } presentHomeScreen(width, height); stationaryBird(&birdY,degrees); flap = drawBird(birdX, birdY, birdR, flap); gfx_flush(); usleep(50000); degrees+=(2*M_PI)/20; } //begin animation int score = startGame(leadPipe, trailPipe, width, height); highScore = endGame(score, highScore, width, height); char d; } return 0; }
char win(void) { gfx_clear_color(0,0,255); //blue background gfx_clear(); gfx_color(255,255,255); //white letters //You gfx_fill_rectangle(370,160,40,60); gfx_fill_rectangle(470,160,40,60); gfx_fill_rectangle(390,220,100,20); gfx_fill_rectangle(410,240,60,60); //yOu gfx_fill_rectangle(530,180,40,100); gfx_fill_rectangle(630,180,40,100); gfx_fill_rectangle(550,160,100,20); gfx_fill_rectangle(550,280,100,20); //yoU gfx_fill_rectangle(690,160,40,120); gfx_fill_rectangle(790,160,40,120); gfx_fill_rectangle(710,280,100,20); //Won gfx_fill_rectangle(370,350,40,140); gfx_fill_rectangle(470,350,40,140); gfx_fill_rectangle(410,430,20,40); gfx_fill_rectangle(430,410,20,40); gfx_fill_rectangle(450,430,20,40); //wOn gfx_fill_rectangle(530,370,40,100); gfx_fill_rectangle(630,370,40,100); gfx_fill_rectangle(550,350,100,20); gfx_fill_rectangle(550,470,100,20); //woN gfx_fill_rectangle(690,350,40,140); gfx_fill_rectangle(790,350,40,140); gfx_fill_rectangle(730,370,20,40); gfx_fill_rectangle(750,390,20,40); gfx_fill_rectangle(770,410,20,40); gfx_text(450,520,"Press any key to play Frogger. Press \'q\' to quit."); return gfx_wait(); }
void background(int w,int h,int level) { int wnum=50,wseg=w/wnum,hnum=100,hseg=h/hnum,i,ic; //define parameters gfx_clear_color(0,0,0); gfx_clear(); gfx_color(255,255,255); //white gfx_text(w/2, h-20, "Use arrow keys to navigate frog safely to a lilly pad. Do not get hit by a car or fall in the water."); gfx_text(w/4,h-20,"LEVEL: "); gfx_text(w/4+50,h-20,num2str(level)); gfx_color(20,0,150); //blue color gfx_fill_rectangle(0,0,w,h/2); //draws water gfx_color(20,150,0); //green color gfx_fill_rectangle(0,0,w,hseg); //draws top green border for(i=0;i<6;i++) //draws lily pads for(ic=1;ic<(3*hseg);ic++) //increment radius to fill circle gfx_circle((i*8+5)*wseg,5*hseg,ic); for(i=0;i<wnum;i++){ //draws pad details if((i+2)%4!=0) gfx_fill_rectangle(wseg*i*2,hseg,2*wseg,hseg); if((i+1)%8<4){ switch((i+2)%4){ case 1: gfx_fill_rectangle(wseg*i,2*hseg,wseg,hseg); gfx_fill_rectangle(wseg*i,4*hseg,wseg,2*hseg); break; case 2: gfx_fill_rectangle(wseg*i,3*hseg,wseg,2*hseg); gfx_fill_rectangle(wseg*i,6*hseg,wseg,1*hseg); break; case 3: gfx_fill_rectangle(wseg*i,2*hseg,wseg,2*hseg); gfx_fill_rectangle(wseg*i,5*hseg,wseg,2*hseg); break; case 0: gfx_fill_rectangle(wseg*i,2*hseg,wseg,hseg); gfx_fill_rectangle(wseg*i,4*hseg,wseg,2*hseg); break; } //end switch((i+2)%4) } //end if((i+1)%8<4) switch(i%8){ //draw middle grass case 0: case 1: case 3: case 6: gfx_fill_rectangle(wseg*i,(h/2)-(4*hseg),wseg,5*hseg); break; case 2: case 7: gfx_fill_rectangle(wseg*i,(h/2)-(5*hseg),wseg,7*hseg); break; case 4: gfx_fill_rectangle(wseg*i,(h/2)-(4*hseg),wseg,6*hseg); break; case 5: gfx_fill_rectangle(wseg*i,(h/2)-(5*hseg),wseg,6*hseg); break; } //end switch((i+2)%4) switch(i%8){ //draw bottom grass case 0: case 1: case 3: case 6: gfx_fill_rectangle(wseg*i,h-(18*hseg),wseg,5*hseg); break; case 2: case 7: gfx_fill_rectangle(wseg*i,h-(19*hseg),wseg,7*hseg); break; case 4: gfx_fill_rectangle(wseg*i,h-(18*hseg),wseg,6*hseg); break; case 5: gfx_fill_rectangle(wseg*i,h-(19*hseg),wseg,6*hseg); break; } //end switch((i+2)%4) } //end for(i=0;i<wnum;i++) gfx_color(150,75,0); //brown color for(i=0;i<wnum;i++){ //draws grass details switch(i%8){ //draw middle grass details case 0: case 1: break; case 3: case 6: gfx_fill_rectangle(wseg*i,(h/2)-(2*hseg),wseg,hseg); break; case 2: case 7: gfx_fill_rectangle(wseg*i,(h/2)-(4*hseg),wseg,hseg); break; case 4: gfx_fill_rectangle(wseg*i,(h/2)-(3*hseg),wseg,hseg); break; case 5: gfx_fill_rectangle(wseg*i,(h/2)-hseg,wseg,hseg); break; } //end switch((i+2)%4) switch(i%8){ //draw bottom grass details case 0: case 1: break; case 3: case 6: gfx_fill_rectangle(wseg*i,h-(16*hseg),wseg,hseg); break; case 2: case 7: gfx_fill_rectangle(wseg*i,h-(18*hseg),wseg,hseg); break; case 4: gfx_fill_rectangle(wseg*i,h-(17*hseg),wseg,hseg); gfx_fill_rectangle(wseg*i,h-(14*hseg),wseg,hseg); break; case 5: gfx_fill_rectangle(wseg*i,h-(15*hseg),wseg,hseg); break; } //end switch((i+2)%4) } //end for(i=0;i<wnum;i++) } //end background
char welcome(void) { gfx_clear_color(0,255,0); //green gfx_clear(); gfx_color(255,255,255); //Frogger gfx_fill_rectangle(50,160,40,140); gfx_fill_rectangle(90,160,100,20); gfx_fill_rectangle(90,220,80,20); //fRogger gfx_fill_rectangle(210,160,40,140); gfx_fill_rectangle(250,160,80,20); gfx_fill_rectangle(310,180,40,60); gfx_fill_rectangle(290,220,20,20); gfx_fill_rectangle(250,240,60,20); gfx_fill_rectangle(270,260,60,20); gfx_fill_rectangle(300,280,60,20); //frOgger gfx_fill_rectangle(370,180,40,100); gfx_fill_rectangle(470,180,40,100); gfx_fill_rectangle(390,160,100,20); gfx_fill_rectangle(390,280,100,20); //froGger gfx_fill_rectangle(570,160,100,20); gfx_fill_rectangle(550,180,40,20); gfx_fill_rectangle(530,200,40,60); gfx_fill_rectangle(550,260,40,20); gfx_fill_rectangle(570,280,100,20); gfx_fill_rectangle(630,260,40,20); gfx_fill_rectangle(610,240,60,20); //frogGer gfx_fill_rectangle(730,160,100,20); gfx_fill_rectangle(710,180,40,20); gfx_fill_rectangle(690,200,40,60); gfx_fill_rectangle(710,260,40,20); gfx_fill_rectangle(730,280,100,20); gfx_fill_rectangle(790,260,40,20); gfx_fill_rectangle(770,240,60,20); //froggEr gfx_fill_rectangle(850,160,40,140); gfx_fill_rectangle(890,160,100,20); gfx_fill_rectangle(890,220,80,20); gfx_fill_rectangle(890,280,100,20); //froggeR gfx_fill_rectangle(1010,160,40,140); gfx_fill_rectangle(1050,160,80,20); gfx_fill_rectangle(1110,180,40,60); gfx_fill_rectangle(1090,220,20,20); gfx_fill_rectangle(1050,240,60,20); gfx_fill_rectangle(1070,260,60,20); gfx_fill_rectangle(1100,280,60,20); gfx_text(530,325, "CSE20211: Final Project"); gfx_text(510,345, "Sara Cunningham and Jenna Wilson"); gfx_text(470,365, "Press any key to play Frogger. Press \'q\' to quit"); return gfx_wait(); } //end welcome
char blood(void) { gfx_clear_color(255,0,0); gfx_clear(); gfx_color(255,255,255); //Game over gfx_fill_rectangle(330,160,100,20); gfx_fill_rectangle(310,180,40,20); gfx_fill_rectangle(290,200,40,60); gfx_fill_rectangle(310,260,40,20); gfx_fill_rectangle(330,280,100,20); gfx_fill_rectangle(390,260,40,20); gfx_fill_rectangle(370,240,60,20); //gAme over gfx_fill_rectangle(450,200,40,100); gfx_fill_rectangle(470,180,40,20); gfx_fill_rectangle(490,160,60,20); gfx_fill_rectangle(530,180,40,20); gfx_fill_rectangle(550,200,40,100); gfx_fill_rectangle(490,240,60,20); //gaMe over gfx_fill_rectangle(610,160,40,140); gfx_fill_rectangle(650,180,20,40); gfx_fill_rectangle(670,200,20,40); gfx_fill_rectangle(690,180,20,40); gfx_fill_rectangle(710,160,40,140); //gamE over gfx_fill_rectangle(770,160,40,140); gfx_fill_rectangle(810,160,100,20); gfx_fill_rectangle(810,220,80,20); gfx_fill_rectangle(810,280,100,20); //game Over gfx_fill_rectangle(290,370,40,100); gfx_fill_rectangle(390,370,40,100); gfx_fill_rectangle(310,350,100,20); gfx_fill_rectangle(310,470,100,20); //game oVer gfx_fill_rectangle(450,350,40,80); gfx_fill_rectangle(550,350,40,80); gfx_fill_rectangle(470,430,40,20); gfx_fill_rectangle(530,430,40,20); gfx_fill_rectangle(490,450,60,20); gfx_fill_rectangle(510,470,20,20); //game ovEr gfx_fill_rectangle(610,350,40,140); gfx_fill_rectangle(650,350,100,20); gfx_fill_rectangle(650,410,80,20); gfx_fill_rectangle(650,470,100,20); //game oveR gfx_fill_rectangle(770,350,40,140); gfx_fill_rectangle(810,350,80,20); gfx_fill_rectangle(870,370,40,60); gfx_fill_rectangle(850,410,20,20); gfx_fill_rectangle(810,430,60,20); gfx_fill_rectangle(830,450,60,20); gfx_fill_rectangle(860,470,60,20); //directions to continue gfx_text(450, 520, "Press any key to play Frogger again. Press \'q\' to quit."); return gfx_wait(); } //end blood
int main() { memcpy(board2,board,sizeof(int)*rows*columns); int height=800,width=800; //height and width of screen gfx_open(width,height,"Pacman"); gfx_clear_color(0,0,0); gfx_clear(); int boardHeight=radius*rows,boardWidth=radius*columns;//Height of the board int xtopleft=width/2-boardWidth/2; //x coord of top left corner of board int ytopleft=height/2-boardHeight*9/16; //y coord of top left corner of board char movement; int i,lives=3;//start with 3 lives int win=0; int active=0; //this changes depending on number of dots left int initialDots=dotsNumber(); int remainingDots=dotsNumber(); int score=0; int loop[4]={0,0,0,0}; int frightenLoop[4]={0}; int newScore[3]={0,0,0};//values [0]:new score to display(when ghost is killed),[1]:xvalue,[2]:yvalue Location pacman; Location ghosts[4];// enumerated to blinky, pinky, inky, clyde; /*There are four states: 0: Chase, 1: Scatter, 2: Frighten, 3: Dead, and 4: Housed */ int state[4]={scatter,scatter,scatter,scatter}; while(1){ titleScreen(height,width,ghosts,&pacman,state); score=0; lives=3; win=0; for(i=0;i<=3;i++) loop[i]=0; //reset the game resetBoard(); gfx_wait(); /* This is the gameplay loop, will repeat every time a life is lost */ while(lives>0){ gfx_clear(); /* Initialize pacman's location */ pacman.x=pacman.prevX=7; pacman.y=pacman.prevY=12; pacman.orientation=right; /* Initialize ghost's locations */ for(i=blinky;i<=clyde;i++){state[i]=scatter;} ghosts[blinky].x=7; ghosts[blinky].prevX=8; ghosts[blinky].y=ghosts[blinky].prevY=6; ghosts[blinky].orientation=left; ghosts[pinky].x=7; ghosts[pinky].prevX=7; ghosts[pinky].y=7; ghosts[pinky].prevY=8; ghosts[pinky].orientation=up; ghosts[inky].x=ghosts[inky].prevX=6; ghosts[inky].y=7; ghosts[inky].prevY=8; ghosts[inky].orientation=right; ghosts[clyde].x=ghosts[clyde].prevX=8; ghosts[clyde].y=7; ghosts[clyde].prevY=8; ghosts[clyde].orientation=left; /* These two statements draw pacman and the board to begin the program */ drawBoard(xtopleft,ytopleft,boardHeight,boardWidth,height,width,lives,2,score); drawPacman(xtopleft+radius*pacman.x+radius/2,ytopleft+radius*pacman.y+radius/2,pacman.orientation,0); for(i=blinky;i<=clyde;i++){ drawGhost(xtopleft+radius*ghosts[i].x+radius/2,ytopleft+radius*ghosts[i].y+radius/2,i,ghosts[i].orientation,state,frightenLoop[i]); } /* This loop is the gameplay after all initialization */ while(1){ /*if(gfx_event_waiting()){prevMovement=movement;*/ movement=gfx_wait();//} /* This block updates pacman position, checks for death * then updates ghosts' positions, then checks for death again */ movePacman(&pacman,ghosts,movement,xtopleft,ytopleft,boardHeight,boardWidth,active,state,&score,frightenLoop); if(checkDeath(&pacman,ghosts,xtopleft,ytopleft,boardHeight,boardWidth,height,width,lives,state,&score,newScore,frightenLoop,loop[0])){ //pacman's death? for(i=0;i<=3;i++) loop[i]=0; //reset the game lives--; //decrease the lives printf("LIVES: %i\n",lives); break; } targetGhosts(ghosts,&pacman,xtopleft,ytopleft,boardHeight,boardWidth,active,state); if(checkDeath(&pacman,ghosts,xtopleft,ytopleft,boardHeight,boardWidth,height,width,lives,state,&score,newScore,frightenLoop,loop[0])){ //pacman's death? for(i=0;i<=3;i++) loop[i]=0; //reset the game lives--; //decrease the lives printf("LIVES: %i\n",lives); break; } ghostState(loop,state,frightenLoop); active=activeGhosts(ghosts,loop); /* The next function animates the motion of all of the objects (pacman and ghosts */ animateMotion(xtopleft,ytopleft,boardHeight,boardWidth,&pacman,ghosts,height,width,lives,state,score,newScore,frightenLoop,loop[0]); /* The case to exit the loop is winning, when there are no dots left */ if(dotsNumber()==0){ //The player got all the dots, they won the game win=1; break; } } if(lives<=0){ gfx_clear(); printf("\n\nGAME OVER\n\n"); drawBoard(xtopleft,ytopleft,boardHeight,boardWidth,height,width,lives,0,score); if(tolower(gfx_wait())=='n'){ return 0; }//This will start the entire game over including the title screen else break;} else if(win){ printf("\n\nWINNER!\n\n"); drawBoard(xtopleft,ytopleft,boardHeight,boardWidth,height,width,lives,win,score); if(tolower(gfx_wait())=='n'){ return 0; }//This will end the game else break;} } } }