void LaunchBall()
    {
        launchball script = ball.GetComponent <launchball>();
        Vector3    vec;

        vec.x = arrow.transform.rotation.y;
        vec.y = arrow.transform.rotation.x;
        vec.z = arrow.transform.rotation.z;
        //vec.Normalize();
        launch_states = SHOT.LAUNCHED;

        Vector3 rotated_vec;

        rotated_vec.x = vec.x;


        //////Z axis
        //float rad_angle = -90 * Mathf.PI / 180;
        //rotated_vec.x = vec.x * Mathf.Cos(rad_angle) - vec.y * Mathf.Sin(rad_angle);
        //rotated_vec.y = vec.x * Mathf.Sin(rad_angle) + vec.y * Mathf.Cos(rad_angle);

        //X axis
        float rad_angle = 50 * Mathf.PI / 180;

        rotated_vec.y = vec.y * Mathf.Cos(rad_angle) - vec.z * Mathf.Sin(rad_angle);
        rotated_vec.z = vec.y * Mathf.Sin(rad_angle) + vec.z * Mathf.Cos(rad_angle);

        float relative_intensity = times_pressed * max_intensity / max_time_pressed;


        script.ThrowBall(rotated_vec * relative_intensity, 1);


        // 50* Mathf.PI / 180
    }
Beispiel #2
0
        /// <summary>
        /// Returns the integer score of the given shot number, either the first shot or the second.
        /// </summary>
        /// <param name="shot">Enum value representing which number shot to get.</param>
        /// <returns>Integer score of the given shot.</returns>
        public int getShotScore(SHOT shot)
        {
            if (shot == SHOT.First)
            {
                if (this.firstBallTextBox.Text == "")
                {
                    return(0);
                }
                else if (this.firstBallTextBox.Text == "/")
                {
                    return(10);
                }
                else if (this.firstBallTextBox.Text == "X")
                {
                    return(10);
                }

                try
                {
                    return(Int32.Parse(this.firstBallTextBox.Text));
                }
                catch (FormatException e)
                {
                    // Shouldn't happen.
                    throw e;
                }
            }
            else
            {
                if (this.secondBallTextBox.Text == "")
                {
                    return(0);
                }
                else if (this.secondBallTextBox.Text == "/")
                {
                    return(10);
                }
                else if (this.secondBallTextBox.Text == "X")
                {
                    return(10);
                }

                try
                {
                    return(Int32.Parse(this.secondBallTextBox.Text));
                }
                catch (FormatException e)
                {
                    // Shouldn't happen.
                    throw e;
                }
            }
        }
    // Update is called once per frame
    void Update()
    {
        switch (launch_states)
        {
        case SHOT.HORIZONTAL:
            ZAxisRot();
            break;

        case SHOT.VERTICAL:
            XAxisRot();
            break;

        case SHOT.INTENSITY:
            Intensity();
            break;

        case SHOT.LAUNCH:
            LaunchBall();
            break;

        case SHOT.LAUNCHED:
            ResetBar();
            break;
        }


        if (Input.GetKeyDown(KeyCode.Space))
        {
            if (launch_states == SHOT.HORIZONTAL)
            {
                launch_states = SHOT.VERTICAL;
            }

            else if (launch_states == SHOT.VERTICAL)
            {
                //launch_states = SHOT.INTENSITY;
                launch_states = SHOT.INTENSITY;
            }
        }
    }
    void Intensity()
    {
        if (Input.GetKeyDown(KeyCode.Space))
        {
            pressed = true;
        }

        if (Input.GetKey(KeyCode.Space) && pressed)
        {
            if (max_time_pressed > times_pressed)
            {
                times_pressed += 1;
                VisualFeedBack();
            }
            // Debug.Log(times_pressed);
        }
        else if (Input.GetKeyUp(KeyCode.Space) && times_pressed > 0)
        {
            pressed       = false;
            launch_states = SHOT.LAUNCH;
        }
    }
 public void ResetStates()
 {
     launch_states = SHOT.HORIZONTAL;
 }
