예제 #1
0
        // Use this for initialization
        void Start()
        {
            //set of base colors
            ColorComponentVO[] colorComponents = ColorComponentVO.GetArray();

            for (int cell_y = 0; cell_y < LOGO_MATRIX.GetLength(0); cell_y++)
            {
                for (int cell_x = 0; cell_x < LOGO_MATRIX.GetLength(1); cell_x++)
                {
                    if (LOGO_MATRIX [cell_y, cell_x] != 0)
                    {
                        int x = (-LOGO_MATRIX.GetLength(1) / 2 + cell_x) * 9;
                        int y = (LOGO_MATRIX.GetLength(0) - cell_y) * 9;

                        float[] tileRelativePos = new float[2] {
                            (float)cell_y / LOGO_MATRIX.GetLength(0),
                            (float)cell_x / LOGO_MATRIX.GetLength(1)
                        };

                        float tint = 0.3f + 0.7f * (Random.Range(3.0f, 5.0f) / 5.0f);

                        Vector3 pos = new Vector3(x, y, 0);

                        if (cell_x % 2 == 0)
                        {
                            pos.x += Random.Range(-100, 100);
                        }
                        else
                        {
                            pos.y += Random.Range(-100, 100);
                        }

                        GameObject tileInstance = (GameObject)Instantiate(PrefabLib.TILE_SMALL, pos, Quaternion.identity);
                        tileInstance.transform.parent = transform;
                        tileInstance.GetComponent <SpriteRenderer> ().color = ColorComponentVO.GetColorAt(tileRelativePos, colorComponents, tint);

                        tileInstance.transform.DOMove(new Vector3(x, y, 0), 0.5f);
                    }
                }
            }
        }
예제 #2
0
        private void Redraw()
        {
            var difficultyModel = DifficultyModel.Instance();
            var maze            = MazeModel.Instance();

            transform.parent.localPosition = new Vector2(
                -(maze.size - 1) * DifficultyModel.NODE_SIZE / 2,
                -(maze.size - 1) * DifficultyModel.NODE_SIZE / 2
                );

            //set of base colors
            ColorComponentVO[] colorComponents = ColorComponentVO.GetArray();

            int index = 0;

            for (int cellX = 0; cellX < maze.size; cellX++)
            {
                for (int cellY = 0; cellY < maze.size; cellY++)
                {
                    NodeVO node = maze.GetNode(cellX, cellY);

                    float[] tileRelativePos = new float[2] {
                        (float)cellX / maze.size,
                        (float)cellY / maze.size
                    };

                    float tint   = 0.6f + 0.4f * (float)(node.score - difficultyModel.minScore) / (difficultyModel.maxScore - difficultyModel.minScore);
                    float zOrder = 10 - (float)(cellY + cellX) / (maze.size + maze.size);

                    GameObject nodeInstance;
                    if (_nodeInstances.Count > index)
                    {
                        nodeInstance = _nodeInstances [index];
                    }
                    else
                    {
                        //create a tile
                        nodeInstance = (GameObject)Instantiate(PrefabLib.NODE);
                        nodeInstance.transform.parent = transform;
                        int value     = Random.Range(0, 3);
                        int randompos = (Random.Range(0, 2) == 1 ? value + maze.size : -(value + 1));
                        if (Random.Range(0, 2) == 1)
                        {
                            nodeInstance.transform.localPosition = new Vector3(cellX * DifficultyModel.NODE_SIZE, randompos * DifficultyModel.NODE_SIZE, zOrder);
                        }
                        else
                        {
                            nodeInstance.transform.localPosition = new Vector3(randompos * DifficultyModel.NODE_SIZE, cellY * DifficultyModel.NODE_SIZE, zOrder);
                        }
                        _nodeInstances.Add(nodeInstance);
                    }

                    nodeInstance.transform.DOLocalMove(new Vector3(
                                                           cellX * DifficultyModel.NODE_SIZE,
                                                           cellY * DifficultyModel.NODE_SIZE,
                                                           zOrder
                                                           ), TRANSITION_TIME);

                    nodeInstance.GetComponent <NodeMediator> ().Redraw(node, ColorComponentVO.GetColorAt(tileRelativePos, colorComponents, tint));

                    index++;
                }
            }
        }