Пример #1
0
        public static void HandleCollision(Koopa koopa, IGameObject target)
        {
            Rectangle koopaRectangle = koopa.GetSizeRectangle();

            if (koopa.state is FlipedKoopaState)
            {
                return;
            }
            if (target is IPipe pipe)
            {
                Rectangle pipeRectangle = pipe.GetSizeRectangle();

                CollisionDirection direction = CollisionDetection.DetectCollisionDirection(koopaRectangle, pipeRectangle);
                if (!(direction is CollisionDirection.NoCollision))
                {
                    if (direction is CollisionDirection.Left)
                    {
                        koopa.position = new Vector2(pipe.GetSizeRectangle().X - koopa.GetSizeRectangle().Width, koopa.position.Y);
                        koopa.TurnLeft();
                        koopa.moveLeft = true;
                    }
                    else if (direction is CollisionDirection.Right)
                    {
                        koopa.position = new Vector2(pipe.GetSizeRectangle().X + pipe.GetSizeRectangle().Width, koopa.position.Y);
                        koopa.TurnRight();
                        koopa.moveLeft = false;
                    }
                }
            }
        }
Пример #2
0
        public static void HandleCollision(Game1 game, Koopa koopa, IGameObject target)
        {
            Rectangle koopaRectangle = koopa.GetSizeRectangle();

            koopa.isOnGround = false;

            if (target is Block block)
            {
                Rectangle          blockRectangle = block.GetSizeRectangle();
                CollisionDirection direction      = CollisionDetection.DetectCollisionDirection(koopaRectangle, blockRectangle);
                if (koopa.state is FlipedKoopaState)
                {
                    return;
                }
                if (!(direction is CollisionDirection.NoCollision) && !(block.state is HiddenBlockState))
                {
                    if (direction is CollisionDirection.Left)
                    {
                        koopa.position = new Vector2(block.GetSizeRectangle().X - koopa.GetSizeRectangle().Width - 5, koopa.position.Y);
                        koopa.TurnLeft();
                        koopa.moveLeft = true;
                    }
                    else if (direction is CollisionDirection.Right)
                    {
                        koopa.position = new Vector2(block.GetSizeRectangle().X + block.GetSizeRectangle().Width, koopa.position.Y);
                        koopa.TurnRight();
                        koopa.moveLeft = false;
                    }
                    else if (direction is CollisionDirection.Top)
                    {
                        koopa.position   = new Vector2(koopa.position.X, block.GetSizeRectangle().Y - koopa.GetSizeRectangle().Height);
                        koopa.isOnGround = true;
                    }
                }
                direction = CollisionDetection.DetectCollisionDirection(blockRectangle, koopaRectangle);
                if (!(direction is CollisionDirection.NoCollision))
                {
                    if ((direction is CollisionDirection.Bottom) && ((block.state is BumpedBrickBlockState) || (block.state is BumpedUsedBlockState) || (block.state is ExplodingBlockState)))
                    {
                        game.HUD.GetScore(ConstantNumber.SCORE_100);
                        koopa.Flip();
                    }
                }
            }
        }
        public static void HandleCollision(Koopa koopa, IGameObject target)
        {
            Rectangle koopaRectangle = koopa.GetSizeRectangle();

            if (koopa.state is FlipedKoopaState)
            {
                return;
            }
            if (target is IEnemy enemy)
            {
                Rectangle          enemyRectangle = enemy.GetSizeRectangle();
                CollisionDirection direction      = CollisionDetection.DetectCollisionDirection(koopaRectangle, enemyRectangle);
                if (!(direction is CollisionDirection.NoCollision))
                {
                    if (direction is CollisionDirection.Left)
                    {
                        koopa.position = new Vector2(enemy.GetSizeRectangle().X - koopa.GetSizeRectangle().Width, koopa.position.Y);
                        if (koopa.state is StompedKoopaState)
                        {
                            enemy.Disappear();
                        }
                        else
                        {
                            koopa.TurnLeft();
                            koopa.moveLeft = true;
                        }
                    }
                    else if (direction is CollisionDirection.Right)
                    {
                        koopa.position = new Vector2(enemy.GetSizeRectangle().X + enemy.GetSizeRectangle().Width, koopa.position.Y);
                        if (koopa.state is StompedKoopaState)
                        {
                            enemy.Disappear();
                        }
                        else
                        {
                            koopa.TurnRight();
                            koopa.moveLeft = false;
                        }
                    }
                }
            }
        }
 public StompedIdleKoopaState(Koopa koopa)
 {
     this.koopa  = koopa;
     koopaSprite = EnemySpriteFactory.Instance.CreateStompedKoopa();
 }
Пример #5
0
 public FlipedKoopaState(Koopa koopa)
 {
     this.koopa  = koopa;
     koopaSprite = EnemySpriteFactory.Instance.CreateFlipedKoopa();
 }
 public RightIdleKoopaState(Koopa koopa)
 {
     this.koopa  = koopa;
     koopaSprite = EnemySpriteFactory.Instance.CreateRightIdleKoopa();
 }