Example #1
0
 public bool isDead(TetrisBlockPlacement block)
 {
     if (block != null)
     {
         return(block.Y < 0);
     }
     return(false);
 }
Example #2
0
    void CreateSimpleBlock()
    {
        GameObject           block = Instantiate(blockPrefab) as GameObject;
        TetrisBlockPlacement p     = block.GetComponent <TetrisBlockPlacement> ();

        blocks.Add(p);
        p.Init(this, Grid, 0);
    }
Example #3
0
    void CreateComplexBlock()
    {
        GameObject root = Instantiate(blockRootPrefab) as GameObject;

        int     i;
        Vector3 pos = Vector3.zero;
        Color   c   = GetRandomColor();

        int tr = Random.Range(0, templates.Length);
        TetrisBlockTemplate t = templates[tr];

        t.length = t.template.Length / 2;

        if (t.length < 1)
        {
            Destroy(root);
            return;
        }

        t.maxX = 0;
        for (i = 0; i < t.template.Length; i++)
        {
            if (t.template[i])
            {
                GameObject block = Instantiate(blockSinglePrefab) as GameObject;
                block.transform.parent     = root.transform;
                block.transform.localScale = Vector3.one;

                block.transform.localPosition = pos;
                block.renderer.material.color = c;

                t.maxX = Mathf.Max(t.maxX, (int)pos.x + 1);
            }

            if (i == t.length - 1)
            {
                pos.y += 1;
                pos.x  = 0f;
            }
            else
            {
                pos.x += 1;
            }
        }

        TetrisBlockPlacement p = root.GetComponent <TetrisBlockPlacement> ();

        p.shape = t;
        blocks.Add(p);
        lastCreated = p;
        p.Init(this, Grid, t.maxX);
    }
Example #4
0
    public bool CanTakeThisPlace(TetrisBlockPlacement block, bool takeIt)
    {
        /*
         *	grid
         *  28 29 30 31
         *  24 25 26 27
         *  20 21 22 23
         *  16 17 18 19
         *	12 13 14 15
         *	8  9  10 11
         *  4  5   6  7
         *  0  1   2  3
         *
         *  block
         *  3 4 5
         *  0 1 2
         */

        if (block.Y < 0)
        {
            Debug.Log("false 0");
            return(false);
        }

        int  idx  = block.X + block.Y * countX;
        bool free = true;
        int  c    = 0;

        for (int i = 0; i < block.shape.template.Length; i++)
        {
            if (c >= (block.shape.length))
            {
                c    = 0;
                idx += countX;
            }

            if (takeIt)
            {
                if (block.shape.template[i])
                {
                    if (((idx + c) < grid.template.Length))
                    {
                        if (grid.template[idx + c] == true)
                        {
                            Debug.LogWarning("Block " + (idx + c) + " is already taken.");
                        }

                        grid.template[idx + c] = true;
                    }
                }
            }
            else
            {
                if (((idx + c) < grid.template.Length))
                {
                    if (grid.template[idx + c] && block.shape.template[i])
                    {
                        Debug.Log("false 1");
                        free = false;
                        return(false);
                    }

                    if (block.shape.template[i] && block.X < 0)
                    {
                        Debug.Log("false 2");
                        free = false;
                        return(false);
                    }

                    if (block.shape.template[i] && (block.X + block.shape.maxX) > countX)
                    {
                        Debug.Log("false 3");
                        free = false;
                        return(false);
                    }
                }
                else
                {
                    Debug.Log("false 4");
                    return(false);
                }
            }

            c++;
        }

        return(free);
    }
	void CreateComplexBlock()
	{
		GameObject root = Instantiate( blockRootPrefab ) as GameObject;

		int i;
		Vector3 pos = Vector3.zero;
		Color c = GetRandomColor();

		int tr = Random.Range( 0, templates.Length );
		TetrisBlockTemplate t = templates[ tr ];
		t.length = t.template.Length / 2;

		if ( t.length < 1 )
		{
			Destroy( root );
			return;
		}

		t.maxX = 0;
		for ( i = 0; i < t.template.Length; i++ )
		{
			if ( t.template[ i ] )
			{
				GameObject block = Instantiate( blockSinglePrefab ) as GameObject;
				block.transform.parent = root.transform;
				block.transform.localScale = Vector3.one;

				block.transform.localPosition = pos;
				block.renderer.material.color = c;

				t.maxX = Mathf.Max( t.maxX, (int)pos.x + 1 );
			}

			if ( i == t.length - 1 )
			{
				pos.y += 1;
				pos.x  = 0f;
			}
			else
			{
				pos.x += 1;
			}
		}

		TetrisBlockPlacement p = root.GetComponent<TetrisBlockPlacement> ();
		p.shape = t;
		blocks.Add (p);
		lastCreated = p;
		p.Init (this, Grid, t.maxX);
	}
	public void BlockDied( TetrisBlockPlacement b )
	{
		blocks.Remove( b );
	}
	public bool CanTakeThisPlace( TetrisBlockPlacement block, bool takeIt )
	{
		/*
		 *	grid
		 * 	28 29 30 31
		 * 	24 25 26 27
		 * 	20 21 22 23
		 * 	16 17 18 19
		 *	12 13 14 15
		 *	8  9  10 11
		 * 	4  5   6  7
		 * 	0  1   2  3
		 * 
		 * 	block
		 * 	3 4 5
		 * 	0 1 2
		 */

		if ( block.Y < 0 )
		{
			Debug.Log( "false 0" );
			return false;
		}

		int idx = block.X + block.Y * countX;
		bool free = true;
		int c = 0;
		for ( int i = 0; i < block.shape.template.Length; i++ )
		{
			if ( c >= ( block.shape.length ) )
			{
				c = 0;
				idx += countX;
			}

			if ( takeIt )
			{
				if ( block.shape.template[ i ] )
				{
					if ( ( ( idx + c ) < grid.template.Length ) )
					{
						if ( grid.template[ idx + c ] == true )
						{
							Debug.LogWarning( "Block " + ( idx + c ) + " is already taken." );
						}

						grid.template[ idx + c ] = true;
					}
				}
			}
			else
			{
				if ( ( ( idx + c ) < grid.template.Length ) )
				{
					if ( grid.template[ idx + c ] && block.shape.template[ i ] )
					{
						Debug.Log( "false 1" );
						free = false;
						return false;
					}

					if ( block.shape.template[ i ] && block.X < 0 )
					{
						Debug.Log( "false 2" );
						free = false;
						return false;
					}

					if ( block.shape.template[ i ] && ( block.X + block.shape.maxX ) > countX )
					{
						Debug.Log( "false 3" );
						free = false;
						return false;
					}
				}
				else
				{
					Debug.Log( "false 4" );
					return false;
				}
			}
			
			c++;
		}

		return free;
	}
	public bool isDead( TetrisBlockPlacement block )
	{
		if ( block != null )
		{
			return block.Y < 0;
		}
		return false;
	}
Example #9
0
 public void BlockDied(TetrisBlockPlacement b)
 {
     blocks.Remove(b);
 }