示例#1
0
    void CreateWorld()
    {
        GameObject worldPrefab = Resources.Load <GameObject>("World");
        GameObject world       = Instantiate(worldPrefab) as GameObject;

        GameObject dirtPrefab = Resources.Load <GameObject>("Dirt");

        Grid worldGrid = world.GetComponent <Grid>();

        worldGrid.AddBlock(dirtPrefab, 0, 2);
        worldGrid.AddBlock(dirtPrefab, 0, 1);
        worldGrid.AddBlock(dirtPrefab, 1, 1);
    }
示例#2
0
    public void FinishSliding(int slideX)
    {
        block.State = Block.BlockState.Idle;

        Direction = BlockSlider.SlideDirection.None;

        block.X = slideX;

        grid.AddBlock(block.X, block.Y, block, GridElement.ElementState.Block);
    }
示例#3
0
    // Untested
    public void InitializeAwakening(int x, int y, int flavor, float popDuration, float awakenDuration, ComboTabulator combo, int popColor)
    {
        X      = x;
        Y      = y;
        Flavor = flavor;

        State            = BlockState.Awakening;
        AwakenDuration   = awakenDuration;
        this.popDuration = popDuration;
        //popDirection = BlockManager.GeneratePopDirection();
        //this.popColor = popColor;
        CurrentCombo = combo;

        CurrentCombo.IncrementInvolvement();

        //Game.AwakeningCount++;

        grid.AddBlock(x, y, this, GridElement.ElementState.Immutable);
    }
示例#4
0
    // Update is called once per frame
    void Update()
    {
        if (block.State == Block.BlockState.Falling)
        {
            FallElapsed += Time.deltaTime;

            if (FallElapsed >= FallDuration)
            {
                // shift our grid position down to the next row
                block.Y--;

                if (grid.StateAt(block.X, block.Y - 1) == GridElement.ElementState.Empty)
                {
                    FallElapsed = 0.0f;

                    if (grid.StateAt(block.X, block.Y + 2) == GridElement.ElementState.Empty)
                    {
                        grid.Remove(block.X, block.Y + 1, block);
                    }
                    grid.AddBlock(block.X, block.Y, block, GridElement.ElementState.Falling);
                }
                else
                {
                    // we've landed

                    // change our state
                    block.State = Block.BlockState.Idle;

                    // update the grid
                    if (grid.StateAt(block.X, block.Y + 2) == GridElement.ElementState.Empty)
                    {
                        grid.Remove(block.X, block.Y + 1, block);
                    }
                    grid.AddBlock(block.X, block.Y, block, GridElement.ElementState.Block);

                    // register for elimination checking
                    grid.RequestMatchCheck(block);
                }
            }
        }
    }
示例#5
0
 public void OnEndDrag(PointerEventData eventData)
 {
     if (grid.isPlaceable(block))
     {
         //Add to grid
         grid.AddBlock(block);
     }
     else
     {
         //Destroy gameObject
         Destroy(blockPrefab);
     }
     gridUI.Hide();
 }
示例#6
0
    public void InitializeIdle(int x, int y, int type)
    {
        X    = x;
        Y    = y;
        Type = type;

        State = BlockState.Idle;

        // Initializing Grid here again. It looks like Start isn't getting called until the next frame
        grid = GameObject.Find("Grid").GetComponent <Grid>();
        grid.AddBlock(x, y, this, GridElement.ElementState.Block);

        transform.position = new Vector3(X, Y, 0.0f);
    }
示例#7
0
    public void InitializeIdle(int x, int y, int type)
    {
        X = x;
        Y = y;
        Type = type;

        State = BlockState.Idle;

        // Initializing Grid here again. It looks like Start isn't getting called until the next frame
        grid = GameObject.Find("Grid").GetComponent<Grid>();
        grid.AddBlock(x, y, this, GridElement.ElementState.Block);

        transform.position = new Vector3(X, Y, 0.0f);
    }
示例#8
0
    public void Initialize(int x, int y, int type)
    {
        X    = x;
        Y    = y;
        Type = type;

        GameObject game = GameObject.Find("Game");

        if (game != null)
        {
            grid = game.GetComponent <Grid>();
        }

        grid.AddBlock(x, y, this, GridElement.ElementState.Block);
    }
示例#9
0
    void Update()
    {
        // don't update the creep row
        if (Y == 0)
        {
            return;
        }

        if (changeState)
        {
            State = BlockState.Falling;

            changeState = false;
        }

        switch (State)
        {
        case BlockState.Idle:
            // we may have to fall
            if (grid.StateAt(X, Y - 1) == GridElement.ElementState.Empty)
            {
                StartFalling();
            }
            break;

        case BlockState.Falling:
            FallElapsed += Time.deltaTime;

            if (FallElapsed >= FallDuration)
            {
                if (grid.StateAt(X, Y - 1) == GridElement.ElementState.Empty)
                {
                    // shift our grid position down to the next row
                    Y--;
                    FallElapsed = 0.0f;

                    grid.Remove(X, Y + 1, this);
                    grid.AddBlock(X, Y, this, GridElement.ElementState.Falling);
                }
                else
                {
                    // we've landed

                    // change our state
                    State = BlockState.Idle;

                    // update the grid
                    grid.ChangeState(X, Y, this, GridElement.ElementState.Block);

                    // register for elimination checking
                    grid.RequestMatchCheck(this);
                }
            }
            break;

        case BlockState.Dying:
            DieElapsed += Time.deltaTime;

            if (DieElapsed >= DieDuration)
            {
                // change the game state
                blockManager.DyingBlockCount--;

                // update the grid
                grid.Remove(X, Y, this);

                // tell our upward neighbor to fall
                if (Y < Grid.PlayHeight - 1)
                {
                    if (grid.StateAt(X, Y + 1) == GridElement.ElementState.Block)
                    {
                        grid.BlockAt(X, Y + 1).StartFalling(Chain);
                    }
                }

                Chain.DecrementInvolvement();

                ParticleManager particleManager = FindObjectOfType <ParticleManager>();
                particleManager.CreateParticles(X, Y, Chain.Magnitude, Type);

                blockManager.DeleteBlock(this);
            }
            break;
        }
    }