Beispiel #1
0
 /// <summary>
 /// Checks if Shell should move or hit Mario instead
 /// </summary>
 /// <param name="mario">Used to check if Mario jumped on top of the Shell or hit the side</param>
 public void CheckHit(Mario mario)
 {
     if (mario.VelocityY > 0.5)
     {
         VelocityX = 0;
         _animator.PauseAnimation();
     }
     else
     {
         if (VelocityX == 0 && mario.Hitbox.Y > Hitbox.Y - mario.Hitbox.Height)
         {
             if (mario.VelocityX > 0)
             {
                 VelocityX = _speed;
                 _animator.UnpauseAnimation();
             }
             else if (mario.VelocityX < 0)
             {
                 VelocityX = -_speed;
                 _animator.UnpauseAnimation();
             }
         }
         else
         {
             if (mario.Hitbox.Y >= Hitbox.Y - Hitbox.Height)
             {
                 mario.GetHit();
             }
         }
     }
 }
Beispiel #2
0
 /// <summary>
 /// Checks if FallingSpike hits Mario
 /// </summary>
 /// <param name="mario">Used to check if Mario hits the FallingSpike</param>
 private void CheckHit(Mario mario)
 {
     if (mario.Hitbox.Intersects(Hitbox))
     {
         mario.GetHit();
     }
 }
Beispiel #3
0
 /// <summary>
 /// Checks if Goomba should Die or hit Mario instead
 /// </summary>
 /// <param name="mario">Used to check if Mario jumped on top of Goomba</param>
 public void CheckDeath(Mario mario)
 {
     if (!_isHit)
     {
         if (mario.VelocityY > 0.5)
         {
             mario.Jump();
             Die();
         }
         else
         {
             mario.GetHit();
         }
     }
 }
Beispiel #4
0
        public bool IsColliding(Level lvl, int offsetX, int offsetY, out Tangible collObject) //TODO: Improve collision (collider class?)
        {
            bool collidesWithSolid = false;

            collObject = null;
            foreach (GameObject gameObject in lvl.GameObjects)
            {
                if (gameObject is Tangible)
                {
                    Tangible  tangibleObject = (Tangible)gameObject;
                    Rectangle testRect       = new Rectangle((int)tangibleObject.Position.X - offsetX, (int)tangibleObject.Position.Y - offsetY, tangibleObject.Hitbox.Width, tangibleObject.Hitbox.Height);

                    if (testRect.Intersects(Hitbox) && tangibleObject != this)
                    {
                        if (tangibleObject.IsSolid)
                        {
                            collidesWithSolid = true;
                            collObject        = tangibleObject;
                        }
                        if (this is Mario)
                        {
                            Mario mario = (Mario)this;
                            if (tangibleObject is Coin)
                            {
                                Coin coin = (Coin)tangibleObject;
                                coin.AddCoin((Mario)this);
                            }
                            else if (tangibleObject is MysteryBlock)
                            {
                                MysteryBlock mysteryBlock = (MysteryBlock)tangibleObject;
                                mysteryBlock.Eject(mario);
                            }
                            else if (tangibleObject is CoinBlock)
                            {
                                CoinBlock coinBlock = (CoinBlock)tangibleObject;
                                coinBlock.Eject(mario);
                            }
                            else if (tangibleObject is Mushroom)
                            {
                                Mushroom mushroom = (Mushroom)tangibleObject;
                                mushroom.CollectMushroom(mario);
                            }
                            else if (tangibleObject is OneUpMushroom)
                            {
                                OneUpMushroom oneUpMushroom = (OneUpMushroom)tangibleObject;
                                oneUpMushroom.CollectMushroom(mario);
                            }
                            else if (tangibleObject is Shell)
                            {
                                Shell shell = (Shell)tangibleObject;
                                shell.CheckHit(mario);
                            }
                            else if (tangibleObject is Koopa)
                            {
                                Koopa koopa = (Koopa)tangibleObject;
                                koopa.CheckDeath(mario);
                            }
                            else if (tangibleObject is Muncher)
                            {
                                mario.GetHit();
                            }
                            else if (tangibleObject is Goomba)
                            {
                                Goomba goomba = (Goomba)tangibleObject;
                                goomba.CheckDeath(mario);
                            }
                        }
                        else if (this is Shell)
                        {
                            if (tangibleObject is Goomba)
                            {
                                Goomba goomba = (Goomba)tangibleObject;
                                goomba.Die();
                            }
                            if (tangibleObject is Koopa)
                            {
                                Koopa koopa = (Koopa)tangibleObject;
                                koopa.DieWithoutShell();
                                collidesWithSolid = false;
                            }
                        }
                    }
                }
            }
            return(collidesWithSolid);
        }