Пример #1
0
    public BlockUnit GetBlock(Vector3 pos, bool isType1, bool isLeft, bool isUp)
    {
        pos.x = pos.x;
        if (isUp)
        {
            pos.y = 2.4f;
        }
        else
        {
            pos.y = -3;
        }

        pos.z = pos.z;
        BlockUnit unit = GetBlock();

        unit.transform.position = pos;
        unit.SetColor(isType1);

        if (isLeft)
        {
            unit.transform.localScale = new Vector3(width, tall, size);
        }
        else
        {
            unit.transform.localScale = new Vector3(size, tall, width);
        }

        return(unit);
    }
Пример #2
0
    public void CreateUnit(BlockUnit template, MapVector2 pos)
    {
        BlockUnit newUnit = Instantiate(template.gameObject).GetComponent <BlockUnit>();

        newUnit.transform.SetParent(transform);
        newUnit.Position = new Vector3(pos.x, pos.y, m_Floor);
    }
    public BlockUnit GetEntryBlock(Vector3 crossingPos, GameDefine.Direction dir, bool correctRoad, bool onRoad)
    {
        Vector3 blockPos = crossingPos;

        blockPos  += BlockOffset[(int)dir];
        blockPos.y = onRoad ?  correctRoad ? 2.6f : 2.4f : -3.0f;

        BlockUnit unit = GetEntryBlock(correctRoad);

        unit.transform.position = blockPos;
        unit.SetVisible(true);
        unit.crossingPos = crossingPos;
        unit.direction   = dir;
        unit.color       = correctRoad;

        if (!correctRoad)
        {
            // TODO: Refactor, put scaling logic in ObsBlock
            if (dir != GameDefine.Direction.Forward)
            {
                unit.transform.localScale = new Vector3(width, tall, size);
            }
            else
            {
                unit.transform.localScale = new Vector3(size, tall, width);
            }
        }

        return(unit);
    }
Пример #4
0
        public void GetYGapTest(Kind kind, int[] expectedResults)
        {
            BlockUnit unit = kind.GetObject();

            foreach (Directions dir in Enum.GetValues(typeof(Directions)))
            {
                int result = unit.GetYGap(dir);
                Assert.AreEqual(expectedResults[(int)dir], result, $"Kind:{kind},Direction:{dir},{unit}");
            }
        }
Пример #5
0
    void CreatePath(Vector3 startPoint, Vector3 endPoint, bool isType1, bool isUp)
    {
        GameObject newRoad = GetRoad();

        listRoadActive.Add(newRoad);
        float   x, y, z;
        Vector3 pos;
        bool    isLeft;
        Vector3 blockPos;

        if (startPoint.x == endPoint.x)
        {
            x        = GameDefine.roadWidth;
            z        = endPoint.z - startPoint.z - GameDefine.roadDistance;
            pos      = startPoint + Vector3.forward * (0.5f * GameDefine.roadWidth + 0.5f * z + GameDefine.roadDistance);
            blockPos = startPoint + Vector3.forward * GameDefine.blockDistance;
            isLeft   = false;
        }
        else
        {
            z = GameDefine.roadWidth;

            if (endPoint.x > startPoint.x)
            {
                x        = endPoint.x - startPoint.x - GameDefine.roadDistance;
                pos      = startPoint + Vector3.right * (0.5f * GameDefine.roadWidth + 0.5f * x + GameDefine.roadDistance);
                blockPos = startPoint + Vector3.right * GameDefine.blockDistance;
            }
            else
            {
                x        = -endPoint.x + startPoint.x - GameDefine.roadDistance;
                pos      = startPoint + Vector3.left * (0.5f * GameDefine.roadWidth + 0.5f * x + GameDefine.roadDistance);
                blockPos = startPoint + Vector3.left * GameDefine.blockDistance;
            }
            isLeft = true;
        }

        y = GameDefine.roadTall;

        newRoad.transform.localScale = new Vector3(x, y, z);
        if (isUp)
        {
            newRoad.transform.position = new Vector3(pos.x, pos.y, pos.z);
        }
        else
        {
            newRoad.transform.position = new Vector3(pos.x, -8, pos.z);
        }

        BlockUnit unit = MainObjControl.Instant.colorBlockCrt.GetBlock(blockPos, isType1, isLeft, isUp);

        listBlock.Add(unit);
    }
