Ejemplo n.º 1
0
        public void update(double delta, GameController.KeyFlags controllerKeyFlags)
        {
            player.updateXaxisMovement(
                controllerKeyFlags.isPressedLeft,
                controllerKeyFlags.isPressedRight);

            player.reactToCollision(border.isCollided(player));

            if (ball.isSticked)
            {
                ball.movement = player.movement;
            }

            else
            {
                ball.reactToCollision(ball.isCollided(player));

                Collision isCollidedWithBorder = border.isCollided(ball);
                if (isCollidedWithBorder == Collision.DOWN)
                {
                    loseLive();
                }
                else
                {
                    ball.reactToCollision(isCollidedWithBorder);
                }

                for (int brickIndex = 0; brickIndex < bricks.Count; ++brickIndex)
                {
                    Collision isCollidedWithBrick = ball.isCollided(bricks[brickIndex]);
                    ball.reactToCollision(isCollidedWithBrick);

                    if (isCollidedWithBrick != Collision.NONE)
                    {
                        addScore(Brick.POINTS);
                        bricks.RemoveAt(brickIndex);
                    }
                }

                if (bricks.Count <= 0)
                {
                    endgame = true;
                    isWin   = true;
                }
            }

            if (controllerKeyFlags.isPressedSpace && ball.isSticked)
            {
                ball.throwBall();
            }


            ball.update(delta);
            player.update(delta);
        }