Maxwell Montes Diaz's profile

Fall 2018 Ai Scholarship Competition

Title Screen Image
First Position the Intro Title Screen goes to , also shows a key place to find the artifact
Second Position the Intro goes to, Shows the top of the hill
Third spot, behind a gate guarded and secluded
Spot where player starts
Enemy spotted the player because he is holding a light source which makes him easily visible
Player defeated
Options screen that auto populates at start
Final View when game is completed with all artifacts stolen and player inside the castle
Cinematic Script in charge of moving around the Cameras and doing animations while the taking control away from the player

[SerializeField]
    private GameObject ArtifactsPanel;
    private GameObject IntroTitleObject;
    private Text startToPlayText;
    private bool finalCinematic = false;
    private bool gameStart = false;
    private void Start()
    {
        source = GetComponent<AudioSource>();
        playerController = FindObjectOfType<WarriorAnimationDemo>();
        artifacts = FindObjectOfType<ArtifactPickupManager>();
        playerController.canMove = false;
        source.clip = introSong;
        source.Play();
        StartCoroutine(IntroCameraCinematic());
        IntroTitleObject = GameObject.Find("IntroTitle");
        startToPlayText = IntroTitleObject.transform.GetChild(1).GetComponent<Text>();
        StartCoroutine(ToggleText());
        ArtifactsPanel.SetActive(false);
    }
    private void LateUpdate()
    {
        if (Input.GetKeyDown("joystick button 7") && !gameStart)
        {
            ResumePlayerControl();
            StartCoroutine(MusicToggle());
            StopCoroutine(IntroCameraCinematic());
            ArtifactsPanel.SetActive(true);
            IntroTitleObject.SetActive(false);
            gameStart = true;
        }
        if (artifacts.objectsPickedUp == 3 && !finalCinematic)
        {
            StartCoroutine(EndCameraCinematic());
            finalCinematic = true;
        }
    }
    private IEnumerator ToggleText()
    {
        while (IntroTitleObject.activeSelf)
        {
            float t = 0;
            while (startToPlayText.color.a >= .05f)
            {
                t = Time.deltaTime / 2;
                Color blend = new Color(0, 0, 0, t);
                startToPlayText.color = startToPlayText.color - blend;
                yield return null;
            }
            t = 0;
            while (startToPlayText.color.a <= .95f)
            {
                t = Time.deltaTime / 2;
                Color blend = new Color(0, 0, 0, t);
                startToPlayText.color = startToPlayText.color + blend;
                yield return null;
            }
        }
    }
    private IEnumerator IntroCameraCinematic()
    {
        playerCamera.SetActive(false);
        introCamera1.SetActive(true);
        if (!playerController.canMove) yield return new WaitForSeconds(8);
        introCamera1.SetActive(false);
        introCamera2.SetActive(true);
        if (!playerController.canMove) yield return new WaitForSeconds(8);
        introCamera2.SetActive(false);
        introCamera3.SetActive(true);
        if (!playerController.canMove) yield return new WaitForSeconds(8);
        introCamera3.SetActive(false);
        introCamera4.SetActive(true);
        if (!playerController.canMove) yield return new WaitForSeconds(8);
        introCamera4.SetActive(false);
        playerCamera.SetActive(true);
    }
    private IEnumerator EndCameraCinematic()
    {
        playerCamera.SetActive(false);
        playerController.canMove = false;
        endCamera1.SetActive(true);
        yield return new WaitForSeconds(4);
        endCamera1.SetActive(false);
        endCamera2.SetActive(true);
        yield return new WaitForSeconds(2);
        float t = 0;
        t += Time.deltaTime;
        doorToRotate.transform.rotation = Quaternion.Slerp(doorToRotate.transform.rotation, Quaternion.Euler(0, -78, 0), t * 5);
        yield return new WaitForSeconds(3.5f);
        endCamera2.SetActive(false);
        playerCamera.SetActive(true);
        playerController.canMove = true;
    }
    private IEnumerator FinaleCameraCinematic()
    {
        playerController.canMove = false;
        playerCamera.SetActive(false);
        finaleCamera1.SetActive(true);
        yield return new WaitForSeconds(3);
        finaleCamera2.SetActive(true);
        finaleCamera1.SetActive(false);
    }
    private IEnumerator MusicToggle()
    {
        while (source.volume != 0)
        {
            source.volume -= Time.deltaTime / 2;
            yield return null;
        }
        source.clip = sceneSong;
        source.Play();
        while (source.volume != 1)
        {
            source.volume += Time.deltaTime / 2;
            yield return null;
        }
    }
    private void ResumePlayerControl()
    {
        playerCamera.SetActive(true);
        playerController.canMove = true;
        introCamera1.SetActive(false);
        introCamera2.SetActive(false);
        introCamera3.SetActive(false);
        introCamera4.SetActive(false);
        endCamera1.SetActive(false);
        endCamera2.SetActive(false);
        finaleCamera1.SetActive(false);
        finaleCamera2.SetActive(false);
    }
    private void OnTriggerEnter(Collider other)
    {
        if (other.name == "Character_Ninja")
        {
            StartCoroutine(FinaleCameraCinematic());
        }
    }
