Beispiel #1
0
    public void AddTile(int x, int y, int id)
    {
        Chunk currentChunk = ManageChunkTile(x, y, id);

        currentChunk.SetTile(new Vector3Int(x % chunkSize, y % chunkSize, 0), tilebaseDictionary[id]);
        lightService.RecursivAddShadow(x, y);
        RefreshLight(CycleDay.GetIntensity());
        RefreshChunkNeightboorTiles(x, y, currentChunk.tilemapTile);
    }
Beispiel #2
0
 public void ChunckVisible(bool isVisible)
 {
     // to to rajouter un test pour ne plus passer par ici si le chunk est visible et a déjà été activé!!!!!!!!!!!!!!!!!!
     isChunkVisible = isVisible;
     if (isVisible && !alreadyVisible)
     {
         alreadyVisible = true;
         tc2d.enabled   = true;
         RefreshShadowMap(CycleDay.GetIntensity());
     }
 }
Beispiel #3
0
    public void DeleteTile(int x, int y)
    {
        var   id           = tilesWorldMap[x, y];
        Chunk currentChunk = ManageChunkTile(x, y, 0);

        currentChunk.SetTile(new Vector3Int(x % chunkSize, y % chunkSize, 0), null);
        lightService.RecursivDeleteShadow(x, y);
        RefreshLight(CycleDay.GetIntensity());
        ManageItems.CreateItemOnMap(x, y, id);
        RefreshChunkNeightboorTiles(x, y, currentChunk.tilemapTile);
    }
Beispiel #4
0
 public void DeleteItem(int posX, int posY)
 {
     if (tilesObjetMap[posX, posY].name == "item_11(Clone)")   // toDo changer cette merde
     {
         lightService.RecursivDeleteLight(posX, posY, true);
         RefreshLight(CycleDay.GetIntensity());
     }
     tilesObjetMap[posX, posY] = null;
     Destroy(tilesObjetMap[posX, posY]);
     ManageItems.CreateItemOnMap(posX, posY, 11);
 }
Beispiel #5
0
    public void AddItem(int posX, int posY, InventoryItem item)
    {
        var id = item.config.id;
        // toDo faire un pool d'objet déjà instancié!
        var go = Instantiate((GameObject)Resources.Load("Prefabs/Items/item_" + id), new Vector3(posX + 0.5f, posY + 0.5f, 0), transform.rotation);

        tilesObjetMap[posX, posY] = go;
        if (id == 11)
        {
            lightService.RecursivAddNewLight(posX, posY, 0);
            RefreshLight(CycleDay.GetIntensity());
        }
    }
Beispiel #6
0
    private void Update()
    {
        var intensity = cycleDay.GetIntensity();

        if (intensity != lastIntensity)
        {
            lastIntensity = intensity;
            var startX = indexX * chunkSize;
            var startY = indexY * chunkSize;
            for (var x = startX; x < startX + chunkSize; x++)
            {
                for (var y = startY; y < startY + chunkSize; y++)
                {
                    var shadow    = tilesShadowMap[x, y] + intensity;
                    var light     = tilesLightMap[x, y];
                    var walltTile = wallTilesMap[x, y];
                    if ((walltTile == 0 && tilesMap[x % chunkSize, y % chunkSize] == 0) || (light == 0 && shadow == 0))
                    {
                        tilemapShadow.SetColor(new Vector3Int(x, y, 0), new Color(0, 0, 0, 0));
                        tilemapLight.SetColor(new Vector3Int(x, y, 0), new Color(0, 0, 0, 0));
                    }
                    else
                    {
                        if (light <= shadow)
                        {
                            tilemapLight.SetColor(new Vector3Int(x, y, 0), new Color(0, 0, 0, light));
                            tilemapShadow.SetColor(new Vector3Int(x, y, 0), new Color(0, 0, 0, 0));
                        }
                        else
                        {
                            tilemapShadow.SetColor(new Vector3Int(x, y, 0), new Color(0, 0, 0, shadow));
                            tilemapLight.SetColor(new Vector3Int(x, y, 0), new Color(0, 0, 0, 0));
                        }
                    }
                }
            }
        }
    }
Beispiel #7
0
    private void SetTilemapOpacity(Tilemap tilemapLight, Tilemap tilemapShadow, float[,] tilesShadowMap, float[,] tilesLightMap, int x, int y)
    {
        var shadow = tilesShadowMap[x, y] + cycleDay.GetIntensity();
        var light  = tilesLightMap[x, y];

        if ((wallTilesMap[x, y] == 0 && tilesWorldMap[x, y] == 0) || (shadow == 0 && light == 0))
        {
            tilemapLight.SetColor(new Vector3Int(x, y, 0), new Color(0, 0, 0, 0));
            tilemapShadow.SetColor(new Vector3Int(x, y, 0), new Color(0, 0, 0, 0));
        }
        else
        {
            if (light <= shadow)
            {
                tilemapLight.SetColor(new Vector3Int(x, y, 0), new Color(0, 0, 0, light));
                tilemapShadow.SetColor(new Vector3Int(x, y, 0), new Color(0, 0, 0, 0));
            }
            else
            {
                tilemapShadow.SetColor(new Vector3Int(x, y, 0), new Color(0, 0, 0, shadow));
                tilemapLight.SetColor(new Vector3Int(x, y, 0), new Color(0, 0, 0, 0));
            }
        }
    }