// Use this for initialization
    void Init()
    {
        // populate the grid of size numCol x numRow
        grid = new Cell[NumCol * NumRow];
        for (int i = 0; i < NumRow * NumCol; i++)
        {
            GameObject go = Instantiate(CellPrefab);
            go.transform.SetParent(transform);
            grid[i] = go.GetComponent <Cell>();
            grid[i].SetGrid(NumRow, NumCol);
            grid[i].SetPosition(i % NumCol, i / NumCol);
            grid[i].SetStatus(Cell.Status.Dead);
        }

        // populate the cell pattern
        for (int i = 0; i < pattern.Positions.Count; i++)
        {
            int x        = pattern.Positions[i].x + NumCol / 2;
            int y        = pattern.Positions[i].y + NumRow / 2;
            int position = y * NumCol + x;
            grid[position].SetStatus(Cell.Status.Alive);
        }

        curPattern = pattern;
    }
Exemplo n.º 2
0
        public Color GetCellPatternColor(CellPattern pat)
        {
            switch (pat)
            {
            case CellPattern.BlurprintMin:
                return(this.blueprintMin);

            case CellPattern.BlurprintMax:
                return(this.blueprintMax);

            case CellPattern.Instance:
                return(this.instance);

            case CellPattern.OtherInstance:
                return(this.otherInstance);

            case CellPattern.OutputCell:
                return(this.outputCell);

            case CellPattern.OutputZone:
                return(this.outputZone);

            case CellPattern.InputCell:
                return(this.inputCell);

            case CellPattern.InputZone:
                return(this.inputZone);
            }
            return(Color.white);
        }
 void Start()
 {
     if (PatternBank.Length > 0)
     {
         pattern = PatternBank[curPatternId];
     }
 }
        public static Color ToColor(this CellPattern pat)
        {
            switch (pat)
            {
            case CellPattern.BlurprintMin:
                return(Color.white);

            case CellPattern.BlurprintMax:
                return(Color.gray.A(0.6f));

            case CellPattern.Instance:
                return(Color.white);

            case CellPattern.OtherInstance:
                return(Color.white.A(0.35f));

            case CellPattern.OutputCell:
                return(Color.blue);

            case CellPattern.OutputZone:
                return(Color.blue.A(0.5f));

            case CellPattern.InputCell:
                return(Color.magenta);

            case CellPattern.InputZone:
                return(Color.magenta.A(0.5f));
            }
            return(Color.white);
        }
    // Update is called once per frame
    void Update()
    {
        // tick each active cell
        if (Input.GetKeyDown(KeyCode.Space))
        {
            //Debug.Log("tick");
            Tick();
        }

        if (Input.GetKeyDown(KeyCode.R))
        {
            if (isRunning == false)
            {
                isRunning = true;
            }
            else if (isRunning == true)
            {
                isRunning = false;
            }
        }

        if (Input.GetKeyDown(KeyCode.UpArrow) && isRunning == true)
        {
            if (DeltaTime > 2 * TIME_CHANGE)
            {
                DeltaTime -= TIME_CHANGE;
            }
        }

        if (Input.GetKeyDown(KeyCode.DownArrow))
        {
            DeltaTime += TIME_CHANGE;
        }

        if (Input.GetKeyDown(KeyCode.LeftArrow))
        {
            curPatternId = (curPatternId + PatternBank.Length - 1) % PatternBank.Length;
            pattern      = PatternBank[curPatternId];
        }

        if (Input.GetKeyDown(KeyCode.RightArrow))
        {
            curPatternId = (curPatternId + 1) % PatternBank.Length;
            pattern      = PatternBank[curPatternId];
        }

        if (isRunning == true)
        {
            if (Time.time - curTime > DeltaTime)
            {
                curTime = Time.time;
                Tick();
            }
        }
    }
Exemplo n.º 6
0
 /// <summary>
 /// Sets callback functions. Sets initial active/inactive state of buttons.
 /// </summary>
 private void Start()
 {
     _gameOfLife = FindObjectOfType <GameOfLife>();
     _gameOfLife.OnGenerationChangedCallback += OnGenerationCountChanged;
     _grid             = FindObjectOfType <Grid>();
     _cellPattern      = FindObjectOfType <CellPattern>();
     _cellsToHighlight = new List <Cell>();
     _startTimerButton.SetActive(true);
     _stopTimerButton.SetActive(false);
     Cell.OnMouseEnterCallback += OnMouseEnteredCell;
 }
Exemplo n.º 7
0
        public override Color GetColor(IntVec3 cell, Map map, Rot4 rot, CellPattern cellPattern)
        {
            var col = base.GetColor(cell, map, rot, cellPattern);

            if (cell.GetPlantable(map).HasValue)
            {
                col = Color.green;
                if (cellPattern == CellPattern.BlurprintMax)
                {
                    col = col.A(0.5f);
                }
            }
            return(col);
        }
Exemplo n.º 8
0
 public virtual Color GetColor(IntVec3 cell, Map map, Rot4 rot, CellPattern cellPattern)
 {
     return(this.Parent.GetCellPatternColor(cellPattern));
 }
 public virtual Color GetColor(IntVec3 cell, Map map, Rot4 rot, CellPattern cellPattern)
 {
     return(cellPattern.ToColor());
 }