예제 #1
0
 public Tile(int x, int y, TileType tileType, Blockable blockable)
 {
     this.tileType  = tileType;
     this.blockable = blockable;
     this.x         = x;
     this.y         = y;
 }
예제 #2
0
        public void Initialize(string[] mapData)
        {
            LoadSprites();
            pathfinder = new Pathfinder(null);

            levelName = mapData[0].Substring(1);

            mapSize = new Point(mapData[1].Length, mapData.Length - 1);
            tiles   = new Tile[mapSize.X, mapSize.Y];

            for (int x = 0; x < mapSize.X; x++)
            {
                for (int y = 0; y < mapSize.Y; y++)
                {
                    char      c         = mapData[y + 1][x];
                    TileType  type      = TileType.Normal;
                    Blockable blockable = null;
                    if (c == ' ')
                    {
                        type = TileType.Empty;
                    }
                    else
                    {
                        type = TileType.Normal;
                    }


                    if (c >= '1' && c <= '3')
                    {
                        int blockableIndex = c - '1';
                        blockable = new Blockable(blockableSprites[blockableIndex], false);
                    }

                    tiles[x, y] = new Tile(x, y, type, blockable);

                    if (c == 's')
                    {
                        SpawnUnit(unitSprite, new Point(x, y));
                    }

                    if (c >= 'a' && c <= 'c')
                    {
                        EnemyType enem = (EnemyType)(c - 'a');
                        SpawnEnemy(enem, new Point(x, y));
                    }
                }
            }

            AutoTile();


            pathfinder.SetTiles(tiles);
        }