예제 #1
0
 public override bool TickStart()
 {
     //add a check for blocks that may be collided with
     if (grabbedBlock == null && BlockController.Instance.blocks.ContainsKey(VectorToInt(loc - transform.forward)) &&
         !flipped && (color == 0 || BlockController.Instance.blocks[VectorToInt(loc - transform.forward)].color == color) &&
         BlockController.Instance.blocks[VectorToInt(loc - transform.forward)].GetComponent <MovableBlock>() != null)
     {
         MovableBlock b = BlockController.Instance.blocks[VectorToInt(loc - transform.forward)].GetComponent <MovableBlock>();
         if (!b.grabbed)
         {
             grabbedBlock = b.transform;
             b.grabbed    = true;
             if (BlockController.Instance.blocksToActivate.Contains(b))
             {
                 BlockController.Instance.blocksToActivate.Remove(b);
             }
             return(true);
         }
     }
     if (flipped)
     {
         return(true);
     }
     return(false);
 }
 void MoveBlock(MovableBlock blockToMove)
 {
     if (blockToMove != null)
     {
         blockToMove.BeMoved(distanceToMove);
     }
 }
예제 #3
0
        private bool TryAddNonStandardTiles(MapTile tile, Point location)
        {
            // ReSharper disable once SwitchStatementMissingSomeCases (cases are covered elsewhere)
            switch (tile)
            {
            case MapTile.Key:
                Items.Add(new Key(location, this));
                break;

            case MapTile.Compass:
                Items.Add(new Compass(location));
                break;

            case MapTile.Map:
                Items.Add(new Map(location));
                break;

            case MapTile.Bow:
                Items.Add(new BowItem(location, Secondary.Bow, 10));
                break;

            case MapTile.Triforce:
                Items.Add(new Triforce(location));
                break;

            case MapTile.PushableBlock:
                var pushableBlock = new MovableBlock(location);
                Collidables.Add(pushableBlock);
                Drawables.Add(pushableBlock);
                TransitionResetables.Add(pushableBlock);
                break;

            case MapTile.SpawnEnemy:
                SpawnTiles.Add(location);
                break;

            case MapTile.Sand:
                Drawables.Add(new Overlay(location, BlockType.Sand));
                break;

            case MapTile.Heart:
                Items.Add(new HeartContainer(location, this));
                break;

            case MapTile.Boomerang:
                Items.Add(new BoomerangItem(location, this, 20));
                break;

            case MapTile.BasementBricks:
            case MapTile.BlackOverlay:
            case MapTile.None:
            case MapTile.Room2_1Block:
                break;

            default:
                return(false);
            }

            return(true);
        }
예제 #4
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKey(interactKey))
        {
            RaycastHit2D[] results = Physics2D.BoxCastAll(transform.position + interactionBoxOffset, GetComponent <SpriteRenderer>().size * 2, 0, new Vector2(1, 0), 0);

            // For each collider found:
            for (int i = 0; i < results.Length; i++)
            {
                string resultsTag = results[i].transform.tag;

                // If the result's tag is the correct color, then:
                if (resultsTag.CompareTo(color) == 0)
                {
                    MovableBlock theBlock = results[i].transform.GetComponent <MovableBlock>();

                    // If the block is a draggable block, then:
                    if ((DraggableBlock)theBlock)
                    {
                        theBlock.Move(GetComponent <Rigidbody2D>().velocity.x *Time.deltaTime);
                    }
                    else if ((WeighableBlock)theBlock)
                    {
                        theBlock.Move(GetComponent <Rigidbody2D>().velocity.y *Time.deltaTime);
                    }
                }
            }
        }
    }
