コード例 #1
0
        public static void HandleCollision(IEnemy enemy, IEnemy item)
        {
            if (!(enemy is Missle) && !(enemy is Octopus) && !(enemy is Nami) && !(item is Missle) && !(item is Octopus) && !(item is Nami))
            {
                ISprite   block = item.Sprite;
                Rectangle collisionRectangle = Rectangle.Intersect(enemy.Sprite.Area(enemy.Location), block.Area(item.Location));
                if (collisionRectangle.Bottom == block.Area(item.Location).Bottom&& collisionRectangle.Width > collisionRectangle.Height)
                {
                    enemy.Location = new Vector2(enemy.Location.X, enemy.Location.Y + collisionRectangle.Height + 1);
                }
                else if (collisionRectangle.Top == block.Area(item.Location).Top&& collisionRectangle.Width > collisionRectangle.Height)
                {
                    enemy.Location  = new Vector2(enemy.Location.X, enemy.Location.Y - (collisionRectangle.Height + 1));
                    enemy.IsFalling = false;
                }

                else if (collisionRectangle.Right == enemy.Sprite.Area(enemy.Location).Right)
                {
                    enemy.MovingLeft = true;
                    item.MovingLeft  = false;
                    enemy.ChangeDirection();
                    item.ChangeDirection();
                    enemy.Location = new Vector2(enemy.Location.X - (collisionRectangle.Width), enemy.Location.Y);
                }
                else if (collisionRectangle.Left == enemy.Sprite.Area(enemy.Location).Left)
                {
                    enemy.MovingLeft = false;
                    item.MovingLeft  = true;
                    enemy.ChangeDirection();
                    item.ChangeDirection();
                    enemy.Location = new Vector2(enemy.Location.X + (collisionRectangle.Width), enemy.Location.Y);
                }
            }
        }
コード例 #2
0
        private static void WidthGreaterThanHeight(IEnemy enemy, IBlock item, Rectangle collisionRectangle, ISprite block)
        {
            if (collisionRectangle.Right == block.Area(item.Location).Right)
            {
                enemy.MovingLeft = false;
                enemy.ChangeDirection();
                enemy.Location = new Vector2(enemy.Location.X + collisionRectangle.Width, enemy.Location.Y);
            }
            else if (collisionRectangle.Left == block.Area(item.Location).Left)
            {
                enemy.MovingLeft = true;
                enemy.ChangeDirection();
                enemy.Location = new Vector2(enemy.Location.X - (collisionRectangle.Width), enemy.Location.Y);
            }
            collisionRectangle = Rectangle.Intersect(enemy.Sprite.Area(enemy.Location), block.Area(item.Location));

            if (collisionRectangle.Bottom == block.Area(item.Location).Bottom)
            {
                enemy.Location = new Vector2(enemy.Location.X, enemy.Location.Y + collisionRectangle.Height + 3);
            }
            else if (collisionRectangle.Top == block.Area(item.Location).Top&& collisionRectangle.Width > collisionRectangle.Height)
            {
                enemy.Location  = new Vector2(enemy.Location.X, enemy.Location.Y - (collisionRectangle.Height + 3));
                enemy.IsFalling = false;
            }
        }
コード例 #3
0
        public static void EnemyHandler(IEnemy enemy1, IEnemy enemy2, int CollisionSide)
        {
            Vector2 newPosition;
            int     TWO = 2;

            if (!(enemy2.enemySprite is GoombaStompedSprite) && enemy2.isVisible && !(enemy1.enemySprite is GoombaStompedSprite) && enemy1.isVisible)
            {
                switch (CollisionSide)
                {
                case 1:

                    break;

                case 2:
                    newPosition.X   = enemy1.enemySprite.desRectangle.X + TWO;
                    newPosition.Y   = enemy1.enemySprite.desRectangle.Y;
                    enemy1.position = newPosition;
                    if (enemy1 is Koopa)
                    {
                        if (enemy1.shellDirection)
                        {
                            enemy2.BeFlipped();
                        }
                        else
                        {
                            enemy2.ChangeDirection();
                        }
                    }
                    enemy1.ChangeDirection();
                    break;

                case 3:

                    break;

                case 4:
                    newPosition.X   = enemy1.enemySprite.desRectangle.X - TWO;
                    newPosition.Y   = enemy1.enemySprite.desRectangle.Y;
                    enemy1.position = newPosition;
                    if (enemy1 is Koopa)
                    {
                        if (enemy1.shellDirection)
                        {
                            enemy2.BeFlipped();
                        }
                        else
                        {
                            enemy2.ChangeDirection();
                        }
                    }
                    enemy1.ChangeDirection();
                    break;
                }
            }
        }
