예제 #1
0
    void InitGame()
    {
        if (allObjectsParent != null)
        {
            Destroy(allObjectsParent);
        }

        if (player != null)
        {
            Destroy(player);
        }

        player = Instantiate(playerPrefab, new Vector3(1, 0, 0), Quaternion.Euler(0, 180, 0));
        vThirdPersonController.inputAllowed = false;

        allObjectsParent      = new GameObject();
        allObjectsParent.name = "game";

        tetrominosParent = new GameObject();
        tetrominosParent.transform.SetParent(allObjectsParent.transform);
        tetrominosParent.name = "tetrominos";

        wallsParent = new GameObject();
        wallsParent.transform.SetParent(allObjectsParent.transform);
        wallsParent.name = "walls";

        numbersParent = new GameObject();
        numbersParent.transform.SetParent(allObjectsParent.transform);
        numbersParent.name = "numbers";

        levelBlocksParent = new GameObject();
        levelBlocksParent.transform.SetParent(allObjectsParent.transform);
        levelBlocksParent.name = "level-separators";

        field      = new List <List <Block> >();
        wallHeight = 0;
        score      = -5;
        speed      = 1;
        lastInsertedStaticNumberWallHeight = -1;
        InsertWalls();
        InsertStaticNumberWalls();
        currentTetrimino = InstantiateTetrimino(new Vector2Int(0, 5), TetriminoType.I(), 0, false);
        UpdateCamera(new Vector3(5f, FindTopRow(false) * spacing + 2, -10));

        iTween.ValueTo(gameObject, iTween.Hash(
                           "from", GetComponent <AudioLowPassFilter>().cutoffFrequency,
                           "to", 10000,
                           "time", 1f,
                           "onupdatetarget", gameObject,
                           "onupdate", "tweenOnUpdateCallBack",
                           "easetype", iTween.EaseType.easeOutQuad
                           )
                       );
    }
예제 #2
0
    public void SpawnRandomTetrimino()
    {
        TetriminoType type     = TetriminoType.I();
        Vector2Int    position = new Vector2Int(Random.Range(4, width - type.Array.GetLength(0)), FindTopRow(false) + 10);

        Debug.Log("spawn_random_tetrimino(" + type.Name + ", (" + position.x + ", " + position.y + ")");

        if (!CanPlaceOnField(type, position))
        {
            return;
        }

        var tetrimino = InstantiateTetrimino(position, type, 0, true);

        InsertTetrimino(tetrimino);
    }
예제 #3
0
    public static TetriminoType Random()
    {
        int r = UnityEngine.Random.Range(1, 8);

        switch (r)
        {
        case 1: return(TetriminoType.I());

        case 2: return(TetriminoType.J());

        case 3: return(TetriminoType.L());

        case 4: return(TetriminoType.O());

        case 5: return(TetriminoType.S());

        case 6: return(TetriminoType.T());

        case 7: return(TetriminoType.Z());
        }

        return(I());
    }