コード例 #1
0
ファイル: PlayArea.cs プロジェクト: coastwise/tojam9
    public void MoveAndBump(CellScript incoming, FlatHexPoint point, FlatHexPoint dir)
    {
        if (!grid.Contains(point))
        {
            Destroy(incoming.gameObject);
            return;
        }
        CellScript bumped = grid[point];

        if (bumped != null)
        {
            MoveAndBump(bumped, point + dir, dir);
        }
        grid[point]              = incoming;
        incoming.hexPoint        = point;
        incoming.animationTarget = map[point];
        incoming.animating       = true;
    }
コード例 #2
0
ファイル: FlatHexTest.cs プロジェクト: ifalvarez/complices
    public void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            Vector3      worldPosition = GridBuilderUtils.ScreenToWorld(root, Input.mousePosition);
            FlatHexPoint hexPoint      = map[worldPosition];

            if (grid.Contains(hexPoint))
            {
                grid[hexPoint].HighlightOn = !grid[hexPoint].HighlightOn;
            }
        }
    }
コード例 #3
0
ファイル: CellScript.cs プロジェクト: coastwise/tojam9
    void Divide()
    {
        float rng = UnityEngine.Random.Range(0.0f, 1.0f);



        if (_calcDivide > rng)
        {
            foreach (FlatHexPoint direction in grid.GetNeighborDirections())
            {
                FlatHexPoint neighbour = hexPoint + direction;
                if (grid.Contains(neighbour) && grid[neighbour] == null)
                {
                    // send ourselves as the prefab!
                    area.SpawnCell(this, neighbour, direction);
                    return;
                }
            }

            if (grid.GetNeighbors(hexPoint, (CellScript n) => n._mutated).Count() ==
                grid.GetNeighbors(hexPoint, (CellScript n) => n != null).Count())
            {
                // don't split, totally surrounded by cancer.
                return;
            }

            if (!onlyDivideIntoEmptyNeighbour)
            {
                // divide anyway because cancer!

                FlatHexPoint[] directions = grid.GetNeighborDirections()
                                            .Where(d => grid.Contains(hexPoint + d))
                                            .ToArray();
                FlatHexPoint dir = directions[UnityEngine.Random.Range(0, directions.Length)];
                area.SpawnCell(this, hexPoint + dir, dir);
            }
        }
    }