Beispiel #1
0
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);
}
Beispiel #2
0
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;}
  }
 }
}
void SvgElementVisitor::visit(clan::DomElement &e)
{
	if (e.get_namespace_uri() != Svg::svg_ns) return;

	// To do: do a more efficient search for the correct handler

	auto local_name = e.get_local_name();
	if (local_name == "a") a(e);
	else if (local_name == "altGlyph") altGlyph(e);
	else if (local_name == "altGlyphDef") altGlyphDef(e);
	else if (local_name == "altGlyphItem") altGlyphItem(e);
	else if (local_name == "animate") animate(e);
	else if (local_name == "animateColor") animateColor(e);
	else if (local_name == "animateMotion") animateMotion(e);
	else if (local_name == "animateTransform") animateTransform(e);
	else if (local_name == "circle") circle(e);
	else if (local_name == "clipPath") clipPath(e);
	else if (local_name == "color-profile") color_profile(e);
	else if (local_name == "cursor") cursor(e);
	else if (local_name == "defs") defs(e);
	else if (local_name == "desc") desc(e);
	else if (local_name == "ellipse") ellipse(e);
	else if (local_name == "feBlend") feBlend(e);
	else if (local_name == "feColorMatrix") feColorMatrix(e);
	else if (local_name == "feComponentTransfer") feComponentTransfer(e);
	else if (local_name == "feComposite") feComposite(e);
	else if (local_name == "feConvolveMatrix") feConvolveMatrix(e);
	else if (local_name == "feDiffuseLighting") feDiffuseLighting(e);
	else if (local_name == "feDisplacementMap") feDisplacementMap(e);
	else if (local_name == "feDistantLight") feDistantLight(e);
	else if (local_name == "feFlood") feFlood(e);
	else if (local_name == "feFuncA") feFuncA(e);
	else if (local_name == "feFuncB") feFuncB(e);
	else if (local_name == "feFuncG") feFuncG(e);
	else if (local_name == "feFuncR") feFuncR(e);
	else if (local_name == "feGaussianBlur") feGaussianBlur(e);
	else if (local_name == "feImage") feImage(e);
	else if (local_name == "feMerge") feMerge(e);
	else if (local_name == "feMergeNode") feMergeNode(e);
	else if (local_name == "feMorphology") feMorphology(e);
	else if (local_name == "feOffset") feOffset(e);
	else if (local_name == "fePointLight") fePointLight(e);
	else if (local_name == "feSpecularLighting") feSpecularLighting(e);
	else if (local_name == "feSpotLight") feSpotLight(e);
	else if (local_name == "feTile") feTile(e);
	else if (local_name == "feTurbulence") feTurbulence(e);
	else if (local_name == "filter") filter(e);
	else if (local_name == "font") font(e);
	else if (local_name == "font-face") font_face(e);
	else if (local_name == "font-face-format") font_face_format(e);
	else if (local_name == "font-face-name") font_face_name(e);
	else if (local_name == "font-face-src") font_face_src(e);
	else if (local_name == "font-face-uri") font_face_uri(e);
	else if (local_name == "foreignObject") foreignObject(e);
	else if (local_name == "g") g(e);
	else if (local_name == "glyph") glyph(e);
	else if (local_name == "glyphRef") glyphRef(e);
	else if (local_name == "hkern") hkern(e);
	else if (local_name == "image") image(e);
	else if (local_name == "line") line(e);
	else if (local_name == "linearGradient") linearGradient(e);
	else if (local_name == "marker") marker(e);
	else if (local_name == "mask") mask(e);
	else if (local_name == "metadata") metadata(e);
	else if (local_name == "missing-glyph") missing_glyph(e);
	else if (local_name == "mpath") mpath(e);
	else if (local_name == "path") path(e);
	else if (local_name == "pattern") pattern(e);
	else if (local_name == "polygon") polygon(e);
	else if (local_name == "polyline") polyline(e);
	else if (local_name == "radialGradient") radialGradient(e);
	else if (local_name == "rect") rect(e);
	else if (local_name == "script") script(e);
	else if (local_name == "set") set(e);
	else if (local_name == "stop") stop(e);
	else if (local_name == "style") style(e);
	else if (local_name == "svg") svg(e);
	else if (local_name == "switch") switch_(e);
	else if (local_name == "symbol") symbol(e);
	else if (local_name == "text") text(e);
	else if (local_name == "textPath") textPath(e);
	else if (local_name == "title") title(e);
	else if (local_name == "tref") tref(e);
	else if (local_name == "tspan") tspan(e);
	else if (local_name == "use") use(e);
	else if (local_name == "view") view(e);
	else if (local_name == "vkern") vkern(e);
}