Example #1
0
    void Tongue()
    {
        if (tongueState == TongueState.Extending)
        {
            if (!TongueFinishedExtending())
            {
                ExtendTongueTowardsTarget();
            }
            else
            {
                ConvertTargetToEdibleForm();
                tongueState = TongueState.Retracting;
            }
        }
        else if (tongueState == TongueState.Retracting)
        {
            RetractTongueTowardsMouth();
            if (TongueReachedMouth())
            {
//				Debug.Log("frog ate finally");
                if (target != null && target.transform != null && target.transform.GetComponent <NumberInfo>() != null && target.transform.parent == tongueEnd)
                {
                    EatIt(target.transform.gameObject);
//					canSetTargetTimer = Random.Range(0.2f,0.6f);
                }
                line.SetVertexCount(0);
                LoseTarget("dist from maw");

//				Debug.Log("reached mouth, can set target.");
            }
        }
    }
Example #2
0
    // Update is called once per frame
    void Update()
    {
        if (this.tongue_state == TongueState.Up || this.tongue_state == TongueState.Down)
        {
            return;
        }

        if (this.tongue_state == TongueState.MovingUp)
        {
            this.timer -= 1;
            if (this.timer <= 0)
            {
                this.timer        = 0;
                this.tongue_state = TongueState.Up;
            }
        }
        else if (this.tongue_state == TongueState.MovingDown)
        {
            this.timer += 1;
            if (this.timer >= this.T)
            {
                this.timer        = this.T;
                this.tongue_state = TongueState.Down;
            }
        }
        float lambda = (float)this.timer / (float)this.T;

        this.transform.position = (1 - lambda) * this.initial_pos + lambda * this.final_pos;
    }
Example #3
0
        /// <summary>
        /// Updates the Tongue.
        /// </summary>
        /// <param name="dt"></param>
        public void Update(float dt)
        {
            if (!IsAttacking)
            {
                return;
            }

            //Hit Enemies
            SMH.EnemyManager.TongueCollision(this, SMH.Player.Damage);

            //Activate stuff - only one thing can be activated per attack
            if (!_hasActivatedSomething)
            {
                if (SMH.Environment.ToggleSwitches(this) ||
                    SMH.NPCManager.TalkToNPCs(this) ||
                    (!SMH.WindowManager.IsWindowOpen && SMH.Environment.HitSaveShrine(this)) ||
                    (!SMH.WindowManager.IsTextBoxOpen && SMH.Environment.HitSigns(this)))
                {
                    _hasActivatedSomething = true;
                }
            }

            switch (_state)
            {
            case TongueState.Extending:
                Animations.SmileyTongue.Update(dt);

                //Once the tongue is fully extended enter swinging state
                if (Animations.SmileyTongue.ActiveFrame == NumFrames - 1)
                {
                    _state = TongueState.Swinging;
                }
                break;

            case TongueState.Swinging:
                _tongueOffsetAngle += 8f * (float)Math.PI * dt;

                //When tongue finishes swinging, start retracting it
                if (_tongueOffsetAngle > AttackRadius / 2f)
                {
                    _tongueOffsetAngle = AttackRadius / 2f;
                    Animations.SmileyTongue.ActiveFrame = NumFrames - 1;
                    Animations.SmileyTongue.Reverse     = true;
                    Animations.SmileyTongue.Play();
                    _state = TongueState.Retracting;
                }
                break;

            case TongueState.Retracting:
                Animations.SmileyTongue.Update(dt);

                //Once the tongue is fully retracted the attack is done
                if (Animations.SmileyTongue.ActiveFrame < 1)
                {
                    IsAttacking = false;
                }
                break;
            }
        }
Example #4
0
    void Awake()
    {
        controls   = new InputControls();
        rb         = GetComponent <Rigidbody>();
        movement   = GetComponent <SCR_PlayerV3>();
        animScript = GetComponentInChildren <SCR_PlayerAnimation>();

        tongueState = TongueState.Retracted;

        InputActions();
    }
Example #5
0
    public override void Eat(GameObject o)
    {
//		Debug.Log("frog eating with state:"+tongueState.ToString());
        if (tongueState == TongueState.Ready)
        {
            canSetTarget = false;
            tongueState  = TongueState.Extending;

            tonguing = true;
        }
    }
Example #6
0
        /// <summary>
        /// Starts swinging the tongue at shit.
        /// </summary>
        public void StartAttack()
        {
            if (IsAttacking || SMH.WindowManager.IsTextBoxOpen)
            {
                return;
            }

            SMH.Sound.PlaySound(GetRandomTongueSound());

            SMH.SaveManager.CurrentSave.NumTongueLicks++;
            _hasActivatedSomething          = false;
            _timeStartedAttack              = SMH.GameTime;
            _tongueOffsetAngle              = -AttackRadius / 2f;
            IsAttacking                     = true;
            Animations.SmileyTongue.Reverse = false;
            Animations.SmileyTongue.Play();
            _state = TongueState.Extending;
        }
Example #7
0
    public override void LoseTarget(string source = "")
    {
        base.LoseTarget(source);
        finishedExtending = false;
        tonguing          = false;
        canSetTarget      = true;
        tongueState       = TongueState.Ready;
        if (tongueEnd && tongueAnchor)
        {
//			Debug.Log("set pos");
            tongueEnd.position = tongueAnchor.position;

            // clear any objects that may linger inside tongueend
            foreach (Transform t in tongueEnd)
            {
                Destroy(t.gameObject);
            }
        }
    }
