Exemplo n.º 1
0
        /// <summary>
        /// Met à jour
        /// </summary>
        public void Update()
        {
            ball.Update();
            bar.Update();

            CollisionManager.CheckAllCollision(context);

            if (ball.Position.Y + ball.Size.Height >= context.Size.Height)
            {
                context.State = new EndState(context);
            }

            if (bricks.Count == 0)
            {
                context.State = new StartState(context);
            }

            ball.Refresh();
            bar.Refresh();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Modifie la taille des éléments
        /// </summary>
        /// <param name="width">La nouvelle largeur</param>
        /// <param name="height">La nouvelle hauteur</param>
        public void ChangeSize(double width, double height)
        {
            double widthDiff  = width / size.Width;
            double heightDiff = height / size.Height;

            double brickWidth  = width / 8;
            double brickHeight = height / 20;

            double ballSize      = (width < height) ? width / 100 : height / 100;
            double ballPositionX = ball.Position.X * widthDiff;
            double ballPositionY = ball.Position.Y * heightDiff;

            double barWidth     = width / 10;
            double barHeight    = height / 50;
            double barPositionX = bar.Position.X * widthDiff;
            double barPositionY = height - (2 * barHeight);

            foreach (Views.Brick brick in bricks)
            {
                double brickPositionX = brick.Position.X * (brickWidth / brick.Size.Width);
                double brickPositionY = brick.Position.Y * (brickHeight / brick.Size.Height);

                brick.SetPosition(brickPositionX, brickPositionY);
                brick.SetSize(brickWidth, brickHeight);
                brick.Refresh();
            }

            ball.SetSize(ballSize, ballSize);
            ball.SetPosition(ballPositionX, ballPositionY);
            ball.Direction = new Vector(ball.Direction.X * widthDiff, ball.Direction.Y * heightDiff);
            ball.Refresh();

            bar.SetSize(barWidth, barHeight);
            bar.SetPosition(barPositionX, barPositionY);
            bar.SetDirection(bar.Direction.X * widthDiff, bar.Direction.Y * heightDiff);
            bar.Refresh();

            size = new Size(width, height);
        }