コード例 #1
0
ファイル: GameFieldScript.cs プロジェクト: metix/tristet
 public Tetrimino(int rotation, Vector2Int position, TetriminoType type, bool staticTetrimino)
 {
     Rotation = rotation;
     Position = position;
     Type     = type;
     IsStatic = staticTetrimino;
 }
コード例 #2
0
ファイル: GameFieldScript.cs プロジェクト: metix/tristet
    public bool CanPlaceOnField(TetriminoType type, Vector2Int position)
    {
        for (var y = 0; y < type.Array.GetLength(0); y++)
        {
            for (var x = 0; x < type.Array.GetLength(0); x++)
            {
                if (position.x + x < 0)
                {
                    continue;
                }

                if (position.x + x >= width)
                {
                    continue;
                }

                if (field[position.y + y][position.x + x] != null && type.Array[y, x] != 0)
                {
                    return(false);
                }
            }
        }

        return(true);
    }
コード例 #3
0
ファイル: Tetrimino.cs プロジェクト: LocketGoma/Sample_Tetris
    public void Initializer(float gap)
    {
        int selected = Random.Range(0, 7);

        tetriminoType = RandomSelect(selected + 1);
        BatchTetrimino(selected);
        SetColor(tetriminoType);
        batchGap = gap;
    }
コード例 #4
0
ファイル: GameFieldScript.cs プロジェクト: metix/tristet
    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
                           )
                       );
    }
コード例 #5
0
ファイル: Tetrimino.cs プロジェクト: LocketGoma/Sample_Tetris
    private void SetColor(TetriminoType tetriminoType)
    {
        Color color;

        Debug.Log("type : " + tetriminoType);
        switch (tetriminoType)
        {
        case TetriminoType.I_mino: {
            color = new Color(100.0f / 255.0f, 100.0f / 255.0f, 250.0f / 255.0f);
            break;
        }

        case TetriminoType.LL_mino: {
            color = new Color(200.0f / 255.0f, 200.0f / 255.0f, 50.0f / 255.0f);
            break;
        }

        case TetriminoType.LR_mino: {
            color = new Color(250.0f / 255.0f, 100.0f / 255.0f, 100.0f / 255.0f);
            break;
        }

        case TetriminoType.ZL_mino: {
            color = new Color(200.0f / 255.0f, 200.0f / 255.0f, 200.0f / 255.0f);
            break;
        }

        case TetriminoType.ZR_mino: {
            color = new Color(50.0f / 255.0f, 200.0f / 255.0f, 50.0f / 255.0f);
            break;
        }

        case TetriminoType.O_mino: {
            color = new Color(50.0f / 255.0f, 50.0f / 255.0f, 150.0f / 255.0f);
            break;
        }

        case TetriminoType.T_mino: {
            color = new Color(200.0f / 255.0f, 50.0f / 255.0f, 200.0f / 255.0f);
            break;
        }

        default: {
            color = new Color(255.0f / 255.0f, 255.0f / 255.0f, 255.0f / 255.0f);
            break;
        }
        }
        foreach (Transform child in transform)
        {
            Debug.Log(child.gameObject.GetComponent <SpriteRenderer>().material.color);
            child.gameObject.GetComponent <SpriteRenderer>().material.color = color;
        }
        Debug.Log("change color : " + color);
    }
コード例 #6
0
ファイル: GameFieldScript.cs プロジェクト: metix/tristet
    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);
    }
コード例 #7
0
ファイル: Tetrimino.cs プロジェクト: davidharabagiu/Tetris
        public static int GenerateType(int?exclude)
        {
            int    type;
            Random r = new Random();

            if (exclude == null)
            {
                type = r.Next(7);
            }
            else
            {
                do
                {
                    type = r.Next(7);
                } while (type == exclude);
            }
            return(type);
        }
コード例 #8
0
ファイル: GameFieldScript.cs プロジェクト: metix/tristet
    public Tetrimino InstantiateTetrimino(Vector2Int pos, TetriminoType type, int rotation, bool staticTetrimino)
    {
        // add empty rows on top of field, to avoid array out of bounds exceptions
        for (var i = 0; i < (pos.y + 30) - field.Count; i++)
        {
            field.Add(EmptyRow());
        }

        int[,] array = RotateNTimes(type.Array, rotation);

        Tetrimino tetrimino = new Tetrimino(rotation, pos, type, staticTetrimino);

        tetrimino.Blocks = new Block[array.GetLength(0), array.GetLength(0)];
        GameObject newTetrimino = new GameObject();

        newTetrimino.transform.SetParent(tetrominosParent.transform);
        newTetrimino.name = "tetrimino_" + type.Name;

        for (var y = 0; y < array.GetLength(0); y++)
        {
            for (var x = 0; x < array.GetLength(0); x++)
            {
                if (array[array.GetLength(0) - y - 1, x] == 1)
                {
                    Block block = new Block();
                    block.Parent   = tetrimino;
                    block.Position = new Vector2Int(pos.x + x, pos.y + y);
                    block.Instance = Instantiate(blockPrefab, new Vector3((pos.x + x) * spacing, (pos.y + y) * spacing), Quaternion.identity);
                    block.Instance.GetComponent <Renderer>().material = type.Material;

                    block.Instance.transform.SetParent(newTetrimino.transform);

                    tetrimino.Blocks[y, x] = block;
                }
            }
        }

        return(tetrimino);
    }
