public void loadData(StreamReader reader) { // TODO: // Chunk cache for metadata blocks _tiles = new Tile[tileDimension, tileDimension, 2]; int x = int.Parse(reader.ReadLine()); int y = int.Parse(reader.ReadLine()); _position = new Vector2I(x, y); for (int i = 0; i < dimension; i++) { for (int j = 0; j < dimension; j++) { for (int k = 0; k < tileDepth; k++) { // Read in the ID value int id = int.Parse(reader.ReadLine()); // Load the specified tile from the store TileAsset asset = TileStore.getTile(id); // Create the new instance and load any extra custom data Tile tile = asset.getTile(); tile.loadData(reader); _tiles[i, j, k] = tile; } } } }
public static void setChunk(Chunk chunk) { Vector2I corner = _world.loadedPosition; Vector2I position = chunk.position; // Determine the Local Array based position of the chunk Vector2I localPos = position - corner; Vector2I blockPos = new Vector2I(localPos.x * Chunk.tileDimension, localPos.y * Chunk.tileDimension); Tile[,,] data = chunk.tiles; //try //{ for (int i = 0; i < data.GetLength(0); i++) { for (int j = 0; j < data.GetLength(1); j++) { // Set foreground tile TileAsset asset = TileStore.getTile(data[i, j, 0].id); _map[i + blockPos.x, j + blockPos.y] = asset.solid; } } rebuildMap(); //} //catch //{ // Debug.Log(string.Format("OOR: {0},{1},{2},{3}", corner, position, localPos, blockPos)); //} }
public virtual void onDestroyed(Vector2 position) { TileAsset tile = TileStore.getTile(id); if (tile.dropItem) { Debug.Log(tile); EntityItem item = (EntityItem)EntityStore.createEntity(0); Debug.Log(item); item.itemID = tile.droppedItem.id; item.transform.position = new Vector3(position.x - 0.5f, position.y - 0.5f, 1.0f); } }
public Tile(int id, int health) { this._id = id; this._health = health; this._asset = TileStore.getTile(id); }