public bool BoundingCollision(CollidableObject sprite) { if (collidable && sprite.collidable && alive && sprite.alive && !sprite.guid.Equals(guid)) { if (GetBounds().Intersects(sprite.GetBounds())) { return true; } } return false; }
public bool HitTest(CollidableObject sprite) { bool collided = false; if (collidable && sprite.collidable && alive && sprite.alive && !sprite.guid.Equals(guid) && Collision.Touches(sprite.GetBounds(), GetBounds())) { Vector2 intersectionDepth = Collision.GetIntersectionDepth(GetBounds(), sprite.GetBounds()); if (intersectionDepth != Vector2.Zero) { float absDepthX = Math.Abs(intersectionDepth.X); float absDepthY = Math.Abs(intersectionDepth.Y); if (absDepthY < absDepthX) { sprite.lastSideTouched = 0; position = new Vector2(position.X, position.Y + intersectionDepth.Y); collided = true; } else { sprite.lastSideTouched = 1; position = new Vector2(position.X + intersectionDepth.X, position.Y); collided = true; } } else sprite.lastSideTouched = -1; } //if collision has happened then remove energy if (collided) { if(currentEnergy>0) currentEnergy -= sprite.power; if(sprite.currentEnergy>0) sprite.currentEnergy -= power; } return collided; }
public void ResolveBounding(CollidableObject sprite) { Vector2 intersectionDepth = Collision.GetIntersectionDepth(GetBounds(), sprite.GetBounds()); if (intersectionDepth != Vector2.Zero) { float absDepthX = Math.Abs(intersectionDepth.X); float absDepthY = Math.Abs(intersectionDepth.Y); if (absDepthY < absDepthX) position = new Vector2(position.X, position.Y + (intersectionDepth.Y * 1.05f)); else position = new Vector2(position.X + (intersectionDepth.X * 1.05f), position.Y); } }