Example #1
0
    public void AddLifeToGraph(LifeDot life)
    {
        Vector3Int coords = GetTilemapCoordsFromWorld(life.transform.position);
        LifeNode   node   = _mapGraph.GetNode(coords) as LifeNode;

        node.AddLife(life);
    }
Example #2
0
 public void ProcessStep()
 {
     foreach (Vector3Int pos in GridSystem.Instance.MainTilemap.cellBounds.allPositionsWithin)
     {
         LifeNode currentNode = GridSystem.Instance.GetNode(pos) as LifeNode;
         if (currentNode is null)
         {
             continue;
         }
         if (currentNode.Status == LifeNode.NodeStatus.Empty && currentNode.NewStatus == LifeNode.NodeStatus.Occupied)
         {
             LifeDot life = LifeHandlerRef.TakeLife();
             life.transform.position = GridSystem.Instance.GetWorldCoordsFromTilemap(pos);
             currentNode.AddLife(life);
             life.gameObject.SetActive(true);
         }
         else if (currentNode.Status == LifeNode.NodeStatus.Occupied && currentNode.NewStatus == LifeNode.NodeStatus.Empty)
         {
             LifeDot life = currentNode.RemoveLife();
             life.Die();
             LifeHandlerRef.ReleaseLife(life);
         }
         else if (currentNode.Status == LifeNode.NodeStatus.Occupied && currentNode.NewStatus == LifeNode.NodeStatus.Occupied)
         {
             LifeDot life = currentNode.ObjectsOnTile[0].GetComponent <LifeDot>();
             life.Grow();
         }
     }
     GameUIRef.UpdateYearsText(Years);
 }
Example #3
0
 public void ReleaseLife(LifeDot life)
 {
     _activeLifes.Remove(life);
     life.gameObject.SetActive(false);
     life.Age = 0;
     _freeLifes.Add(life);
 }
Example #4
0
 public void AddLife(LifeDot life)
 {
     if (ObjectsOnTile.Count == 0)
     {
         ObjectsOnTile.Add(life.gameObject);
         Status = NodeStatus.Occupied;
     }
 }
Example #5
0
 public LifeDot RemoveLife()
 {
     if (ObjectsOnTile.Count != 0)
     {
         GameObject lifeObject = ObjectsOnTile[0];
         LifeDot    life       = lifeObject.GetComponent <LifeDot>();
         ObjectsOnTile.Clear();
         Status = NodeStatus.Empty;
         return(life);
     }
     return(null);
 }
Example #6
0
 protected void RemoveLife(LifeNode node)
 {
     if (node.GetLife() == null)
     {
         return;
     }
     if (ChangePower(-1))
     {
         LifeDot lifeDot = node.RemoveLife();
         LifeHandlerRef.ReleaseLife(lifeDot);
         OnRemove.Invoke();
     }
 }
Example #7
0
    public void Initialize(int tileCount = 100)
    {
        _activeLifes = new List <LifeDot>();
        _freeLifes   = new List <LifeDot>();

        int startCount = tileCount / 2;

        for (int i = 0; i < startCount; ++i)
        {
            GameObject lifeGameObject = Instantiate(LifePrefab, transform);
            LifeDot    life           = lifeGameObject.GetComponent <LifeDot>();
            lifeGameObject.SetActive(false);
            _freeLifes.Add(life);
        }
    }
Example #8
0
 protected void SpawnLife(LifeNode node)
 {
     if (node.GetLife() != null)
     {
         return;
     }
     if (ChangePower(-1))
     {
         LifeDot life = LifeHandlerRef.TakeLife();
         life.transform.position = GridSystem.Instance.GetWorldCoordsFromTilemap(node.Coords);
         node.AddLife(life);
         life.gameObject.SetActive(true);
         OnSpawn.Invoke();
     }
 }
Example #9
0
 public void AddNewLife(LifeDot life)
 {
     _activeLifes.Add(life);
 }
Example #10
0
 public void RegisterLife(LifeDot life)
 {
     GridSystem.Instance.AddLifeToGraph(life);
 }