Пример #6
0
 BlockUnit GetBlock()
 {
     if (listBlock.Count == 0)
     {
         return((Instantiate(blockPrefab) as GameObject).GetComponent <BlockUnit>());
     }
     else
     {
         BlockUnit newBlock = listBlock[listBlock.Count - 1];
         listBlock.RemoveAt(listBlock.Count - 1);
         return(newBlock);
     }
 }
Пример #7
0
    IEnumerator MoveBlock(BlockUnit unit, Vector3 to, float duration)
    {
        float     elapsed = 0;
        Transform block   = unit.transform;
        Vector3   from    = block.position;

        while (elapsed <= duration)
        {
            block.position = Vector3.Lerp(from, to, elapsed / duration);
            elapsed       += Time.deltaTime;
            yield return(null);
        }

        block.position = to;

        MainObjControl.Instant.colorBlockCrt.SetBlock(unit);
    }
    public BlockUnit GetExtraBlock(Vector3 crossingPos, GameDefine.Direction dir)
    {
        // Currently, diamond is the only extra block available
        Vector3 blockPos = crossingPos;

        blockPos  += BlockOffset[(int)dir] * 1.5f;
        blockPos.y = 2.6f;

        BlockUnit unit = Instantiate(diamondPrefab).GetComponent <BlockUnit>();

        unit.transform.position = blockPos;
        unit.SetVisible(true);
        unit.crossingPos = crossingPos;
        unit.direction   = dir;

        return(unit);
    }
Пример #9
0
    IEnumerator ChangeColor(bool isType1)
    {
        float     timer = 0;
        BlockUnit unit  = MainObjControl.Instant.roadCrt.listBlock[0];

        if (currentType != isType1)
        {
            yield return(new WaitForSeconds(0.4f));


            MainObjControl.Instant.colorBlockCrt.SetBlock(unit);
            MainObjControl.Instant.boomControl.ShowBoom(unit.transform);
            MainAudio.Main.PlaySound(TypeAudio.SoundScore);
            unit.transform.position = new Vector3(0, -100, 0);
            while (timer < duration)
            {
                timer += Time.deltaTime;
                Color newColor;

                if (isType1)
                {
                    newColor = Color.Lerp(c2, c1, timer / duration);
                }
                else
                {
                    newColor = Color.Lerp(c1, c2, timer / duration);
                }
                playerMat.SetColor("_Color", newColor);
                yield return(null);
            }

            currentType = isType1;
        }
        else
        {
            yield return(new WaitForSeconds(0.4f));

            MainObjControl.Instant.colorBlockCrt.SetBlock(unit);
            MainObjControl.Instant.boomControl.ShowBoom(unit.transform);
            unit.transform.position = new Vector3(0, -100, 0);
            MainAudio.Main.PlaySound(TypeAudio.SoundScore);
        }
    }
Пример #10
0
    public void Set(Vector3 startPoint, GameDefine.Direction direction, float length)
    {
        this.startPoint = startPoint;
        this.length     = length;
        this.direction  = direction;
        arrow           = null;
        block           = null;
        next            = null;

        Vector3 scale;
        Vector3 pos;

        float scaleLength = length - GameDefine.roadDistance;

        if (direction == GameDefine.Direction.Forward)
        {
            scale.x = GameDefine.roadWidth;
            scale.z = scaleLength;
            pos     = startPoint + Vector3.forward * (0.5f * GameDefine.roadWidth + 0.5f * scale.z + GameDefine.roadDistance);
        }
        else
        {
            scale.z = GameDefine.roadWidth;

            if (direction == GameDefine.Direction.Right)
            {
                scale.x = scaleLength;
                pos     = startPoint + Vector3.right * (0.5f * GameDefine.roadWidth + 0.5f * scale.x + GameDefine.roadDistance);
            }
            else
            {
                scale.x = scaleLength;
                pos     = startPoint + Vector3.left * (0.5f * GameDefine.roadWidth + 0.5f * scale.x + GameDefine.roadDistance);
            }
        }

        scale.y = GameDefine.roadTall;

        transform.localScale = scale;
        transform.position   = pos;
    }