Example #8
0
    public void trigger()
    {
        switch (this.tongue_state)
        {
        case TongueState.MovingUp:
            this.tongue_state = TongueState.MovingDown;
            break;

        case TongueState.MovingDown:
            this.tongue_state = TongueState.MovingUp;
            break;

        case TongueState.Down:
            this.tongue_state = TongueState.MovingUp;
            break;

        case TongueState.Up:
            this.tongue_state = TongueState.MovingDown;
            break;
        }
    }
Example #9
0
    IEnumerator TongueRetract(Vector3 targetPos, float startingDistance)
    {
        tongueState = TongueState.Retracting;

        // Tell animation that tongue is retracted
        animScript.tongueOut = false;

        float TongueDistance = startingDistance;

        while (TongueDistance > 0)
        {
            // Linearly interpolate tongue's position from target back to body
            // (promote speed to variable later)
            TongueDistance         -= 10 * Time.deltaTime;
            tongueCollider.position = Vector3.Lerp(tongueMeshAnchor.position, targetPos, TongueDistance);

            yield return(null);
        }
        tongueCollider.position = tongueMeshAnchor.position;

        tongueState = TongueState.Retracted;
    }
Example #10
0
    void Update()
    {
        // Targeting behavior
        if (tongueState == TongueState.Retracted)
        {
            if (lockedOnTarget)
            {
                LockedTarget();
            }
            else
            {
                AutoTarget();
            }
        }

        // Check for tongue attack initiation
        if (controls.Player.TongueButtonPress.triggered &&
            tongueState == TongueState.Retracted &&
            currentTarget != null)
        {
            StartCoroutine(TongueAttack(currentTarget));
            tongueState = TongueState.Attacking;
        }
    }
Example #11
0
    /*
     * This region contains the various interactions that can be performed once tongue has hit a target.
     * The type of interaction performed is determined by checking the targetType of the target object.
     *
     * FUNCTIONS IN THIS REGION:
     * Tongue Swing
     * Tongue Eat
     * Tongue Grab
     * Terminate Grab
     */

    IEnumerator TongueSwing(SCR_TongueTarget target)
    {
        // Stop targeting
        currentTarget = null;
        tongueState   = TongueState.Attached;

        ConfigurableJoint targetJoint   = target.GetComponentInChildren <ConfigurableJoint>();
        Rigidbody         targetJointRb = targetJoint.GetComponent <Rigidbody>();

        // Turn player towards target
        Quaternion targetRotation = Quaternion.LookRotation(target.transform.position - tongueTargetAnchor.position);

        transform.rotation             = targetRotation;
        targetJoint.transform.rotation = targetRotation;

        // Tell target that player is swinging on it
        target.isBeingSwung = true;

        // Connect player to target joint
        targetJoint.connectedBody = rb;

        // Set target distance while swinging (promote to variable later)
        targetJoint.targetPosition = new Vector3(0, 0, Vector3.Distance(tongueTargetAnchor.position, targetJoint.transform.position) - variables.swingDistance);

        // Set initial swing velocity. Change this in future to convert linear velocity to angular
        //rb.velocity = rb.velocity.normalized * 7;
        rb.velocity = new Vector3(rb.velocity.x, 0, rb.velocity.z);

        // Deactivate normal movement
        movement.overrideNormalMovement = true;
        movement.overrideJump           = true;
        movement.overrideRotation       = true;
        movement.canMidairJump          = false;
        rb.constraints &= ~RigidbodyConstraints.FreezeRotationX;
        rb.constraints &= ~RigidbodyConstraints.FreezeRotationY;
        rb.constraints &= ~RigidbodyConstraints.FreezeRotationZ;

        float swingTime = 0;

        while ((holdingTongueButton || swingTime < 0.2f) && target != null)
        {
            swingTime += Time.deltaTime;

            // Add some forward rotation at the beginning of swing
            if (target.startWithVelocity && swingTime < 0.1f)
            {
                targetJointRb.AddRelativeTorque(-400 * Time.deltaTime, 0, 0, ForceMode.Impulse);
            }

            tongueCollider.position = target.transform.position;
            yield return(null);
        }

        if (target != null)
        {
            // Break connection to joint
            targetJoint.connectedBody = null;

            // Tell target that player stopped swinging on it
            target.isBeingSwung = false;
        }


        // Set velocity on swing end. Change this in future to convert linear velocity to angular
        //rb.velocity = rb.velocity.normalized * targetJointRb.angularVelocity.magnitude * 2;
        movement.externalVelocity.velocity = rb.velocity;
        if (movement.externalVelocity.velocity.y < 1)
        {
            movement.externalVelocity.velocity = new Vector3(movement.externalVelocity.velocity.x, 1, movement.externalVelocity.velocity.z);
        }

        // Re-activate normal movement
        movement.overrideNormalMovement = false;
        movement.overrideJump           = false;
        movement.overrideRotation       = false;
        rb.constraints = RigidbodyConstraints.FreezeRotation;

        // Refresh midair jump after swinging
        movement.canMidairJump = true;

        StartCoroutine(TongueRetract(tongueCollider.transform.position, 1));
    }
Example #12
0
 void Initialize()
 {
     this.timer = 0;
     this.transform.position = initial_pos;
     this.tongue_state       = TongueState.Up;
 }