Beispiel #1
0
    public override void _Input(InputEvent @event)
    {
        // For testing only
        if (@event is InputEventKey keyEvent && keyEvent.Pressed)
        {
            if ((KeyList)keyEvent.Scancode == KeyList.T)
            {
                BouncingItem bounceTest = (BouncingItem)GD.Load <PackedScene>("res://BouncingItem.tscn").Instance();
                bounceTest.Position = Position;
                bounceTest.Initialise(new Vector2(15f, 0f), -60f);

                GetParent().AddChild(bounceTest);
            }
        }

        // 'action button' input
        if (@event is InputEventScreenTouch screenTouchEvent && screenTouchEvent.Pressed)
        {
            if (screenTouchEvent.Pressed && screenTouchEvent.Position.x > GetViewport().GetVisibleRect().Size.x / 2)
            {
                ActionButtonPressed(screenTouchEvent.Position);
            }
            else
            {
                ((Node2D)_joystick.GetParent()).GlobalPosition = screenTouchEvent.Position;
            }
        }
    }
Beispiel #2
0
    public bool Interact(Player player)
    {
        if (!_empty)
        {
            _tween.InterpolateProperty(_nodeToShake, "rotation_degrees", 0f, rotateDegs, .15f, Tween.TransitionType.Quart, Tween.EaseType.InOut);
            _tween.InterpolateProperty(_nodeToShake, "rotation_degrees", rotateDegs, -rotateDegs, .3f, Tween.TransitionType.Quart, Tween.EaseType.InOut, .15f);
            _tween.InterpolateProperty(_nodeToShake, "rotation_degrees", -rotateDegs, 0f, .15f, Tween.TransitionType.Quart, Tween.EaseType.InOut, .45f);
            _tween.Start();

            BouncingItem newBounce = (BouncingItem)_bouncingItem.Instance();
            GetParent().AddChild(newBounce);

            newBounce.Initialise(new Vector2((GD.Randf() * 2) - 1f, (GD.Randf() * 2) - 1f) * 25f, (float)GD.RandRange(-40, -60));
            newBounce.Position  = Position;
            newBounce.ItemStack = _itemStack;

            _empty = true;
            _nodeToHide.Visible = false;
        }

        return(false);
    }