Пример #1
0
    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;
                }
            }
        }
    }
Пример #2
0
    public override bool activateItem(Stack stack)
    {
        Tile    tile = TileStore.createTile(_tileAsset.id);
        Vector3 pos  = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 10));

        // Background tiles are placed in the background
        if (_tileAsset.backgroundTile)
        {
            if (World.instance.backgroundEmpty(pos))
            {
                World.instance.setBackground(tile, pos);
                return(true);
            }
        }
        else // Foreground tile
        {
            if (World.instance.blockEmpty(pos))
            {
                World.instance.setBlock(tile, pos);
                return(true);
            }
        }

        return(false);
    }
Пример #3
0
    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));
        //}
    }
Пример #4
0
        private void load(JsonStore jsonStore, TileStore textureStore)
        {
            TileAtlas tileAtlas = new TileAtlas(textureStore, jsonStore, "Json/tiles.json");

            Add(new TileAtlasWindow
            {
                State     = Visibility.Visible,
                TileAtlas = tileAtlas,
            });
        }
Пример #5
0
    void Awake()
    {
        //  MapLoader.loadSector(new Vector2I(0, 0));
        //SaveGame.Instance.RefreshScene();
        instance    = this;
        _properties = Resources.Load <WorldProperties>("World Properties");

        _chunkPool = new Pool <ChunkWorldObject>();

        Atlas.initialize();
        ItemStore.initialize();
        EntityStore.initialize();
        RecipeManager.loadRecipes();
        CollisionGrid.initialize(this, _properties.worldDimension * _properties.chunkDimension);
        TileStore.initialize();
        Mesher.initialize();

        int half = (_properties.worldDimension - 1) / 2;

        Vector2I spawnPos = new Vector2I(3, 3);

        _position = spawnPos - new Vector2I(half, half);

        // Create and initialize the map handler behaviour
        _mapHandler = new MapHandler(this, spawnPos);

        //_mapHandler.setPosition(new Vector2I(0, 0));
        //_mapHandler.populateSectors();

        //_mapHandler.updatePosition(new Vector2I(0, 0));

        createWorld();
        createLoader(spawnPos);
        //createLoader(spawnPos);
        if (SaveGame.Instance.IsSaveGame)
        {
            getPlayerPos();
        }
        // TEMP
        CollisionGrid.rebuildMap();

        return;

        for (int i = 0; i < 4; i++)
        {
            EntityItem entity = (EntityItem)EntityStore.createEntity(0);
            entity.itemID             = i;
            entity.transform.position = new Vector3(5 + i, 10, 5);
        }
    }
Пример #6
0
    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);
        }
    }
Пример #7
0
        private void load(TileStore textures, JsonStore jsonStore)
        {
            TileAtlas atlas = new TileAtlas(textures, jsonStore, world);

            Add(new FillFlowContainer
            {
                AutoSizeAxes = Axes.Both,
                Children     = new[]
                {
                    new DrawableTile(atlas[0])
                    {
                        Size = new Vector2(Chunk.TILE_SIZE)
                    },
                    new DrawableTile(atlas[1])
                    {
                        Size = new Vector2(Chunk.TILE_SIZE)
                    }
                }
            });
        }
Пример #8
0
 public Tile(int id, int health)
 {
     this._id     = id;
     this._health = health;
     this._asset  = TileStore.getTile(id);
 }