Esempio n. 1
0
        public static void HandleMovement(IItem item)
        {
            item.Velocity = new Vector2(item.Velocity.X, item.Velocity.Y + Constants.G_CONST);
            Vector2 targetPosition = new Vector2(item.Position.X + item.Velocity.X, item.Position.Y + item.Velocity.Y);
            Vector2 finalPosition  = targetPosition;

            if (!CollisionDetector.IsPositionFree(item, targetPosition))
            {
                if (item.Velocity.Y >= Constants.CRUSHING_SPD_CONST)
                {
                    List <IEnemy> crushList = CollisionDetector.GetObjectsAtPosition <IEnemy>(item, targetPosition);
                    foreach (IEnemy enemy in crushList)
                    {
                        enemy.Kill();
                        ScoreManager.IncreaseScore(Constants.CRUSHING_PTS_CONST);
                    }
                }
                finalPosition = CollisionHelper.GetNewPosition(item, targetPosition);
                HandleCollisionDirections(item, finalPosition, targetPosition);
            }



            item.Position = finalPosition;
        }
        private static void HandleCollectableCollisions(AbstractCharacter character, Vector2 newPosition)
        {
            List <ICollectable> collectableList = CollisionDetector.GetObjectsAtPosition <ICollectable>(character, newPosition);

            foreach (ICollectable collectable in collectableList)
            {
                RespondToICollectableCollision(collectable, character);
            }
        }
        private static void HandleEnemyCollisions(AbstractCharacter character, Vector2 newPosition)
        {
            List <IEnemy> enemyList = CollisionDetector.GetObjectsAtPosition <IEnemy>(character, newPosition);

            foreach (IEnemy enemy in enemyList)
            {
                RespondToIEnemyCollision(enemy, character);
            }
        }
        private static void HandleItemCollisions(AbstractCharacter character, Vector2 newPosition)
        {
            List <IItem> itemList = CollisionDetector.GetObjectsAtPosition <IItem>(character, newPosition);

            HandlePushing(character, newPosition, itemList);
            foreach (IItem item in itemList)
            {
                RespondToIItemCollision(item, character);
            }
        }
Esempio n. 5
0
 public void Update()
 {
     if (!isWaitingForActivation)
     {
         List <AbstractCharacter> characters = CollisionDetector.GetObjectsAtPosition <AbstractCharacter>(hitbox, hitbox.Position);
         foreach (AbstractCharacter character in characters)
         {
             character.Position = new Vector2(destination.X, destination.Y - character.Size.Y);
         }
     }
 }
        public virtual void PickupItem()
        {
            if (CurrentItem == null)
            {
                float newItemX = ItemXPosition();

                List <PickupItem> items = CollisionDetector.GetObjectsAtPosition <PickupItem>(this, new Vector2(newItemX, Position.Y));
                if (items.Count > 0)
                {
                    CurrentItem                   = items[0];
                    items[0].CollisionType        = CollisionType.Liquid;
                    StateManager.IsCarryingObject = true;
                }
            }
        }
Esempio n. 7
0
 public override void PickupItem()
 {
     if (CurrentItem == null)
     {
         float newItemX;
         if (StateManager.IsFacingRight)
         {
             newItemX = Position.X + Size.X + 1;
         }
         else
         {
             newItemX = Position.X - 1;
         }
         List <PickupItem> items = CollisionDetector.GetObjectsAtPosition <PickupItem>(this, new Vector2(newItemX, Position.Y));
         if (items.Count > 0)
         {
             CurrentItem                   = items[0];
             items[0].CollisionType        = CollisionType.Liquid;
             StateManager.IsCarryingObject = true;
         }
     }
 }