Beispiel #1
0
    public override void Perform()
    {
        if (!manipulate.isManipulating)
        {
            return;
        }

        Vector2     dir         = player.lastPotentAim.normalized;
        Manipulable manipulable = manipulate.FindManipulateable(dir);

        if (!manipulable)
        {
            return;
        }

        Rigidbody2D otherRigid = manipulable.rigid;

        otherRigid.SendMessage("Hit", SendMessageOptions.DontRequireReceiver);
        Vector2 velocity = otherRigid.velocity;

        velocity           += dir * speed;
        otherRigid.velocity = velocity;

        EffectManager.CreateRockHitEffect(otherRigid.position, dir);
    }
Beispiel #2
0
    public override void Perform()
    {
        if (!manipulate.isManipulating)
        {
            return;
        }

        Vector2     dir         = player.myRigid.velocity.normalized;
        Manipulable manipulable = manipulate.FindManipulateable(dir);

        if (!manipulable)
        {
            return;
        }

        Rigidbody2D otherRigid = manipulable.rigid;

        Vector2 aim      = player.lastPotentAim.normalized;
        Vector2 deltaVel = aim * jumpSpeed;

        player.myRigid.velocity = Vector2.zero;
        Bending.AddVelocity(player.myRigid, deltaVel);
        Bending.AddVelocity(otherRigid, -deltaVel);

        EffectManager.CreateRockHitEffect(transform.position, deltaVel);
        EffectManager.CreateRockHitEffect(otherRigid.position, -deltaVel);
    }
Beispiel #3
0
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            _viewBox = Template.FindName("PART_VIEWBOX", this) as FrameworkElement;

            if (IsManipulable)
            {
                _manipulable = new Manipulable()
                {
                    Container = _parent
                };
                TapBehavior _tapbehavior = new TapBehavior()
                {
                    Threshold = 5
                };
                _manipulable.SupportedManipulations = ManipulationTypes.All;

                _manipulable.Manipulate += new EventHandler <ManipulationDeltaEventArgs>(_manipulable_Manipulate);
                _tapbehavior.Tap        += new EventHandler <TapEventArgs>(_tapbehavior_DoubleTap);

                BehaviorCollection bCollection = Interaction.GetBehaviors(this);
                bCollection.Add(_manipulable);
                bCollection.Add(_tapbehavior);
            }
        }
Beispiel #4
0
    public override void Perform()
    {
        if (selection)
        {
            return;
        }

        Vector2 dir = player.lastPotentAim;

        selection = manipulate.FindManipulateable(dir, maxMass);
    }
Beispiel #5
0
    private void Update()
    {
        //Nothing to do if there is no selection
        if (!selection)
        {
            return;
        }
        //Stopped manipulating... Let go
        if (!manipulate.isManipulating)
        {
            selection = null; //No Launch
            return;
        }

        Vector2 myPos  = transform.position;
        Vector2 selPos = selection.rigid.position;

        //If out of reach... Let go
        float distance = Vector2.Distance(myPos, selPos);

        if (distance > manipulate.radius)
        {
            selection = null;
            return;
        }

        // Check if its getting closer or further?
        Vector2 nextMyPos    = myPos + player.myRigid.velocity * Time.deltaTime;
        Vector2 nextSelPos   = selPos + selection.rigid.velocity * Time.deltaTime;
        float   nextdistance = Vector2.Distance(nextMyPos, nextSelPos);

        // If getting closer, do nothing
        if (nextdistance < distance)
        {
            return;
        }

        //Redirect
        Vector2 dir        = (selPos - myPos).normalized;
        Vector2 tangent    = Vector2.Perpendicular(dir).normalized;
        Vector2 velocity   = selection.rigid.velocity;
        float   tangentDir = Mathf.Sign(Vector2.Dot(tangent, velocity));

        velocity = tangent * tangentDir * velocity.magnitude;
        selection.rigid.velocity = velocity;

        Debug.DrawRay(selection.rigid.position, velocity);
    }
    public override void Perform()
    {
        Vector2 dir = player.lastPotentAim;

        Manipulable manipulable = manipulate.FindManipulateable(dir);

        if (!manipulable)
        {
            return;
        }

        Rigidbody2D otherRigid = manipulable.rigid;

        if (otherRigid && (otherRigid.mass <= maxMass || otherRigid.bodyType == RigidbodyType2D.Kinematic))
        {
            otherRigid.gameObject.SendMessage("Break");
        }
    }
Beispiel #7
0
    public void Cancel()
    {
        if (!selection)
        {
            return;
        }

        Vector2 velocity = selection.rigid.velocity;

        if (velocity.magnitude < launchSpeed)
        {
            velocity = velocity.normalized * launchSpeed;
        }
        selection.rigid.velocity = velocity;

        EffectManager.CreateRockHitEffect(selection.rigid.position, velocity.normalized);

        selection = null;
    }
    public Manipulable FindClosestManipulable(float maxMass = 1000)
    {
        if (!isManipulating)
        {
            return(null);
        }

        Manipulable closest         = null;
        float       closestDistance = radius + 10;

        foreach (Manipulable m in manipulables)
        {
            float distance = ((Vector2)transform.position - m.rigid.position).magnitude;
            if (distance < closestDistance && m.rigid.mass < maxMass)
            {
                closest         = m;
                closestDistance = distance;
            }
        }
        return(closest);
    }
    //Finds closest manipulables relative to an direction
    public Manipulable FindManipulateable(Vector2 dir, float maxMass = 1000)
    {
        if (!isManipulating)
        {
            return(null);
        }

        Vector2 myPosition = (Vector2)transform.position + dir * radius;

        Manipulable closest         = null;
        float       closestDistance = radius * 2 + 10;

        foreach (Manipulable m in manipulables)
        {
            float distance = ((Vector2)myPosition - m.rigid.position).magnitude;
            distance += ((Vector2)transform.position - m.rigid.position).magnitude * 2;
            if (distance < closestDistance && m.rigid.mass < maxMass)
            {
                closest         = m;
                closestDistance = distance;
            }
        }
        return(closest);
    }
    //Finds all Manipulables (Rigidbody2D) in its manipulateRadius.
    public Manipulable[] FindManipulables()
    {
        if (!isManipulating)
        {
            return(new Manipulable[0]);
        }

        List <Manipulable> manipulables = new List <Manipulable>();

        Collider2D[] colliders = Physics2D.OverlapCircleAll(transform.position, radius, layerMask);
        foreach (Collider2D c in colliders)
        {
            if (c.attachedRigidbody)
            {
                Manipulable manipulable = c.GetComponent <Manipulable>();
                if (manipulable)
                {
                    manipulables.Add(manipulable);
                }
            }
        }

        return(manipulables.ToArray());
    }
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            _viewBox = Template.FindName("PART_VIEWBOX", this) as FrameworkElement;

            if (IsManipulable)
            {
                _manipulable = new Manipulable() { Container = _parent };
                TapBehavior _tapbehavior = new TapBehavior() { Threshold= 5};
                _manipulable.SupportedManipulations = ManipulationTypes.All;

                _manipulable.Manipulate += new EventHandler<ManipulationDeltaEventArgs>(_manipulable_Manipulate);
                _tapbehavior.Tap += new EventHandler<TapEventArgs>(_tapbehavior_DoubleTap);

                BehaviorCollection bCollection = Interaction.GetBehaviors(this);
                bCollection.Add(_manipulable);
                bCollection.Add(_tapbehavior);
            }
        }