public void Collision(CollisionEventArgs e) { return; }
// This method will resolve collisions the object is involved in by moving it out of any intersecting solid objects. public void ResolveCollisions(object sender, CollisionEventArgs e) { ICollidable otherObject = e.CollidedObject; // If the hitboxes no longer intersect (due to a previous collision resolution etc.), prevent the resolution from occuring if (!Hitbox.Intersects(otherObject.Hitbox)) return; if (otherObject.Solid) { // Find the dimensions of the overlap // Pick the shallow axis and move the object to its previous position along that axis only int x1, x2, y1, y2; x1 = Math.Max(Hitbox.X, otherObject.Hitbox.X); x2 = Math.Min(Hitbox.X + Hitbox.Width, otherObject.Hitbox.X + otherObject.Hitbox.Width); y1 = Math.Max(Hitbox.Y, otherObject.Hitbox.Y); y2 = Math.Min(Hitbox.Y + Hitbox.Height, otherObject.Hitbox.Y + otherObject.Hitbox.Height); int xPen = x2 - x1; int yPen = y2 - y1; // If X penetration is shallower... if (xPen <= yPen) { // Resolve along the X axis //If collision comes from the right if(PreviousPosition.X > Position.X) Position = new Vector2(Position.X + (xPen + 1), Position.Y); else Position = new Vector2(Position.X - (xPen + 1), Position.Y); } else { // Otherwise resolve around Y // If the collision occurs from above... if (PreviousPosition.Y < Position.Y) { Position = new Vector2(Position.X, Position.Y - yPen); //Position = new Vector2(Position.X, otherObject.Hitbox.Y - Hitbox.Height); CheckForFloor(); } else { Position = new Vector2(Position.X, Position.Y + yPen); } // Make a recursive call in the fringe case that both sides have to be resolved. ResolveCollisions(this, e); } } }
// This is called when the player collides with the crystal public void CrystalReached(object sender, CollisionEventArgs e) { thisScene.SequenceUp(); triggered = true; Destroy(); }
public void Collision(CollisionEventArgs e) { if (OnCollision != null) OnCollision(this, e); }