Exemple #1
0
        private static Vector2 AbsoluteFixOffsetCollision(ICollidable collidable, Vector2 guessedPosition, Vector2 offset, List <ICollidable> ignoreList)
        {
            List <ICollidable> otherList;

            if (ignoreList == null)
            {
                otherList = CollisionDetector.GetCollisionsAtPosition(collidable, Vector2.Add(guessedPosition, offset));
            }
            else
            {
                otherList = CollisionDetector.GetCollisionsAtPosition(collidable, Vector2.Add(guessedPosition, offset), ignoreList);
            }

            int xDirection = -Math.Sign(offset.X);
            int yDirection = -Math.Sign(offset.Y);

            foreach (ICollidable other in otherList)
            {
                Vector2 tempCollisionPosition;
                Vector2 tempCollisionSize;
                OutCollisionRectangle(collidable, Vector2.Add(guessedPosition, offset), other, out tempCollisionPosition, out tempCollisionSize);
                if (tempCollisionSize != Vector2.Zero)
                {
                    guessedPosition = MoveOutOfOtherInDirection(collidable, offset, other, tempCollisionSize);
                }
            }

            return(guessedPosition);
        }
Exemple #2
0
        public void Update()
        {
            List <ICollidable> collidableList;

            sprite.Update();
            collidableList = CollisionDetector.GetCollisionsAtPosition(hitboxTop, hitboxTop.Position);
            MoveColliders(collidableList, TotalSpeed());
            collidableList = CollisionDetector.GetCollisionsAtPosition(hitboxBot, hitboxBot.Position);
            MoveColliders(collidableList, TotalSpeed());
        }