public static void SaveGameSettings(ref GameSettings gameSettings) { Directory.CreateDirectory(FileNames.SettingsDirectory); string jsonSettings = JsonConvert.SerializeObject(gameSettings); File.WriteAllText(FileNames.GameSettings, jsonSettings); gameSettings.HasChanges = true; }
private static void CreateDefaultSettingsFile() { GameSettings defaultSettings = new GameSettings() { HasChanges = false, Scale = .5f, Resolution = new Vector2(1024, 768), ShowGlow = true }; string defaultSettingsJson = JsonConvert.SerializeObject(defaultSettings); Directory.CreateDirectory(FileNames.SettingsDirectory); File.WriteAllText(FileNames.DefaultGameSettings, defaultSettingsJson); }
public static void LoadGameSettings(ref GameSettings gameSettings) { try { Directory.CreateDirectory(FileNames.SettingsDirectory); if (!File.Exists(FileNames.GameSettings)) { FileIO.ResetGameSettings(); gameSettings.HasChanges = true; } using (StreamReader fs = File.OpenText(FileNames.GameSettings)) { JsonSerializer js = new JsonSerializer(); gameSettings = (GameSettings)js.Deserialize(fs, typeof(GameSettings)); } } catch { FileIO.ResetGameSettings(); FileIO.LoadGameSettings(ref gameSettings); } }
public IState UpdateContent(GameTime gameTime, Camera camera, ref GameSettings gameSettings) { IStateSpace nextLevel = CurrentStateSpace; nextLevel = CurrentStateSpace.UpdateSpace(gameTime, Content, Graphics, PrevKeyboardState, PrevMouseState, PrevGamepadState, camera, ref gameSettings); if (nextLevel != CurrentStateSpace && nextLevel != null) { SetStateSpace(nextLevel, camera); } if (nextLevel == null || (Keyboard.GetState().IsKeyDown(Keys.Escape) && PrevKeyboardState.IsKeyUp(Keys.Escape))) { previousState.SetPrevInput(Keyboard.GetState(), Mouse.GetState(), GamePad.GetState(PlayerIndex.One)); if(previousState.GetType().Name == "TitleState") { return new TitleState(camera, Content, Graphics, keyboardState: Keyboard.GetState()); //Fixes bug about title not rendering when you go back for some reason.. } return previousState; } PrevKeyboardState = Keyboard.GetState(); PrevMouseState = Mouse.GetState(); PrevGamepadState = GamePad.GetState(PlayerIndex.One); return this; }
public IState UpdateContent(GameTime gameTime, Camera camera, ref GameSettings gameSettings) { IStateSpace nextLevel = CurrentStateSpace; nextLevel = CurrentStateSpace.UpdateSpace(gameTime, Content, Graphics, PrevKeyboardState, PrevMouseState, PrevGamepadState, camera, ref gameSettings); if (nextLevel != CurrentStateSpace && nextLevel != null) { SetStateSpace(nextLevel, camera); } if (nextLevel == null) { return previousState; } if (Keyboard.GetState().IsKeyDown(Keys.Escape) && PrevKeyboardState.IsKeyUp(Keys.Escape)) { return new PauseState(camera, Content, Graphics, this, keyboardState: Keyboard.GetState()); } PrevKeyboardState = Keyboard.GetState(); PrevMouseState = Mouse.GetState(); PrevGamepadState = GamePad.GetState(PlayerIndex.One); return this; }
public void DrawLevel(SpriteBatch spriteBatch, GraphicsDeviceManager graphics, Camera camera, ref GameSettings gameSettings) { DisplaySystem.DrawTiles(camera, spriteBatch, dungeonGrid, dungeonDimensions, DevConstants.Grid.CellSize, dungeonSprites, dungeonColorInfo, mapToPlayer, asciiDisplay, stateSpaceComponents); DisplaySystem.DrawAIFieldOfViews(stateSpaceComponents, camera, spriteBatch, UI, DevConstants.Grid.CellSize, dungeonGrid); if(gameSettings.ShowGlow) { DisplaySystem.DrawOutlines(stateSpaceComponents, camera, spriteBatch, UI, dungeonGrid); } DisplaySystem.DrawDungeonEntities(stateSpaceComponents, camera, spriteBatch, sprites, DevConstants.Grid.CellSize, dungeonGrid, asciiDisplay, dungeonColorInfo); LabelDisplaySystem.DrawString(spriteBatch, stateSpaceComponents, messageFont, camera); }
public IStateSpace UpdateSpace(GameTime gameTime, ContentManager content, GraphicsDeviceManager graphics, KeyboardState prevKeyboardState, MouseState prevMouseState, GamePadState prevGamepadState, Camera camera, ref GameSettings gameSettings) { IStateSpace nextStateSpace = this; //Check to see if the player has died if(stateSpaceComponents.Entities.Where(x => (x.ComponentFlags & ComponentMasks.Player) == ComponentMasks.Player).Count() == 0) { //Game End, High Score, and Save Data handling } else {//Check to see if the next level needs to be loaded if (stateSpaceComponents.PlayerComponent.GoToNextFloor || Keyboard.GetState().IsKeyDown(Keys.LeftShift)) { nextStateSpace = new RandomlyGeneratedStateSpace(new CaveGeneration(), 75, 125); PlayerComponent player = stateSpaceComponents.PlayerComponent; player.GoToNextFloor = false; player.PlayerJustLoaded = true; stateSpaceComponents.PlayerComponent = player; LevelChangeSystem.RetainPlayerStatistics(stateComponents, stateSpaceComponents); LevelChangeSystem.RetainNecessaryComponents(stateComponents, stateSpaceComponents); } //Toggle Inventory Menu if (Keyboard.GetState().IsKeyDown(Keys.I) && prevKeyboardState.IsKeyUp(Keys.I) && !showObserver) { showInventory = !showInventory; } else if (Keyboard.GetState().IsKeyDown(Keys.Enter) && prevKeyboardState.IsKeyUp(Keys.Enter) && !showInventory) { //If observer exists, remove it and add input component to player(s), otherwise, remove input component from all players and create an observer. if (ObserverSystem.CreateOrDestroyObserver(stateSpaceComponents)) { showObserver = true; } else { showObserver = false; } } //Actions to complete if the inventory is open if (showInventory) { //Deletion and Cleanup if (stateSpaceComponents.EntitiesToDelete.Count > 0) { foreach (Guid entity in stateSpaceComponents.EntitiesToDelete) { stateSpaceComponents.DestroyEntity(entity); } stateSpaceComponents.EntitiesToDelete.Clear(); } showInventory = InventorySystem.HandleInventoryInput(stateSpaceComponents, gameTime, prevKeyboardState, Keyboard.GetState()); } //Actions to complete if inventory is not open if (showObserver) { ObserverComponent observer = stateSpaceComponents.ObserverComponent; observer.Observed = new List<Guid>(); stateSpaceComponents.ObserverComponent = observer; InputMovementSystem.HandleDungeonMovement(stateSpaceComponents, graphics, gameTime, prevKeyboardState, prevMouseState, prevGamepadState, camera, dungeonGrid, dungeonDimensions); CameraSystem.UpdateCamera(camera, gameTime, stateSpaceComponents, DevConstants.Grid.CellSize, prevKeyboardState); ObserverSystem.HandleObserverFindings(stateSpaceComponents, Keyboard.GetState(), prevKeyboardState, dungeonGrid); stateSpaceComponents.InvokeDelayedActions(); } else if (!showInventory && !showObserver) { //Deletion and Cleanup DestructionSystem.UpdateDestructionTimes(stateSpaceComponents, gameTime); //Non-turn-based AnimationSystem.UpdateFovColors(stateSpaceComponents, gameTime); AnimationSystem.UpdateOutlineColors(stateSpaceComponents, gameTime); MovementSystem.UpdateMovingEntities(stateSpaceComponents, gameTime); MovementSystem.UpdateIndefinitelyMovingEntities(stateSpaceComponents, gameTime); //Movement and Reaction InputMovementSystem.HandleDungeonMovement(stateSpaceComponents, graphics, gameTime, prevKeyboardState, prevMouseState, prevGamepadState, camera, dungeonGrid, dungeonDimensions); CameraSystem.UpdateCamera(camera, gameTime, stateSpaceComponents, DevConstants.Grid.CellSize, prevKeyboardState); TileSystem.RevealTiles(ref dungeonGrid, dungeonDimensions, stateSpaceComponents); TileSystem.IncreaseTileOpacity(ref dungeonGrid, dungeonDimensions, gameTime, stateSpaceComponents); MessageDisplaySystem.ScrollMessage(prevKeyboardState, Keyboard.GetState(), stateSpaceComponents); DungeonMappingSystem.ShouldPlayerMapRecalc(stateSpaceComponents, dungeonGrid, dungeonDimensions, ref mapToPlayer); //AI and Combat AISystem.AICheckDetection(stateSpaceComponents); AISystem.AIMovement(stateSpaceComponents, dungeonGrid, dungeonDimensions, mapToPlayer); InventorySystem.TryPickupItems(stateSpaceComponents, dungeonGrid); AISystem.AIUpdateVision(stateSpaceComponents, dungeonGrid, dungeonDimensions); CombatSystem.HandleMeleeCombat(stateSpaceComponents, DevConstants.Grid.CellSize); AISystem.AICheckFleeing(stateSpaceComponents); //End-Of-Turn Status Effects StatusSystem.RegenerateHealth(stateSpaceComponents); StatusSystem.ApplyBurnDamage(stateSpaceComponents, dungeonGrid); TileSystem.SpreadFire(ref dungeonGrid, dungeonDimensions, stateSpaceComponents); //Resetting Systems if (stateSpaceComponents.PlayerComponent.PlayerJustLoaded || stateSpaceComponents.PlayerComponent.PlayerTookTurn) { PlayerComponent player = stateSpaceComponents.PlayerComponent; player.PlayerJustLoaded = false; player.PlayerTookTurn = false; stateSpaceComponents.PlayerComponent = player; } CollisionSystem.ResetCollision(stateSpaceComponents); if (stateSpaceComponents.EntitiesToDelete.Count > 0) { foreach (Guid entity in stateSpaceComponents.EntitiesToDelete) { stateSpaceComponents.DestroyEntity(entity); } stateSpaceComponents.EntitiesToDelete.Clear(); } stateSpaceComponents.InvokeDelayedActions(); } } return nextStateSpace; }
public void DrawContent(SpriteBatch spriteBatch, Camera camera, ref GameSettings gameSettings) { CurrentStateSpace.DrawLevel(spriteBatch, Graphics, camera, ref gameSettings); }
public IState UpdateContent(GameTime gameTime, Camera camera, ref GameSettings gameSettings) { IState nextState = this; KeyboardState keyState = Keyboard.GetState(); if (keyState.IsKeyDown(Keys.Escape) && PrevKeyboardState.IsKeyUp(Keys.Escape)) { nextState = previousState; nextState.SetPrevInput(Keyboard.GetState(), Mouse.GetState(), GamePad.GetState(PlayerIndex.One)); } else if (keyState.IsKeyDown(Keys.Up) && PrevKeyboardState.IsKeyUp(Keys.Up)) { optionSelection -= 1; if (optionSelection < 0) { optionSelection = optionsAmount - 1; } if (optionSelection >= optionsAmount) { optionSelection = 0; } while (!menuOptions[optionSelection].Enabled) { optionSelection -= 1; } } else if (keyState.IsKeyDown(Keys.Down) && PrevKeyboardState.IsKeyUp(Keys.Down)) { optionSelection += 1; if (optionSelection < 0) { optionSelection = optionsAmount - 1; } if (optionSelection >= optionsAmount) { optionSelection = 0; } while (!menuOptions[optionSelection].Enabled) { optionSelection += 1; } } else if (keyState.IsKeyDown(Keys.Enter) && PrevKeyboardState.IsKeyUp(Keys.Enter)) { switch (optionSelection) { case (int)Options.OPTIONS: GameSettingsMenuStateSpace nextStateSpace = new GameSettingsMenuStateSpace(ref gameSettings); nextState = new MenuState(nextStateSpace, camera, Content, Graphics, this, keyboardState: Keyboard.GetState()); break; case (int)Options.SAVE_TITLE: FileIO.SaveDungeonData(((PlayingState)previousState).GetSaveData()); nextState = new TitleState(camera, Content, Graphics, Mouse.GetState(), GamePad.GetState(PlayerIndex.One), keyState); break; case (int)Options.UNPAUSE: nextState = previousState; nextState.SetPrevInput(Keyboard.GetState(), Mouse.GetState(), GamePad.GetState(PlayerIndex.One)); break; } } PrevKeyboardState = Keyboard.GetState(); PrevMouseState = Mouse.GetState(); PrevGamepadState = GamePad.GetState(PlayerIndex.One); return nextState; }
public void DrawContent(SpriteBatch spriteBatch, Camera camera, ref GameSettings gameSettings) { //Ain't nothing here }
public GameSettingsMenuStateSpace(ref GameSettings gameSettings) { this.gameSettings = gameSettings; }
public void DrawLevel(SpriteBatch spriteBatch, GraphicsDeviceManager graphics, Camera camera, ref GameSettings gameSettings) { //Nothing here }
public IStateSpace UpdateSpace(GameTime gameTime, ContentManager content, GraphicsDeviceManager graphics, KeyboardState prevKeyboardState, MouseState prevMouseState, GamePadState prevGamepadState, Camera camera, ref GameSettings gameSettings) { IStateSpace nextSpace = this; KeyboardState keyState = Keyboard.GetState(); if (keyState.IsKeyDown(Keys.Escape) && prevKeyboardState.IsKeyUp(Keys.Escape)) { nextSpace = null; } else if (keyState.IsKeyDown(Keys.Up) && prevKeyboardState.IsKeyUp(Keys.Up)) { optionSelection -= 1; if (optionSelection < 0) { optionSelection = optionsAmount - 1; } if (optionSelection >= optionsAmount) { optionSelection = 0; } } else if (keyState.IsKeyDown(Keys.Down) && prevKeyboardState.IsKeyUp(Keys.Down)) { optionSelection += 1; if (optionSelection < 0) { optionSelection = optionsAmount - 1; } if (optionSelection >= optionsAmount) { optionSelection = 0; } } else if (keyState.IsKeyDown(Keys.Left) && prevKeyboardState.IsKeyUp(Keys.Left) && menuOptions[optionSelection].OptionsCollection != null) { menuOptions[optionSelection].Selection -= 1; if (menuOptions[optionSelection].Selection < 0) { menuOptions[optionSelection].Selection = menuOptions[optionSelection].OptionsCollection.Count - 1; } if (menuOptions[optionSelection].Selection >= menuOptions[optionSelection].OptionsCollection.Count) { menuOptions[optionSelection].Selection = 0; } } else if (keyState.IsKeyDown(Keys.Right) && prevKeyboardState.IsKeyUp(Keys.Right) && menuOptions[optionSelection].OptionsCollection != null) { menuOptions[optionSelection].Selection += 1; if (menuOptions[optionSelection].Selection < 0) { menuOptions[optionSelection].Selection = menuOptions[optionSelection].OptionsCollection.Count - 1; } if (menuOptions[optionSelection].Selection >= menuOptions[optionSelection].OptionsCollection.Count) { menuOptions[optionSelection].Selection = 0; } } else if (keyState.IsKeyDown(Keys.Enter) && prevKeyboardState.IsKeyUp(Keys.Enter)) { switch (optionSelection) { case (int)Options.SAVE_CHANGES: gameSettings.Resolution = (Vector2)menuOptions[(int)Options.RESOLUTION].OptionsCollection[menuOptions[(int)Options.RESOLUTION].Selection]; gameSettings.Scale = (float)menuOptions[(int)Options.GRAPHICS_SCALE].OptionsCollection[menuOptions[(int)Options.GRAPHICS_SCALE].Selection]; gameSettings.Borderless = (bool)menuOptions[(int)Options.BORDERLESS].OptionsCollection[menuOptions[(int)Options.BORDERLESS].Selection]; gameSettings.ShowGlow = (bool)menuOptions[(int)Options.GLOW_FILTER].OptionsCollection[menuOptions[(int)Options.GLOW_FILTER].Selection]; gameSettings.Vsync = (bool)menuOptions[(int)Options.VSYNC].OptionsCollection[menuOptions[(int)Options.VSYNC].Selection]; FileIO.SaveGameSettings(ref gameSettings); nextSpace = null; break; case (int)Options.RESTORE_DEFAULTS: FileIO.ResetGameSettings(); FileIO.LoadGameSettings(ref gameSettings); nextSpace = new GameSettingsMenuStateSpace(ref gameSettings); break; case (int)Options.CANCEL: nextSpace = null; break; } } return nextSpace; }
public IState UpdateContent(GameTime gameTime, Camera camera, ref GameSettings gameSettings) { camera.Position = Vector2.Zero; camera.Target = Vector2.Zero; IState nextState = this; KeyboardState keyState = Keyboard.GetState(); if (keyState.IsKeyDown(Keys.Up) && PrevKeyboardState.IsKeyUp(Keys.Up)) { optionSelection -= 1; if (optionSelection < 0) { optionSelection = optionsAmount - 1; } if (optionSelection >= optionsAmount) { optionSelection = 0; } while (!menuOptions[optionSelection].Enabled) { optionSelection -= 1; } } else if (keyState.IsKeyDown(Keys.Down) && PrevKeyboardState.IsKeyUp(Keys.Down)) { optionSelection += 1; if (optionSelection < 0) { optionSelection = optionsAmount - 1; } if (optionSelection >= optionsAmount) { optionSelection = 0; } while (!menuOptions[optionSelection].Enabled) { optionSelection += 1; } } else if (keyState.IsKeyDown(Keys.Enter) && PrevKeyboardState.IsKeyUp(Keys.Enter)) { switch (optionSelection) { case (int)Options.NEW_GAME: RandomlyGeneratedStateSpace nextStateSpace = new RandomlyGeneratedStateSpace(new CaveGeneration(), 75, 125); nextState = new PlayingState(nextStateSpace, camera, Content, Graphics, this, keyboardState: keyState); break; case (int)Options.LOAD_GAME: RandomlyGeneratedStateSpace nextSpace = new RandomlyGeneratedStateSpace(DungeonInfo); nextState = new PlayingState(nextSpace, camera, Content, Graphics, saveInfo: DungeonInfo, keyboardState: keyState); break; case (int)Options.OPTIONS: GameSettingsMenuStateSpace nextMenu = new GameSettingsMenuStateSpace(ref gameSettings); nextState = new MenuState(nextMenu, camera, Content, Graphics, this, keyboardState: keyState); break; case (int)Options.QUIT_GAME: nextState = previousState; break; } } PrevKeyboardState = Keyboard.GetState(); PrevMouseState = Mouse.GetState(); PrevGamepadState = GamePad.GetState(PlayerIndex.One); return nextState; }