public override void Update(GameTime gameTime, StateManager screen, GamePadState gamePadState, MouseState mouseState, KeyboardState keyState, InputHandler input) { if (input.KeyboardState.WasKeyPressed(Keys.Escape) || input.WasPressed(0, InputHandler.ButtonType.B, Keys.B)) { screen.Pop(); } if (input.KeyboardState.WasKeyPressed(Keys.P) || input.WasPressed(0, InputHandler.ButtonType.Start, Keys.Tab)) { PauseScreen pause = new PauseScreen(); screen.Push(pause); } elapsedTime += gameTime.ElapsedGameTime; if (Keyboard.GetState().IsKeyDown(Keys.Up)) { if (elapsedTime > TimeSpan.FromSeconds(2)) { if (lander.fuel > 0) { soundEffects[0].Play(); } elapsedTime = TimeSpan.Zero; } } lander.Update(gameTime); fuelWord.Update("Fuel " + lander.fuel); lander.CreateLines(); CollisionCheck(); }
public override void Update(GameTime gameTime, StateManager screens, GamePadState gamePadState, MouseState mouseState, KeyboardState keyState, InputHandler input) { if (oldKeyboardState != keyState) { if (keyState.IsKeyDown(Keys.P)) { StateManager.Push(new PauseScreen()); } if (keyState.IsKeyDown(Keys.Escape)) { StateManager.Pop(); } if (keyState.IsKeyDown(Keys.Enter) && lander.State == Lander.landerState.landed) { StateManager.Pop(); terrainNumber += 1; StateManager.Push(new PlayScreen((terrainNumber % 3))); } oldKeyboardState = keyState; } lander.Update(gameTime); terrain.Update(gameTime); if (testCollision(lander.Points.ToArray(), terrain.Land.ToArray())) { lander.Crash(); bgColor = Color.DarkRed; } else if (testCollision(lander.Points.ToArray(), terrain.LandingPads.ToArray())) { if (lander.XSpeed < 0.3f && lander.YSpeed < 0.6f && lander.Angle == 0) { if (!sentScore) { StateManager.Score = StateManager.Score + (int)(lander.Fuel * 100); sentScore = true; } lander.winGame(); bgColor = Color.DarkGreen; } else { lander.Crash(); bgColor = Color.DarkRed; } } handleSound(); }
public override void Update(GameTime gameTime, StateManager screen, GamePadState gamePadState, MouseState mouseState, KeyboardState keyboardState, InputHandler input) { #region Key Presses if (input.KeyboardState.WasKeyPressed(Keys.Escape) || input.WasPressed(0, InputHandler.ButtonType.A, Keys.P)) { screen.Push(new PauseScreen()); } #endregion #region Global Checks [Reset Game, Main Menu] if (GlobalValues.ResetGame) { ResetValues(); } if (GlobalValues.GoToMainMenu) { screen.Pop(); } else { lander.Update(gameTime); } #endregion #region Scroll Map if (GlobalValues.LevelLoaded == "Random") { shiftTime += gameTime.ElapsedGameTime; float xVelocity = LanderValues.Velocity.X; if (xVelocity < 0) { xVelocity *= -1; } float speed = (MathHelper.Lerp(800, 75, (xVelocity / 5f))); if (speed < 0) { speed *= -1; } if (shiftTime > TimeSpan.FromMilliseconds(speed)) { shiftTime -= TimeSpan.FromMilliseconds(speed); if (LanderValues.RightBoundHit) { mapShiftPosition -= new Vector2(GlobalValues.ScreenBuffer, 0); Terrain.NewRandomLine(false, mapShiftPosition.X); } if (LanderValues.LeftBoundHit) { mapShiftPosition += new Vector2(GlobalValues.ScreenBuffer, 0); Terrain.NewRandomLine(true, mapShiftPosition.X); } Terrain.FixTerrainHitboxes(mapShiftPosition); Terrain.FixPadHitboxes(mapShiftPosition); } } #endregion #region Win Loss Check if (lander.DidLose()) { LoadContent(); ResetValues(); screen.Push(new LoseScreen()); } if (lander.DidWin()) { TimeSpan landerTime = lander.GetGameTime(); LoadContent(); lander.SetGameTime(landerTime); screen.Push(new WinScreen()); } #endregion #region Debug //Show debug info if (input.KeyboardState.WasKeyPressed(Keys.OemTilde)) { //Switches debug mode on or off debugMode = !debugMode; } #endregion }
/// <summary> /// Updates the Fitness property by running a landing simulation. /// TODO implement running multiple simulations for varying environments. /// </summary> public void CalculateFitness() { List<double> inputs = new List<double>(); Model.Environment environment = new Model.Environment(); Lander lander = new Lander(environment, this.settings.StartingFuel, this.settings.StartingHorizontal, this.settings.StartingHeight); IList<double> output; for (int i = 0; i < 7; i++) { inputs.Add(0); } this.Fitness = 0; //for (double varWind = -1.0; varWind < 1.0; varWind += 0.1) //{ // this.settings.LanderEnvironment.WindSpeed = varWind; // lander.Enviroment.WindSpeed = varWind; for (double varGravity = 1; varGravity < 3; varGravity += 0.5) { //this.settings.LanderEnvironment.Gravity = varGravity; lander.Enviroment.Gravity = varGravity; lander.Reset(); do { inputs[0] = lander.PositionX; inputs[1] = lander.PositionY; inputs[2] = lander.VelocityX; inputs[3] = lander.VelocityY; inputs[4] = lander.Enviroment.WindSpeed; // this.settings.LanderEnvironment.WindSpeed; inputs[5] = lander.Enviroment.Gravity; // varGravity; // this.settings.LanderEnvironment.Gravity; inputs[6] = lander.Fuel; output = this.neuralNet.Run(inputs); lander.Burn = output[0]; lander.Thrust = output[1]; lander.Update(); //this.settings.LanderEnvironment.Update(); } while (lander.Status == LanderStatus.Flying); this.Fitness += lander.CalculateFitness(); } //} }