Code in charge of making AI enemies attack the player if they see him because he is in his line of sight and there is enough light to see him or else just patrol around their assigned area

public class GruntController : MonoBehaviour
{
    [SerializeField]
    private GameObject lantern;
    [SerializeField]
    private GameObject weapon;
    [SerializeField]
    private GameObject representation;
    [SerializeField]
    private GameObject[] waypoints;
    private GameObject currentWaypoint;
    private Vector3 playerPosition;
    private Vector3 lastPlayerPosition;
    private bool playerActive = false;
    private Animator animator;
    private int hits = 0;
    private float waitTime = 0;
    private ShadowDetector detector;
    private void Start()
    {
        animator = GetComponent<Animator>();
        detector = FindObjectOfType<ShadowDetector>();
        if (waypoints.Length != 0)
            currentWaypoint = waypoints[0];
    }
    private void FixedUpdate()
    {
        if (animator.GetBool("PlayerFound"))
        {
            Attack();
        }
        else if (animator.GetBool("PlayerDetected"))
        {
            Investigate();
        }
        else
        {
            waitTime = 0;
            Patrol();
        }
    }
    private void OnAnimatorMove()
    {
        if (animator.GetCurrentAnimatorStateInfo(0).IsName("WalkSlow"))
        {
            transform.position += transform.forward * animator.GetFloat("WalkSpeed") * 0.6f;
        }
        else if(animator.GetCurrentAnimatorStateInfo(0).IsName("WalkForward"))
        {
            transform.position += transform.forward * animator.GetFloat("WalkSpeed") * 0.9f;
        }
        else if(animator.GetCurrentAnimatorStateInfo(0).IsName("Run-Sheathed"))
        {
            transform.position += transform.forward * animator.GetFloat("WalkSpeed") * 1.2f;
        }
    }
    private void Attack()
    {
        playerActive = lastPlayerPosition == playerPosition ? false : true;
        transform.LookAt(playerPosition);
        lastPlayerPosition = playerPosition;
        if (Vector3.Distance(transform.position, playerPosition) > 4 && playerActive)
        {
            animator.SetBool("Pursue", true);
        }
        else
        {
            animator.SetBool("Pursue", false);
        }
        if (Vector3.Distance(transform.position, playerPosition) < 2 && playerActive)
        {
            animator.SetTrigger("Attack");
        }
        if (Vector3.Distance(transform.position, playerPosition) < 1)
            animator.SetBool("Arrived", true);
        else
            animator.SetBool("Arrived", false);
        if (!playerActive)
            waitTime += Time.deltaTime;
        if (waitTime > 5)
            animator.SetBool("PlayerFound", false);
    }
    private void Investigate()
    {
        transform.LookAt(playerPosition);
        waitTime += Time.deltaTime;
        if (waitTime > 5)
        {
            animator.SetBool("PlayerDetected", false);
        }
        if (Vector3.Distance(transform.position, playerPosition) < 1)
            animator.SetBool("Arrived", true);
        else
            animator.SetBool("Arrived", false);
    }
    private void Patrol()
    {
        if (waypoints.Length > 1)
        {
            if (Vector3.Distance(transform.position, currentWaypoint.transform.position) > 2)
            {
                transform.LookAt(currentWaypoint.transform);
            }
            else if (!animator.GetBool("Arrived"))
            {
                animator.SetBool("Arrived", true);
                Invoke("UpdateCurrentWaypoint", 5);
            }
        }
        else if (waypoints.Length <= 1)
        {
            animator.SetBool("Arrived", true);
        }
    }
    private void UpdateCurrentWaypoint()
    {
        if (waypoints.Length > 1)
        {
            for (int i = 0; i < waypoints.Length; i++)
            {
                animator.SetBool("Arrived", false);
                if (currentWaypoint == waypoints[i] && (i + 1) < waypoints.Length)
                {
                    currentWaypoint = waypoints[i + 1];
                    return;
                }
                else if (currentWaypoint == waypoints[i])
                {
                    currentWaypoint = waypoints[0];
                    return;
                }
            }
        }
        else
        {
            return;
        }
    }
    private void OnTriggerEnter(Collider other)
    {
        if (other.name == "Character_Ninja" && detector.hidden)
        {
            animator.SetBool("PlayerDetected", true);
        }
    }
    private void OnTriggerStay(Collider other)
    {
        if (other.name == "Character_Ninja" && !detector.hidden)
        {
            animator.SetBool("PlayerFound", true);
        }
        if (other.name == "Character_Ninja")
        {
            playerPosition = other.transform.position;
        }
    }
    private void OnTriggerExit(Collider other)
    {
        if (other.name == "Character_Ninja")
        {
        }
    }
    private void OnCollisionEnter(Collision collision)
    {
        if (collision.gameObject.tag == "PlayerWeapon")
        {
            if (!animator.GetBool("PlayerDetected"))
            {
                animator.SetTrigger("Death");
                Destroy(gameObject, 10);
            }
            else
            {
                animator.SetTrigger("Hit");
                hits++;
                animator.SetInteger("Hits", hits);
                if (hits > 2)
                {
                    animator.SetTrigger("Death");
                    Destroy(gameObject, 10);
                }
            }
        }
        if (collision.gameObject.tag == "Kunai")
        {
            animator.SetBool("Death", true);
            Destroy(gameObject, 10);
        }
    }
    public void WeaponSwitch()
    {
        weapon.SetActive(!weapon.activeSelf);
        representation.SetActive(!representation.activeSelf);
    }
}
The Complete Game logic for controlling and populating the Pause Menu and its controls

