示例#1
0
 private void SetupFieldObjects()
 {
     xBorder = MathExt.GetPercentOf(window.Size.X, 2);
     yBorder = MathExt.GetPercentOf(window.Size.Y, 2);
     (UpperGate[0], UpperGate[1]) = MathExt.CreateGates(window.Size, true);
     (Gate[0], Gate[1])           = MathExt.CreateGates(window.Size, false);
     ball.ChangePosition(new Vector2f(window.Size.X / 2, window.Size.Y / 2));
     bot.racket.GoToStartPoint(window.Size, 10);
     gameRacket.GoToStartPoint(window.Size, 80);
 }
示例#2
0
        private void Cycle()
        {
            time = clock.ElapsedTime.AsMicroseconds();
            clock.Restart();
            time /= 800;                                              //for smoother movement of ball

            window.Clear();
            window.DispatchEvents();


            itemListRef.CheckCircleOnCollisionWithItemsAndUseFeature(gameRacket, window.Size);
            itemListRef.CheckCircleOnCollisionWithItemsAndUseFeature(bot.racket, window.Size);

            gameRacket.ChangePosition(new Vector2f(mouseX - gameRacket.GetRadius(), mouseY - gameRacket.GetRadius()));

            ChangeDirection(MathExt.CheckForIntersectAndDetectDirection(gameRacket, ball));
            ChangeDirection(MathExt.CheckForIntersectAndDetectDirection(bot.racket, ball));

            if (!MathExt.IsVectorBiggerThenWindowY(bot.racket, window.Size))
            {
                bot.MoveTo(ball.GetCenter(), (float)time);
            }
            else
            {
                bot.MoveTo(new Vector2f(window.Size.X / 2, MathExt.GetPercentOf(window.Size.Y, 10)), (float)time);
            }


            if (direction != new Vector2f(0, 0))
            {
                ChangeDirection(ball.Reflect(window.Size, direction, xBorder, yBorder));
            }

            if (direction != new Vector2f(0, 0))
            {
                ball.Move(direction, window.Size, (float)time);
            }

            SomeoneScore();
            DrawObjects();
            window.Display();
        }
示例#3
0
 public void GoToStartPoint(Vector2u window, float percentage)
 {
     ChangePosition(new Vector2f(window.X / 2, MathExt.GetPercentOf(window.Y, percentage)));
 }