}//eom protected override void Update(GameTime gameTime) { InputKeyManager.Triggers currentKeys = InputKeyManager.Read(); switch (drawingState) { case DrawingState.Initialize: // initialize game values if ((currentKeys & InputKeyManager.Triggers.Resume) != 0) { drawingState = DrawingState.Drawing; } //end if break; case DrawingState.Drawing: // check for pause button if ((currentKeys & InputKeyManager.Triggers.Pause) != 0) { drawingState = DrawingState.Paused; } //end if // draw graphics // update each ball foreach (Ball redBall in redBalls) { redBall.Update(gameTime); } //end foreach break; case DrawingState.Paused: // pause drawing if ((currentKeys & InputKeyManager.Triggers.Resume) != 0) { drawingState = DrawingState.Drawing; } //end if break; case DrawingState.Reset: // reset for another demo break; case DrawingState.Resume: // resume demo drawingState = DrawingState.Drawing; break; case DrawingState.Done: // finished break; } //end switch base.Update(gameTime); } //eom
}//eom protected override void Update(GameTime gameTime) { InputKeyManager.Triggers currentKeys = InputKeyManager.Read(); switch (gameState) { case GameState.Initialize: // initialize - set drawingState to Drawing #region User input to change shift and scale if ((currentKeys & InputKeyManager.Triggers.UpArrow) != 0) { if (transformToggle == TransformToggle.Shift) { shiftY += 1.0f; } //end if else { scaleY += 1.0f; if (scaleY == 0) { scaleY = 1; } } //end else } //end if if ((currentKeys & InputKeyManager.Triggers.DownArrow) != 0) { if (transformToggle == TransformToggle.Shift) { shiftY -= 1.0f; } //end if else { scaleY -= 1.0f; if (scaleY == 0) { scaleY = 1; } } //end else } //end if if ((currentKeys & InputKeyManager.Triggers.Minus) != 0) { if (transformToggle == TransformToggle.Shift) { shiftZ -= 1.0f; } //end if else { scaleZ -= 1.0f; if (scaleZ == 0) { scaleZ = 1; } } //end else } //end if if ((currentKeys & InputKeyManager.Triggers.LeftArrow) != 0) { if (transformToggle == TransformToggle.Shift) { shiftX -= 1.0f; } //end if else { scaleX -= 1.0f; if (scaleX == 0) { scaleX = 1; } } //end else } //end if if ((currentKeys & InputKeyManager.Triggers.RightArrow) != 0) { if (transformToggle == TransformToggle.Shift) { shiftX += 1.0f; } //end if else { scaleX += 1.0f; if (scaleX == 0) { scaleX = 1; } } //end else } //end if if ((currentKeys & InputKeyManager.Triggers.Plus) != 0) { if (transformToggle == TransformToggle.Shift) { shiftZ += 1.0f; } //end if else { scaleZ += 1.0f; //if (scaleZ == 0) // scaleZ = 1; } //end else } //end if #endregion if ((currentKeys & InputKeyManager.Triggers.Toggle) != 0) { if (transformToggle == TransformToggle.Shift) { transformToggle = TransformToggle.Scale; } //end if else { transformToggle = TransformToggle.Shift; } //end else } //end if // press spacebar to start the game if ((currentKeys & InputKeyManager.Triggers.Fire) != 0) { threeDObject.Scale = new Vector3(scaleX, scaleY, scaleZ); threeDObject.Shift = new Vector3(shiftX, shiftY, shiftZ); gameState = GameState.Drawing; } //end if if ((currentKeys & InputKeyManager.Triggers.Reset) != 0) { gameState = GameState.Reset; } //end if #region Move Camera if ((currentKeys & InputKeyManager.Triggers.CamLeft) != 0) { camPosition.X -= 5.0f; } //end if if ((currentKeys & InputKeyManager.Triggers.CamRight) != 0) { camPosition.X += 5.0f; } //end if if ((currentKeys & InputKeyManager.Triggers.CamUp) != 0) { camPosition.Y += 5.0f; } //end if if ((currentKeys & InputKeyManager.Triggers.CamDown) != 0) { camPosition.Y -= 5.0f; } //end if viewMatrix = Matrix.CreateLookAt(camPosition, camTarget, Vector3.Up); basicEffect.View = viewMatrix; #endregion if ((currentKeys & InputKeyManager.Triggers.ExitLevel) != 0) { gameState = GameState.Quit; } //end if break; case GameState.Drawing: // draw objects // user input to transform the twoDObject threeDObject.Update(gameTime); SetVertices(); // pause gameState = GameState.Initialize; // reset if ((currentKeys & InputKeyManager.Triggers.ExitLevel) != 0) { gameState = GameState.Reset; } //end if break; case GameState.Reset: shiftX = 0; shiftY = 0; shiftZ = 0; scaleX = 1; scaleY = 1; scaleZ = 1; threeDObject = new ThreeDObject(camTarget, new Vector3(shiftX, shiftY, shiftZ), new Vector3(scaleX, scaleY, scaleZ)); threeDObject.LoadContent(Content); transformToggle = TransformToggle.Shift; SetVertices(); //rest camera and view camPosition = new Vector3(100f, 100f, 100f); basicEffect.View = viewMatrix; if ((currentKeys & InputKeyManager.Triggers.Quit) != 0) { gameState = GameState.Quit; } //end if if ((currentKeys & InputKeyManager.Triggers.Reset) != 0) { gameState = GameState.Initialize; } //end if break; case GameState.Quit: // finished - exit this.Exit(); break; } //end switch base.Update(gameTime); } //eom
}//eom protected override void Update(GameTime gameTime) { InputKeyManager.Triggers currentKeys = InputKeyManager.Read(); switch (gameState) { case GameState.Initialize: // initialize the game // change the mass if ((currentKeys & InputKeyManager.Triggers.UpArrow) != 0) { wagon.Mass += 5.0f; } //end if if ((currentKeys & InputKeyManager.Triggers.DownArrow) != 0) { wagon.Mass -= 5.0f; } //end if // change the friction coefficient if ((currentKeys & InputKeyManager.Triggers.LeftArrow) != 0) { wagon.FrictionCoefficient -= 0.01f; } //end if if ((currentKeys & InputKeyManager.Triggers.RightArrow) != 0) { wagon.FrictionCoefficient += 0.01f; } //end if // press spacebar to start the game if ((currentKeys & InputKeyManager.Triggers.Fire) != 0) { gameState = GameState.Playing; } //end if break; case GameState.Playing: // puase the game if ((currentKeys & InputKeyManager.Triggers.Pause) != 0) { gameState = GameState.Paused; } //end if // reset if ((currentKeys & InputKeyManager.Triggers.ExitLevel) != 0) { gameState = GameState.GameOver; } //end if // play the game // check if the up arrow was pressed if ((currentKeys & InputKeyManager.Triggers.UpArrow) != 0) { // move the handle angle up in increments of 5 degrees to a maximum of 85 degrees wagon.HandleAngle -= 5; } //end if // check if the down arrow was pressed if ((currentKeys & InputKeyManager.Triggers.DownArrow) != 0) { // move the handle down in increments of 5 degreees to a minimum of 0 degrees wagon.HandleAngle += 5; } //end if // check if the left arrow was pressed if ((currentKeys & InputKeyManager.Triggers.LeftArrow) != 0) { // decrease the applied force in increments of 5N to a minimum of 0N wagon.ForceMagnitude -= 5; } //end if // check if the right arrow was pressed if ((currentKeys & InputKeyManager.Triggers.RightArrow) != 0) { // increase the applied force in increments of 5N to a maximum of 5000N wagon.ForceMagnitude += 5; } //end if // update the wagon wagon.Update(gameTime); break; case GameState.Paused: // game is paused if ((currentKeys & InputKeyManager.Triggers.Pause) != 0) { gameState = GameState.Playing; } //end if break; case GameState.GameOver: // end the game if ((currentKeys & InputKeyManager.Triggers.Reset) != 0) { wagon.Mass = mass; wagon.FrictionCoefficient = frictionCoefficient; wagon.ForceMagnitude = forceMagnitude; wagon.HandleAngle = handleAngle; wagon.Location = new Vector2((WindowWidth - Wagon.HandleDimensions.X - Wagon.WagonDimensions.X) / 8, BottomBorder - Wagon.WagonDimensions.Y); gameState = GameState.Initialize; } //end if if ((currentKeys & InputKeyManager.Triggers.Quit) != 0) { gameState = GameState.Quit; } //end if break; case GameState.Quit: // close the game completely this.Exit(); break; } //end switch base.Update(gameTime); } //eom
}//eom #endregion protected override void Update(GameTime gameTime) { InputKeyManager.Triggers currentKeys = InputKeyManager.Read(); switch (drawingState) { case DrawingState.Initialize: // initialize - set drawingState to Drawing // user input to change origin of rotation if ((currentKeys & InputKeyManager.Triggers.UpArrow) != 0) { twoDObject.RotationPoint -= new Vector2(0, 5); } //end if if ((currentKeys & InputKeyManager.Triggers.DownArrow) != 0) { twoDObject.RotationPoint += new Vector2(0, 5); } //end if if ((currentKeys & InputKeyManager.Triggers.LeftArrow) != 0) { twoDObject.RotationPoint -= new Vector2(5, 0); } //end if if ((currentKeys & InputKeyManager.Triggers.RightArrow) != 0) { twoDObject.RotationPoint += new Vector2(5, 0); } //end if if ((currentKeys & InputKeyManager.Triggers.CCW) != 0) { twoDObject.Direction = -1.0f; } //end if if ((currentKeys & InputKeyManager.Triggers.CW) != 0) { twoDObject.Direction = 1.0f; } //end if if ((currentKeys & InputKeyManager.Triggers.Origin) != 0) { twoDObject.RotationPoint = GridCenter; } //end if if ((currentKeys & InputKeyManager.Triggers.Center) != 0) { // get the current position of the 2D object List <Point> points = twoDObject.Points; // calculate the center float cX = 0f, cY = 0f; foreach (Point p in points) { cX += p.PointLocation.X; cY += p.PointLocation.Y; } //end foreach cX /= points.Count; cY /= points.Count; // set the rotation point twoDObject.RotationPoint = new Vector2(cX, cY); } //end if // press spacebar to start the game if ((currentKeys & InputKeyManager.Triggers.Fire) != 0) { drawingState = DrawingState.Drawing; } //end if break; case DrawingState.Drawing: // draw objects // user input to rotate the twoDObject clockwise and counteclockwise twoDObject.Update(gameTime); SetVertices(); // pause // reset if ((currentKeys & InputKeyManager.Triggers.ExitLevel) != 0) { drawingState = DrawingState.Reset; } //end if break; case DrawingState.Paused: // rotation is paused break; case DrawingState.Reset: // reset/clear the drawing if ((currentKeys & InputKeyManager.Triggers.Reset) != 0) { //twoDObject.RotationPoint = GRID_CENTER; drawingState = DrawingState.Initialize; } //end if if ((currentKeys & InputKeyManager.Triggers.Quit) != 0) { drawingState = DrawingState.Done; } //end if break; case DrawingState.Done: // finished - exit this.Exit(); break; } //end switch base.Update(gameTime); } //eom
}//eom protected override void Update(GameTime gameTime) { InputKeyManager.Triggers currentKeys = InputKeyManager.Read(); switch (drawingState) { case DrawingState.Initialize: // initialize and set drawing state pathVertices.Add(new VertexPositionColor(new Vector3(pointPosition.X, pointPosition.Y, 0), Color.AliceBlue)); //pathVertices.Add(new VertexPositionColor(new Vector3(pointPosition.X, pointPosition.Y, 0), Color.AliceBlue)); // change firing angle and magnitude based on keyboard input if ((currentKeys & InputKeyManager.Triggers.UpArrow) != 0) { firingAngle += 1.0f; if (firingAngle > 89) { firingAngle = 89; } //end if } //end if if ((currentKeys & InputKeyManager.Triggers.DownArrow) != 0) { firingAngle -= 1.0f; if (firingAngle < 0.0f) { firingAngle = 0.0f; } //end if } //end if if ((currentKeys & InputKeyManager.Triggers.LeftArrow) != 0) { firingMagnitude -= 5.0f; if (firingMagnitude < 0.0f) { firingMagnitude = 0.0f; } //end if } //end if if ((currentKeys & InputKeyManager.Triggers.RightArrow) != 0) { firingMagnitude += 5.0f; if (firingMagnitude > 250) { firingMagnitude = 250; } //end if } //end if // create component form of velocity velocity = new Vector3((float)(firingMagnitude * Math.Cos(MathHelper.ToRadians(firingAngle))), (float)(firingMagnitude * Math.Sin(MathHelper.ToRadians(firingAngle))), 0); // move the starting posiion up and down if ((currentKeys & InputKeyManager.Triggers.Up) != 0) { launchPoint.Y += 1; if (launchPoint.Y > WindowHeight) { launchPoint.Y = WindowHeight; } //end if } //end if if ((currentKeys & InputKeyManager.Triggers.Down) != 0) { launchPoint.Y -= 1; if (launchPoint.Y < 0) { launchPoint.Y = 0; } //end if } //end if // now set the starting pointPosition pointPosition.X = launchPoint.X; pointPosition.Y = WindowHeight - launchPoint.Y; // press spacebar to start the game if ((currentKeys & InputKeyManager.Triggers.Fire) != 0) { drawingState = DrawingState.Drawing; } //end if break; case DrawingState.Drawing: // draw objects time += (float)gameTime.ElapsedGameTime.TotalSeconds; pointPosition = launchPoint + velocity * time + 0.5f * acceleration * time * time; pointPosition.Y = WindowHeight - pointPosition.Y; pathVertices.Add(new VertexPositionColor(pointPosition, Color.Red)); twoDObject.CenterOfMass = new Vector2(pointPosition.X, pointPosition.Y); twoDObject.Update(gameTime); SetVertices(); // check if point is off the screen if (pointPosition.Y - WindowHeight >= 0 || pointPosition.X >= WindowWidth) { drawingState = DrawingState.Reset; // may need to add another state } //end if // pause // reset if ((currentKeys & InputKeyManager.Triggers.ExitLevel) != 0) { drawingState = DrawingState.Reset; } //end if break; case DrawingState.Paused: // drawing is paused break; case DrawingState.Reset: // reset/clear the drawing if ((currentKeys & InputKeyManager.Triggers.Reset) != 0) { time = 0.0f; firingAngle = 45.0f; firingMagnitude = 100.0f; velocity = Vector3.Zero; launchPoint = new Vector3(WindowMargin, WindowMargin, 0); pointPosition = new Vector3(launchPoint.X, WindowHeight - launchPoint.Y, launchPoint.Z); pathVertices.Clear(); drawingState = DrawingState.Initialize; } //end if if ((currentKeys & InputKeyManager.Triggers.Quit) != 0) { drawingState = DrawingState.Done; } //end if break; case DrawingState.Done: // finished - exit this.Exit(); break; } //end switch base.Update(gameTime); } //eom
}//eom protected override void Update(GameTime gameTime) { InputKeyManager.Triggers currentKeys = InputKeyManager.Read(); switch (drawingState) { case DrawingState.Initialize: // initialize - set drawingState to Drawing // user input to change shift and scale if ((currentKeys & InputKeyManager.Triggers.UpArrow) != 0) { if (transformToggle == TransformToggle.Shift) { shiftY += 1.0f; } //end if else { scaleY += 1.0f; if (scaleY == 0) { scaleY = 1; } } //end else } //end if if ((currentKeys & InputKeyManager.Triggers.DownArrow) != 0) { if (transformToggle == TransformToggle.Shift) { shiftY -= 1.0f; } //end if else { scaleY -= 1.0f; if (scaleY == 0) { scaleY = 1; } } //end else } //end if if ((currentKeys & InputKeyManager.Triggers.LeftArrow) != 0) { if (transformToggle == TransformToggle.Shift) { shiftX -= 1.0f; } //end if else { scaleX -= 1.0f; if (scaleX == 0) { scaleX = 1; } } //end else } //end if if ((currentKeys & InputKeyManager.Triggers.RightArrow) != 0) { if (transformToggle == TransformToggle.Shift) { shiftX += 1.0f; } //end if else { scaleX += 1.0f; if (scaleX == 0) { scaleX = 1; } } //end else } //end if if ((currentKeys & InputKeyManager.Triggers.Toggle) != 0) { if (transformToggle == TransformToggle.Shift) { transformToggle = TransformToggle.Scale; } //end if else { transformToggle = TransformToggle.Shift; } //end else } //end if // press spacebar to start the game if ((currentKeys & InputKeyManager.Triggers.Fire) != 0) { twoDObject.Scale = new Vector2(scaleX, scaleY); twoDObject.Shift = new Vector2(shiftX, shiftY); drawingState = DrawingState.Drawing; } //end if if ((currentKeys & InputKeyManager.Triggers.ExitLevel) != 0) { drawingState = DrawingState.Reset; } //end if break; case DrawingState.Drawing: // draw objects // user input to transform the twoDObject twoDObject.Update(gameTime); SetVertices(); // pause drawingState = DrawingState.Initialize; // reset if ((currentKeys & InputKeyManager.Triggers.ExitLevel) != 0) { drawingState = DrawingState.Reset; } //end if break; case DrawingState.Paused: // drawing is paused break; case DrawingState.Reset: // reset the drawing if ((currentKeys & InputKeyManager.Triggers.Reset) != 0) { twoDObject = new TwoDObject(Grid_Center, Vector2.Zero, Vector2.Zero); twoDObject.LoadContent(Content); shiftX = 0; shiftY = 0; scaleX = 1; scaleY = 1; transformToggle = TransformToggle.Shift; SetVertices(); drawingState = DrawingState.Initialize; } //end if if ((currentKeys & InputKeyManager.Triggers.Quit) != 0) { drawingState = DrawingState.Done; } //end if break; case DrawingState.Done: // finished - exit this.Exit(); break; } //end switch base.Update(gameTime); } //eom
}//eom protected override void Update(GameTime gameTime) { InputKeyManager.Triggers currentKeys = InputKeyManager.Read(); switch (drawingState) { case DrawingState.Initialize: // initialize starting values vertices.Add(new VertexPositionColor(new Vector3(0, WindowHeight, 0), Color.Red)); vertices.Add(new VertexPositionColor(new Vector3(0, WindowHeight, 0), Color.Red)); if ((currentKeys & InputKeyManager.Triggers.UpArrow) != 0) { firingAngle += 1.0f; if (firingAngle > 89) { firingAngle = 89; } //end if } //end if if ((currentKeys & InputKeyManager.Triggers.DownArrow) != 0) { firingAngle -= 1.0f; if (firingAngle < 0.0f) { firingAngle = 0.0f; } //end if } //end if if ((currentKeys & InputKeyManager.Triggers.LeftArrow) != 0) { firingMagnitude -= 5.0f; if (firingMagnitude < 0.0f) { firingMagnitude = 0.0f; } //end if } //end if if ((currentKeys & InputKeyManager.Triggers.RightArrow) != 0) { firingMagnitude += 5.0f; if (firingMagnitude > 250) { firingMagnitude = 250; } //end if } //end if // create component form of velocity velocity = new Vector3((float)(firingMagnitude * Math.Cos(MathHelper.ToRadians(firingAngle))), (float)(firingMagnitude * Math.Sin(MathHelper.ToRadians(firingAngle))), 0); // move the starting posiion up and down if ((currentKeys & InputKeyManager.Triggers.Up) != 0) { initialPosition.Y += 1; if (initialPosition.Y > WindowHeight) { initialPosition.Y = WindowHeight; } //end if } //end if if ((currentKeys & InputKeyManager.Triggers.Down) != 0) { initialPosition.Y -= 1; if (initialPosition.Y < 0) { initialPosition.Y = 0; } //end if } //end if // now set the starting pointPosition pointPosition.X = initialPosition.X; pointPosition.Y = WindowHeight - initialPosition.Y; // press spacebar to start the game if ((currentKeys & InputKeyManager.Triggers.Fire) != 0) { drawingState = DrawingState.Drawing; } //end if break; case DrawingState.Drawing: // draw objects on the screen time += (float)gameTime.ElapsedGameTime.TotalSeconds; pointPosition = initialPosition + velocity * time + 0.5f * acceleration * time * time; pointPosition.Y = WindowHeight - pointPosition.Y; vertices.Add(new VertexPositionColor(pointPosition, Color.Red)); // check if point is off the screen if (pointPosition.Y - WindowHeight >= 0 || pointPosition.X >= WindowWidth) { drawingState = DrawingState.Reset; // may need to add another state } //end if // reset if ((currentKeys & InputKeyManager.Triggers.ExitLevel) != 0) { drawingState = DrawingState.Reset; } //end if GetMaximumHeight(); break; case DrawingState.Paused: // pause drawing on the scren break; case DrawingState.Reset: // reset/clear the drawing if ((currentKeys & InputKeyManager.Triggers.Reset) != 0) { time = 0.0f; firingAngle = 0.0f; firingMagnitude = 0.0f; maxHeight = 0.0f; velocity = Vector3.Zero; pointPosition = Vector3.Zero; initialPosition = Vector3.Zero; vertices.Clear(); drawingState = DrawingState.Initialize; } //end if if ((currentKeys & InputKeyManager.Triggers.Quit) != 0) { drawingState = DrawingState.Done; } //end if break; case DrawingState.Done: // finished - exit this.Exit(); break; } //end switch base.Update(gameTime); } //eom