コード例 #4
0
        public static void BlockHandler(IEnemy enemy, IBlock block, int CollisionSide)
        {
            Vector2 newPosition;
            int     SIX = 6;

            if (!enemy.flip && block.isBroken == false && block.isVisible)
            {
                switch (CollisionSide)
                {
                case 1:
                    newPosition.X  = enemy.enemySprite.desRectangle.X;
                    newPosition.Y  = block.blockSprite.desRectangle.Y - enemy.enemySprite.desRectangle.Height - SIX;
                    enemy.position = newPosition;
                    break;

                case 2:
                    newPosition.X  = block.blockSprite.desRectangle.X + block.blockSprite.desRectangle.Width;
                    newPosition.Y  = enemy.enemySprite.desRectangle.Y;
                    enemy.position = newPosition;
                    enemy.ChangeDirection();
                    if (enemy.shellMoving == GameConstants.Right)
                    {
                        enemy.shellMoving = GameConstants.Left;
                    }
                    else if (enemy.shellMoving == GameConstants.Left)
                    {
                        enemy.shellMoving = GameConstants.Right;
                    }
                    break;

                case 3:
                    newPosition.X  = enemy.enemySprite.desRectangle.X;
                    newPosition.Y  = block.blockSprite.desRectangle.Y + enemy.enemySprite.desRectangle.Height;
                    enemy.position = newPosition;
                    break;

                case 4:
                    newPosition.X  = block.blockSprite.desRectangle.X - enemy.enemySprite.desRectangle.Width;
                    newPosition.Y  = enemy.enemySprite.desRectangle.Y;
                    enemy.position = newPosition;
                    enemy.ChangeDirection();
                    if (enemy.shellMoving == GameConstants.Right)
                    {
                        enemy.shellMoving = GameConstants.Left;
                    }
                    else if (enemy.shellMoving == GameConstants.Left)
                    {
                        enemy.shellMoving = GameConstants.Right;
                    }
                    break;
                }
            }
        }
コード例 #5
0
        public static void HandleCollision(IEnemy enemy, IBlock block, Game1.Side side)
        {
            EnemyGravityHandler gravity = new EnemyGravityHandler();

            if (side.Equals(Game1.Side.Left) || side.Equals(Game1.Side.Right))// || side.Equals(Game1.Side.Top))
            {
                if (block.IsHit())
                {
                    enemy.BeFlipped();
                    gravity.ApplyGravityToEnemy(enemy);
                }


                else if (block is UnbreakableBlock)
                {
                    enemy.ChangeDirection();
                }
            }

            else if (side.Equals(Game1.Side.Bottom))
            {
                if (block.IsHit())
                {
                    enemy.BeFlipped();
                    gravity.ApplyGravityToEnemy(enemy);
                    Display.UpdateKilledEnemy();
                }

                enemy.ManualMoveY(-1 * enemy.GetVerticalVelocity());
            }
        }
コード例 #6
0
        public void HandleCollision(IEnemy enemy, ISprite border, Direction side)
        {
            if (border is AbstractBorderFilling)
            {
                if (!(enemy is ManhandlaLimb) && !(enemy is PatraMinion) && !(enemy is Trapparatus))
                {
                    switch (side)
                    {
                    case Direction.North:
                        enemy.Location = new Rectangle(enemy.Location.X, border.Location.Bottom, enemy.Location.Width, enemy.Location.Height);
                        break;

                    case Direction.South:
                        enemy.Location = new Rectangle(enemy.Location.X, border.Location.Top - enemy.Location.Height, enemy.Location.Width, enemy.Location.Height);
                        break;

                    case Direction.East:
                        enemy.Location = new Rectangle(border.Location.Left - enemy.Location.Width, enemy.Location.Y, enemy.Location.Width, enemy.Location.Height);
                        break;

                    case Direction.West:
                        enemy.Location = new Rectangle(border.Location.Right, enemy.Location.Y, enemy.Location.Width, enemy.Location.Height);
                        break;
                    }
                    enemy.ChangeDirection();
                }
            }
        }
