Beispiel #1
0
//hook into who is ahead in chain or maybe ahead knows behind? so when ahead tries to move it tries to move behind
    public void SetBlockInstance(LevelManager.BlockInstance toSet) //important guy ayyyyyy
    {
        myBlockInstance        = toSet;
        myBlockInstance.script = this;
    }
Beispiel #2
0
    private void OnConsume()
    {
        Vector2Int direction = new Vector2Int(Mathf.RoundToInt(transform.forward.x), Mathf.RoundToInt(transform.forward.z));

        LevelManager.Instance.AttemptConsume(myBlockInstance, direction, (blockToConsume) =>
        {
            if (blockToConsume.block.Properties.Contains(Block.PROPERTY.Consumable))
            {
                //if (blockToConsume.block.Properties.Contains(Block.PROPERTY.Player))
                //LevelManager.Instance.RemoveFromSolid(blockToConsume);
                LevelTemplate.BlockDefinition def = new LevelTemplate.BlockDefinition
                {
                    position = (Vector2Int)myBlockInstance.gridPos,
                    block    = blockToConsume.block.consumedForm,
                };
                if (!blockToConsume.block.Properties.Contains(Block.PROPERTY.Player))
                {
                    LevelManager.Instance.RemoveAtUnchecked(blockToConsume.gridPos);
                }
                else if (blockToConsume?.linkedBlock != null)
                {
                    blockToConsume.linkedBlock.script.Decouple();
                    LevelManager.Instance.RemoveAtUnchecked(blockToConsume.gridPos);
                }
                else
                {
                    LevelManager.Instance.RemoveAtUnchecked(blockToConsume.gridPos);
                }
                LevelManager.BlockInstance tempLinkInstance = myBlockInstance.linkedBlock;
                LevelManager.BlockInstance newSegment       = LevelManager.Instance.LoadBlock(def, tempLinkInstance, myBlockInstance);
                LevelManager.Instance.SetBlockLink(myBlockInstance, newSegment);
                if (newSegment.linkedBlock != null)
                {
                    LevelManager.Instance.SetBlockOwner(newSegment.linkedBlock, newSegment);
                }

                newSegment.gameObject.transform.forward = this.transform.forward;

                Tween.LocalScale(transform, transform.localScale, moveDur, 0f, Tween.EaseWobble, Tween.LoopType.None, null,
                                 () => { transform.localPosition = (Vector3)Vector3Int.RoundToInt(transform.localPosition); canControl = true; });

                canControl           = false;
                Direction tempfacing = facing;
                Action undoRot       = () => { MortisController.Instance.Set_Rotate(tempfacing); };
                LevelManager.Instance.undoInstructions.Peek().Enqueue(undoRot);


                LevelManager.Instance.MoveBlock(myBlockInstance, direction);
                Direction sealingDir = Direction.None;
                if (-direction == Vector2Int.up)
                {
                    sealingDir = Direction.Up;
                }
                else if (-direction == Vector2Int.down)
                {
                    sealingDir = Direction.Down;
                }
                else if (-direction == Vector2Int.left)
                {
                    sealingDir = Direction.Left;
                }
                else if (-direction == Vector2Int.right)
                {
                    sealingDir = Direction.Right;
                }
                SetSealing(sealingDir);
                //start new undo stack
                LevelManager.Instance.undoInstructions.Push(new Queue <Action>());
                // On eat logic

                //LevelManager.Instance.OnAfterMove();


                if (blockToConsume.block.Properties.Contains(Block.PROPERTY.Pusheable))
                {
                    SfxManager.Instance.PlayEatSound(SfxManager.EatSoundStyle.Wet);
                }
                else if (blockToConsume.block.Properties.Contains(Block.PROPERTY.Player))
                {
                    SfxManager.Instance.PlayEatSound(SfxManager.EatSoundStyle.Wet);
                }
                else
                {
                    SfxManager.Instance.PlayEatSound(SfxManager.EatSoundStyle.Dry);
                }
            }
        });
    }