コード例 #9
0
ファイル: Tetrimino.cs プロジェクト: davidharabagiu/Tetris
        public Tetrimino(int type, ContentManager content, SoundControl soundControl)
        {
            this.type    = (TetriminoType)type;
            position     = new Vector2(START_X, START_Y);
            blocks       = new Block[4, 4];
            times        = new double[3];
            falling      = true;
            this.content = content;

            byte[,] shape = GetShape(type);
            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    if (shape[i, j] == 1)
                    {
                        blocks[i, j] = new Block(GetColor(type), content);
                    }
                }
            }

            this.soundControl = soundControl;
        }
コード例 #10
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());
    }
コード例 #11
0
ファイル: GameFieldScript.cs プロジェクト: metix/tristet
    public void Update()
    {
        if (gameStop)
        {
            return;
        }

        float newScore = Mathf.Round(player.transform.position.y * 100) / 100;

        if (newScore > score)
        {
            score = newScore;
            if (score > 0)
            {
                speed = Mathf.Pow(score, speedIncreaseFactor);
            }
        }

        InsertStaticNumberWalls();
        InsertWalls();

        if (Input.GetKeyDown(KeyCode.D))
        {
            if (currentTetrimino != null)
            {
                if (CanMoveRight(currentTetrimino))
                {
                    MoveRight(currentTetrimino);
                }
            }
        }
        else if (Input.GetKeyDown(KeyCode.A))
        {
            if (currentTetrimino != null)
            {
                if (CanMoveLeft(currentTetrimino))
                {
                    MoveLeft(currentTetrimino);
                }
            }
        }
        else if (Input.GetKeyDown(KeyCode.Q))
        {
            if (CanRotateLeft(currentTetrimino))
            {
                RotateLeft(currentTetrimino);
            }
        }
        else if (Input.GetKeyDown(KeyCode.E))
        {
            if (CanRotateRight(currentTetrimino))
            {
                RotateRight(currentTetrimino);
            }
        }
        else if (Input.GetKeyDown(KeyCode.S))
        {
            while (CanMoveDown(currentTetrimino))
            {
                MoveDown(currentTetrimino);
            }
        }

        if (period > speed)
        {
            if (currentTetrimino != null)
            {
                if (CanMoveDown(currentTetrimino))
                {
                    MoveDown(currentTetrimino);
                }
                else
                {
                    InsertTetrimino(currentTetrimino);
                    UpdateCamera(new Vector3(5, FindTopRow(false) * spacing + 2, -10));

                    currentTetrimino = InstantiateTetrimino(new Vector2Int(0, FindTopRow(false) + 4), TetriminoType.Random(), 0, false);
                }
            }
            period = 0;
        }

        frustumPlanes = GeometryUtility.CalculateFrustumPlanes(Camera.main);
        if (!GeometryUtility.TestPlanesAABB(frustumPlanes, player.GetComponent <Collider>().bounds))
        {
            GameOver();
            ui.GetComponent <UIScript>().Show(score, best);
        }

        period += Time.deltaTime;
    }
コード例 #12
0
 public Tetrimino Create(TetriminoType type)
 {
     return(new Tetrimino(texture, type));
 }
コード例 #13
0
        public Tetrimino(Texture2D texture, TetriminoType type)
        {
            offsets          = new List <Vector2>();
            rectangles       = new List <Rectangle>();
            shadowRectangles = new List <Rectangle>();
            this.texture     = texture;
            this.type        = type;

            topLeftPosition       = startPos;
            shadowTopLeftPosition = startPos;

            active = true;

            switch (type)
            {
            case TetriminoType.I:
                offsets.Add(new Vector2(-1, 0));
                offsets.Add(new Vector2(0, 0));
                offsets.Add(new Vector2(1, 0));
                offsets.Add(new Vector2(2, 0));
                color = Color.Cyan;
                break;

            case TetriminoType.J:
                offsets.Add(new Vector2(-1, 0));
                offsets.Add(new Vector2(0, 0));
                offsets.Add(new Vector2(1, 0));
                offsets.Add(new Vector2(1, 1));
                color = Color.DeepSkyBlue;
                break;

            case TetriminoType.L:
                offsets.Add(new Vector2(-1, 1));
                offsets.Add(new Vector2(-1, 0));
                offsets.Add(new Vector2(0, 0));
                offsets.Add(new Vector2(1, 0));
                color = Color.Orange;
                break;

            case TetriminoType.O:
                offsets.Add(new Vector2(0, 0));
                offsets.Add(new Vector2(1, 0));
                offsets.Add(new Vector2(0, -1));
                offsets.Add(new Vector2(1, -1));
                color = Color.Yellow;
                break;

            case TetriminoType.S:
                offsets.Add(new Vector2(-1, 1));
                offsets.Add(new Vector2(0, 1));
                offsets.Add(new Vector2(0, 0));
                offsets.Add(new Vector2(1, 0));
                color = Color.LawnGreen;
                break;

            case TetriminoType.T:
                offsets.Add(new Vector2(-1, 0));
                offsets.Add(new Vector2(0, 0));
                offsets.Add(new Vector2(1, 0));
                offsets.Add(new Vector2(0, 1));
                color = Color.MediumPurple;
                break;

            case TetriminoType.Z:
                offsets.Add(new Vector2(-1, 0));
                offsets.Add(new Vector2(0, 0));
                offsets.Add(new Vector2(0, 1));
                offsets.Add(new Vector2(1, 1));
                color = Color.Red;
                break;
            }
            UpdateRectangles();
        }
コード例 #14
0
 public TetriminoFactory(TetriminoType type)
 {
     Assert.AreEqual(type, TetriminoType.Four, "まだ4個のテトリミノしか作ってないよ");
     this.type = type;
 }