Beispiel #1
0
    void OnCollisionEnter(Collision other)
    {
        GrapplePoint g = other.collider.GetComponent <GrapplePoint>();
        Tile         t = other.collider.GetComponent <Tile>();

        // Debug.Log("Object on hit: " + other.transform.ToString());
        if (t != null && !t.GetHasWall() && !t.GetIsFakeWall())
        {
            _ObjectOnCollsion    = other.transform.position;
            _ObjectOnCollsion.y += 2 * halfHeight;
            ResetInitialPosisiton();
            _OnHit = true;
        }
        else if (g != null)
        {
            _ObjectOnCollsion    = g.GetTileAttached().transform.position;
            _ObjectOnCollsion.y += 2 * halfHeight;
            ResetInitialPosisiton();
            _GrapplePointHit = true;
        }
        else
        {
            _TMP.SetText("You cannot reach there!");
            ResetInitialPosisiton();
        }
    }
Beispiel #2
0
 private void DestroyCurrentGrapplePoint()
 {
     if (currentForceGrabProjectile != null)
     {
         // Trash the grapple point if we've hit a wall.
         // If we haven't hit a wall yet, then it'll garbage collect by itself after its lifespan is up.
         GrapplePoint gp = currentForceGrabProjectile.GetComponent <GrapplePoint>();
         if (gp.hasCollided)
         {
             gp.DestroySelf();
         }
     }
 }
Beispiel #3
0
    void OnCollisionEnter2D(Collision2D col)
    {
        // Debug.Log("Collision:" + col.gameObject, col.gameObject);
        GrapplePoint gp = col.gameObject.GetComponent <GrapplePoint>();

        if (gp != null)
        {
            // Debug.Log("ReelingIn");
            if (fsm.State == HookStates.Shooting)
            {
                fsm.ChangeState(HookStates.ReelingIn);
            }
        }
    }
Beispiel #4
0
    void Grapple()
    {
        var activeGrapplePoint = GetActiveGrapplePoint();

        if (activeGrapplePoint != null)
        {
            this.isGrappling        = true;
            this.activeGrapplePoint = activeGrapplePoint;
            this.activeGrapplePoint.GetComponent <SpriteRenderer>().color = colorActive;

            var playerPos2 = new Vector2(gameObject.transform.position.x, gameObject.transform.position.y);

            this.ropeObject.SetActive(true);
            this.ropeLength = (playerPos2 - GetGrapplePointPosition()).magnitude;
            this.ropeObject.transform.localScale = Vector3.one * this.ropeLength;
        }
    }
Beispiel #5
0
    void Populate(int numPoints)
    {
        int pointsPlaced = 0;

        while (pointsPlaced < numPoints)
        {
            Vector2    position = new Vector2(Random.Range(cellCollider.bounds.min.x, cellCollider.bounds.max.x), Random.Range(cellCollider.bounds.min.y, cellCollider.bounds.max.y));
            Collider2D col      = Physics2D.OverlapCircle(position, 2, 1 << RADIUS_LAYER_ID);

            if (col == null || !col.CompareTag("Grapple Point Outer"))
            {
                GrapplePoint grapplePoint = Instantiate(grapplePointPrefab, position, Quaternion.identity).GetComponent <GrapplePoint>();
                grapplePoint.transform.parent = transform;
                grapplePoint.grapple          = grid.playerGrapple;
                grapplePoints.Add(grapplePoint);
                ++pointsPlaced;
            }
        }
    }
Beispiel #6
0
    // Update is called once per frame
    void Update()
    {
        if (!this.isGrappling)
        {
            if (this.activeGrapplePoint != null)
            {
                this.activeGrapplePoint.GetComponent <SpriteRenderer>().color = colorDefault;
            }

            // highlight the grapple point that will be selected
            var newActiveGrapplePoint = GetActiveGrapplePoint();
            if (newActiveGrapplePoint != null)
            {
                this.activeGrapplePoint = newActiveGrapplePoint;
                this.activeGrapplePoint.GetComponent <SpriteRenderer>().color = colorActive;
            }
        }
        else
        {
        }
    }
Beispiel #7
0
    // Update is called once per frame
    void Update()
    {
        if (InputMapper.Instance.GetButtonDown(Action.Whip))
        {
            //Debug.Log("looking for grapple");
            GrapplePoint nearestGrapplePoint = null;
            float        shortestDistance    = 0;
            foreach (GrapplePoint grapplePoint in grapplePoints)
            {
                float distance = Vector3.Distance(transform.position, grapplePoint.transform.position);
                if (nearestGrapplePoint == null || distance < shortestDistance)
                {
                    nearestGrapplePoint = grapplePoint;
                    shortestDistance    = distance;
                }
            }

            if (nearestGrapplePoint != null && shortestDistance < grappleDistance)
            {
                // A valid grapple point has been found.
                //Debug.Log("connecting to grapple");

                AudioManager.Instance.Play("grapple_connect");
                grappling            = true;
                currentGrapplePoint  = nearestGrapplePoint;
                currentGrappleLength = shortestDistance;
                rope.enabled         = true;
            }
        }

        if (grappling && !InputMapper.Instance.GetButton(Action.Whip))
        {
            // Stopped grappling
            AudioManager.Instance.Play("grapple_disconnect");
            grappling           = false;
            currentGrapplePoint = null;
            rope.enabled        = false;
        }
    }