コード例 #7
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);
             }
         }
     }
 }
コード例 #8
0
        public static void HandleCollision(IEnemy enemy, IBlock block, CollisionSide side)
        {
            if (!(enemy.PhysicsState is EnemyDeadState))
            {
                switch (side)
                {
                case CollisionSide.Left:
                case CollisionSide.Right:
                    enemy.ChangeDirection();
                    break;

                case CollisionSide.Bottom:
                    if (!(block is EmptyBlock) && !(block.PhysicsState is JulianKnockBackState))
                    {
                        enemy.Location     = new Vector2(enemy.Location.X, block.Location.Y + block.HitBox.Height);
                        enemy.PhysicsState = new FallState(enemy);
                    }
                    break;

                case CollisionSide.Top:
                    if (!(block is EmptyBlock) && !(block.PhysicsState is JulianKnockBackState) && !(enemy.PhysicsState is JulianPowerPunchState) && !(enemy.PhysicsState is JulianMetaAttackState))
                    {
                        enemy.Location     = new Vector2(enemy.Location.X, block.Location.Y - enemy.HitBox.Height);
                        enemy.PhysicsState = new StandingState(enemy);
                    }
                    break;

                default:
                    break;
                }
            }
        }
コード例 #9
0
        public void HandleCollision(IEnemy enemy1, IEnemy enemy2, Direction side)
        {
            if (((enemy1.Type == EnemyType.None && enemy2.Type == EnemyType.None) || enemy1.Type != enemy2.Type) && !(enemy1 is Trapparatus) && !(enemy2 is Trapparatus))
            {
                switch (side)
                {
                case Direction.North:
                    enemy1.Location = new Rectangle(enemy1.Location.X, enemy2.Location.Bottom, enemy1.Location.Width, enemy1.Location.Height);
                    break;

                case Direction.South:
                    enemy1.Location = new Rectangle(enemy1.Location.X, enemy2.Location.Top - enemy1.Location.Height, enemy1.Location.Width, enemy1.Location.Height);
                    break;

                case Direction.East:
                    enemy1.Location = new Rectangle(enemy2.Location.Left - enemy1.Location.Width, enemy1.Location.Y, enemy1.Location.Width, enemy1.Location.Height);
                    break;

                case Direction.West:
                    enemy1.Location = new Rectangle(enemy2.Location.Right, enemy1.Location.Y, enemy1.Location.Width, enemy1.Location.Height);
                    break;
                }
                enemy1.ChangeDirection();
                enemy2.ChangeDirection();
            }
        }
コード例 #10
0
        public void HandleCollision(IEnemy enemy, IBlock block, Direction side)
        {
            if (!block.IsWalkable())
            {
                if (!(enemy is ManhandlaLimb) && !(enemy is PatraMinion) && !(enemy is Trapparatus))
                {
                    switch (side)
                    {
                    case Direction.North:
                        enemy.Location = new Rectangle(enemy.Location.X, block.Location.Bottom, enemy.Location.Width, enemy.Location.Height);
                        break;

                    case Direction.South:
                        enemy.Location = new Rectangle(enemy.Location.X, block.Location.Top - enemy.Location.Height, enemy.Location.Width, enemy.Location.Height);
                        break;

                    case Direction.East:
                        enemy.Location = new Rectangle(block.Location.Left - enemy.Location.Width, enemy.Location.Y, enemy.Location.Width, enemy.Location.Height);
                        break;

                    case Direction.West:
                        enemy.Location = new Rectangle(block.Location.Right, enemy.Location.Y, enemy.Location.Width, enemy.Location.Height);
                        break;
                    }
                    enemy.ChangeDirection();
                }
            }
        }
