コード例 #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();

            //Mouse
            mouseState = Mouse.GetState();

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

            //Count the gameTick
            gameTick = gameTime.ElapsedGameTime.TotalSeconds * timeIncrease;
            gameTicks += gameTick;
            currentTime = DateTime.Now;

            otherPress = false;

            //True on and off debug
            debugToggle();

            musicToggle();

            songSelect();
            
            //Play first music
            if (music && !firstPlay)
            {
                MediaPlayer.Play(smoothJazz);
                firstPlay = true;
            }

            if (screen == 0)
            {
                mainMenuSelect();
            }

            if (screen == 1 || screen == 2)
            {
                pauseToggle();

                tabListToggle();

                resetBalls();

                addNewBall();

                selectBall();

                curveLine();

                zoomLevel();

                if (ballMoveTest)
                    ballChange(); //Change Ball
                if (editMode)
                {
                    editPause = true;
                }
                if (!editMode)
                    editPause = false;

                UpdateTextBox();
                if (sliderActive)
                {
                    detectSelection();
                    changeTextBox();
                }

                if (!pause && !editPause)
                {
                    if (ballMoveTest)
                        //Runs Ball Movement Test
                        ballMovementTest();

                    //Runs Ball Position Calculations
                    ballCalculations();
                    if (screen == 1)
                        ballGravity();

                    // Determines if a collision is occuring between any 2 balls.
                    int element = 0;
                    while (Balls.Count > element)
                    {
                        int other = element + 1;
                        while (Balls.Count > other)
                        {
                            if (ballDetectCollision(Balls[element], Balls[other]))
                            {
                                CollisionCalculation(Balls[element], Balls[other]);
                                ballCollisions = new Collision(Balls[element], Balls[other]);
                                activeCollision = true;
                                Console.Clear();
                                Console.WriteLine(currentTime + ": A collision is occuring between ball {0} and ball {1}.", element, other);
                            }
                            else
                                activeCollision = false;
                            other++;
                        }
                        element++;
                    }
                }

                moveScreen();

            }
        }
コード例 #2
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();

	        //Count the gameTick
	        gameTick = gameTime.ElapsedGameTime.TotalSeconds;

            //Math!
            Balls[currentBall].velT = Math.Sqrt(Balls[currentBall].velX * Balls[currentBall].velX + Balls[currentBall].velY * Balls[currentBall].velY);
            Balls[currentBall].angleRad = Math.Atan(Balls[currentBall].velY / Balls[currentBall].velX);
            Balls[currentBall].angleDeg = Balls[currentBall].angleRad * 180 / Math.PI;

            //True on and off debug
            debugToggle();

            if (ballMoveTest)
            {
                //Runs Ball Movement Test
                ballMovementTest();

                //Change Ball
                ballChange();
            }

            //Runs Ball Position Calculations
            ballCalculations();

            //Detects Ball Collosion (TEST)
            for (int a = 0; a <= Balls.Length - 2; a++)
            {
                for (int b = a + 1; b <= Balls.Length - 1; b++)
                {
                    if (ballDetectCollision(Balls[a], Balls[b]))
                    {
                        ballCollisions = new Collision(Balls[a], Balls[b]);
                        activeCollision = true;
                        a = Balls.Length;
                        b = Balls.Length;
                    }
                    else if (!ballDetectCollision(Balls[a], Balls[b]))
                        activeCollision = false;
                }
            }
        }
コード例 #3
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();

            //Count the gameTick
            gameTick = gameTime.ElapsedGameTime.TotalSeconds;

            //True on and off debug
            debugToggle();

            pauseToggle();

            resetBalls();

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

            if (!pause)
            {
                if (ballMoveTest)
                    //Runs Ball Movement Test
                    ballMovementTest();

                //Runs Ball Position Calculations
                ballCalculations();

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

                //Simulates Ball Collision
                ballCollisionMovement();
            }
        }
コード例 #4
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();

            //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(smoothJazz);
                firstPlay = true;
            }


            //True on and off debug
            debugToggle();

            musicToggle();

            songSelect();

            pauseToggle();

            tabListToggle();

            resetBalls();

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

            //Update Sliders
            for (int i = 0; i <= Sliders.Length - 1; i++)
                UpdateSlider(i);

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

                if (ballMoveTest)
                    //Runs Ball Movement Test
                    ballMovementTest();

                //Runs Ball Position Calculations
                ballCalculations();

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

                //Simulates Ball Collision
                //ballCollisionMovement();


                // 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 (ballDetectCollision(Balls[element], Balls[other]))
                            CollisionCalculation(Balls[element], Balls[other]);
                        other++;
                    }
                    element++;
                }
            }
        }
コード例 #5
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++;
                }
            }
        }
コード例 #6
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();

            //Count the gameTick
            gameTick = gameTime.ElapsedGameTime.TotalSeconds;

            // Simulate a hit from a cue stick into the centre of the current ball.
            cueStick();
            
            //True on and off debug
            debugToggle();

            musicToggle();

            songSelect();

            pauseToggle();

            resetBalls();

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

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

                if (ballMoveTest)
                    //Runs Ball Movement Test
                    ballMovementTest();

                //Runs Ball Position Calculations
                ballCalculations();

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

                //Simulates Ball Collision
                //ballCollisionMovement();

                int element = 0;
                while (Balls.Length > element)
                {
                    int other = element + 1;
                    while (Balls.Length > other)
                    {
                        if (ballDetectCollision(Balls[element], Balls[other]))
                        {
                            ballBallCollision.Play();
                            CollisionCalculation(Balls[element], Balls[other]);
                        }
                        other++;
                    }
                    element++;
                }
            }
        }