Beispiel #8
0
    GrapplePoint GetActiveGrapplePoint()
    {
        if (validGrapplingPoints.Count == 0)
        {
            return(null);
        }

        var          playerPosition      = gameObject.transform.position;
        var          closestDistance     = float.MaxValue;
        GrapplePoint closestGrapplePoint = null;

        foreach (GrapplePoint grapplePoint in validGrapplingPoints)
        {
            var distance = (playerPosition - grapplePoint.gameObject.transform.position).magnitude;
            if (distance < closestDistance)
            {
                closestDistance     = distance;
                closestGrapplePoint = grapplePoint;
            }
        }
        return(closestGrapplePoint);
    }
Beispiel #9
0
    // --------------------------------------------------------------------------------
    // New Grapple
    // --------------------------------------------------------------------------------
    // TODO: Apply motion += grapplePoint.velocity?
    private void DoGrab(SteamVR_Action_Boolean fromAction, SteamVR_Input_Sources fromSource, bool newState)
    {
        // TODO: This is causing the player to freeze in place if they activate DoGrab() with their off hand
        //if (doGrabAction.trackedDeviceIndex != parentHand.GetDeviceIndex()) return;
        if (blaster.IsPrimaryFireModeBlockingGrapple())
        {
            ReleaseGrip();
        }

        // If the player lets go of the grab button
        if (!newState)
        {
            //audioSource.Stop();

            // If we have vertical momentum on the way up, give ourselves a little extra boost
            if (fromAction.stateUp && motion.y > 0 && currentGrapplePoint != null)
            {
                if (currentGrapplePoint.hasCollided)
                {
                    Debug.Log("Added boost");
                }
                motion.y += addedVerticalMomentum;
            }
            ReleaseGrip();

            smoothLocomotion.enabled = true;
            return;
        }

        // If this is the first time that we've pressed the grab button
        if (fromAction.stateDown)
        {
            // If we haven't connected with anything yet, fire a projectile
            if (forceGrabbableTarget == null)
            {
                DestroyCurrentGrapplePoint();

                currentForceGrabProjectile = blaster.FireNewProjectile(forceGrabProjectilePrefab,
                                                                       forceGrabProjectileVelocity);

                currentGrapplePoint = currentForceGrabProjectile.GetComponent <GrapplePoint>();
                currentGrapplePoint.parentGrappler = this;
            }
        }

        // When the grapple point collided with the target...
        if (newState && currentForceGrabProjectile != null)
        {
            //audioSource.Play();
            //audioSource.loop = true;

            if (currentGrapplePoint.hasCollided)
            {
                if (forceGrabbableTarget != null)
                {
                    // -- This is a force-grabbable object, then pick it up
                    DoForceGrabDistance();

                    // Not sure why this is needed, but smooth locomotion gets disabled without it.
                    smoothLocomotion.enabled = true;
                }
                else
                {
                    // -- If we've collided with a wall, then grapple to it.
                    smoothLocomotion.activeGrappler = this;
                    smoothLocomotion.enabled        = false;

                    GrappleTo(blaster.spawnTransform.position, currentForceGrabProjectile.transform.position);
                }
            }
        }
        else
        {
            smoothLocomotion.enabled = true;
        }
    }
Beispiel #10
0
    private void Update()
    {
        if (Input.GetKeyDown(KeyCode.G))
        {
            ButtonClicked();
        }
        if (_IsButtonClicked && !_IsUsed)
        {
            _Ray = Camera.main.ScreenPointToRay(Input.mousePosition);

            if (Input.GetButtonDown("Fire1"))
            {
                if (EventSystem.current.IsPointerOverGameObject())
                {
                    Debug.Log(EventSystem.current);
                    Debug.Log("Is over UI");
                    ResetInitialPosisiton();
                }
                else if (Physics.Raycast(_Ray, out _Hit))
                {
                    //Debug.Log("Is NOT UI");
                    Tile         t = _Hit.collider.GetComponent <Tile>();
                    GrapplePoint g = _Hit.collider.GetComponent <GrapplePoint>();
                    Debug.Log("Grapple Point: " + (g != null));
                    if (t != null && t.GetIsInGHRange())
                    {
                        _MouseClickedPosition    = t.transform.position;
                        _MouseClickedPosition.y += halfHeight;
                        _Heading = _MouseClickedPosition - transform.position;
                        GetComponent <Collider>().enabled = true;
                        //Debug.Log("Shooting");
                        Shoot();
                        _IsButtonClicked      = false;
                        _sfxGadgetSource.clip = _sfxGadgetClip;
                        _sfxGadgetSource.Play();
                    }
                    else if (g != null && g.GetIsPlayerInRange())
                    {
                        Debug.Log("GrapplePoint:  " + g.ToString());
                        _MouseClickedPosition    = g.transform.position;
                        _MouseClickedPosition.y += halfHeight;
                        _Heading = _MouseClickedPosition - transform.position;
                        GetComponent <Collider>().enabled = true;
                        //Debug.Log("Shooting");
                        Shoot();
                        _IsButtonClicked      = false;
                        _sfxGadgetSource.clip = _sfxGadgetClip;
                        _sfxGadgetSource.Play();
                    }
                    else
                    {
                        _TMP.SetText("You can't shoot toward that position!");
                        _IsButtonClicked = false;
                        ResetInitialPosisiton();
                    }
                }
            }
        }
        else
        {
            if (hitColliders != null)
            {
                Reset();
            }
        }
        // else if (_IsUsed && !p.GetIsTurnEnd())
        // {
        //     _TMP.SetText("You have used the grapling hook!!!");
        // }
        if (_OnHit || _GrapplePointHit)
        {
            p.MoveTo(_ObjectOnCollsion);
            if (!_IsFinishedMoving)
            {
                p.UseEnergy(_EnergyNeeded);
                p.UseActionPoint(_ActionPointNeeded);
                ResetInitialPosisiton();
                p.ResetRotation();
            }
            _IsUsed = true;
        }
        //move the player
    }