Ejemplo n.º 1
0
 Tile TypeToTile(MapTile.TileType type)
 {
     if (type == MapTile.TileType.Ground)
     {
         return(GroundTile);
     }
     return(WallTile);
 }
Ejemplo n.º 2
0
        public static char EncodeTileImpl(MapTile.TileType tileType, MovingObject.ObjectType objectType)
        {
            char result;

            result  = (char)tileType;
            result |= (char)((int)objectType << 3);
            return(encodingChars[result]);
        }
Ejemplo n.º 3
0
    void UpdateMapTiles()
    {
        rooms.Sort();
        rooms.Reverse();
        for (int i = 0; i < rooms.Count; i++)
        {
            Vector2    position   = rooms[i].position;
            LayoutType layoutType = rooms[i].layoutType;

            for (int x = 0; x < rooms[i].length; x++)
            {
                for (int y = 0; y < rooms[i].height; y++)
                {
                    MapTile.TileType tileType = MapTile.TileType.Floor;
                    if (x == 0 || x == rooms[i].length - 1 || y == 0 || y == rooms[i].height - 1)
                    {
                        tileType = MapTile.TileType.Wall;
                    }

                    MapTile test = mapTiles[new Vector2(x, y) + position];
                    test.layoutType = layoutType;
                    test.tileType   = tileType;
                    mapTiles[new Vector2(x, y) + position] = test;
                    //MapTile newTile = new MapTile(tileType, layoutType, new Vector2(x, y) + position);
                    //mapTiles[new Vector2(x, y) + position] = newTile;
                }
            }
        }

        //Create neighbour lists.
        for (int x = 0; x < mLength; x++)
        {
            for (int y = 0; y < mHeight; y++)
            {
                Vector2 position = new Vector2(x, y);
                MapTile newTile  = mapTiles[position];

                if (x > 0)
                {
                    newTile.neighbours.Add(mapTiles[position + Vector2.left]);
                }
                if (x < mLength - 1)
                {
                    newTile.neighbours.Add(mapTiles[position + Vector2.right]);
                }
                if (y > 0)
                {
                    newTile.neighbours.Add(mapTiles[position + Vector2.down]);
                }
                if (y < mHeight - 1)
                {
                    newTile.neighbours.Add(mapTiles[position + Vector2.up]);
                }

                mapTiles[position] = newTile;
            }
        }
    }
Ejemplo n.º 4
0
    public void SetTile(Location location, MapTile.TileType type)
    {
        int x;
        int y;
        int roomNum;

        location.GetLocation(out x, out y, out roomNum);
        rooms[roomNum].SetTile(x, y, type);
    }
Ejemplo n.º 5
0
        public static bool DecodeTileImpl(char input, out MapTile.TileType tileType, out MovingObject.ObjectType objectType)
        {
            tileType   = MapTile.TileType.Empty;
            objectType = MovingObject.ObjectType.None;

            switch (input)
            {
            case ' ':
                tileType = MapTile.TileType.Empty;
                break;

            case 'e':
                tileType = MapTile.TileType.Exit;
                break;

            case 'x':
                tileType = MapTile.TileType.Trap;
                break;

            case '#':
                tileType = MapTile.TileType.Block;
                break;

            case '<':
                tileType = MapTile.TileType.PusherLeft;
                break;

            case '>':
                tileType = MapTile.TileType.PusherRight;
                break;

            case '^':
                tileType = MapTile.TileType.PusherUp;
                break;

            case '_':
                tileType = MapTile.TileType.PusherDown;
                break;

            case '@':
                objectType = MovingObject.ObjectType.Actor;
                break;

            case 'a':
                objectType = MovingObject.ObjectType.AntiActor;
                break;

            case 'b':
                objectType = MovingObject.ObjectType.Box;
                break;

            default:
                return(false);
            }
            return(true);
        }
Ejemplo n.º 6
0
 public TileData GetTileData(MapTile.TileType tileType)
 {
     foreach (TileData tileData in TileDatas)
     {
         if (tileData.TileType == tileType)
         {
             return(tileData);
         }
     }
     Debug.Assert(false, "Tile Data for type " + tileType + " not found.");
     return(null);
 }
    public int GetTilesOfType(MapTile.TileType t)
    {
        int count = 0;

        for (int i = 0; i < map.GetLength(0); i++)
        {
            for (int j = 0; j < map.GetLength(1); j++)
            {
                if (map[i, j].tileType == t)
                {
                    count++;
                }
            }
        }

        return(count);
    }
Ejemplo n.º 8
0
    public MapTile[] GetMapTiles(MapTile.TileType wantedTileType)
    {
        List <MapTile> mapTiles = new List <MapTile>();

        for (int i = 0; i < mapSize_X; ++i)
        {
            for (int j = 0; j < mapSize_Y; ++j)
            {
                if (tiles[i][j].tileType == wantedTileType)
                {
                    mapTiles.Add(tiles[i][j]);
                }
            }
        }

        return(mapTiles.ToArray());
    }
