Пример #1
0
        /// <summary>
        /// Move the object in the Y axis by the value of speed. Sweeping collision test.
        /// </summary>
        /// <param name="speed">The speed to move by (remember SpeedScale is applied.)</param>
        /// <param name="collider">The Collider to use when moving.</param>
        public virtual void MoveY(int speed, Collider collider = null)
        {
            MoveBufferY += speed;

            while (Math.Abs(MoveBufferY) >= SpeedScale) {
                int move = Math.Sign(MoveBufferY);
                if (collider != null) {
                    Collider c = collider.Collide(Entity.X, Entity.Y + move, CollisionsSolid);
                    if (c == null) {
                        Entity.Y += move;
                        MoveBufferY = (int)Util.Approach(MoveBufferY, 0, SpeedScale);
                    }
                    else {
                        MoveBufferY = 0;
                        MoveCollideY(c);
                    }
                }
                if (collider == null || CollisionsSolid.Count == 0) {
                    Entity.Y += move;
                    MoveBufferY = (int)Util.Approach(MoveBufferY, 0, SpeedScale);
                }
            }
        }
Пример #2
0
        public override void MoveY(int speed, Collider collider = null) {
            MoveBufferY += speed;

            while (Math.Abs(MoveBufferY) >= SpeedScale) {
                int move = Math.Sign(MoveBufferY);
                if (collider != null) {
                    bool freeToMove = true;
                    Collider c = null;

                    if (move > 0) {
                        c = collider.Collide(Entity.X, Entity.Y + move, CollisionsSolid);
                        if (c == null) {
                            if (JumpThroughCollider != null) {
                                var hasPlatformBelow = JumpThroughCollider.Overlap(Entity.X, Entity.Y + move, CollisionsJumpThrough);
                                if (hasPlatformBelow) {
                                    hasPlatformBelow = false;

                                    // Check to see if only bottom 1 pixel is overlapping jump throughs
                                    var platform = JumpThroughCollider.Collide(Entity.X, Entity.Y + move, CollisionsJumpThrough);
                                    if (!JumpThroughCollider.Overlap(Entity.X, Entity.Y, platform)) {
                                        // This makes sense just trust me ok
                                        hasPlatformBelow = true;
                                    }
                                }

                                if (hasPlatformBelow) {
                                    freeToMove = false;
                                    c = JumpThroughCollider.Collide(Entity.X, Entity.Y + move, CollisionsJumpThrough);
                                }
                            }
                        }
                        else {
                            freeToMove = false;
                        }
                    }
                    else {
                        c = collider.Collide(Entity.X, Entity.Y + move, CollisionsSolid);
                        if (c != null) {
                            freeToMove = false;
                        }
                    }

                    if (freeToMove) {
                        Entity.Y += move;
                        MoveBufferY = (int)Util.Approach(MoveBufferY, 0, SpeedScale);
                    }
                    else {
                        MoveBufferY = 0;
                        MoveCollideY(c);
                    }
                }
                if (collider == null || CollisionsSolid.Count == 0) {
                    Entity.Y += move;
                    MoveBufferY = (int)Util.Approach(MoveBufferY, 0, SpeedScale);
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Move the object in the X axis by the value of speed. Sweeping collision test.
        /// </summary>
        /// <param name="speed">The speed to move by (remember SpeedScale is applied.)</param>
        /// <param name="collider">The Collider to use when moving.</param>
        public void MoveX(int speed, Collider collider = null)
        {
            MoveBufferX += speed;

            while (Math.Abs(MoveBufferX) >= SpeedScale) {
                int move = Math.Sign(MoveBufferX);
                if (collider != null) {
                    Collider c = collider.Collide(Entity.X + move, Entity.Y, CollidesWith);
                    if (c == null) {
                        Entity.X += move;
                        MoveBufferX = (int)Util.Approach(MoveBufferX, 0, SpeedScale);
                    }
                    else {
                        MoveBufferX = 0;
                        MoveCollideX(c);
                    }
                }
                if (collider == null || CollidesWith.Count == 0) {
                    Entity.X += move;
                    MoveBufferX = (int)Util.Approach(MoveBufferX, 0, SpeedScale);
                }

            }
        }