예제 #5
0
    void movement()
    {
        if (stack != null && stack.Count > 0)
        {
            //me muevo
            Tuple <uint, uint> pos = stack.Pop().Position;
            targetPosition = new Position(pos.Item1, pos.Item2);
            MovableBlock block_ = tablero.GetBlock(new Position(targetPosition.GetRow(), targetPosition.GetColumn()));
            this.transform.position = new Vector3(block_.transform.position.x, this.transform.position.y, block_.transform.position.z);
            current = targetPosition;

            /*if (targetPosition == null) {
             *      Tuple<uint, uint> pos = stack.Pop ().Position;
             *      targetPosition = new Position(pos.Item1, pos.Item2);
             * } else if (targetPosition != getCurrent ()) {
             *      MovableBlock block_ = tablero.GetBlock (new Position (targetPosition.GetRow (), targetPosition.GetColumn ()));
             *      this.transform.position = new Vector3 (block_.transform.position.x, this.transform.position.y, block_.transform.position.z);
             *      current = targetPosition;
             * } else {
             *      targetPosition = null;
             * }*/
        }
        else
        {
            CancelInvoke();
        }
    }
예제 #6
0
 // Start is called before the first frame update
 void Start()
 {
     Debug.Log("started");
     yellowButton = GameObject.Find("YellowButton").GetComponent <BlockButton>();
     redButton    = GameObject.Find("RedButton").GetComponent <BlockButton>();
     blueButton   = GameObject.Find("BlueButton").GetComponent <BlockButton>();
     yellowBlock  = GameObject.Find("YellowBlock").GetComponent <MovableBlock>();
     redBlock     = GameObject.Find("RedBlock").GetComponent <MovableBlock>();
     blueBlock    = GameObject.Find("BlueBlock").GetComponent <MovableBlock>();
     exitDoor     = GameObject.Find("ExitDoor");
 }
예제 #7
0
    private void OnCollisionEnter(Collision collision)
    {
        //when against a movable block, set againstBlock to true
        // and get that objects script component
        if (collision.gameObject.tag == "Movable")
        {
            againstBlock  = true;
            blockTouching = collision.gameObject.GetComponent <MovableBlock>();
        }

        //when touching the exit door notify room manager
        else if (collision.gameObject.tag == "Exit")
        {
            roomControl.ExitStage();
        }
    }
예제 #8
0
    public void Initialize(BlockBoard board)
    {
        tablero  = board;
        clicked_ = false;
        changeColor();

        int w = tablero.getWidth();
        int h = tablero.getHeight();

        MovableBlock block_ = null;

        do
        {
            uint x = (uint)rnd.Next(0, w);
            uint y = (uint)rnd.Next(0, h);

            block_ = tablero.GetBlock(new Position(x, y));
        }while(block_.getType() == MovableBlock.TipoCasilla.R || block_.getType() == MovableBlock.TipoCasilla.F);

        current = block_.position;
        //print ("hellooo: " + current);
        this.transform.position = new Vector3(block_.transform.position.x, this.transform.position.y, block_.transform.position.z);
    }
예제 #9
0
    private bool CanMove(Direction md)
    {
        Vector2 vec;

        switch (md)
        {
        case Direction.UP:
            vec = Vector2.up;
            break;

        case Direction.DOWN:
            vec = Vector2.down;
            break;

        case Direction.LEFT:
            vec = Vector2.left;
            break;

        case Direction.RIGHT:
            vec = Vector2.right;
            break;

        default:
            vec = Vector2.up;
            break;
        }
        RaycastHit2D hit = Physics2D.Raycast(transform.position, vec, .6f);

        // return if hit collides w/ something
        if (hit.collider != null)
        {
            if (hit.collider.tag == "WalkableTile" || hit.collider.tag == "Item")
            {
                return(true);
            }

            if (hit.collider.tag == "Actor")
            {
            }

            if (hit.collider.tag == "UnwalkableTile")
            {
                //Moving Wall Tile
                MovableBlock mb = hit.transform.gameObject.GetComponent <MovableBlock>();
                if (mb != null)
                {
                    return(mb.AcceptCollision(vec));
                }

                KeyDoor kd = hit.transform.gameObject.GetComponent <KeyDoor>();
                if (kd != null)
                {
                    return(kd.TryToUnlock(player));
                }

                //Wall
                return(false);
            }
        }

        return(true);
    }