Exemple #1
0
        public PlayState(Map battleMap)
        {
            allies = Character.createTestAllies(5, battleMap);
            enemies = Character.createTestEnemies(5, battleMap); //create teams of characters
            allCharacters = new List<Character>(0);
            allCover = Cover.createTestCover(battleMap);

            allCharacters.AddRange(allies);
            allCharacters.AddRange(enemies);
            moveableSpaces = new MoveableSpacesTileSet();

            currentMap = battleMap;

            playerTurn = true;

            playMode = Mode.moving;
        }
Exemple #2
0
        /// <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)
        {
            currentControlState.keyState = Keyboard.GetState();

            MouseState mouseState = Mouse.GetState();

            mousePosition = new Point(mouseState.X, mouseState.Y);

            currentControlState.mouseState = mouseState;

            for (int x = 1; x < mapWidth; x++)
            {
                for (int y = 1; y < mapHeight; y++)
                {
                    Tile currentTile = battleMap.tiles[x, y];
                    Rectangle currentSourceRect = Tile.getSourceRect();

                    int xOrigin = ((x * (Tile.width / 2)) + ((y - 1) * (Tile.width / 2)) + (int)gameCamera.cameraLocation.X);
                    int yOrigin = ((y * (Tile.height / 2)) - ((x - 1) * Tile.height / 2) + (int)gameCamera.cameraLocation.Y);
                    int drawWidth = Tile.width;
                    int drawHeight = Tile.height;

                    Rectangle thisTileRect = new Rectangle(xOrigin, yOrigin, drawWidth, drawHeight);

                    if (thisTileRect.Contains(mousePosition) && moveableSpaces.containsTile(currentTile))
                    {
                        Tile potentialHoveredTile = Controls.getCursorCurrentTile(currentTile, battleMap, mousePosition, thisTileRect);

                        if (potentialHoveredTile != null && moveableSpaces.containsTile(potentialHoveredTile))
                        {
                            currentControlState.hoveredTile = Controls.getCursorCurrentTile(currentTile, battleMap, mousePosition, thisTileRect);
                        }
                    }
                }
            }

            //if an ally is moving, move them!
            foreach (Character character in allCharacters)
            {
                if (character.state == charState.moveing)
                {
                    CharacterMovement.PerformCharacterMovement(character);
                }
            }

            if ((oldControlState.hoveredTile != currentControlState.hoveredTile) && (currentControlState.hoveredTile != null))
            {
                currentPath = Pathfinding.shortestPath(battleMap, battleMap.tiles[(int)currentlySelectedChar.position.X, (int)currentlySelectedChar.position.Y], battleMap.tiles[currentControlState.hoveredTile.xPos, currentControlState.hoveredTile.yPos]);
            } else if(currentControlState.hoveredTile == null)
            {
                currentPath = null;
            }

            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
                Exit();

            if (currentControlState.keyState.IsKeyDown(Keys.Left))
            {
                //increment x
                gameCamera.cameraLocation.X = MathHelper.Clamp(gameCamera.cameraLocation.X + 4, 0 - Map.mapBuffer - battleMap.mapWidthInPixels(), 0 + Map.mapBuffer);
            }

            if (currentControlState.keyState.IsKeyDown(Keys.Right))
            {
                //decrement x
                gameCamera.cameraLocation.X = MathHelper.Clamp(gameCamera.cameraLocation.X - 4, 0 - Map.mapBuffer - battleMap.mapWidthInPixels(), 0 + Map.mapBuffer);
            }

            if (currentControlState.keyState.IsKeyDown(Keys.Up))
            {
                //increment y
                gameCamera.cameraLocation.Y = MathHelper.Clamp(gameCamera.cameraLocation.Y + 4, 0 - Map.mapBuffer, 0 + Map.mapBuffer);
            }

            if (currentControlState.keyState.IsKeyDown(Keys.Down))
            {
                //decrement y
                gameCamera.cameraLocation.Y = MathHelper.Clamp(gameCamera.cameraLocation.Y - 4, 0 - Map.mapBuffer, 0 + Map.mapBuffer);
            }

            if (currentControlState.keyState.IsKeyDown(Keys.Tab) && oldControlState.keyState.IsKeyUp(Keys.Tab))
            {
                //determine if any characters are currently selected. If they are, select the one after them in [allies], and de-select the current one.
                //if none are selected, select allies[0]
                currentlySelectedChar = Character.selectNextCharacter(allies);
                Camera.panToCharacter(currentlySelectedChar, gameCamera, battleMap, graphics);
                moveableSpaces = Pathfinding.moveableSpaces(battleMap, currentlySelectedChar);

                //List<Tile> path = Pathfinding.shortestPath(battleMap, battleMap.tiles[(int)nextCharacter.position.X, (int)nextCharacter.position.Y], battleMap.tiles[8, 9]);
            }

            if (currentPath != null)
            {
                if (currentControlState.mouseState.LeftButton == ButtonState.Pressed && oldControlState.mouseState.LeftButton == ButtonState.Released)
                {
                    CharacterMovement.setCharMovement(currentlySelectedChar, currentPath); //calculate current character movement path and execute movement, if the current character doesnt have one.
                }
            }

            if (currentControlState.keyState.IsKeyDown(Keys.X))
                gameCamera.cameraLocation = Vector2.Zero;
            // Check the state and location of the mouse - act accordingly

            oldControlState.keyState = currentControlState.keyState;
            oldControlState.hoveredTile = currentControlState.hoveredTile;
            oldControlState.mouseState = currentControlState.mouseState;
            //oldControlState = currentControlState;

            base.Update(gameTime);
        }
Exemple #3
0
        public static MoveableSpacesTileSet moveableSpaces(Map map, Character selectedCharacter)
        {
            List<Tile> checkedTiles = new List<Tile>();
            MoveableSpacesTileSet tileSet = new MoveableSpacesTileSet();
            List<Tile> tilesToCheckThisLevel = new List<Tile>();
            List<Tile> tilesToCheckNextLevel = new List<Tile>();

            int startingTileX = (int)selectedCharacter.position.X;
            int startingTileY = (int)selectedCharacter.position.Y;
            int maxMoves = (2 * selectedCharacter.stats.movement) + 1;

            Tile startingTile = map.tiles[startingTileX, startingTileY];

            tilesToCheckThisLevel.Add(startingTile);

            for (int dist = 0; dist < maxMoves; dist++)
            {
                foreach(Tile tile in tilesToCheckThisLevel.ToList())
                {
                    List<Tile> adjacentUncheckedTiles = getAdjacentUncheckedTiles(tile, map, checkedTiles);

                    checkedTiles.Add(tile);
                    tileSet.AllMoveableTiles.Add(tile);

                    if (dist <= selectedCharacter.stats.movement){
                        tileSet.FirstMoveMoveableTiles.Add(tile);
                    } else {
                        tileSet.SecondMoveMoveableTiles.Add(tile);
                    }

                    tilesToCheckNextLevel.AddRange(adjacentUncheckedTiles);
                    tilesToCheckThisLevel.Remove(tile); //remove the one we just checked. No need to check it again.
                }

                //level complete
                tilesToCheckThisLevel = tilesToCheckNextLevel;
                tilesToCheckNextLevel = new List<Tile>();

            }

            return tileSet;
        }