示例#1
0
char TGame::doHitTest(int x, int y) {
	//do hit test
	
	if(Tank1.hitTest(x,y,2,2))//could be for dynamic bullet size
	{
		//delete &Tank1
		Tank1.isHit = true;
		return '1';
	}

	if(Tank2.hitTest(x,y,2,2))//could be for dynamic bullet size
	{
		//delete &Tank2
		Tank2.isHit = true;
		return '2';
	}

	for(int i=0;i<vObs.size();i++)
	{
		 Obstacle O = (Obstacle) vObs[i];
		 int w,h;
		 w = .5;
		 h = .5;
		 if(O.hitTest(x,y,w,h))
		 return 'w';
	}

	

	return 'n';
}
示例#2
0
void TGame::moveTank2(char direction) {
	bool canMove = true;

   	point tm;
	tm = Tank2.getMovePoint(direction);
	if(!Tank1.hitTest(tm.x,tm.y,Tank2.width,Tank2.height))//check contact with opposing tank
	{
	  for(int i=0;i<vObs.size();i++)
	  {
		 Obstacle O = (Obstacle) vObs[i];
		 int x,y,w,h;
		 point p = Tank2.getMovePoint(direction);
		 x= p.x;
		 y= p.y;
		 w = Tank1.width;
		 h = Tank1.height;
		 if(O.hitTest(x,y,w+2,h+2))
		  canMove = false;
	  }
	}
	else{canMove = false;}
	
	  if(canMove)
	  Tank2.move(direction);
	
}