Beispiel #1
0
 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);
 }
Beispiel #2
0
 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);
 }
Beispiel #3
0
        /// <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;
        }
Beispiel #4
0
 public void ChangeTarget(GameObject target)
 {
     this.target = target;
     targetPosition = Vector2.Zero;
     Pan(target.Position);
 }
Beispiel #5
0
 public void ChangeTarget(Vector2 target)
 {
     this.target = null;
     targetPosition = target;
     Pan(targetPosition);
 }
Beispiel #6
0
        /// <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;
        }
Beispiel #7
0
 public virtual void CollideWithObject(GameObject obj, Room room, BBox collision)
 {
 }
Beispiel #8
0
 public void Remove(GameObject obj)
 {
     toRemove.Add(obj);
 }
Beispiel #9
0
        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;
        }
Beispiel #10
0
 public void Add(GameObject obj)
 {
     toAdd.Add(obj);
 }
Beispiel #11
0
 private bool ShouldSpoutCollide(GameObject obj)
 {
     return true;
 }
Beispiel #12
0
        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);
        }
Beispiel #13
0
 public Vector2 GetMapPosition(GameObject obj)
 {
     return obj.Position * Scale;
 }
Beispiel #14
0
 public bool Contains(GameObject obj)
 {
     return obj.Box.Rectangle.Intersects(box);
 }