コード例 #11
0
 public static void HandleCollision(IEnemy enemy1, IEnemy enemy2, Game1.Side side)
 {
     if (side.Equals(Game1.Side.Left) || side.Equals(Game1.Side.Right))
     {
         enemy1.ChangeDirection();
         enemy2.ChangeDirection();
     }
 }
コード例 #12
0
 public static void HandleCollision(IBlock block, IEnemy enemy, CollisionDetection.CollisionSide side)
 {
     if (CollisionDetection.EnemyCollision(side))
     {
         enemy.ChangeDirection(side);
         NewLocation(block, enemy, side);
     }
 }
コード例 #13
0
        public static void HandleCollision(IEnemy enemy, IPipe pipe, Game1.Side side)
        {
            if (side.Equals(Game1.Side.Left) || side.Equals(Game1.Side.Right) || side.Equals(Game1.Side.Top))
            {
                enemy.ChangeDirection();
            }

            else
            {
                //just keep walking
            }
        }
コード例 #14
0
 public static void HandleEnemyEnemyCollision(IEnemy enemy1, IEnemy enemy2, CollisionSide enemy1Side, CollisionSide enemy2Side)
 {
     if (enemy1.Collidable && enemy2.Collidable && !enemy1.Flipped && !enemy2.Flipped)
     {
         enemy1.ChangeDirection(enemy1Side);
         enemy2.ChangeDirection(enemy2Side);
         NewLocation(enemy1, enemy2, enemy2Side);
         NewLocation(enemy2, enemy1, enemy1Side);
         enemy1.EnemyPhysics.InCollision = true;
         enemy2.EnemyPhysics.InCollision = true;
     }
 }
コード例 #15
0
        public void Handle(IEntity entity, IEntity target, Side side)
        {
            IEnemy enemy = (IEnemy)entity;

            // Enemy is colliding into another enemy
            if (target is IEnemy)
            {
                IEnemy tEnemy = (IEnemy)target;
                if (tEnemy.IsAlive())
                {
                    enemy.ChangeDirection();
                }
            }
            // Enemy is colliding into a block
            else if (target is IBlock)
            {
                if (side == Side.LEFT || side == Side.RIGHT)
                {
                    // Enemy changes direction
                    enemy.ChangeDirection();
                }
            }
        }
コード例 #16
0
        public static void HandleCollision(IMario mario, IEnemy item)
        {
            ISprite   enemy = item.Sprite;
            Rectangle collisionRectangle = Rectangle.Intersect(mario.Area(), enemy.Area(item.Location));

            if (collisionRectangle.Top == enemy.Area(item.Location).Top&& collisionRectangle.Width + 2 > collisionRectangle.Height)
            {
                CollideTop(mario, item);
            }
            else if (collisionRectangle.Bottom == enemy.Area(item.Location).Bottom&& collisionRectangle.Width > collisionRectangle.Height)
            {
                CollideBottom(mario, item, collisionRectangle);
            }
            else if (collisionRectangle.Right == enemy.Area(item.Location).Right)
            {
                CollideRight(mario, item, collisionRectangle);
                item.ChangeDirection();
            }
            else if (collisionRectangle.Left == enemy.Area(item.Location).Left)
            {
                CollideLeft(mario, item, collisionRectangle);
                item.ChangeDirection();
            }
        }
コード例 #17
0
 public static void EnemyHorizontallyBounce(IEnemy enemy, IBlock block, Direction direction)
 {
     MoverHorizontallyBounce(enemy, block, direction);
     enemy.ChangeDirection();
 }
コード例 #18
0
 public static void EnemyHorizontalBounce(IEnemy enemy, IPipe pipe, Direction direction)
 {
     enemy.ChangeDirection();
     ResolveOverlap(enemy, pipe, direction);
 }
コード例 #19
0
 public static void MoverChangeDirection(IEnemy mover, IEnemy target, Direction direction)
 {
     mover.ChangeDirection();
     ResolveOverlap(mover, target, direction);
 }
コード例 #20
0
 public static void EnemyChangeDirection(IEnemy mover, IEnemy target, Direction direction)
 {
     ResolveOverlap(mover, target, direction);
     mover.ChangeDirection();
     target.ChangeDirection();
 }