protected override void Initialize() { WorldGeneration.Screen = new Rectangle(0, 0, 800, 800); WorldGeneration.NodeSize = 80; WorldGeneration.WorldGenerationType = WorldGenType.Random; WorldGeneration.Generate(); //GridNode.Weight = 5; PathFindAStar(); keyDelay = 0f; 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) { if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) { Exit(); } KeyboardState state = Keyboard.GetState(); if (IsActive) { if (keyDelay == 0f) { if (state.IsKeyDown(Keys.R)) { WorldGeneration.Generate(); PathFindAStar(); } else if (state.IsKeyDown(Keys.F11)) { showPathInfo = !showPathInfo; } else if (state.IsKeyDown(Keys.F10)) { showNodeInfo = !showNodeInfo; } else if (state.IsKeyDown(Keys.F9)) { showInvalidPath = !showInvalidPath; } keyDelay = 100f; } if (state.IsKeyDown(Keys.LeftControl)) { if (state.IsKeyDown(Keys.L)) { pfLoader = new PreFab.PreFabLoader(); pfLoader.Show(); } else if (state.IsKeyDown(Keys.S)) { pfSaver = new PreFab.PreFabSaver(); pfSaver.Show(); } } } keyDelay -= gameTime.ElapsedGameTime.Milliseconds > keyDelay ? keyDelay : gameTime.ElapsedGameTime.Milliseconds; base.Update(gameTime); }
private static void LogException(Action a) { try { a(); } catch (Exception e) { int crashNumber = System.IO.Directory.GetFiles(System.IO.Directory.GetCurrentDirectory(), "*.dat").Select(file => file.StartsWith("Crash_")).Count() + 1; PreFab.PreFabUser.Write($"Crash_{crashNumber}.dat"); System.IO.File.WriteAllText($"CrashReport_{crashNumber}.txt", e.Source + "\n\n" + e.Message); } finally { WorldGeneration.Generate(); //Program.GameT.PathFindAStar(); } }