Esempio n. 1
0
 public void CheckIntersectionAndChangeDirection(GameBall ball)
 {
     if (IsIntersection(ball))
     {
         ball.shape.FillColor = Color.Yellow;
         AddSore();
         ball.SetRandomDirection();
     }
 }
Esempio n. 2
0
        public bool IsIntersection(GameBall ball)
        {
            (float boxMinX, float boxMaxX) = MathHelper.GetMinAndMaxForRectangle(shape.Position.X, width);
            (float boxMinY, float boxMaxY) = MathHelper.GetMinAndMaxForRectangle(shape.Position.Y, height);

            float x = Math.Max(boxMinX, Math.Min(ball.Center().X, boxMaxX));
            float y = Math.Max(boxMinY, Math.Min(ball.Center().Y, boxMaxY));

            float distance = MathHelper.GetDistance(x, y, ball.Center().X, ball.Center().Y);

            if (distance <= ball.shape.Radius)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 3
0
        public void Start()
        {
            CreateAllAbilities();
            (Player leftPlayer, Player rightPlayer) = CreatePlayers();
            GameBall ball = new GameBall(40, 500, 420, Color.Red, allShapesToDraw);

            window.Closed += WindowClosed;
            // window.KeyPressed += OnKeyPressed(leftPlayer, rightPlayer);
            window.SetFramerateLimit(600);

            while (window.IsOpen)
            {
                Event pressed = new Event();
                window.Clear();

                leftPlayer.TryToMove(Keyboard.Key.S, Keyboard.Key.W);
                rightPlayer.TryToMove(Keyboard.Key.Down, Keyboard.Key.Up);

                ball.Move();
                ball.CheckIntersectionWithFloorAndWalls();

                //if (leftPlayer.abilityDictionary.ContainsKey(pressed.Key.Code))
                //{
                //    leftPlayer.currentAbilitie = leftPlayer.abilityDictionary[pressed.Key.Code];
                //    leftPlayer.currentAbilitie.SetAbilityActive(leftPlayer);
                //}
                if (Keyboard.IsKeyPressed(Keyboard.Key.Q))
                {
                    leftPlayer.currentAbilitie = allAbilities[0];
                    leftPlayer.SetAbilityActive();
                }

                leftPlayer.CheckIntersectionAndChangeDirection(ball);
                rightPlayer.CheckIntersectionAndChangeDirection(ball);


                DrawAllShapes(window);
                window.DispatchEvents();
                window.Display();
            }
        }