Ejemplo n.º 1
0
 public override void OnCollisionResponse(ICollider otherCollider, CollisionDetection.CollisionSide collisionSide)
 {
     if (otherCollider is IPlayer)
     {
         EnemyCollisionHandler.OnCollisionResponse((IPlayer)otherCollider, collisionSide);
     }
 }
Ejemplo n.º 2
0
 public void OnCollisionResponse(IBlock block, CollisionDetection.CollisionSide collisionSide)
 {
     if (block is CrossableTile)
     {
         player.LadderTimer = 5;
     }
 }
Ejemplo n.º 3
0
 public static void HandleCollision(IBlock block, IEnemy enemy, CollisionDetection.CollisionSide side)
 {
     if ((!block.Collided && enemy.Collidable) || block is BlankBlock)
     {
         if (CollisionDetection.HorizontalCollision(side))
         {
             enemy.ChangeDirection(side);
             NewLocation(block, enemy, side);
         }
         else
         {
             if (enemy is Goomba || enemy is Koopa)
             {
                 enemy.EnemyPhysics.Velocity = new Vector2(enemy.EnemyPhysics.Velocity.X, 0);
                 enemy.EnemyPhysics.Gravity  = false;
                 NewLocation(block, enemy, side);
             }
             else if (enemy is Jellyfish || enemy is Fish)
             {
                 NewLocation(block, enemy, side);
                 enemy.EnemyPhysics.Velocity = new Vector2(enemy.EnemyPhysics.Velocity.X, -enemy.EnemyPhysics.Velocity.Y);
             }
         }
     }
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Prevents two objects from moving through each other.
        /// </summary>
        /// <param name="source">The stationary object that doesn't move.</param>
        /// <param name="target">The object that gets moved into the stationary object.</param>
        /// <param name="collisionSide">The side of the stationary object that underwent a collision.</param>
        public void SetBounds(Physics source, Physics target, CollisionDetection.CollisionSide collisionSide)
        {
            int side = 0;

            switch (collisionSide)
            {
            case CollisionDetection.CollisionSide.Top:
                side          = source.Bounds.Top - target.Bounds.Height;
                target.Bounds = new Rectangle(target.Bounds.X, side, target.Bounds.Width, target.Bounds.Height);
                target.StopKnockbackY();
                break;

            case CollisionDetection.CollisionSide.Bottom:
                target.StopKnockbackY();
                side          = source.Bounds.Bottom;
                target.Bounds = new Rectangle(target.Bounds.X, side, target.Bounds.Width, target.Bounds.Height);
                break;

            case CollisionDetection.CollisionSide.Left:
                side          = source.Bounds.Left - target.Bounds.Width;
                target.Bounds = new Rectangle(side, target.Bounds.Y, target.Bounds.Width, target.Bounds.Height);
                target.StopKnockbackX();
                break;

            case CollisionDetection.CollisionSide.Right:
                side          = source.Bounds.Right;
                target.Bounds = new Rectangle(side, target.Bounds.Y, target.Bounds.Width, target.Bounds.Height);
                target.StopKnockbackX();
                break;

            default:
                break;
            }
            target.SetLocation();
        }
Ejemplo n.º 5
0
 public void OnCollisionResponse(IDoor door, CollisionDetection.CollisionSide collisionSide)
 {
     if (door.DoorType != Door.DoorTypes.Unlocked)
     {
         PreventDoorEntry(door);
     }
 }
Ejemplo n.º 6
0
 public void OnCollisionResponse(ICollider otherCollider, CollisionDetection.CollisionSide collisionSide)
 {
     if (otherCollider is IEnemy && !(State is PickupItemState))
     {
         linkCollisionHandler.OnCollisionResponse((IEnemy)otherCollider, collisionSide);
     }
     else if (otherCollider is IProjectile && !(State is PickupItemState))
     {
         linkCollisionHandler.OnCollisionResponse((IProjectile)otherCollider, collisionSide);
     }
     else if (otherCollider is IBlock)
     {
         linkCollisionHandler.OnCollisionResponse((IBlock)otherCollider, collisionSide);
     }
     else if (otherCollider is IDoor)
     {
         linkCollisionHandler.OnCollisionResponse((IDoor)otherCollider, collisionSide);
     }
     else if (otherCollider is IItem && !(State is PickupItemState))
     {
         if (otherCollider is PurchaseRupee)
         {
             if (Inventory.Rupees >= 50 && PurchaseLockout <= 0)
             {
                 linkCollisionHandler.OnCollisionResponse((IItem)otherCollider, collisionSide);
             }
         }
         else
         {
             linkCollisionHandler.OnCollisionResponse((IItem)otherCollider, collisionSide);
         }
     }
 }
Ejemplo n.º 7
0
 public void OnCollisionResponse(IProjectile projectile, CollisionDetection.CollisionSide collisionSide)
 {
     // If the player has no magic shield, is in a boss room, or fails to block, take damage normally.
     if (!player.Blocked(collisionSide))
     {
         if (projectile is BoomerangProjectile || projectile is MagicBoomerangProjectile)
         {
             projectile.Returning = true;
             player.Stun(projectile.StunDuration);
         }
         if (!(projectile is BoomerangProjectile || projectile is MagicBoomerangProjectile) && player.DamageTimer <= 0)
         {
             DetermineDirectPushback(projectile.Physics, player.Physics);
         }
         player.TakeDamage(projectile.Damage);
     }
     // If the player successfully blocks, either expire or return the projectile.
     else
     {
         if (projectile is BoomerangProjectile || projectile is MagicBoomerangProjectile)
         {
             projectile.Returning = true;
         }
         else
         {
             projectile.IsExpired = true;
         }
         player.Physics.KnockbackVelocity = Vector2.Zero;
     }
 }
Ejemplo n.º 8
0
        public bool Blocked(CollisionDetection.CollisionSide collisionSide)
        {
            bool blocked = false;

            if (Inventory.HasMagicShield && !LoZGame.Instance.Dungeon.CurrentRoom.IsBossRoom)
            {
                if (Physics.CurrentDirection == Physics.Direction.North && collisionSide == CollisionDetection.CollisionSide.Top)
                {
                    blocked = true;
                }
                else if (Physics.CurrentDirection == Physics.Direction.South && collisionSide == CollisionDetection.CollisionSide.Bottom)
                {
                    blocked = true;
                }
                else if (Physics.CurrentDirection == Physics.Direction.West && collisionSide == CollisionDetection.CollisionSide.Left)
                {
                    blocked = true;
                }
                else if (Physics.CurrentDirection == Physics.Direction.East && collisionSide == CollisionDetection.CollisionSide.Right)
                {
                    blocked = true;
                }
            }

            return(blocked);
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Used to optionally expire projectiles that collide with blocks.
 /// </summary>
 /// <param name="block">This is the block that is collided with by the projectile.</param>
 /// <param name="collisionSide">This is the side of the block that the projectile collides with..</param>
 public void OnCollisionResponse(IBlock block, CollisionDetection.CollisionSide collisionSide)
 {
     if (!block.IsTransparent)
     {
         projectile.IsExpired = true;
     }
 }
Ejemplo n.º 10
0
 public void OnCollisionResponse(ICollider otherCollider, CollisionDetection.CollisionSide collisionSide)
 {
     if (otherCollider is IPlayer)
     {
         blockCollisionHandler.OnCollisionResponse((IPlayer)otherCollider, collisionSide);
     }
 }
Ejemplo n.º 11
0
 public void OnCollisionResponse(int sourceWidth, int sourceHeight, CollisionDetection.CollisionSide collisionSide)
 {
     if (item is Fairy)
     {
         SetBounds(item.Physics, collisionSide);
         item.Physics.SetLocation();
     }
 }
Ejemplo n.º 12
0
 public override void OnCollisionResponse(ICollider otherCollider, CollisionDetection.CollisionSide collisionSide)
 {
     base.OnCollisionResponse(otherCollider, collisionSide);
     if (IsExpired)
     {
         CreateExplosion();
     }
 }
 public static void HandleCollision(IBlock block, IEnemy enemy, CollisionDetection.CollisionSide side)
 {
     if (CollisionDetection.EnemyCollision(side))
     {
         enemy.ChangeDirection(side);
         NewLocation(block, enemy, side);
     }
 }
Ejemplo n.º 14
0
 public override void OnCollisionResponse(ICollider otherCollider, CollisionDetection.CollisionSide collisionSide)
 {
     base.OnCollisionResponse(otherCollider, collisionSide);
     if (otherCollider is IBlock)
     {
         CollisionHandler.OnCollisionResponse((IBlock)otherCollider, collisionSide);
     }
 }
Ejemplo n.º 15
0
 public void OnCollisionResponse(IItem item, CollisionDetection.CollisionSide collisionSide)
 {
     if (item.PickUpItemTime >= 0)
     {
         item.Physics.Location = new Vector2(player.Physics.Location.X + 5, player.Physics.Location.Y - 45);
         item.Physics.Bounds   = new Rectangle(new Point((int)item.Physics.Location.X, (int)item.Physics.Location.Y), new Point(0, 0));
         player.State          = new PickupItemState(player, item);
     }
 }
Ejemplo n.º 16
0
 public void OnCollisionResponse(IEnemy enemy, CollisionDetection.CollisionSide collisionSide)
 {
     if (!collisionBlackList.Contains(enemy.AI))
     {
         if (enemy.AI != EnemyEssentials.EnemyAI.PolsVoice)
         {
             SetBounds(block.Physics, enemy.Physics, collisionSide);
         }
     }
 }
Ejemplo n.º 17
0
 public void ReverseMovement(Physics target, CollisionDetection.CollisionSide side)
 {
     if (side == CollisionDetection.CollisionSide.Top || side == CollisionDetection.CollisionSide.Bottom)
     {
         target.MovementVelocity = new Vector2(target.MovementVelocity.X, target.MovementVelocity.Y * -1);
     }
     else
     {
         target.MovementVelocity = new Vector2(target.MovementVelocity.X * -1, target.MovementVelocity.Y);
     }
 }
Ejemplo n.º 18
0
 public virtual void OnCollisionResponse(ICollider otherCollider, CollisionDetection.CollisionSide collisionSide)
 {
     if (otherCollider is IPlayer)
     {
         CollisionHandler.OnCollisionResponse((IPlayer)otherCollider, collisionSide);
     }
     else if (otherCollider is IEnemy)
     {
         CollisionHandler.OnCollisionResponse((IEnemy)otherCollider, collisionSide);
     }
 }
Ejemplo n.º 19
0
 public void OnCollisionResponse(ICollider otherCollider, CollisionDetection.CollisionSide collisionSide)
 {
     if (otherCollider is IPlayer && !(state is CosmeticDoorState || state is HiddenDoorState))
     {
         doorCollisionHandler.OnCollisionResponse((IPlayer)otherCollider, collisionSide);
     }
     else if (otherCollider is IProjectile)
     {
         doorCollisionHandler.OnCollisionResponse((IProjectile)otherCollider);
     }
 }
Ejemplo n.º 20
0
        public void OnCollisionResponse(IPlayer player, CollisionDetection.CollisionSide collisionSide)
        {
            bool movable = true;

            if (!(player.State is GrabbedState) && block is MovableBlock)
            {
                switch (collisionSide)
                {
                case CollisionDetection.CollisionSide.Top:
                    movable = !block.InvalidDirections.Contains(MovableBlock.InvalidDirection.North);
                    break;

                case CollisionDetection.CollisionSide.Bottom:
                    movable = !block.InvalidDirections.Contains(MovableBlock.InvalidDirection.South);
                    break;

                case CollisionDetection.CollisionSide.Right:
                    movable = !block.InvalidDirections.Contains(MovableBlock.InvalidDirection.East);
                    break;

                case CollisionDetection.CollisionSide.Left:
                    movable = !block.InvalidDirections.Contains(MovableBlock.InvalidDirection.West);
                    break;
                }
                if (movable)
                {
                    DeterminePushVelocity(player, collisionSide);
                }
                SetBounds(block.Physics, player.Physics, collisionSide);
            }
            else if (block is Tile)
            {
                SoundFactory.Instance.PlayClimbStairs();
            }
            else if (block is BlockTile)
            {
                if (!(player.State is GrabbedState))
                {
                    SetBounds(block.Physics, player.Physics, collisionSide);
                }
            }
            else if (block is CrossableTile)
            {
                if (!(player.State is GrabbedState) && (!player.Inventory.HasLadder || player.Inventory.LadderInUse))
                {
                    if (!((CrossableTile)block).BeingCrossed)
                    {
                        SetBounds(block.Physics, player.Physics, collisionSide);
                    }
                }
            }
        }
 public static void NewLocation(IEnemy enemy1, IEnemy enemy2, CollisionDetection.CollisionSide side)
 {
     if (side == CollisionDetection.CollisionSide.Left)
     {
         enemy2.EnemyPhysics.Position     = new Vector2(enemy1.EnemyPhysics.Position.X - enemy2.EnemyBox.Width, enemy2.EnemyPhysics.Position.Y);
         enemy2.EnemyPhysics.Acceleration = new Vector2(0, enemy2.EnemyPhysics.Acceleration.Y);
     }
     else if (side == CollisionDetection.CollisionSide.Right)
     {
         enemy2.EnemyPhysics.Position     = new Vector2(enemy1.EnemyPhysics.Position.X + enemy1.EnemyBox.Width, enemy2.EnemyPhysics.Position.Y);
         enemy2.EnemyPhysics.Acceleration = new Vector2(0, enemy2.EnemyPhysics.Acceleration.Y);
     }
 }
Ejemplo n.º 22
0
 public void OnCollisionResponse(int sourceWidth, int sourceHeight, CollisionDetection.CollisionSide collisionSide)
 {
     if (enemy is Keese || enemy is VireKeese)
     {
         ReverseMovement(enemy.Physics, collisionSide);
     }
     else
     {
         if (!(enemy is WallMaster && enemy.CurrentState is AttackingWallMasterState))
         {
             SetBounds(enemy.Physics, collisionSide);
         }
     }
 }
Ejemplo n.º 23
0
 public static void HandleCollision(IBlock block, IItem item, CollisionDetection.CollisionSide side)
 {
     if (!item.Collided && !block.Collided)
     {
         if (side == CollisionDetection.CollisionSide.Right || side == CollisionDetection.CollisionSide.Right)
         {
             NewLocation(block, item, side);
         }
         else
         {
             NewLocation(block, item, side);
         }
     }
 }
Ejemplo n.º 24
0
 public virtual void OnCollisionResponse(ICollider otherCollider, CollisionDetection.CollisionSide collisionSide)
 {
     if (otherCollider is IPlayer)
     {
         EnemyCollisionHandler.OnCollisionResponse((IPlayer)otherCollider, collisionSide);
     }
     else if (otherCollider is IBlock)
     {
         EnemyCollisionHandler.OnCollisionResponse((IBlock)otherCollider, collisionSide);
     }
     else if (otherCollider is IProjectile)
     {
         EnemyCollisionHandler.OnCollisionResponse((IProjectile)otherCollider, collisionSide);
     }
 }
Ejemplo n.º 25
0
 public override void OnCollisionResponse(ICollider otherCollider, CollisionDetection.CollisionSide collisionSide)
 {
     if (otherCollider is IPlayer)
     {
         EnemyCollisionHandler.OnCollisionResponse((IPlayer)otherCollider, collisionSide);
     }
     else if (otherCollider is IBlock)
     {
         EnemyCollisionHandler.OnCollisionResponse((IBlock)otherCollider, collisionSide);
     }
     else if (otherCollider is IProjectile && CurrentState is OpenEyeState)
     {
         EnemyCollisionHandler.OnCollisionResponse((IProjectile)otherCollider, collisionSide);
     }
 }
Ejemplo n.º 26
0
 public void OnCollisionResponse(ICollider otherCollider, CollisionDetection.CollisionSide collisionSide)
 {
     if (otherCollider is IPlayer)
     {
         blockCollisionHandler.OnCollisionResponse((IPlayer)otherCollider, collisionSide);
         if (((IPlayer)otherCollider).Inventory.HasLadder && (!((IPlayer)otherCollider).Inventory.LadderInUse || playerCrossing))
         {
             ladderTime = 0;
         }
     }
     else if (otherCollider is IEnemy)
     {
         blockCollisionHandler.OnCollisionResponse((IEnemy)otherCollider, collisionSide);
     }
 }
Ejemplo n.º 27
0
 public override void OnCollisionResponse(ICollider otherCollider, CollisionDetection.CollisionSide collisionSide)
 {
     if (otherCollider is IPlayer && !(((Link)otherCollider).State is PickupItemState || CurrentState is StunnedEnemyState) && !LoZGame.Instance.Players[0].Inventory.HasClock)
     {
         CurrentState.Attack();
     }
     else if (otherCollider is IBlock && !(CurrentState is AttackingWallMasterState))
     {
         EnemyCollisionHandler.OnCollisionResponse((IBlock)otherCollider, collisionSide);
     }
     else if (otherCollider is IProjectile && Timer <= 100)
     {
         EnemyCollisionHandler.OnCollisionResponse((IProjectile)otherCollider, collisionSide);
     }
 }
Ejemplo n.º 28
0
        public override void OnCollisionResponse(int sourceWidth, int sourceHeight, CollisionDetection.CollisionSide collisionSide)
        {
            base.OnCollisionResponse(sourceWidth, sourceHeight, collisionSide);
            switch (collisionSide)
            {
            case CollisionDetection.CollisionSide.Top:
            case CollisionDetection.CollisionSide.Bottom:
                Physics.MovementVelocity = new Vector2(Physics.MovementVelocity.X, -Physics.MovementVelocity.Y);
                break;

            case CollisionDetection.CollisionSide.Left:
            case CollisionDetection.CollisionSide.Right:
                Physics.MovementVelocity = new Vector2(-Physics.MovementVelocity.X, Physics.MovementVelocity.Y);
                break;
            }
        }
Ejemplo n.º 29
0
 public void OnCollisionResponse(IProjectile projectile, CollisionDetection.CollisionSide collisionSide)
 {
     /*
      * if (projectile is MagicBoomerangProjectile || projectile is BoomerangProjectile)
      * {
      *  if (this.item is IDrop) { }
      *  if (!this.item.IsGrabbed)
      *  {
      *      this.boomerang = projectile;
      *      //this.GrabbedOffset = new Vector2((this.item.Bounds.Width - this.boomerang.Bounds.Width) / 2, (this.item.Bounds.Height - this.boomerang.Bounds.Height) / 2);
      *      this.grabbed = true;
      *  }
      *  this.item.Physics.Location = new Vector2(this.boomerang.Physics.Location.X - GrabbedOffset.X, this.boomerang.Physics.Location.Y - this.GrabbedOffset.Y);
      *  this.item.Bounds = new Rectangle((int)this.item.Physics.Location.X, (int)this.item.Physics.Location.Y, this.item.Bounds.Width, this.item.Bounds.Height);
      * }
      */
 }
Ejemplo n.º 30
0
 public void OnCollisionResponse(IEnemy enemy, CollisionDetection.CollisionSide collisionSide)
 {
     if (enemy is WallMaster)
     {
         if (!(enemy.CurrentState is StunnedEnemyState) && !LoZGame.Instance.Players[0].Inventory.HasClock)
         {
             player.State = new GrabbedState(player, (WallMaster)enemy);
         }
     }
     else if (enemy is Likelike)
     {
         if (!(enemy.CurrentState is StunnedEnemyState))
         {
             player.State = new SwallowedState(player, (Likelike)enemy);
         }
     }
     else if (enemy is Bubble)
     {
         if (player.DamageTimer <= 0)
         {
             player.DamageTimer   = LoZGame.Instance.UpdateSpeed / 2;
             player.DisarmedTimer = LoZGame.Instance.UpdateSpeed * 3;
             DeterminePushbackValues(enemy.Physics, player.Physics);
             SoundFactory.Instance.PlayLinkHurt();
         }
     }
     else if (enemy is OldMan || enemy is Merchant || enemy is BlockEnemy || (enemy is Vire && enemy.CurrentState is HiddenVireState))
     {
         // do nothing
     }
     else
     {
         if (!(player.State is PickupItemState || player.State is AttackState))
         {
             if (player.DamageTimer <= 0)
             {
                 DeterminePushbackValues(enemy.Physics, player.Physics);
             }
             int damage = enemy.Damage;
             damage += LoZGame.Instance.Difficulty * GameData.Instance.DifficultyConstants.DamageMod;
             damage  = damage <= 0 ? 1 : damage;
             player.TakeDamage(damage);
         }
     }
 }