Exemple #1
0
    private void PlaceNeighbours(int x, int y, int radiusDepth)       // Triggered Upon Player entering tile at coord (x,y)
    //Debug.Log ("Tile Entered At: "+x + " , " + y);
    // Check neighbouring tiles in all directions within the radiusDepth
    // Generate and add new tiles

    {
        for (int i = x - radiusDepth; i <= x + radiusDepth; i++)
        {
            for (int j = y - radiusDepth; j <= y + radiusDepth; j++)
            {
                int     tileType = GenerateTileType();
                MapNode mapNode  = map.AddTileToMap(i, j, tileType);
                if (mapNode != null)                                                 // Check Tile. If no tile is present add a new one
                {
                    mapNode.SetObject(PlaceTileInWorld(i, j, mapNode.GetTileNum())); // Place the new tile on physical map
                }
            }
        }

        // Remove past neighbours from gameworld
        for (int i = x - radiusDepth - 1; i <= x + radiusDepth + 1; i++)
        {
            MapNode mp = map.GetTileAt(i, y - radiusDepth - 1);
            if (mp != null)
            {
                Destroy(mp.GetObject());
                mp.ClearObject();
            }
            mp = map.GetTileAt(i, y + radiusDepth + 1);
            if (mp != null)
            {
                Destroy(mp.GetObject());
                mp.ClearObject();
            }
        }
        for (int j = y - radiusDepth; j <= y + radiusDepth; j++)
        {
            MapNode mp = map.GetTileAt(x - radiusDepth - 1, j);
            if (mp != null)
            {
                Destroy(mp.GetObject());
                mp.ClearObject();
            }
            mp = map.GetTileAt(x + radiusDepth + 1, j);
            if (mp != null)
            {
                Destroy(mp.GetObject());
                mp.ClearObject();
            }
        }
    }
Exemple #2
0
    // Clears a tile from game world. NOTE: The tile will still be stored in map
    public void RemoveTileFromWorld(int x, int y)
    {
        MapNode mapNode = map.GetTileAt(x, y);

        mapNode.ClearObject();
    }