Пример #11
0
    // Return: Position of next crossing
    RoadUnit CreateRoad(Vector3 crossingPoint, GameDefine.Direction direction, float length, bool correctRoad)
    {
        // Add path to listRoadActive
        // Add block to listBlock

        bool      onRoad  = true;
        RoadUnit  newRoad = GetRoad();
        BlockUnit unit    = MainObjControl.Instant.blockCtrl.GetEntryBlock(crossingPoint, direction, correctRoad, onRoad);

        newRoad.Set(crossingPoint, direction, length);
        newRoad.block = unit;
        unit.road     = newRoad;

        // Randomly generate a diamond on the wrong road
        if (!correctRoad && Random.value < 0.5)
        {
            newRoad.extraBlocks.Add(MainObjControl.Instant.blockCtrl.GetExtraBlock(crossingPoint, direction));
        }

        activeRoads.Add(newRoad);
        activeBlocks.Add(unit);

        return(newRoad);
    }
 // Start is called before the first frame update
 void Start()
 {
     unit   = GetComponent <BlockUnit>();
     player = MainObjControl.Instant.playerCtrl;
 }
Пример #13
0
    void CreateRoadBounus(Vector3 p1, Vector3 p2, Vector3 p3, bool isType1, bool isUp)
    {
        GameObject newRoad = GetRoad();

        newRoad.name = "roadX";
        listBonusActive.Add(newRoad);
        bool    isLeft;
        float   x, y, z;
        Vector3 pos;
        Vector3 blockPos;

        if (p1.z == p3.z)
        {
            x        = GameDefine.roadWidth;
            z        = GameDefine.roadRandSize;
            pos      = p2 + Vector3.forward * (0.5f * GameDefine.roadWidth + 0.5f * z + GameDefine.roadDistance);
            blockPos = p2 + Vector3.forward * GameDefine.blockDistance;
            isLeft   = false;
        }
        else if (p1.x == p3.x)
        {
            z = GameDefine.roadWidth;
            x = GameDefine.roadRandSize;

            pos      = p2 + Vector3.left * (0.5f * GameDefine.roadWidth + 0.5f * x + GameDefine.roadDistance);
            blockPos = p2 + Vector3.left * GameDefine.blockDistance;
            isLeft   = false;

            isLeft = true;
        }
        else
        {
            if (p1.x == p2.x)
            {
                x        = GameDefine.roadWidth;
                z        = GameDefine.roadRandSize;
                pos      = p2 + Vector3.forward * (0.5f * GameDefine.roadWidth + 0.5f * z + GameDefine.roadDistance);
                blockPos = p2 + Vector3.forward * GameDefine.blockDistance;
                isLeft   = false;
            }
            else
            {
                z = GameDefine.roadWidth;
                x = GameDefine.roadRandSize;

                if (p1.x > p2.x)
                {
                    pos      = p2 + Vector3.left * (0.5f * GameDefine.roadWidth + 0.5f * x + GameDefine.roadDistance);
                    blockPos = p2 + Vector3.left * GameDefine.blockDistance;
                }
                else
                {
                    pos      = p2 + Vector3.right * (0.5f * GameDefine.roadWidth + 0.5f * x + GameDefine.roadDistance);
                    blockPos = p2 + Vector3.right * GameDefine.blockDistance;
                }
                isLeft = true;
            }
        }

        y = GameDefine.roadTall;

        newRoad.transform.localScale = new Vector3(x, y, z);
        if (isUp)
        {
            newRoad.transform.position = new Vector3(pos.x, pos.y, pos.z);
        }
        else
        {
            newRoad.transform.position = new Vector3(pos.x, -8, pos.z);
        }

        BlockUnit unit = MainObjControl.Instant.colorBlockCrt.GetBlock(blockPos, isType1, isLeft, isUp);

        listBlockBonus.Add(unit);
    }
Пример #14
0
 public void SetBlock(BlockUnit unit)
 {
     listBlock.Add(unit);
 }
 public void FreeBlock(BlockUnit unit)
 {
     idleBlock.Add(unit);
 }