Exemplo n.º 1
0
    public GameObject GiveNeighbourGameObject(int posX, int posY, Character.Directions direction)
    {
        switch (direction)
        {
        case Character.Directions.up:
            if (charactersMap[posY + 1][posX] != null)
            {
                return(charactersMap[posY + 1][posX].gameObject);
            }
            return(tileMap[posY + 1][posX].gameObject);

        case Character.Directions.down:
            if (charactersMap[posY - 1][posX] != null)
            {
                return(charactersMap[posY - 1][posX].gameObject);
            }
            return(tileMap[posY - 1][posX].gameObject);

        case Character.Directions.right:
            if (charactersMap[posY][posX + 1] != null)
            {
                return(charactersMap[posY][posX + 1].gameObject);
            }
            return(tileMap[posY][posX + 1].gameObject);

        case Character.Directions.left:
            if (charactersMap[posY][posX - 1] != null)
            {
                return(charactersMap[posY][posX - 1].gameObject);
            }
            return(tileMap[posY][posX - 1].gameObject);

        default: return(tileMap[posY][posX].gameObject);
        }
    }
Exemplo n.º 2
0
    public Tile GiveNeighbourTile(int posX, int posY, Character.Directions direction)
    {
        switch (direction)
        {
        case Character.Directions.up: return(tileMap[posY - 1][posX]);

        case Character.Directions.down: return(tileMap[posY + 1][posX]);

        case Character.Directions.right: return(tileMap[posY][posX + 1]);

        case Character.Directions.left: return(tileMap[posY][posX - 1]);

        default: return(tileMap[posY][posX]);
        }
    }
        public static List <Character.Directions> checkIfOneOfDoubleDirectionsIsOk(RogueSharp.Cell currentCell, Character.Directions currentDirection, Level level, GraphicsDevice graphicsDevice)
        {
            List <Character.Directions> dirList = new List <Character.Directions>(2);

            if (currentDirection == Character.Directions.TopLeft)
            {
                Character.Directions top  = Character.Directions.Top;
                Character.Directions left = Character.Directions.Left;

                if (!checkCollisionInGivenCell(getCellFromDirection(currentCell, top, level), level, graphicsDevice))
                {
                    dirList.Add(top);
                }
                if (!checkCollisionInGivenCell(getCellFromDirection(currentCell, left, level), level, graphicsDevice))
                {
                    dirList.Add(left);
                }

                return(dirList);
            }

            if (currentDirection == Character.Directions.TopRight)
            {
                Character.Directions top   = Character.Directions.Top;
                Character.Directions right = Character.Directions.Right;

                if (!checkCollisionInGivenCell(getCellFromDirection(currentCell, top, level), level, graphicsDevice))
                {
                    dirList.Add(top);
                }
                if (!checkCollisionInGivenCell(getCellFromDirection(currentCell, right, level), level, graphicsDevice))
                {
                    dirList.Add(right);
                }

                return(dirList);
            }

            if (currentDirection == Character.Directions.BottomLeft)
            {
                Character.Directions bottom = Character.Directions.Bottom;
                Character.Directions left   = Character.Directions.Left;

                if (!checkCollisionInGivenCell(getCellFromDirection(currentCell, bottom, level), level, graphicsDevice))
                {
                    dirList.Add(bottom);
                }
                if (!checkCollisionInGivenCell(getCellFromDirection(currentCell, left, level), level, graphicsDevice))
                {
                    dirList.Add(left);
                }

                return(dirList);
            }

            if (currentDirection == Character.Directions.BottomRight)
            {
                Character.Directions bottom = Character.Directions.Bottom;
                Character.Directions right  = Character.Directions.Right;

                if (!checkCollisionInGivenCell(getCellFromDirection(currentCell, bottom, level), level, graphicsDevice))
                {
                    dirList.Add(bottom);
                }
                if (!checkCollisionInGivenCell(getCellFromDirection(currentCell, right, level), level, graphicsDevice))
                {
                    dirList.Add(right);
                }

                return(dirList);
            }
            return(dirList);
        }
        public static RogueSharp.Cell getCellFromDirection(RogueSharp.Cell currentCell, Character.Directions currentDirection, Level level)
        {
            if (currentDirection == Character.Directions.Top)
            {
                return(level.map.GetCell(currentCell.X, currentCell.Y - 1));
            }

            if (currentDirection == Character.Directions.Bottom)
            {
                return(level.map.GetCell(currentCell.X, currentCell.Y + 1));
            }

            if (currentDirection == Character.Directions.Left)
            {
                return(level.map.GetCell(currentCell.X - 1, currentCell.Y));
            }

            if (currentDirection == Character.Directions.Right)
            {
                return(level.map.GetCell(currentCell.X + 1, currentCell.Y));
            }

            if (currentDirection == Character.Directions.TopLeft)
            {
                return(level.map.GetCell(currentCell.X - 1, currentCell.Y - 1));
            }

            if (currentDirection == Character.Directions.TopRight)
            {
                return(level.map.GetCell(currentCell.X + 1, currentCell.Y - 1));
            }

            if (currentDirection == Character.Directions.BottomLeft)
            {
                return(level.map.GetCell(currentCell.X - 1, currentCell.Y + 1));
            }

            if (currentDirection == Character.Directions.BottomRight)
            {
                return(level.map.GetCell(currentCell.X + 1, currentCell.Y + 1));
            }

            return(null);
        }
Exemplo n.º 5
0
    /*
     * returns:
     * 0-passable
     * 1-not passable-wall
     * 2-not passable-enemy/special item
     * 3-not passable-hero
     * */
    public int IsTilePassable(int posX, int posY, Character.Directions direction)
    {
        switch (direction)
        {
        case Character.Directions.up:
            if (!tileMap[posY + 1][posX].isPassable)
            {
                return(1);
            }
            else if (charactersMap[posY + 1][posX] != null)
            {
                if (charactersMap[posY + 1][posX] is PlayerCharacter)
                {
                    return(3);
                }
                else
                {
                    return(2);
                }
            }
            return(0);

        case Character.Directions.down:
            if (!tileMap[posY - 1][posX].isPassable)
            {
                return(1);
            }
            else if (charactersMap[posY - 1][posX] != null)
            {
                if (charactersMap[posY - 1][posX] is PlayerCharacter)
                {
                    return(3);
                }
                else
                {
                    return(2);
                }
            }
            return(0);

        case Character.Directions.right:
            if (!tileMap[posY][posX + 1].isPassable)
            {
                return(1);
            }
            else if (charactersMap[posY][posX + 1] != null)
            {
                if (charactersMap[posY][posX + 1] is PlayerCharacter)
                {
                    return(3);
                }
                else
                {
                    return(2);
                }
            }
            return(0);

        case Character.Directions.left:
            if (!tileMap[posY][posX - 1].isPassable)
            {
                return(1);
            }
            else if (charactersMap[posY][posX - 1] != null)
            {
                if (charactersMap[posY][posX - 1] is PlayerCharacter)
                {
                    return(3);
                }
                else
                {
                    return(2);
                }
            }
            return(0);

        default: return(1);
        }
    }