Esempio n. 1
0
    // Create a wall
    // (x, y) is the coordinate of the tile
    // direction is the direction from the tile where the wall should be created
    public void CreateWall(int x, int y, int direction)
    {
        TileClass   tile      = GetTileAtCoordinate(x, y).GetComponent <TileClass>();
        TileClass   otherTile = null;
        GameObject  obj;
        ObjectStore objStore = Camera.main.GetComponent <ObjectStore>();
        GameObject  wall;
        float       wallX = x;
        float       wallY = y;

        switch (direction)
        {
        case TileClass.NORTH:
            obj = GetTileAtCoordinate(x, y + 1);
            if (obj)
            {
                otherTile = obj.GetComponent <TileClass>();
            }
            if (!tile.HasWall(TileClass.NORTH) && otherTile != null && !otherTile.HasWall(TileClass.SOUTH))
            {
                wallY += 0.5f;
                wall   = objStore.CreateHorizontalWall(wallX, wallY);
                tile.SetWall(TileClass.NORTH, wall);
                otherTile.SetWall(TileClass.SOUTH, wall);
            }
            break;

        case TileClass.EAST:
            obj = GetTileAtCoordinate(x + 1, y);
            if (obj)
            {
                otherTile = obj.GetComponent <TileClass>();
            }
            if (!tile.HasWall(TileClass.EAST) && otherTile != null && !otherTile.HasWall(TileClass.WEST))
            {
                wallX -= 0.5f;
                wall   = objStore.CreateVerticalWall(wallX, wallY);
                tile.SetWall(TileClass.EAST, wall);
                otherTile.SetWall(TileClass.WEST, wall);
            }
            break;

        case TileClass.SOUTH:
            obj = GetTileAtCoordinate(x, y - 1);
            if (obj)
            {
                otherTile = obj.GetComponent <TileClass>();
            }
            if (!tile.HasWall(TileClass.SOUTH) && otherTile != null && !otherTile.HasWall(TileClass.NORTH))
            {
                wallY -= 0.5f;
                wall   = objStore.CreateHorizontalWall(wallX, wallY);
                tile.SetWall(TileClass.SOUTH, wall);
                otherTile.SetWall(TileClass.NORTH, wall);
            }
            break;

        case TileClass.WEST:
            obj = GetTileAtCoordinate(x - 1, y);
            if (obj)
            {
                otherTile = obj.GetComponent <TileClass>();
            }
            if (!tile.HasWall(TileClass.WEST) && otherTile != null && !otherTile.HasWall(TileClass.EAST))
            {
                wallX += 0.5f;
                wall   = objStore.CreateVerticalWall(wallX, wallY);
                tile.SetWall(TileClass.WEST, wall);
                otherTile.SetWall(TileClass.EAST, wall);
            }
            break;
        }
    }