/// <summary> /// Must construct with a state space and a piece of application data /// </summary> /// <param name="_stateSpace">The state space that this node belongs to</param> /// <param name="_data">The application data represented by this node</param> public StateNode(IStateSpace _stateSpace, TData _data) { StateSpace = _stateSpace ?? throw new ArgumentNullException("Cannot create a StateNode with a NULL state space"); Data = _data ?? throw new ArgumentNullException("Cannot create a StateNode with NULL data"); ResetState(); }
public IStateSpace UpdateLevel(GameTime gameTime, ContentManager content, GraphicsDeviceManager graphics, KeyboardState prevKeyboardState, MouseState prevMouseState, GamePadState prevGamepadState, Camera camera) { if (stateSpaceComponents.EntitiesToDelete.Count > 0) { foreach (Guid entity in stateSpaceComponents.EntitiesToDelete) { stateSpaceComponents.DestroyEntity(entity); } } IStateSpace nextStateSpace = this; #region Debug changing levels if (Keyboard.GetState().IsKeyDown(Keys.Enter) && !prevKeyboardState.IsKeyDown(Keys.Enter)) { nextStateSpace = new RandomlyGeneratedStateSpace(new CaveGeneration(), 75, 125); } if (Mouse.GetState().RightButton == ButtonState.Pressed) { camera.Target = Vector2.Transform(Mouse.GetState().Position.ToVector2(), camera.GetInverseMatrix()); camera.AttachedToPlayer = false; } if (Keyboard.GetState().IsKeyDown(Keys.R)) { camera.AttachedToPlayer = true; } #endregion InputMovementSystem.HandleDungeonMovement(stateSpaceComponents, graphics, gameTime, prevKeyboardState, prevMouseState, prevGamepadState, camera, dungeonGrid); TileRevealSystem.RevealTiles(dungeonGrid, dungeonDimensions, stateSpaceComponents); UpdateCamera(camera, gameTime); stateSpaceComponents.EntitiesToDelete.Clear(); return(nextStateSpace); }
public PlayingState(IStateSpace space, Camera camera, ContentManager content, GraphicsDeviceManager graphics, MouseState mouseState = new MouseState(), GamePadState gamePadState = new GamePadState(), KeyboardState keyboardState = new KeyboardState()) { this.Content = new ContentManager(content.ServiceProvider, "Content"); Graphics = graphics; PrevMouseState = mouseState; PrevGamepadState = gamePadState; PrevKeyboardState = keyboardState; SetStateSpace(space, camera); }
public void SetStateSpace(IStateSpace stateSpace, Camera camera, bool createEntities = true) { if (Content != null && stateSpace != null) { Content.Unload(); CurrentStateSpace = stateSpace; stateSpace.LoadLevel(Content, Graphics, camera, StateComponents, createEntities); } }
public void SetStateSpace(IStateSpace stateSpace, Camera camera) { if (Content != null && stateSpace != null) { Content.Unload(); CurrentLevel = stateSpace; stateSpace.LoadLevel(Content, Graphics, camera); } }
public void SetStateSpace(IStateSpace stateSpace, Camera camera, bool createEntities = true) { if (Content != null && stateSpace != null) { Content.Unload(); CurrentStateSpace = stateSpace; stateSpace.LoadLevel(Content, Graphics, camera, StateComponents); } }
public MenuState(IStateSpace space, Camera camera, ContentManager content, GraphicsDeviceManager graphics, IState prevState = null, MouseState mouseState = new MouseState(), GamePadState gamePadState = new GamePadState(), KeyboardState keyboardState = new KeyboardState(), DungeonInfo saveInfo = null) { this.Content = new ContentManager(content.ServiceProvider, "Content"); Graphics = graphics; PrevMouseState = mouseState; PrevGamepadState = gamePadState; PrevKeyboardState = keyboardState; StateComponents = saveInfo == null ? new StateComponents() : saveInfo.stateComponents; SetStateSpace(space, camera, saveInfo == null); previousState = prevState; }
public PlayingState(IStateSpace space, Camera camera, ContentManager content, GraphicsDeviceManager graphics, IState prevState = null, MouseState mouseState = new MouseState(), GamePadState gamePadState = new GamePadState(), KeyboardState keyboardState = new KeyboardState(), DungeonInfo saveInfo = null) { this.Content = new ContentManager(content.ServiceProvider, "Content"); Graphics = graphics; PrevMouseState = mouseState; PrevGamepadState = gamePadState; PrevKeyboardState = keyboardState; SkillLevelsComponent newPlayerStats = new SkillLevelsComponent() { CurrentHealth = 100, Health = 100, Accuracy = 100, Defense = 10, Wealth = 0, MinimumDamage = 1, MaximumDamage = 3, DieNumber = 1 }; StateComponents = saveInfo == null ? new StateComponents() { PlayerSkillLevels = newPlayerStats } : saveInfo.stateComponents; SetStateSpace(space, camera, saveInfo == null); previousState = prevState; }
public IState UpdateContent(GameTime gameTime, Camera camera) { IStateSpace nextLevel = CurrentLevel; nextLevel = CurrentLevel.UpdateLevel(gameTime, Content, Graphics, PrevKeyboardState, PrevMouseState, PrevGamepadState, camera); if (nextLevel != CurrentLevel && nextLevel != null) { SetStateSpace(nextLevel, camera); } if (nextLevel == null) { return(null); } PrevKeyboardState = Keyboard.GetState(); PrevMouseState = Mouse.GetState(); PrevGamepadState = GamePad.GetState(PlayerIndex.One); return(this); }
/// <summary> /// The AStar algorithm implementation /// </summary> /// <param name="p_stateSpace">The state space to explore</param> /// <returns>TRUE if a path was found, FALSE if not</returns> public IStateNode GeneratePath(IStateSpace p_stateSpace) { if (p_stateSpace == null) { throw new InvalidOperationException("Cannot generate a path with a NULL state space"); } p_stateSpace.ResetPath(); m_openList.Clear(); var node = p_stateSpace.GetStartState(); if (node == null) { throw new InvalidOperationException("The state space did not return a valid Start State"); } node.ActualCostFromStart = 0; m_openList.Add(node); while (m_openList.Count > 0) { var state = m_openList.RemoveLowest(); state.IsClosed = true; if (p_stateSpace.IsGoalState(state)) { return(state); } foreach (var sp in p_stateSpace.Successors(state)) { if (!sp.IsClosed) { UpdateCell(state, sp, p_stateSpace); } } } return(null); // no path found }
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 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 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 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); }
/// <summary> /// A state node has not yet been evaluated, so test it using the "current" path and /// update its values if its a shorter path /// </summary> /// <param name="p_current">The node being evaluated</param> /// <param name="p_successor"> /// A successor to that node that needs to be checked for update /// </param> /// <param name="p_stateSpace">The state space governing the algorithm</param> protected virtual void UpdateCell(IStateNode p_current, IStateNode p_successor, IStateSpace p_stateSpace) { var deltaCost = p_stateSpace.FnCalculateActualCost(p_current, p_successor); // If its actually shorter to get to this node from the current node if (p_current.ActualCostFromStart + deltaCost < p_successor.ActualCostFromStart) { // Update the node's information to reflect its new position in the path p_successor.ActualCostFromStart = p_current.ActualCostFromStart + deltaCost; p_successor.Parent = p_current; m_openList.Update(p_successor); // Will "Add" or "Update" depending on whether or not its in the queue } }
public void SetStateSpace(IStateSpace stateSpace, Camera camera, bool createEntities = true) { //Nothing here. }