示例#1
0
    private void OnTriggerExit2D(Collider2D collider)
    {
        PushBlock block = InteractiveHelpers.GetBlock(collider);

        if (block)
        {
            isPressed = false;
            spriteRenderer.enabled = true;
            pressEmitter.Emit(isPressed);
            //trigger.CallTriggerAction(isPressed);
            AudioSingleton.PlaySound(AudioSingleton.Instance.clips.button);
        }
    }
        private void GeneratePushPuzzle()
        {
            // Generate a bunch of stuff you have to push into place in a pattern
            // This is reminiscent of the old Lufia 2 block-pushing puzzles.

            // Simple: generate blocks of alternating colours in a line.
            // Player has to reassemble them in a grid.

            var red  = ColourTuple.Red;
            var blue = ColourTuple.Blue;

            for (var i = 0; i < Config.Instance.Get <int>("PushPuzzleBlocks"); i++)
            {
                // Block
                var colour = i % 2 == 0 ? red : blue;
                var block  = new PushBlock(colour, colour == red ? "Red" : "Blue");
                block.Move(this.FindEmptyPosition());
                this.entities.Add(block);
            }

            bool  foundEmptySpace = false;
            Point startingPoint   = this.FindEmptyPosition();

            while (!foundEmptySpace)
            {
                // Empty 3x2 space
                if (this.IsWalkable(startingPoint.X, startingPoint.Y) && this.IsWalkable(startingPoint.X + 1, startingPoint.Y) && this.IsWalkable(startingPoint.X + 2, startingPoint.Y) &&
                    this.IsWalkable(startingPoint.X, startingPoint.Y + 1) && this.IsWalkable(startingPoint.X + 1, startingPoint.Y + 1) && this.IsWalkable(startingPoint.X + 2, startingPoint.Y + 1))
                {
                    foundEmptySpace = true;
                }
                else
                {
                    startingPoint = this.FindEmptyPosition();
                }
            }

            red  = new ColourTuple(192, 64, 0);
            blue = new ColourTuple(64, 64, 192);

            for (var i = 0; i < Config.Instance.Get <int>("PushPuzzleBlocks"); i++)
            {
                var colour     = i % 2 == 0 ? red : blue;
                var receptacle = new PushReceptacle(colour, colour == red ? "Red" : "Blue");
                var position   = new Point(startingPoint.X + (i % 3), startingPoint.Y + (i / 3));
                receptacle.Move(position);
                this.entities.Add(receptacle);
            }
        }
示例#3
0
    bool CheckForBlocks()
    {
        bool          blockedByBlock = false;
        BoxCollider2D col            = gameObject.GetComponent <BoxCollider2D> ();

        if ((gameObject.layer == LayerMask.NameToLayer("Wall") || gameObject.layer == LayerMask.NameToLayer("HalfWall")) && col != null)
        {
            Collider2D[] colsHit = Physics2D.OverlapBoxAll(transform.position, (new Vector2(col.transform.localScale.x * col.size.x, col.transform.localScale.y * col.size.y)) + new Vector2((-0.02f), (-0.02f)), 0f);
            for (int i = 0; i < colsHit.Length; i++)
            {
                PushBlock block = colsHit [i].GetComponent <PushBlock> ();
                if (block != null)
                {
                    Vector2 blockDir = ((Vector2)block.transform.position - (Vector2)transform.position).normalized;
                    if ((blockDir.x >= 0.2 && _movementVector.x >= 0.1) || (blockDir.x <= -0.2 && _movementVector.x <= -0.1) || (blockDir.y >= 0.2 && _movementVector.y >= 0.1) || (blockDir.y <= -0.2 && _movementVector.y <= -0.1))
                    {
                        if (block.InStasis())
                        {
                            //block is in stasis, freeze the moving object.
                            blockedByBlock = true;
                        }
                        else
                        {
                            Vector2 blockOffset = (Vector2)(block.transform.position - transform.position);
                            if (_active && !inStasis && !GameManager.isPaused())
                            {
                                block.transform.position = Vector2.MoveTowards(block.transform.position, _points [_nextPoint] + blockOffset, _moveSpeed * Time.deltaTime);
                            }
                        }
                    }
                }
            }
        }
        stuckOnBlock = blockedByBlock;
        return(false);
    }
示例#4
0
 // Start is called before the first frame update
 void Start()
 {
     block = transform.parent.GetComponent <PushBlock>();
 }
示例#5
0
    private static PushBlock parsePushBlock(XMLNode node, World world)
    {
        PushBlock result = new PushBlock(world);
        result.SetPosition((float.Parse(node.attributes["x"]) + 8f), -(float.Parse(node.attributes["y"]) - 8f));

        return result;
    }