public override void CollideWithObject(GameObject obj, Room room, BBox collision) { if (obj is Player && obj.Color == Color && !Symbolizing) { if (this != room.CorrectPortal) { Unlocked = true; room.Failed = true; room.Finish(); } else { if (type != RoomType.Acceptance) { curSymAnimation = animations.Find((set) => set.IsCalled(SYM + "1")); Symbolizing = true; } else { Unlocked = true; } } } base.CollideWithObject(obj, room, collision); }
public override void CollideWithObject(GameObject obj, Room room, BBox collision) { base.CollideWithObject(obj, room, collision); // ink blobs should smash into each other, but avoid awkward behavior with ink blobs // coming out of the same generator if (obj is InkBlob && !(obj is WaterBlob) && (obj.Color != Color)) room.Add(new InkBlob(Position, Vector2.Lerp(Velocity, obj.Velocity, 0.5f), Color.Combine(obj.Color), Vector2.Lerp(Size, obj.Size, 0.5f), shouldBounce)); room.Remove(this); }
/// <summary> /// Make a new camera focusing on the given game object. /// </summary> /// <param name="target">The target to focus on.</param> /// <param name="roomWidth">The width of the room this camera resides in. Used to prevent the camera from looking /// out of bounds.</param> /// <param name="roomHeight">The height of the room this camera resides in. Used to prevent the camera from looking /// out of bounds.</param> /// <param name="zoomLevel">The zoom level of the camera.</param> public Camera(GameObject target, int roomWidth, int roomHeight, float zoomLevel) { Zoom = zoomLevel; Rotation = 0.0f; position = target.Position; this.target = target; this.roomWidth = roomWidth; this.roomHeight = roomHeight; }
public void ChangeTarget(GameObject target) { this.target = target; targetPosition = Vector2.Zero; Pan(target.Position); }
public void ChangeTarget(Vector2 target) { this.target = null; targetPosition = target; Pan(targetPosition); }
/// <summary> /// Returns whether or not the given object is colliding with this object. /// </summary> /// <param name="obj">The object to check.</param> /// <param name="collisionRegion">The region of collision. Empty if no collision occurred.</param> /// <returns>True if the objects are colliding, false otherwise.</returns> public virtual bool IsColliding(GameObject obj, out BBox collisionRegion) { float collisionForgiveness = (this is Spout || obj is Spout) ? SPOUT_CFF : COLLISION_FORGIVENESS_FACTOR; collisionRegion = box.Intersect(obj.box); // only do forgiveness on the smaller box, a small enough box might not even be allowed // to collide on the larger box if we don't care BBox smallerBox = BBox.SmallerOf(box, obj.box); // because boxes are cruel, and not very true to the shape of the objects, only return true // if the area of collision is larger than we're willing to forgive. return collisionRegion != null && !collisionRegion.IsEmpty() && collisionRegion.Area >= smallerBox.Area * collisionForgiveness; }
public virtual void CollideWithObject(GameObject obj, Room room, BBox collision) { }
public void Remove(GameObject obj) { toRemove.Add(obj); }
public Section GetDeepestSection(GameObject obj) { Section deepestSection = null; foreach (Section section in sections) if (section.Contains(obj) && (deepestSection == null || section.Area < deepestSection.Area)) deepestSection = section; return deepestSection; }
public void Add(GameObject obj) { toAdd.Add(obj); }
private bool ShouldSpoutCollide(GameObject obj) { return true; }
public override void CollideWithObject(GameObject obj, Room room, BBox collision) { if (!dying && obj.IsCollidable) { // water is special, kills player if (obj is WaterBlob || (obj is Wave && obj.Color == Color.LightBlue) || (obj is Spout && obj.Color == Color.LightBlue && ShouldSpoutCollide(obj))) Die(room); else if (obj is InkBlob || obj is Wave || obj is Spout && ShouldSpoutCollide(obj)) { if (obj.Color == Color.Black) color = Color.Black; else color = color.Combine(obj.Color); } if (obj is Portal) if (color == obj.Color) { if (room.Portals.Count > 1 && obj != room.CorrectPortal) room.Failed = true; //room.Finish(); } if (obj as Spike != null) { // only punish the player if they're moving towards the spikes, too unforgiving otherwise if ((obj.Color == Color.White || obj.Color != Color) && (obj.Facing == Direction.Left && Velocity.X >= 0 || obj.Facing == Direction.Right && Velocity.X <= 0 || obj.Facing == Direction.Up && Velocity.Y >= 0 || obj.Facing == Direction.Down && Velocity.Y <= 0) && collision.Area >= box.Area / 7) //&& Math.Max(MathHelper.Distance(Box.Center.X, obj.Box.Center.X), // MathHelper.Distance(Box.Center.Y, obj.Box.Center.Y)) < 20f) Die(room); } } base.CollideWithObject(obj, room, collision); }
public Vector2 GetMapPosition(GameObject obj) { return obj.Position * Scale; }
public bool Contains(GameObject obj) { return obj.Box.Rectangle.Intersects(box); }