/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { // TODO: Add your initialization logic here Slider sliderInstance = new Slider("null", 0, 0, 0); resolutionX = 1280; resolutionY = 720; graphics.PreferredBackBufferWidth = (int)resolutionX; graphics.PreferredBackBufferHeight = (int)resolutionY; graphics.ApplyChanges(); //Starting values for ball Sliders = new Slider[4]; moveSlider = new bool[4]; Sliders[0] = new Slider("Friction", Window.ClientBounds.Width - 180, 80, 0); Sliders[1] = new Slider("Elasticity", Window.ClientBounds.Width - 180, 120, 34); Sliders[2] = new Slider("Current Ball Elast.", Window.ClientBounds.Width - 180, 160, 0); Sliders[3] = new Slider("Current Ball Mass", Window.ClientBounds.Width - 180, 200, 0); for (int i = 0; i <= Sliders.Length - 1; i++) Slider.SliderLabelInt(Sliders, i); Position = new Vector2[16]; Balls = new Ball[2]; Balls[0] = new Ball(0, 100, 240, 0.16, 1, gameTick); Balls[1] = new Ball(1, 400, 240, 0.16, 1, gameTick); //Array for each toggleable key keyDown = new bool[15]; for (int i = 0; i <= keyDown.Length - 1; i++) keyDown[i] = false; for (int i = 0; i <= moveSlider.Length - 1; i++) moveSlider[i] = false; mouseDown = false; //Starting general values currentBall = 0; accelDefault = 500; frictDefault = 0; debug = false; music = false; sliderActive = false; ballMoveTest = true; pause = false; console = true; currentCollision = false; firstPlay = false; bumperElasticity = 0; //Between 0 and 1 (0-100%) bounceBuffer = 2; Songs = new Song[5]; base.Initialize(); }
public static void SliderLabelInt(Slider[] Sliders, int i) { //Label 1 if (Sliders[i].sliderName == "Friction") Sliders[i].label1 = "0"; if (Sliders[i].sliderName == "Elasticity") Sliders[i].label1 = "-33"; if (Sliders[i].sliderName == "Current Ball Elast.") Sliders[i].label1 = "0"; if (Sliders[i].sliderName == "Current Ball Mass") Sliders[i].label1 = "0"; //Label 2 if (Sliders[i].sliderName == "Friction") Sliders[i].label2 = "25"; if (Sliders[i].sliderName == "Elasticity") Sliders[i].label2 = "0"; if (Sliders[i].sliderName == "Current Ball Elast.") Sliders[i].label2 = "25"; if (Sliders[i].sliderName == "Current Ball Mass") Sliders[i].label2 = "0.25"; //Label 3 if (Sliders[i].sliderName == "Friction") Sliders[i].label3 = "50"; if (Sliders[i].sliderName == "Elasticity") Sliders[i].label3 = "33"; if (Sliders[i].sliderName == "Current Ball Elast.") Sliders[i].label3 = "50"; if (Sliders[i].sliderName == "Current Ball Mass") Sliders[i].label3 = "0.5"; //Label 4 if (Sliders[i].sliderName == "Friction") Sliders[i].label4 = "75"; if (Sliders[i].sliderName == "Elasticity") Sliders[i].label4 = "66"; if (Sliders[i].sliderName == "Current Ball Elast.") Sliders[i].label4 = "75"; if (Sliders[i].sliderName == "Current Ball Mass") Sliders[i].label4 = "0.75"; //Label 5 if (Sliders[i].sliderName == "Friction") Sliders[i].label5 = "100"; if (Sliders[i].sliderName == "Elasticity") Sliders[i].label5 = "100"; if (Sliders[i].sliderName == "Current Ball Elast.") Sliders[i].label5 = "100"; if (Sliders[i].sliderName == "Current Ball Mass") Sliders[i].label5 = "1"; }
public void UpdateSlider(Slider[] Sliders, bool[] moveSlider, int i, Ball[] Balls, int currentBall, Vector2 mousePos, MouseState mouseState, double frictDefault, double bumperElasticity) { //Updates movement of Sliders if (Sliders[i].sliderName == "Current Ball Elast.") Sliders[i].curX = Balls[currentBall].elast * 145; if (Sliders[i].sliderName == "Current Ball Mass") Sliders[i].curX = Balls[currentBall].mass * 145; if (mousePos.X >= Sliders[i].posX + Sliders[i].curX && mousePos.X <= Sliders[i].posX + Sliders[i].curX + 15 && mousePos.Y >= Sliders[i].posY - 3 && mousePos.Y <= Sliders[i].posY + 20 && mouseState.LeftButton == ButtonState.Pressed && !moveSlider[i]) moveSlider[i] = true; else if (mouseState.LeftButton == ButtonState.Released) moveSlider[i] = false; if (moveSlider[i]) Sliders[i].curX = mousePos.X - Sliders[i].posX; if (Sliders[i].curX <= 0) Sliders[i].curX = 0; else if (Sliders[i].curX >= 145) Sliders[i].curX = 145; //Updates effected values of sliders }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { // TODO: Add your initialization logic here graphics.PreferredBackBufferWidth = 1280; graphics.PreferredBackBufferHeight = 720; graphics.ApplyChanges(); //Starting values for ball Sliders = new Slider[3]; moveSlider = new bool[3]; Sliders[0] = new Slider("Friction", Window.ClientBounds.Width - 180, 80, 0); Sliders[1] = new Slider("Elasticity", Window.ClientBounds.Width - 180, 120, 34); Sliders[2] = new Slider("Current Ball Elast.", Window.ClientBounds.Width - 180, 160, 0); Position = new Vector2[16]; Balls = new Ball[10]; Balls[0] = new Ball(0, 100, 240, 0.16, 1, gameTick); Balls[1] = new Ball(1, 400, 240, 0.16, 1, gameTick); //Balls[2] = new Ball(2, 415, 231, 0.16, 1, gameTick); //Balls[3] = new Ball(3, 415, 249, 0.16, 1, gameTick); //Balls[4] = new Ball(4, 430, 222, 0.16, 1, gameTick); //Balls[5] = new Ball(5, 430, 240, 0.16, 1, gameTick); //Balls[6] = new Ball(6, 430, 258, 0.16, 1, gameTick); //Balls[7] = new Ball(7, 445, 213, 0.16, 1, gameTick); //Balls[8] = new Ball(8, 445, 231, 0.16, 1, gameTick); //Balls[9] = new Ball(9, 445, 249, 0.16, 1, gameTick); //Balls[10] = new Ball(10, 445, 267, 0.16, 1, gameTick); //Balls[11] = new Ball(11, 460, 204, 0.16, 1, gameTick); //Balls[12] = new Ball(12, 460, 222, 0.16, 1, gameTick); //Balls[13] = new Ball(13, 460, 240, 0.16, 1, gameTick); //Balls[14] = new Ball(14, 460, 258, 0.16, 1, gameTick); //Balls[15] = new Ball(15, 460, 276, 0.16, 1, gameTick); Balls[2] = new Ball(2, 420, 236, 0.16, 1, gameTick); Balls[3] = new Ball(3, 420, 254, 0.16, 1, gameTick); Balls[4] = new Ball(4, 435, 227, 0.16, 1, gameTick); Balls[5] = new Ball(5, 435, 245, 0.16, 1, gameTick); Balls[6] = new Ball(6, 435, 263, 0.16, 1, gameTick); Balls[7] = new Ball(7, 450, 218, 0.16, 1, gameTick); Balls[8] = new Ball(8, 450, 236, 0.16, 1, gameTick); Balls[9] = new Ball(9, 450, 254, 0.16, 1, gameTick); //Array for each toggleable key keyDown = new bool[15]; for (int i = 0; i <= keyDown.Length - 1; i++) keyDown[i] = false; for (int i = 0; i <= moveSlider.Length - 1; i++) moveSlider[i] = false; mouseDown = false; //Starting general values currentBall = 0; accelDefault = 500; frictDefault = 0; debug = false; music = false; sliderActive = false; ballMoveTest = true; pause = false; console = true; currentCollision = false; firstPlay = false; bumperElasticity = 0; //Between 0 and 1 (0-100%) bounceBuffer = 2; base.Initialize(); }
/// <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++; } } }
public static double BallMassSlider(Slider[] Sliders, int currentBall, Ball[] Balls) { Balls[currentBall].mass = Sliders[3].curX / 145; return Balls[currentBall].mass; }
public static double BallElasticitySlider(Slider[] Sliders, int currentBall, Ball[] Balls) { Balls[currentBall].elast = Sliders[2].curX / 145; return Balls[currentBall].elast; }
public static double ElasticitySlider(Slider[] Sliders, double bumperElasticity) { bumperElasticity = (Sliders[1].curX - 34) / 145; return bumperElasticity; }
public static double FricitonSlider(Slider[] Sliders, double frictDefault) { frictDefault = Sliders[0].curX / -14; return frictDefault; }