void drawPacman(int x,int y,int orientation,int mouthOpen){ static int pacLoop=0; int i; gfx_color(255,255,0); gfx_fill_circle(x,y,radius/2-1); gfx_color(0,0,0); int r=radius/2-1; if(mouthOpen || pacLoop%2){ switch(orientation){ case up: gfx_fill_triangle(x-r,y-r,x+r,y-r,orientation); break; case down: gfx_fill_triangle(x-r,y+r,x+r,y+r,orientation); break; case right: gfx_fill_triangle(x+r,y-r,x+r,y+r,orientation); break; case left: gfx_fill_triangle(x-r,y-r,x-r,y+r,orientation); break; } } if(!mouthOpen) pacLoop++; }
void drawBackground(int width, int height) { //draw clouds gfx_color(255, 255, 255); int i; for (i = 0; i<10; i++) { gfx_fill_circle(i*width/8, height - height/10, 50); } for (i = 0; i<3; i++) { gfx_fill_circle(i*width/3, height - height/7, 40); } gfx_fill_circle(width*3/4+10, height - height/6+10, 45); gfx_fill_circle(width*2/9-5, height - height/7, 45); //draw buildings for (i = 0; i<5; i++) { //outlines gfx_color(200, 207, 201); gfx_rectangle(-30+i*width/4-1, height-60-1, 22, 60); gfx_rectangle(-30+i*width/4+20-1, height-55-1, 22, 55); gfx_rectangle(-30+i*width/4+25-1, height-45-1, 27, 45); gfx_rectangle(-30+i*width/4+30-1, height-75-1, 32, 75); gfx_rectangle(-30+i*width/4+30-1, height-80-1, 15, 80); gfx_rectangle(-30+i*width/4+50-1, height-62-1, 22, 62); gfx_rectangle(-30+i*width/4+55-1, height-55-1, 27, 55); //fills gfx_color(218, 227, 219); gfx_fill_rectangle(-30+i*width/4, height-60, 20, 60); gfx_fill_rectangle(-30+i*width/4+20, height-55, 20, 55); gfx_fill_rectangle(-30+i*width/4+25, height-45, 25, 45); gfx_fill_rectangle(-30+i*width/4+30, height-75, 30, 75); gfx_fill_rectangle(-30+i*width/4+30, height-80, 15, 80); gfx_fill_rectangle(-30+i*width/4+50, height-62, 20, 62); gfx_fill_rectangle(-30+i*width/4+55, height-55, 25, 55); } //draw greenery for (i = 0; i<10; i++) { gfx_color(107, 179, 118); gfx_circle(i*width/8, height - 5, 30); gfx_color(153, 224, 163); gfx_fill_circle(i*width/8, height - 5, 30); } for (i = 0; i<6; i++) { gfx_fill_circle(i*width/6, height - 5, 25); } for (i = 0; i<10; i++) { gfx_color(107, 179, 118); gfx_circle(i*width/8+20, height - 5, 24); gfx_color(153, 224, 163); gfx_fill_circle(i*width/8+20, height - 5, 24); } //draw base rectangle to cover outlines gfx_fill_rectangle(0, height-15, width, 15); }
int drawBird(double x, double y, double r, int flap){ //body gfx_color(255,255,0); //gfx_fill_circle(x,y,r); gfx_fill_arc(x-16, y-16, 29, 24, 0, 360 ); gfx_color(0,0,0); gfx_arc(x-16, y-16, 29, 24, 0, 360); //eye ball gfx_color(255,255,255); gfx_fill_circle(x+7,y-7,(0.50)*r+1); //wings if(flap<=5){ gfx_fill_arc(x-18,y-11,12, 6, 0, 360); gfx_color(0,0,0); gfx_arc(x-18,y-12,11, 6, 0, 360); flap++; } else if( (flap>=5)&&(flap<=10) ){ gfx_fill_arc(x-18,y-7, 12, 6, 0, 360); gfx_color(0,0,0); gfx_arc(x-18,y-7, 12, 6, 0, 360); flap++; } else{ gfx_fill_arc(x-18,y-5,12, 6, 0, 360); gfx_color(0,0,0); gfx_arc(x-18,y-5,12, 6, 0, 360); flap--; } //pupil gfx_fill_rectangle(x+9,y-8,2,4); gfx_circle(x+7,y-7,(0.50)*r+1); //lips gfx_color(255,128,0); gfx_fill_arc(x+1, y-1, 16, 4, 0, 360); gfx_fill_arc(x+1, y+3, 14, 3, 0 ,360); gfx_color(0,0,0); gfx_arc(x+1, y+3, 14, 3, 0, 360); gfx_arc(x+1, y-1, 16, 4, 0, 360); gfx_color(255,128,0); gfx_fill_rectangle(x+1,y+0,4,6); return flap; }
void titleScreen(int height,int width,Location ghosts[],Location *pacman,int state[]){ /*Draws the title screen */ int i=-1,x,y; gfx_clear(); gfx_color(255,255,255); gfx_text(width*.35+10,height*.8,"Programmed By: CORY JBARA"); gfx_text(width*.7,height*.8-32,"Use the arrow keys to move"); gfx_text(width*.7,height*.8,"Press any button to start"); /* Draw dots and point values */ gfx_color(255,200,0); gfx_fill_rectangle(width*.8-2,height/2-15,4,4); gfx_color(255,255,255); gfx_text(width*.8+10,height/2-9,"- 10 Points"); gfx_color(255,200,0); gfx_fill_circle(width*.8-4,height/2+15,8); gfx_color(255,255,255); gfx_text(width*.8+10,height/2+20,"- 50 Points"); /* Draws ghosts and their names */ x=width/3; y=height*.45+i*height/15; gfx_text(x,y,"CHARACTER ------------------------ NICKNAME"); for(i=0;i<4;i++){ state[i]=chase; x=width/4; y=height*.45+i*height/15; drawGhost(x,y,i,right,state,0); x=width/3; switch(i){ case blinky: gfx_color(255,0,0); gfx_text(x,y,"SHADOW -------------------------- \"BLINKY\""); break; case pinky: gfx_color(255,150,200); gfx_text(x,y,"SPEEDY -------------------------- \"PINKY\""); break; case inky: gfx_color(0,255,255); gfx_text(x,y,"BASHFUL -------------------------- \"INKY\""); break; case clyde: gfx_color(255,130,0); gfx_text(x,y,"POKEY -------------------------- \"CLYDE\""); break; } } /* Pacman being chased */ i++; y=height*.72; for(i=0;i<=3;i++){ x=width*.4+i*width/20; drawGhost(x,y,i,left,state,0); } drawPacman(width*.4-width/20,y,left,1); /* P */ gfx_color(255,255,0); gfx_fill_rectangle(10,height/5-50,width/15,150); gfx_fill_circle(10+width/15,height/5,50); gfx_color(0,0,0); gfx_fill_circle(10+width/15,height/5,10); /* A */ gfx_color(255,255,0); int loop=0; int x1=width*.1; int x2=width*.27; int center=(x1+x2)/2; y=height/5+100-1; while(x1<x2){//down gfx_line(x1,y,x2,y); if(loop%2){ x1++; x2--; } y--; loop++; } gfx_color(0,0,0); gfx_fill_circle(center,height*.24,10); /* C ::::: Code copied from drawPacman*/ int rad=200; x=width*.24+rad/2; y=height/5; gfx_color(255,255,0); gfx_fill_circle(x,y,rad/2-1); gfx_color(0,0,0); int r=rad/2-1; gfx_fill_triangle(x+r,y-r,x+r,y+r,right); /* M */ gfx_color(255,255,0); x=width*.47; y=height/5-50; gfx_fill_rectangle(x,y,width*.15,150); gfx_color(0,0,0); gfx_fill_triangle(x,y,x+width*.15,y,up); /* A */ gfx_color(255,255,0); loop=0; x1=width*.63; x2=width*.17 +x1; center=(x1+x2)/2; y=height/5+100-1; while(x1<x2){//down gfx_line(x1,y,x2,y); if(loop%2){ x1++; x2--; } y--; loop++; } gfx_color(0,0,0); gfx_fill_circle(center,height*.24,10); /* N */ gfx_color(255,255,0); x=width*.81; y=height/5-50; gfx_fill_rectangle(x,y,width*.15,150); gfx_color(0,0,0); x-=2; y-=height/10; gfx_fill_triangle(x+width*.1,y,x+width*.1,y+height*.2,right); }
void deathAnimation(Location *pacman,Location ghosts[],int xtl,int ytl,int boardHeight,int boardWidth,int height,int width,int lives,int state[],int score,int newScore[],int frightenLoop[],int loop){ /* Death animation is in four states, first full circle, then pacman oriented upward, then half circle, then small sliver below, then gone, then explode */ int r=radius/2-1; int timer=1000000; int x=xtl+pacman->x*radius+radius/2; //first location to draw, will increment 5 times int y=ytl+pacman->y*radius+radius/2; animateMotion(xtl,ytl,boardHeight,boardWidth,pacman,ghosts,height,width,lives,state,score,newScore,frightenLoop,loop); gfx_wait(); gfx_clear(); drawBoard(xtl,ytl,boardHeight,boardWidth,height,width,lives,5,score); gfx_color(255,255,0); gfx_fill_circle(x,y,radius/2-1); //gfx_wait(); gfx_wait(); //usleep(timer); gfx_clear(); drawBoard(xtl,ytl,boardHeight,boardWidth,height,width,lives,6,score); drawPacman(x,y,up,1); gfx_wait(); //usleep(timer); gfx_clear(); drawBoard(xtl,ytl,boardHeight,boardWidth,height,width,lives,7,score); gfx_color(255,255,0); drawPacman(x,y,0,0); gfx_color(0,0,0); gfx_fill_rectangle(x-radius/2-1,y-radius/2+1,radius,radius/2-1); gfx_wait(); //usleep(timer); gfx_clear(); drawBoard(xtl,ytl,boardHeight,boardWidth,height,width,lives,8,score); gfx_color(255,255,0); gfx_fill_circle(x,y,radius/2-1); gfx_color(0,0,0); gfx_fill_triangle(x-r,y-r,x+r,y-r,up); gfx_fill_triangle(x+r,y-r,x+r,y+r,right); gfx_fill_triangle(x-r,y-r,x-r,y+r,left); gfx_wait(); //usleep(timer); gfx_clear(); drawBoard(xtl,ytl,boardHeight,boardWidth,height,width,lives,9,score); gfx_wait(); //usleep(timer); gfx_clear(); drawBoard(xtl,ytl,boardHeight,boardWidth,height,width,lives,10,score); gfx_color(255,255,0); float angle=2*M_PI/5; //partial snowflake int i,xnew[5],ynew[5]; for(i=1;i<=5;i++){ xnew[i-1]=x+r*cos(i*angle+3*M_PI/2); ynew[i-1]=y+r*sin(i*angle+3*M_PI/2); gfx_line(x,y,xnew[i-1],ynew[i-1]); } gfx_wait(); //usleep(timer); gfx_clear(); drawBoard(xtl,ytl,boardHeight,boardWidth,height,width,lives,11,score); gfx_color(255,255,0); angle=2*M_PI/5; //snowflake with short lines for(i=1;i<=5;i++){ xnew[i-1]=x+r*cos(i*angle+3*M_PI/2); ynew[i-1]=y+r*sin(i*angle+3*M_PI/2); gfx_line((x+xnew[i-1])/2,(y+ynew[i-1])/2,xnew[i-1],ynew[i-1]); } gfx_wait(); //usleep(timer); }
void drawGhost(int x,int y,int ghost,int orientation,int state[],int frightenLoop){ /* ghost is the number of ghost to draw * 0:blinky, 1:pinky, 2:inky, 3:clyde */ static int ghostLoop[4]={0,1,1,0}; int f; //f determines whether a frightened ghost is white or blue (flashes at end of frightened state) if(frightenLoop>=20 && state[ghost]==frighten){ f=frightenLoop%2; } else { f=-1; } /* Choose color */ if(state[ghost]==frighten){ if(!f){ gfx_color(0,0,150); } else if(f==1){ gfx_color(255,255,255); } else {gfx_color(0,0,150);} } else { switch(ghost){ case blinky: gfx_color(255,0,0); ghostLoop[blinky]++; break; case pinky: gfx_color(255,150,200); ghostLoop[pinky]++; break; case inky: gfx_color(0,255,255); ghostLoop[inky]++; break; case clyde: gfx_color(255,130,0); ghostLoop[clyde]++; break; } } /* Draw body */ int P=radius/10; //value that helped make the ghosts look better int i,r=radius/2-P; if(state[ghost]!=dead){ gfx_fill_circle(x,y-P,r); for(i=0;i<=r;i++){//left leg gfx_line(x-r+i,y-P, x-r+i, y+r-i); } for(i=1;i<=r;i++){//right leg gfx_line(x+i, y-P, x+i, y+i); } gfx_fill_rectangle(x-r,y-P,2*r,r); if(ghostLoop[ghost]%2){ for(i=0;i<r;i++){//right middle leg gfx_line(x+i, y-P, x+i, y+r-i); } for(i=0;i<=r;i++){//left middle leg gfx_line(x-r+i, y-P, x-r+i, y+i); } } else { for(i=3*P/2;i<=r;i++){//left middle leg gfx_line(x-i, y-P, x-i, y+r+3*P/2-i); } for(i=3*P/2;i<=r;i++){//right leg gfx_line(x+i, y-P, x+i, y+r+3*P/2-i); } } } /* Add the eyes based on orientation * * Frightened ghosts will have two whit dot eyes and a mouth * Values for all circle centers are made by trial and error, until the ghost looked good */ gfx_color(255,255,255); if(state[ghost]==frighten){ if(f==1){gfx_color(0,0,150);} gfx_fill_circle(x-4*r/10,y-2*P,r/4); gfx_fill_circle(x+4*r/10,y-2*P,r/4); //next six are the mouth gfx_line(x-r,y+2*P,x-2*r/3,y+P); gfx_line(x-2*r/3,y+P,x-r/3,y+2*P); gfx_line(x-r/3,y+2*P,x,y+P); gfx_line(x,y+P,x+r/3,y+2*P); gfx_line(x+r/3,y+2*P,x+2*r/3,y+P); gfx_line(x+2*r/3,y+P,x+r,y+2*P); } else { gfx_fill_circle(x-4*r/10,y-2*P,r/3); gfx_fill_circle(x-4*r/10,y-3*P/2,r/3); gfx_fill_circle(x+4*r/10,y-2*P,r/3); gfx_fill_circle(x+4*r/10,y-3*P/2,r/3); /* Now on to the pupils */ gfx_color(0,0,150); switch(orientation){ case up: /*pupils*/ gfx_fill_circle(x-4*r/10,y-11*P/4,r/6); gfx_fill_circle(x+4*r/10,y-11*P/4,r/6); break; case down: gfx_fill_circle(x-4*r/10,y-3*P/4,r/6);/*pupils are 1/2 radius of the entire eye */ gfx_fill_circle(x+4*r/10,y-3*P/4,r/6); break; case left: gfx_fill_circle(x-4*r/10-3*P/4,y-7*P/4,r/6); gfx_fill_circle(x+4*r/10-3*P/4,y-7*P/4,r/6); break; case right: gfx_fill_circle(x-4*r/10+3*P/4,y-7*P/4,r/6); gfx_fill_circle(x+4*r/10+3*P/4,y-7*P/4,r/6); break; } } }
void drawBoard(int x,int y,int height,int width,int h,int w,int lives,int win,int score){ /* This function draws the board in blue, one pixel wide borders * x and y are the coordinates of the top left corner of the board */ gfx_color(0,0,255); /* This loop draws the rectangles (1) in blue to prevent pacman from going over them * It also draws the dots (0) if pacman has not eaten them yet * Also draws the big dots (7) if pacman has not eaten them yet */ int i,j; for(i=0;i<rows;i++){ for(j=0;j<columns;j++){ if(board[i][j]==1){ gfx_color(0,0,255); gfx_fill_rectangle(x+radius*j,y+radius*i,radius,radius); } else if(board[i][j]==0){//draws dots in place gfx_color(255,200,0); gfx_fill_rectangle(x+radius*(j+0.5)-2,y+radius*(i+0.5)-2,4,4); } else if (board[i][j]==7){//draw big dots gfx_color(255,200,0); gfx_fill_circle(x+radius*(j+.5),y+radius*(i+.5),8); } else if(board[i][j]==8){ gfx_color(0,0,255); gfx_rectangle(x+radius*j,y+radius*i,radius,radius); }//printf("%i",board[i][j]); }//printf("\n"); } /* This block draws borders for the board */ gfx_color(0,0,255); gfx_line(x,y,x+width,y); //top border gfx_line(x,y+height,x+width,y+height); //bottom border gfx_line(x,y,x,y+radius*7); //left top border (above gap) gfx_line(x,y+radius*8,x,y+height); //left bottom border (below gap) gfx_line(x+width,y,x+width,y+radius*7); //right top border (above gap) gfx_line(x+width,y+radius*8,x+width,y+height); //right bottom border (below gap) /* This block draws the score and number of lives left */ gfx_color(255,255,255); gfx_text((w-width)/4-radius/2,h*1/2-2*radius/3,"LIVES:"); gfx_text((w-width)/4-radius/2,h*.3-16,"SCORE:"); gfx_text((w-width)/4-radius/2,h*.3,num2str(score)); for(i=0;i<lives;i++){ drawPacman((w-width)/4,h*1/2+radius*i,right,1); } if(lives<=0){ gfx_color(255,255,255); gfx_text(w/2-27,h/2-8,"GAME OVER"); gfx_text(w/2-48,h/2+8,"Play Again? (y/n)"); } else if(win==1){ gfx_color(255,255,255); gfx_text(w/2-18,h/2-8,"WINNER!"); gfx_text(w/2-48,h/2+8,"Play Again? (y/n)"); } else if(win==2){ gfx_color(255,255,255); gfx_text(w/2-18,h/2-8,"READY?"); } else if(win==3){ gfx_color(255,255,255); gfx_text(w/2-8,h/2-8,"GO!"); } else if(win==5){ gfx_color(255,255,255); gfx_text(w/2-23,h/2-8,"YOU DIED"); gfx_text(w/2-38,h/2+8,"Click 7 times"); } else if(win==6){ gfx_color(255,255,255); gfx_text(w/2-23,h/2-8,"YOU DIED"); gfx_text(w/2-38,h/2+8,"Click 6 times"); } else if(win==7){ gfx_color(255,255,255); gfx_text(w/2-23,h/2-8,"YOU DIED"); gfx_text(w/2-38,h/2+8,"Click 5 times"); } else if(win==8){ gfx_color(255,255,255); gfx_text(w/2-23,h/2-8,"YOU DIED"); gfx_text(w/2-38,h/2+8,"Click 4 times"); } else if(win==9){ gfx_color(255,255,255); gfx_text(w/2-23,h/2-8,"YOU DIED"); gfx_text(w/2-38,h/2+8,"Click 3 times"); } else if(win==10){ gfx_color(255,255,255); gfx_text(w/2-23,h/2-8,"YOU DIED"); gfx_text(w/2-38,h/2+8,"Click 2 times"); } else if(win==11){ gfx_color(255,255,255); gfx_text(w/2-23,h/2-8,"YOU DIED"); gfx_text(w/2-36,h/2+8,"Click 1 time"); } }
int presentEndScreen (int score, int highScore, int width, int height) { //present end screen gfx_color(255, 255, 255); gfx_changefont("-*-helvetica-bold-r-*-*-*-250-90-90-p-*-iso8859-1"); gfx_text(width/2-88, 150, "GAME OVER"); //draw score block gfx_color(0,0,0); gfx_fill_rectangle(50, 180, width-100, 164); gfx_color(237, 206, 111); gfx_fill_rectangle(54, 184, width-108, 156); gfx_color(209, 181, 98); gfx_fill_rectangle(61, 191, width-122, 142); gfx_color(245, 228, 176); gfx_fill_rectangle(62, 192, width-124, 140); //labels gfx_color(209, 181, 98); gfx_changefont("-*-helvetica-bold-r-*-*-*-160-85-85-p-*-iso8859-1"); gfx_text(width/2-110, height/2-50, "MEDAL"); gfx_text(width/2+50, height/2-50, "SCORE"); gfx_text(width/2+65, height/2+8, "BEST"); if (score > highScore) { highScore = score; //print new best label gfx_color(250, 0, 46); gfx_fill_rectangle(width/2+14, height/2-9, 46, 20); gfx_color(255, 255, 255); gfx_text (width/2+15, height/2+8, "NEW"); } //scores gfx_changefont("-*-helvetica-bold-r-*-*-*-200-90-90-p-*-iso8859-1"); char scoreStr[5], highScoreStr[5]; sprintf(scoreStr, "%d", score); sprintf(highScoreStr, "%d", highScore); gfx_color(255, 255, 255); gfx_text(width/2+100, height/2-25, scoreStr); gfx_text(width/2+100, height/2+33, highScoreStr); //medals int red, green, blue; if (score > 40) { //platinum red = 245; green = 245; blue = 245; } else if (score > 30) { //gold red = 250; green = 239; blue = 82; } else if (score > 20) { //silver red = 214; green = 214; blue = 214; } else { //bronze red = 242; green = 152; blue = 87; } gfx_color(red, green, blue); gfx_fill_circle(width/2-80, height/2, 28); //medal bird int birdX = 105; int birdY = 264; //draw the bird gfx_color(red, green, blue); gfx_fill_arc(birdX, birdY, 29, 24, 0, 360); gfx_color(red-60,green-20,blue); gfx_arc(birdX, birdY, 29, 24, 0, 360); gfx_color(red, green, blue); gfx_fill_circle(birdX+23,birdY+9,(0.50)*12+1); gfx_color(red-60,green-20,blue); gfx_circle(birdX+23,birdY+9,(0.50)*12+1); gfx_color(red, green, blue); gfx_fill_arc(birdX-2,birdY+4,11, 6, 0, 360); gfx_color(red-60,green-20,blue); gfx_arc(birdX-2,birdY+4,11, 6, 0, 360); gfx_color(red, green, blue); gfx_fill_arc(birdX+17, birdY+19, 14, 3, 0, 360); gfx_color(red-60,green-20,blue); gfx_arc(birdX+17, birdY+19, 14, 3, 0, 360); gfx_color(red, green, blue); gfx_fill_arc(birdX+17, birdY+15, 16, 4, 0, 360); gfx_color(red-60, green-20,blue); gfx_arc(birdX+17, birdY+15, 16, 4, 0, 360); gfx_color(red, green, blue); gfx_fill_rectangle(birdX+25,birdY+8, 2, 4); gfx_color(red-60,green-20,blue); gfx_rectangle(birdX+25,birdY+8, 2, 4); //play again button gfx_color(0, 0, 0); gfx_fill_rectangle(width/2-79, height/2+96, 158, 28); gfx_color(255, 255, 255); gfx_fill_rectangle(width/2-77, height/2+98, 154, 24); gfx_color(250, 0, 46); gfx_fill_rectangle(width/2-75, height/2+100, 150, 20); gfx_color(255, 255, 255); gfx_changefont("-*-helvetica-bold-r-*-*-*-120-75-75-p-*-iso8859-1"); gfx_text(width/2-38, height/2+115, "PLAY AGAIN"); return highScore; }