Esempio n. 1
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (Keyboard.GetState().IsKeyDown(Keys.Escape))
                this.Exit();

            // TODO: Add your update logic here
            prevKeyState = keyState;
            keyState = Keyboard.GetState();
            KeyToggles keyInstance = new KeyToggles();
            Slider sliderInstance = new Slider();
            Ball ballInstance = new Ball();

            //Mouse
            mouseState = Mouse.GetState();

            mousePos.X = mouseState.X;
            mousePos.Y = mouseState.Y;

            //Count the gameTick
            gameTick = gameTime.ElapsedGameTime.TotalSeconds;
            
            //Play first music
            if (music && !firstPlay)
            {
                MediaPlayer.Play(Songs[4]);
                firstPlay = true;
            }

            sliderActive = sliderInstance.tabListToggle(mousePos, resolutionX, resolutionY);

            debug = keyInstance.debugToggle(keyState, debug, keyDown);

            music = keyInstance.musicToggle(keyState, music, keyDown);

            pause = keyInstance.pauseToggle(keyState, pause, keyDown);

            keyInstance.songSelect(keyState, Songs);

            keyInstance.resetBalls(keyState, Balls);

            if (ballMoveTest)
                ballChange(); //Change Ball

            //Update Sliders
            for (int i = 0; i <= Sliders.Length - 1; i++)
            {
                sliderInstance.UpdateSlider(Sliders, moveSlider, i, Balls, currentBall, mousePos, mouseState, frictDefault, bumperElasticity);
                frictDefault = Slider.FricitonSlider(Sliders, frictDefault);
                bumperElasticity = Slider.BallElasticitySlider(Sliders, currentBall, Balls);
                Balls[currentBall].elast = Slider.BallElasticitySlider(Sliders, currentBall, Balls);
            }

            Balls[currentBall].mass = Slider.BallMassSlider(Sliders, currentBall, Balls);

            if (!pause)
            {
                if (console)
                    consoleWindow();

                if (ballMoveTest)
                    //Runs Ball Movement Test
                    ballInstance.ballMovementTest(keyState, Balls, currentBall, accelDefault, frictDefault, bumperElasticity, bounceBuffer, resolutionX, resolutionY);

                //Runs Ball Position Calculationspublic void ballMovementTest(KeyboardState keyState, Ball[] Balls, int currentBall, double accelDefault, double frictDefault, double bumperElasticity, double bounceBuffer, double resX, double resY)
                Ball.ballCalculations(Balls, frictDefault, gameTick, bumperElasticity, bounceBuffer, resolutionX, resolutionY);

                //Detects Ball Collosion (TEST)
                for (int a = 0; a <= Balls.Length - 2; a++)
                {
                    for (int b = a + 1; b <= Balls.Length - 1; b++)
                    {
                        if (Collision.ballDetectCollision(Balls[a], Balls[b]))
                        {
                            ballCollisions = new Collision(Balls[a], Balls[b]);
                            activeCollision = true;
                            a = Balls.Length;
                            b = Balls.Length;
                        }
                        else if (!Collision.ballDetectCollision(Balls[a], Balls[b]))
                            activeCollision = false;
                    }
                }

                // Determines if a collision is occuring between any 2 balls.
                int element = 0;
                while (Balls.Length > element)
                {
                    int other = element + 1;
                    while (Balls.Length > other)
                    {
                        if (Collision.ballDetectCollision(Balls[element], Balls[other]))
                            Collision.CollisionCalculation(Balls[element], Balls[other], ballBallCollision);
                        other++;
                    }
                    element++;
                }
            }
        }