예제 #1
0
        public Ground GetPlayerGroundCollision(Vector2 playerPosition, bool isPlayerStanding)
        {
            Hitbox playerHitbox = GetPlayerHitbox(playerPosition, isPlayerStanding);

            foreach (Ground ground in level.Grounds)
            {
                Hitbox groundHitbox = Hitboxes.GetGroundHitbox(ground);

                if (playerHitbox.CollidesWith(groundHitbox))
                {
                    return(ground);
                }
            }

            return(null);
        }
예제 #2
0
        public bool DoesPlayerCollideWithAnObstacle(LevelProgression levelProgression)
        {
            Hitbox playerHitbox = GetPlayerHitbox(levelProgression.CurrentPlayerPosition, levelProgression.IsPlayerStanding);

            foreach (Obstacle obstacle in level.Obstacles)
            {
                Hitbox obstacleHitbox = Hitboxes.GetObstacleHitbox(obstacle);

                if (playerHitbox.CollidesWith(obstacleHitbox))
                {
                    return(true);
                }
            }

            return(false);
        }
예제 #3
0
        public bool CollidesWith(Hitbox otherHitbox)
        {
            foreach (Vector2 corner in otherHitbox.Corners)
            {
                if (IsVectorWithinHitbox(corner))
                {
                    return(true);
                }
            }

            foreach (Vector2 corner in Corners)
            {
                if (otherHitbox.IsVectorWithinHitbox(corner))
                {
                    return(true);
                }
            }

            return(false);
        }
예제 #4
0
        /*
         * public bool DoesPlayerCollideWithASolidObstacle(LevelProgression levelProgression)
         * {
         *      return DoesPlayerCollideWithASolidObstacle(levelProgression.CurrentPlayerPosition,
         *              levelProgression.IsPlayerStanding);
         * }
         *
         * private bool DoesPlayerCollideWithASolidObstacle(Vector2 playerPosition, bool isPlayerStanding)
         * {
         *      Hitbox playerHitbox = GetPlayerHitbox(playerPosition, isPlayerStanding);
         *
         *      foreach (Obstacle obstacle in level.SolidObstacles)
         *      {
         *              Hitbox obstacleHitbox = Hitboxes.GetObstacleHitbox(obstacle);
         *
         *              if (playerHitbox.CollidesWith(obstacleHitbox)) return true;
         *      }
         *
         *      return false;
         * }
         */

        public List <Collectible> GetPlayerCollectibleCollisions(LevelProgression levelProgression)
        {
            List <Collectible> collectedCollectibles = new List <Collectible>();

            Hitbox playerHitbox = GetPlayerHitbox(levelProgression.CurrentPlayerPosition, levelProgression.IsPlayerStanding);

            foreach (Collectible collectible in level.Collectibles)
            {
                if (levelProgression.IsCollectibleAlreadyCollected(collectible))
                {
                    continue;
                }

                Hitbox collectibleHitbox = Hitboxes.GetCollectibleHitbox(collectible);

                if (playerHitbox.CollidesWith(collectibleHitbox))
                {
                    collectedCollectibles.Add(collectible);
                }
            }

            return(collectedCollectibles);
        }
예제 #5
0
        public List <Projectile> GetPlayerProjectileCollisions(LevelProgression levelProgression)
        {
            List <Projectile> projectilesCollidedWith = new List <Projectile>();

            Hitbox playerHitbox = GetPlayerHitbox(levelProgression.CurrentPlayerPosition, levelProgression.IsPlayerStanding);

            foreach (Projectile projectile in level.Projectiles)
            {
                if (levelProgression.IsProjectileDeflected(projectile))
                {
                    continue;
                }

                Hitbox projectileHitbox = Hitboxes.GetProjectileHitbox(levelProgression.GetProjectilePosition(projectile));

                if (playerHitbox.CollidesWith(projectileHitbox))
                {
                    projectilesCollidedWith.Add(projectile);
                }
            }

            return(projectilesCollidedWith);
        }