Beispiel #1
0
bool Player::collided(Object* collider)
{
	// Grab information about the collision :NOTE: Could be done in a better way, ie collided has that information as a parameter
	Collision collision = polyCollision(collider->getBody(), this->getBody());

	// True if the player is on the ground
	// Needs to check the y velocity because the objects can still be inside each other, but on their way of separating, might take 2-4 frames for them to be 100% separated
	if(collision.pushY < 0 && getVelocity().y > 0)	{
		// Test of collided with self or the weapon :NOTE: Check against itself shouldn't be needed
		if(collider != this && collider->getParent() != this)
		{
 			if(mInAir)	{	
   				mInAir = false;
				mAnimation->setFrame(0);
			}
		}
	}

	if(collider->getType() == PARTICLE)	{
		mStunned = true;
		mStunnedCounter = 0.30f;
	}

	return true;
}
Beispiel #2
0
int collision(OBJECT* obj1, OBJECT* obj2, GAME_STATE* state){
  if(obj1->ghost || obj2->ghost){
    obj1->collResp.cirCollided = 0;
    obj1->collResp.objCollided = 0;
    obj1->collResp.axis.x = 0.0;
    obj1->collResp.axis.y = 0.0;
    obj1->collResp.mag = 0.0;
    obj2->collResp.cirCollided = 0;
    obj2->collResp.objCollided = 0;
    obj2->collResp.axis.x = 0.0;
    obj2->collResp.axis.y = 0.0;
    obj2->collResp.mag = 0.0;
    return 0;
                                }
  int animCurr1, animCurr2, subFrameCurr1, subFrameCurr2;
  int polyTot1, polyTot2, ctrl1, ctrl2, ctrl3;
  int pixelWidth1, pixelHeight1, pixelWidth2, pixelHeight2;
  float r1, r2;
  VECT pos1, pos2, pointA[state->WIN.polyMaxPoints], pointB[state->WIN.polyMaxPoints];
  POLY A, B;
  A.point = pointA;
  B.point = pointB;
  animCurr1 = obj1->animCurrent;
  subFrameCurr1 = obj1->anim[animCurr1].subFrameCurrent;
  pos1.x = obj1->anim[animCurr1].coll[subFrameCurr1].pos.x * obj1->scale + obj1->pos.x;
  pos1.y = obj1->anim[animCurr1].coll[subFrameCurr1].pos.y * obj1->scale + obj1->pos.y;
  r1 = obj1->scale * obj1->anim[animCurr1].coll[subFrameCurr1].radius;
  animCurr2 = obj2->animCurrent;
  subFrameCurr2 = obj2->anim[animCurr2].subFrameCurrent;
  pos2.x = obj2->anim[animCurr2].coll[subFrameCurr2].pos.x * obj2->scale + obj2->pos.x;
  pos2.y = obj2->anim[animCurr2].coll[subFrameCurr2].pos.y * obj2->scale + obj2->pos.y;
  r2 = obj2->scale * obj2->anim[animCurr2].coll[subFrameCurr2].radius;
  if(obj1->camRelative){
    pos1.x -= state->CAM.pos.x;
    pos1.y -= state->CAM.pos.y;
                       }
  if(obj2->camRelative){
    pos2.x -= state->CAM.pos.x;
    pos2.y -= state->CAM.pos.y;
                       }
  obj1->collResp.cirCollided = cirCollision(&pos1, r1, &pos2, r2);
  obj2->collResp.cirCollided = obj1->collResp.cirCollided;
  if(obj1->collResp.cirCollided){
    polyTot1 = obj1->anim[animCurr1].coll[subFrameCurr1].polyTotal;
    polyTot2 = obj2->anim[animCurr2].coll[subFrameCurr2].polyTotal;
    for(ctrl1=0; ctrl1<polyTot1; ctrl1++){
      pixelWidth1 = obj1->anim[animCurr1].subFramePixelWidth;
      pixelHeight1 = obj1->anim[animCurr1].subFramePixelHeight;
      A.pointTotal = obj1->anim[animCurr1].coll[subFrameCurr1].poly[ctrl1].pointTotal;
      for(ctrl3=0; ctrl3<A.pointTotal; ctrl3++){
        A.point[ctrl3].x = obj1->anim[animCurr1].coll[subFrameCurr1].poly[ctrl1].point[ctrl3].x;
        A.point[ctrl3].y = obj1->anim[animCurr1].coll[subFrameCurr1].poly[ctrl1].point[ctrl3].y;
                                               }
      A.pos.x = obj1->anim[animCurr1].coll[subFrameCurr1].poly[ctrl1].pos.x;
      A.pos.y = obj1->anim[animCurr1].coll[subFrameCurr1].poly[ctrl1].pos.y;
      A.radius = obj1->anim[animCurr1].coll[subFrameCurr1].poly[ctrl1].radius;
      pos1.x = 0.5*pixelWidth1;
      pos1.y = 0.5*pixelHeight1;
      polyScale(&A, &pos1, obj1->scale);
      pos1.x *= obj1->scale;
      pos1.y *= obj1->scale;
      polyRotate(&A, &pos1, obj1->rotation);
      pos1.x = obj1->pos.x;
      pos1.y = obj1->pos.y;
      if(obj1->camRelative){
        pos1.x -= state->CAM.pos.x;
        pos1.y -= state->CAM.pos.y;
                           }
      polyTranslate(&A, &pos1);
      for(ctrl2=0; ctrl2<polyTot2; ctrl2++){
        pixelWidth2 = obj2->anim[animCurr2].subFramePixelWidth;
        pixelHeight2 = obj2->anim[animCurr2].subFramePixelHeight;
        B.pointTotal = obj2->anim[animCurr2].coll[subFrameCurr2].poly[ctrl2].pointTotal;
        for(ctrl3=0; ctrl3<A.pointTotal; ctrl3++){
          B.point[ctrl3].x = obj2->anim[animCurr2].coll[subFrameCurr2].poly[ctrl2].point[ctrl3].x;
          B.point[ctrl3].y = obj2->anim[animCurr2].coll[subFrameCurr2].poly[ctrl2].point[ctrl3].y;
                                                 }
        B.pos.x = obj2->anim[animCurr2].coll[subFrameCurr2].poly[ctrl2].pos.x;
        B.pos.y = obj2->anim[animCurr2].coll[subFrameCurr2].poly[ctrl2].pos.y;
        B.radius = obj2->anim[animCurr2].coll[subFrameCurr2].poly[ctrl2].radius;
        pos2.x = 0.5*pixelWidth2;
        pos2.y = 0.5*pixelHeight2;
        polyScale(&B, &pos2, obj2->scale);
        pos2.x *= obj2->scale;
        pos2.y *= obj2->scale;
        polyRotate(&B, &pos2, obj2->rotation);
        pos2.x = obj2->pos.x;
        pos2.y = obj2->pos.y;
        if(obj2->camRelative){
          pos2.x -= state->CAM.pos.x;
          pos2.y -= state->CAM.pos.y;
                             }
        polyTranslate(&B, &pos2);
        if(cirCollision(&A.pos, A.radius, &B.pos, B.radius)){
          if(polyCollision(&A, &B, &obj1->collResp, &obj2->collResp)){
            obj1->collResp.objCollided = 1;
            obj2->collResp.objCollided = 1;
            normalize(&obj1->collResp.axis);
            normalize(&obj2->collResp.axis);
            return 1;
                                                                   }
                                                            }
                                           }
                                         }
                        }
  obj1->collResp.objCollided = 0;
  obj1->collResp.axis.x = 0.0;
  obj1->collResp.axis.y = 0.0;
  obj1->collResp.mag = 0.0;
  obj2->collResp.objCollided = 0;
  obj2->collResp.axis.x = 0.0;
  obj2->collResp.axis.y = 0.0;
  obj2->collResp.mag = 0.0;
  return 0;
}