Ejemplo n.º 9
0
        public static bool DecodeTileImpl(char input, out MapTile.TileType tileType, out MovingObject.ObjectType objectType)
        {
            var idx = encodingChars.IndexOf(input);

            if (idx == -1)
            {
                tileType   = MapTile.TileType.Empty;
                objectType = MovingObject.ObjectType.None;
                return(false);
            }
            var tt = idx & 0x7;

            tileType   = (MapTile.TileType)tt;
            tt         = (idx >> 3) & 0x3;
            objectType = (MovingObject.ObjectType)tt;
            return(true);
        }
Ejemplo n.º 10
0
    public void Init()
    {
        if (!useSeed)
        {
            seed = Random.Range(0, 999999999);
        }
        Random.InitState(seed);
        Debug.Log(seed);
        rooms    = new List <Room>();
        mapTiles = new Dictionary <Vector2, MapTile>();

        int length = Random.Range(minMapSize, maxMapSize);
        int height = Random.Range(minMapSize, maxMapSize);

        mLength = length;
        mHeight = height;
        int area = length * height;

        for (int x = 0; x < length; x++)
        {
            for (int y = 0; y < height; y++)
            {
                MapTile.TileType tileType = MapTile.TileType.Floor;
                if (x == 0 || x == length - 1 || y == 0 || y == height - 1)
                {
                    tileType = MapTile.TileType.Wall;
                }

                mapTiles.Add(new Vector2(x, y), new MapTile(tileType, LayoutType.Default, new Vector2(x, y)));
            }
        }

        CreateRooms(length, height, area);
        UpdateMapTiles();
        DrawMap();
        //yield return new WaitForSeconds(5f);
        CarveDoorways();
        //CarveExits();
        DrawMap();
    }
Ejemplo n.º 11
0
 public MapTile(Vector2 coords)
 {
     Coordinates = coords;
     Type        = MapTile.TileType.None;
     Flower      = null;
 }
Ejemplo n.º 12
0
 public bool DecodeTile(char input, out MapTile.TileType tileType, out MovingObject.ObjectType objectType)
 {
     return(DecodeTileImpl(input, out tileType, out objectType));
 }
Ejemplo n.º 13
0
 public char EncodeTile(MapTile.TileType tileType, MovingObject.ObjectType objectType)
 {
     return(EncodeTileImpl(tileType, objectType));
 }
Ejemplo n.º 14
0
 public char EncodeTile(MapTile.TileType tileType, MovingObject.ObjectType objectType)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 15
0
        private MapTile[,] tiles; // x,y indexing

        private bool LoadMapImpl(Tuple <MapTile.TileType, MovingObject.ObjectType>[,] map)
        {
            this.width  = map.GetLength(1);
            this.height = map.GetLength(0);

            tiles = new MapTile[width, height];

            ExitTile = null;

            int actorsCount = 0;

            int x = 0, y = 0;
            int index = 0;

            foreach (var t in map)
            {
                x = index % width;
                y = index / width;
                index++;

                MapTile.TileType        tileType   = t.Item1;
                MovingObject.ObjectType objectType = t.Item2;

                var tile = new MapTile(tileType, x, y, index, this);

                tiles[x, y] = tile;

                if (tileType == MapTile.TileType.Exit)
                {
                    if (ExitTile != null)
                    {
                        //Console.WriteLine( "Map exit already defined" );
                        return(false);
                    }
                    ExitTile = tile;
                }

                if (objectType != MovingObject.ObjectType.None)
                {
                    tile.obj = new MovingObject {
                        type = objectType
                    }
                }
                ;

                if (objectType == MovingObject.ObjectType.Actor)
                {
                    actors[actorsCount++] = tile;
                }
                else if (objectType == MovingObject.ObjectType.AntiActor)
                {
                    contrActors.Add(tile);
                }
            }

            if (index != width * height)
            {
                //Console.WriteLine( "Invalid map data" );
                return(false);
            }

            if (TestIsOn == false && actorsCount == 0)
            {
                //Console.WriteLine( "No actors on map" );
                return(false);
            }

            if (TestIsOn == false && ExitTile == null)
            {
                //Console.WriteLine( "No exit on map" );
                return(false);
            }

            SetupTileNeighbourhood();

            Symmetry = eMapSymmetry.None;

            FindSymmetry();

            var res = CalculateDistanceToExit();

            return(res);
        }
Ejemplo n.º 16
0
 public Rule(int size)
 {
     array = new MapTile.TileType[9];
 }
Ejemplo n.º 17
0
 public void SetTile(int x, int y, MapTile.TileType type)
 {
     grid[x, y].setTileType(type);
 }
Ejemplo n.º 18
0
 private MapTile CreateTile(MapTile.TileType type)
 {
     return(new MapTile(type));
 }