Ejemplo n.º 1
0
    private void LoadPlayerLate()
    {
        LevelTemplate.BlockDefinition pBlock = new LevelTemplate.BlockDefinition
        {
            position = Levels[CurrentLevelIndex].PlayerStartPostion,
            block    = playerBlock,
        };
        LoadBlock(pBlock);

        //purge undo of level make
        undoInstructions.Pop();
        undoInstructions.Push(new Queue <Action>());
    }
Ejemplo n.º 2
0
 public void Decouple()
 {
     if (myBlockInstance.linkedBlock != null)
     {
         myBlockInstance.linkedBlock.script.Decouple();
     }
     LevelTemplate.BlockDefinition dcDef = new LevelTemplate.BlockDefinition
     {
         position = (Vector2Int)myBlockInstance.gridPos,
         block    = decoupledForm,
     };
     LevelManager.Instance.LoadBlock(dcDef);
     LevelManager.Instance.RemoveAtUnchecked(myBlockInstance.gridPos);
 }
Ejemplo n.º 3
0
    public BlockInstance LoadBlock(LevelTemplate.BlockDefinition bD, BlockInstance linkedInstance, BlockInstance ownerInstance)
    {
        GameObject instance      = Instantiate(bD.block.Prefab, transform);
        Vector3    localPosition = bD.block.Prefab.gameObject.transform.localPosition + new Vector3(bD.position.x, 0.0f, bD.position.y);

        instance.transform.localPosition = localPosition;
        BlockInstance someBlockInstance = new BlockInstance
        {
            block       = bD.block,
            gameObject  = instance,
            gridPos     = Vector3Int.zero, //assign to this post def so we can check props for layer
            linkedBlock = null,            //assign in way we can undo
            ownerBlock  = null,
        };

        if (ownerInstance != null)
        {
            SetBlockOwner(someBlockInstance, ownerInstance);
        }
        if (linkedInstance != null)
        {
            SetBlockLink(someBlockInstance, linkedInstance);
        }
        List <Block.PROPERTY> sbProps = someBlockInstance.block.Properties;
        int layerAssign = 0;

        if (sbProps.Contains(Block.PROPERTY.Player))
        {
            layerAssign = 2;
        }
        else if (sbProps.Contains(Block.PROPERTY.Solid))
        {
            layerAssign = 1;
        }

        someBlockInstance.gridPos = new Vector3Int(bD.position.x, bD.position.y, layerAssign);
        if (sbProps.Contains(Block.PROPERTY.Solution))
        {
            SolutionBlockPositions.Add(someBlockInstance.gridPos);
        }

        CurrentLevel[bD.position.x, bD.position.y, layerAssign] = someBlockInstance;
        instance.SendMessage("SetBlockInstance", someBlockInstance, SendMessageOptions.DontRequireReceiver);
        //to undo
        Action unMake = () => { RemoveAt(new Vector3Int(bD.position.x, bD.position.y, layerAssign)); };

        undoInstructions.Peek().Enqueue(unMake);
        return(someBlockInstance);
    }
Ejemplo n.º 4
0
 public BlockInstance LoadBlock(LevelTemplate.BlockDefinition bD)
 {
     return(LoadBlock(bD, null, null));
 }
Ejemplo n.º 5
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);
                }
            }
        });
    }