Exemple #1
0
        public IState UpdateState(ref GameSettings gameSettings, GameTime gameTime, Camera camera, KeyboardState currentKey, KeyboardState prevKey, MouseState currentMouse, MouseState prevMouse)
        {
            Guid playerId = this._components.Entities.Where(c => c.HasComponents(ComponentFlags.IS_PLAYER)).FirstOrDefault().Id;

            // Level input
            if (currentKey.IsKeyDown(Keys.Escape) && prevKey.IsKeyUp(Keys.Escape))
            {
                return(new PauseState(this._content, this));
            }
            if (currentKey.IsKeyDown(Keys.Q) && prevKey.IsKeyUp(Keys.Q))
            {
                return(new TestLevel(this._content, camera));
            }

            if (currentKey.IsKeyDown(Keys.F) && prevKey.IsKeyUp(Keys.F))
            {
                this._components.DelayedActions.Add(new Action(() =>
                {
                    for (int i = 0; i < 10; i++)
                    {
                        Guid testId = ArkCreation.SpawnEntityWithOverrides(Constants.Ark.Monsters.TestNpc, ref this._components, new BaseEntity(ComponentFlags.POSITION)
                        {
                            Position = new Position()
                            {
                                OriginPosition = new Vector2(Constants.Random.Next(20, this._gridCols * 48), Constants.Random.Next(0, this._gridRows * 48))
                            }
                        });
                        InventorySystem.GenerateRandomInventoryItemsForEntity(this._components, testId);
                    }
                }));
            }
            if (currentKey.IsKeyDown(Keys.E) && prevKey.IsKeyUp(Keys.E))
            {
                this._components.DelayedActions.Add(new Action(() =>
                {
                    Guid testId = ArkCreation.SpawnEntityWithOverrides(Constants.Ark.Monsters.TestNpc, ref this._components, new BaseEntity(ComponentFlags.POSITION)
                    {
                        Position = new Position()
                        {
                            OriginPosition = this._components.Positions[playerId].OriginPosition
                        }
                    });
                    InventorySystem.GenerateRandomInventoryItemsForEntity(this._components, testId);
                }));
            }
            if (currentKey.IsKeyDown(Keys.R) && prevKey.IsKeyUp(Keys.R))
            {
                this._components.DelayedActions.Add(new Action(() =>
                {
                    Guid id = this._components.Entities.Where(x => x.HasDrawableSprite() && !x.HasComponents(ComponentFlags.IS_PLAYER) && x.HasComponents(ComponentFlags.INVENTORY)).First().Id;
                    InventorySystem.DropEntityInventory(this._components, id);
                    this._components.DestroyEntity(id);
                }));
            }

            // Camera Updates
            CameraSystem.ControlCamera(currentKey, prevKey, camera, gameTime);
            CameraSystem.PanCamera(camera, gameTime);

            // Entity Movement Updates
            this._components.Entities.ForEach(c =>
            {
                if (c.IsMovable())
                {
                    switch (this._components.Movements[c.Id].MovementType)
                    {
                    case MovementType.AI:
                        //AI Movement System Call
                        break;

                    case MovementType.INPUT:
                        MovementSystem.InputMovement(currentKey, prevKey, gameTime, this._components.Positions[c.Id], this._components.Movements[c.Id]);
                        break;

                    case MovementType.DIRECTED:
                        MovementSystem.UpdateMovingEntities(this._components.Movements[c.Id], this._components.Positions[c.Id], gameTime, this._components, c);
                        break;
                    }
                }
            });

            // Entity Information Updates
            // Collision
            CollisionSystem.CheckForCollisions(this._components, this._collisionPartition);
            CollisionSystem.HandleCollisions(this._components);

            // Set up for next frame
            CameraSystem.UpdateCameraTarget(this._components, camera);
            CollisionSystem.ResetCollisions(ref this._components);
            this._components.InvokeDelayedActions();

            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);
        }