예제 #1
0
//The main function:
int main(){
  //Local variables to store the coordinates of the points:
  Point_2D point, intersectPoint;
  printf("Put the 2 coordinates of the point: \n");
  scanf("%f", &point.coord[0]);
  scanf("%f", &point.coord[1]);

  //Local variables to store the wall segments:
  Segment_2D wall1, wall2;

  printf("Put the 4 (2x2) coordinates of the first wall bounds: \n");
  for(int i=0; i<2; i++){
    for(int j=0; j<2; j++){
      scanf("%f", &wall1.bounds[i].coord[j]);
    }
  }

  printf("Put the 4 (2x2) coordinates of the second wall bounds: \n");
  for(int i=0; i<2; i++){
    for(int j=0; j<2; j++){
      scanf("%f", &wall2.bounds[i].coord[j]);
    }
  }

  //Calculate the vector representations of the two walls (segments):
  for(int i=0; i<2; i++){
    wall1.vector.coord[i] = wall1.bounds[1].coord[i] - wall1.bounds[0].coord[i];
    wall2.vector.coord[i] = wall2.bounds[1].coord[i] - wall2.bounds[0].coord[i];
  }


  //Calculate the coordinates of the image source:
  Point_2D image_source = createIS_2D(point, wall1.bounds[0], wall1.bounds[1]);
  //Print the results:
  printf("Front or back (with first wall): %d\n", isFrontBack(point, wall1.bounds[0], wall1.bounds[1]));
  printf("Image Source coordinates: [%f, %f]\n", image_source.coord[0], image_source.coord[1]);
  if(intersectCheck(wall1, wall2, &intersectPoint)==1){
    printf("The segments intersect at: [%f, %f]\n", intersectPoint.coord[0], intersectPoint.coord[1]);
  }
  else {
    printf("The segments do NOT intersect.\n");
  }
}
예제 #2
0
void Hanger::doAction(float _f, GameControl * _gameControl)
{
	switch(status)
	{
	case HANGER_STATUS_SWAYING:
#ifdef							GOLDEN_MINER_2_VERSION_TIME
		if(tmpStatusTimeCount <= 0)
		{
			canThrow = true;
			//Global::getInstance()->setHangerCanThrow(canThrow);
		}
		else
		{
			tmpStatusTimeCount -= _f*SCHEDULE_TIMES;
		}
#else
		if(tmpStatusTimeCount == 0)
		{
			canThrow = true;
			//Global::getInstance()->setHangerCanThrow(canThrow);
		}
		else
		{
			tmpStatusTimeCount--;
		}
#endif
		// 钩子摇摆状态要改变角度 以及图片显示
		changeAngle();
		//setSwayPostion();
		break;
	case HANGER_STATUS_THROW:
		setMovePostion(_gameControl);
		intersectCheck(_gameControl);
		break;
	case HANGER_STATUS_PULL_HAVING:
#ifdef							GOLDEN_MINER_2_VERSION_TIME
		if(tmpStatusTimeCount <= 0)
		{
			setMovePostion(_gameControl);
		}
		else
		{
			tmpStatusTimeCount -= _f*SCHEDULE_TIMES;
			if((tmpStatusTimeCount <= HANGER_PULL_START) && ((tmpStatusTimeCount+_f*SCHEDULE_TIMES) >= HANGER_PULL_START))
			{
				// 换图
				rope->changeImageByStatus(ROPE_STATUS_PULL, this);
			}
			else if((tmpStatusTimeCount <= 0) && ((tmpStatusTimeCount+_f*SCHEDULE_TIMES) >= 0))
			{
				// 换图
				rope->changeImageByStatus(ROPE_STATUS_NORMAL, this);
			}
		}
#else
		if(tmpStatusTimeCount == 0)
		{
			setMovePostion(_gameControl);
		}
		else
		{
			tmpStatusTimeCount--;
			if(tmpStatusTimeCount == HANGER_PULL_START)
			{
				// 换图
				rope->changeImageByStatus(ROPE_STATUS_PULL, this);
			}
			else if(tmpStatusTimeCount == 0)
			{
				// 换图
				rope->changeImageByStatus(ROPE_STATUS_NORMAL, this);
			}
		}
#endif
		break;
	case HANGER_STATUS_PULL_UNHAVING:
		// 出钩子/收钩子 只有位置变化
		//CCLOG("Hanger doAction: status = %d", status);
#ifdef									GOLDEN_MINER_2_VERSION_TIME
		if(tmpStatusTimeCount < 0)
		{
			setMovePostion(_gameControl);
		}
		else
		{
			tmpStatusTimeCount -= _f*SCHEDULE_TIMES;
			if((tmpStatusTimeCount <= 0) && ((tmpStatusTimeCount+_f*SCHEDULE_TIMES) >= 0))
			{
				// 换图
				rope->changeImageByStatus(ROPE_STATUS_NORMAL, this);
			}
		}
#else
		if(tmpStatusTimeCount == 0)
		{
			setMovePostion(_gameControl);
		}
		else
		{
			tmpStatusTimeCount--;
			if(tmpStatusTimeCount == 0)
			{
				// 换图
				rope->changeImageByStatus(ROPE_STATUS_NORMAL, this);
			}
		}
#endif
		setMovePostion(_gameControl);
		break;
	case HANGER_STATUS_PAUSE:
		break;
	default:
		// 不能出现其他状态 有错误
		break;
	}

	rope->doAction(_f, this);
}