Beispiel #6
0
    /// <summary>
    /// calculates the result of the scenario (what to display to the user)
    /// </summary>
    /// <returns>string containing the result of the scenario</returns>
    public string calculateFinalResult()
    {
        string result = "";

        //what scene is it?
        if (currentScene == SCENE.INTRO)
        {
            result = "Result: FAIL\n\nThere was no threat; discharge of a firearm without reasonable grounds for believing it necessary is illegal.";//FAIL
        }
        else if (currentScene == SCENE.T1)
        {
checkVictimT1:
            SHOT victim = (SHOT)Enumerable.Range(0, shot.Count()).Aggregate((a, b) => (shot[a] > shot[b]) ? a : b);

            //account for bad accuracy (user may have missed more shots than they hit)
            if (victim == SHOT.NOTHING)
            {
                for (int i = 0; i < shot.Count() - 1; i++)
                {
                    if (shot[i] > 0)
                    {
                        shot[(int)SHOT.NOTHING] = 0;
                        goto checkVictimT1;
                    }
                }

                result = "Result: FAIL\n\nThere was no threat; discharge of a firearm without reasonable grounds for believing it necessary is illegal.";//FAIL
            }
            else if (victim == SHOT.JIM)
            {
                result = "Result: FAIL\n\nThe suspect was not an immediate danger to anyone's life.";//FAIL
            }
        }
        else
        {
            //T2; who did the shooting?
            if (scenarioResult == SCENARIO_RESULT.USER_KILL)
            {
                //check accuracy
                //user did the shooting and it was a person; who was shot?
                SHOT victim = (SHOT)Enumerable.Range(0, shot.Count()).Aggregate((a, b) => (shot[a] > shot[b]) ? a : b);
checkVictim:
                switch (victim)
                {
                case SHOT.NOTHING:
                    shot[(int)SHOT.NOTHING] = 0;
                    victim = (SHOT)Enumerable.Range(0, shot.Count()).Aggregate((a, b) => (shot[a] > shot[b]) ? a : b);
                    goto checkVictim;

                case SHOT.JIM:
                    //was kill triggered?
                    if (scFSM.Kill)
                    {
                        result = "Result: PASS\n\nThe suspect was an immediate danger.";
                    }
                    else
                    {
                        result = "Result: FAIL\n\nThe suspect was not an immediate danger to anyone's life.";    //FAIL
                    }
                    break;

                case SHOT.GUARD:
                    //no reason for this
                    result = "Result: FAIL\n\nThe guard was not a threat.";
                    break;

                case SHOT.BOSS:
                    //no reason for this
                    result = "Result: FAIL\n\nThe boss was not a threat.";
                    break;
                }
            }
            else if (scenarioResult == SCENARIO_RESULT.DISCHARGE)
            {
                //Illegal discharge of weapon
                result = "Result: FAIL\n\nThere was no threat; discharge of a firearm without reasonable grounds for believing it necessary is illegal.";//FAIL
            }
            else if (scenarioResult == SCENARIO_RESULT.SUSPECT_KILL)
            {
                //suspect did the killing
                if (currentScene == SCENE.T2_OUTSIDE)
                {
                    result = "Result: FAIL\n\nThe situation was not defused resulting in the suspect shooting the security guard.";//FAIL
                }
                else
                {
                    result = "Result: FAIL\n\nThe situation was not defused resulting in the suspect shooting the boss.";//FAIL
                }
            }
        }

        return(result);
    }
        /// <summary>
        /// Returns the integer score of the given shot number, either the first shot, the second, or the third.
        /// </summary>
        /// <param name="shot">Enum value representing which number shot to get.</param>
        /// <returns>Integer score of the given shot.</returns>
        public int getShotScore(SHOT shot)
        {
            switch (shot)
            {
            case SHOT.First:
                if (this.firstBallTextBox.Text == "")
                {
                    return(0);
                }
                else if (this.firstBallTextBox.Text == "/")
                {
                    return(10);
                }
                else if (this.firstBallTextBox.Text == "X")
                {
                    return(10);
                }

                try
                {
                    return(Int32.Parse(this.firstBallTextBox.Text));
                }
                catch (FormatException e)
                {
                    // Shouldn't happen.
                    throw e;
                }

            case SHOT.Second:
                if (this.secondBallTextBox.Text == "")
                {
                    return(0);
                }
                else if (this.secondBallTextBox.Text == "/")
                {
                    return(10);
                }
                else if (this.secondBallTextBox.Text == "X")
                {
                    return(10);
                }

                try
                {
                    return(Int32.Parse(this.secondBallTextBox.Text));
                }
                catch (FormatException e)
                {
                    // Shouldn't happen.
                    throw e;
                }

            case SHOT.Third:
                if (this.thirdBallTextBox.Text == "")
                {
                    return(0);
                }
                else if (this.thirdBallTextBox.Text == "/")
                {
                    return(10);
                }
                else if (this.thirdBallTextBox.Text == "X")
                {
                    return(10);
                }

                try
                {
                    return(Int32.Parse(this.thirdBallTextBox.Text));
                }
                catch (FormatException e)
                {
                    // Shouldn't happen.
                    throw e;
                }

            default:
                throw new ArgumentException("The given enum value was invalid.", nameof(shot));
            }
        }