private void Update()
    {
        if((Input.GetKeyDown(KeyCode.Escape) || Input.GetKeyDown("joystick button 7")) && playerControl.canMove)
        {
            if (Background.transform.Find("OptionsMenu") != null)
            {
                Background.transform.Find("OptionsMenu").gameObject.SetActive(false);
                Background.transform.Find("MainButtons").gameObject.SetActive(true);
            }
            if (Time.timeScale != 0)
                Time.timeScale = 0;
            else
                Time.timeScale = 1;
            Background.SetActive(!Background.activeSelf);
        }
    }
    void Start()
    {
        //settings = LaunchSettings.Load(Path.Combine(Application.dataPath, "LaunchData.xml"));
        //Screen.SetResolution(settings.width, settings.height, settings.fullscreenOn);
        fullscreenToggle.isOn = Screen.fullScreen;
        fullscreenToggle.onValueChanged.AddListener((value) => { ChangeFullScreen(value); });
        // Assign all possible display resolutions to the buttons when they are created
        Resolution[] resolutions = Screen.resolutions;
        foreach (var res in resolutions)
        {
            GameObject go = Instantiate(resolutionButtonPrefab, resolutionButtonsParent);
            go.transform.Find("Height").GetComponent<Text>().text = res.height.ToString();
            go.transform.Find("Width").GetComponent<Text>().text = res.width.ToString();
            Button button = go.GetComponent<Button>();
            button.onClick.AddListener(() => ChangeResolution(button));
        }
        foreach (Transform quality in qualityButtonsParent.transform)
        {
            Button button = quality.GetComponent<Button>();
            button.onClick.AddListener(() => ChangeQualityLevel(quality));
        }
        soundSlider.onValueChanged.AddListener(delegate { ChangeSound(); } );
        brightnessSlider.onValueChanged.AddListener(delegate { ChangeBrightness(); });
        directionalLight.intensity = brightnessSlider.value;
    }
    
    void ChangeResolution(Button button)
    {
        string width = button.transform.Find("Width").GetComponent<Text>().text;
        string height = button.transform.Find("Height").GetComponent<Text>().text;
        Screen.SetResolution(Convert.ToInt16(width) , Convert.ToInt16(height), fullscreenToggle.isOn);
    }
    private void ChangeFullScreen(bool change)
    {
        Screen.fullScreen = change;
    }
    private void ChangeQualityLevel(Transform button)
    {
        int childCount = qualityButtonsParent.childCount;
        for (int i = 0; i < childCount; i++)
        {
            if (qualityButtonsParent.GetChild(i) == button.gameObject)
            {
                QualitySettings.SetQualityLevel(i);
            }
        }
    }
    private void ChangeSound()
    {
        AudioListener.volume = soundSlider.value;
    }
    private void ChangeBrightness()
    {
        directionalLight.intensity = brightnessSlider.value;
    }
    public void ResumeGame()
    {
        if (Time.timeScale != 0)
            Time.timeScale = 0;
        else
            Time.timeScale = 1;
    }
    public void RestartGame()
    {
        SceneManager.LoadScene(0);
    }
    public void QuitGame()
    {
        Application.Quit();
#if UNITY_EDITOR
        UnityEditor.EditorApplication.isPlaying = false;
#endif
    }
Fall 2018 Ai Scholarship Competition
Published:

Fall 2018 Ai Scholarship Competition

Maxwell Montes Diaz VGPA305 Robert Dunlap Visual & Game Programming This project was for Advance Software Development where we had to attempt to Read More

Published: