Soren Rogiers

Game developer

Capt’n Eugene


Capt'n Eugene is our first real introduction to the Unity game engine where we had to create a game based of the WII game Captain Toad

A fearsome pirate explorer trots around all corners of the ocean in search of hidden treasure.
He sets off on his adventure through a variety of tricky maze-like stages, infested with enemies to find coins and hidden treasure chests and claiming the land by hoisting the pirate flag.

Captain Eugene isn’t particularly strong but sometimes in order to beat the levels all you need is wits and perspective.
Twisting the camera to reveal different angles will show players new ways to overcome obstacles or find some hidden treasures, coins and secrets. Should you need a closer look at your surroundings, a quick use of the zoom function makes the camera zoom in on Eugene. In order to complete most levels, you need to find treasures and hoist the pirate flag under extreme conditions.

For the true treasure tracker, there are plenty of challenges that asks you to look at old stages in new ways.

I was responsible for the following:
  • Level 1 design
  • Different types of enemies and their behaviour
  • Camera behaviour
  • Player behaviour

Code snippets


									
//***********************
//Camera behaviour script
//***********************
using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;

public class CameraBehaviour: MonoBehaviour
{
    public Transform Target;
    public bool IsLevelCompleted = false;
    public float MaxViewDistance = 30f;
    public float MinViewDistance = 15f;
    public float XMovementSpeed = 80.0f;
    public float YMovementSpeed = 50.0f;
    public int YMinLimit = 10;
    public int YMaxLimit = 80;
    public int ZoomSpeed = 1;
    public float ZoomDampening = 5.0f;
    public Vector3 StartRotation;

    private float Distance = 0.0f;
    private float xDegrees = 0.0f;
    private float yDegrees = 0.0f;
    private float currentDistance;
    private float desiredDistance;

    private Quaternion currentRotation;
    private Quaternion desiredRotation;

    private Quaternion rotation;
    private Vector3 position;

    private void Start()
    {
        if (Target == null)
        {
            Debug.Log("Set Camerapivot as target");
        }

        Distance = Vector3.Distance(transform.position, Target.position);
        currentDistance = Distance;
        desiredDistance = Distance;

        position = transform.position;
        rotation = transform.rotation;
        currentRotation = transform.rotation;
        desiredRotation = transform.rotation;

        xDegrees = Vector3.Angle(Vector3.right, transform.right);
        yDegrees = Vector3.Angle(Vector3.up, transform.up);

       // _cameraPivot = GameObject.Find("CameraPivot");
    }
	
    private void LateUpdate()
    {
        if (!IsLevelCompleted)
        {
            if (Input.GetAxis("RightJoystickX") != 0.0f || Input.GetAxis("RightJoystickY") != 0.0f ||
                (Input.GetMouseButton(0) && (Input.GetAxis("Mouse X") != 0.0f || Input.GetAxis("Mouse Y") != 0.0f)))
            {
                xDegrees += Input.GetAxis("RightJoystickX")*XMovementSpeed*Time.deltaTime;
                yDegrees -= Input.GetAxis("RightJoystickY")*YMovementSpeed*Time.deltaTime;

                xDegrees += Input.GetAxis("Mouse X")*XMovementSpeed*Time.deltaTime;
                yDegrees -= Input.GetAxis("Mouse Y")*YMovementSpeed*Time.deltaTime;

                //Clamp the vertical axis for the orbit
                yDegrees = ClampAngle(yDegrees, YMinLimit, YMaxLimit);
                // set camera rotation 
                desiredRotation = Quaternion.Euler(yDegrees, xDegrees, 0);
                currentRotation = transform.rotation;
                //Debug.Log(desiredRotation);
                rotation = Quaternion.Lerp(currentRotation, desiredRotation, Time.deltaTime*ZoomDampening);
                transform.rotation = rotation;
                
            }

            // affect the desired Zoom distance if we roll the scrollwheel
            desiredDistance -= Input.GetAxis("RT")*Time.deltaTime*ZoomSpeed*Mathf.Abs(desiredDistance);
            desiredDistance += Input.GetAxis("LT")*Time.deltaTime*ZoomSpeed*Mathf.Abs(desiredDistance);
            desiredDistance -= Input.GetAxis("Mouse ScrollWheel")*Time.deltaTime*ZoomSpeed*40*Mathf.Abs(desiredDistance);

            //Clamp zoom Min/Max
            desiredDistance = Mathf.Clamp(desiredDistance, MinViewDistance, MaxViewDistance);
            // Smoothing Zoom with lerp
            currentDistance = Mathf.Lerp(currentDistance, desiredDistance, Time.deltaTime*ZoomDampening);

            // Calculate new position
            position = Target.position - (rotation*Vector3.forward*currentDistance);
            transform.position = position;
        }
    }

    private static float ClampAngle(float angle, float min, float max)
    {
        if (angle < -360)
            angle += 360;
        if (angle > 360)
            angle -= 360;
        return Mathf.Clamp(angle, min, max);
    }
    
}

//***********************
//Player behaviour script
//***********************
using UnityEngine;
using System.Collections;
using UnityEngine.SocialPlatforms.GameCenter;
using UnityEngine.SceneManagement;
using System.Collections.Generic;
using JetBrains.Annotations;

public class PlayerBehaviour : MonoBehaviour
{
    public GameObject Camera;
    public List CheckpointList;
    public bool _isHitByEnemy = false;
    private int _hitDelayCounter = 0;

    private float _movementSpeed = 3.0f;
    private float _gravity = 9.81f;
    private float _climbSpeed = 25.0f;
    private CharacterController _characterController;
    private GameObject _gameManager;
    private GameObject _cameraPivot;

    private Vector3 _newRight = Vector3.zero;
    private Vector3 _newForward = Vector3.zero;
    private Vector3 _movementVector = Vector3.zero;

    private int _frameCounter = 0;
    private int _lastLadderFrame = 0;

    private bool _isClimbing = false;

    private bool _hasTNTPickedUp = false;
    private GameObject _pickedUpTnt;
    private int _AButtonCooldown = 0;
    private bool _pickUpTNT = false;
    private bool _difuseTNT = false;

    private Vector3 _nearestCheckpoint = Vector3.zero;

    public int _treasuesCollected = 0;

    private void Start()
    {
        _characterController = GetComponent();
        _gameManager = GameObject.Find("GameManager");
        _cameraPivot = GameObject.Find("CameraPivot");
        _nearestCheckpoint = CheckpointList[0].transform.position;
    }

    private void Update()
    {
        MovePlayer();
        ResetPosition();

        if (_hasTNTPickedUp && (Input.GetButtonDown("AButton") || Input.GetKeyDown(KeyCode.R)) && _AButtonCooldown <= 10)//if we need to drop the tnt
        {
            _AButtonCooldown = 10;
            _hasTNTPickedUp = false;
            //Debug.Log("release");
            _pickedUpTnt.transform.parent = null;
            _pickedUpTnt.transform.localScale = new Vector3(1.7f, 1.7f, 1.7f);
            _pickedUpTnt.transform.position = this.transform.position;
        }

        if (_pickUpTNT) //if we need to pick up the tnt
        {
            _pickUpTNT = false;

            _AButtonCooldown = 10;
            _hasTNTPickedUp = true;
            //Debug.Log("pickup");
            _pickedUpTnt.transform.position = this.transform.position + new Vector3(0.0f, 1.0f, 0.0f); //set the position of the TNT above the player
            _pickedUpTnt.transform.localScale = new Vector3(1, 1, 1); // make the tnt smaller above the player
            _pickedUpTnt.transform.SetParent(this.transform); //set the parent of the tnt to the avatar
        }

        if (_difuseTNT) //defuse the tnt if B is pressed
        {
            _difuseTNT = false;
            _pickedUpTnt.GetComponent().SetDefuse = true;

        }
        _AButtonCooldown--;

    }

    void MovePlayer()
    {
        if (_characterController.isGrounded && !_isClimbing)
        {
            _newRight = Vector3.Cross(Vector3.up, Camera.transform.forward).normalized;
            _newForward = Vector3.Cross(_newRight, Vector3.up).normalized;

            _movementVector = (_newRight * Input.GetAxis("LeftJoystickX")) + (_newForward * -Input.GetAxis("LeftJoystickY")).normalized;
            _movementVector = (_newRight * Input.GetAxis("Horizontal")) + (_newForward * Input.GetAxis("Vertical")).normalized;

            
        }
        else if (_isClimbing)
        {
            _movementVector = (_newRight * Input.GetAxis("LeftJoystickX")) + (_newForward * -Input.GetAxis("LeftJoystickY")).normalized;
            _movementVector = (_newRight * Input.GetAxis("Horizontal")) + (_newForward * Input.GetAxis("Vertical")).normalized;

            _movementVector.y = -Input.GetAxis("LeftJoystickY") * _movementSpeed * _climbSpeed * Time.deltaTime;
            _movementVector.y = Input.GetAxis("Vertical") * _movementSpeed * _climbSpeed / 2 * Time.deltaTime;

        }
        _movementVector.y -= _gravity * Time.deltaTime;
        _characterController.Move(_movementVector * _movementSpeed * Time.deltaTime);

        //Rotation player
        Vector3 rotVector3 = new Vector3(_movementVector.x, 90, _movementVector.z);

        if (rotVector3.x != 0 && rotVector3.z != 0 )
        {
            //rotVector3.y *= -90;            
            transform.rotation = Quaternion.LookRotation(rotVector3);
        }


        //test if the avatar should leave the ladder
        _frameCounter++;
        if (_lastLadderFrame <= _frameCounter - 2 || (_characterController.isGrounded && Input.GetAxis("Vertical") == 0))
        {
            _isClimbing = false;
        }
    }

    private void OnControllerColliderHit(ControllerColliderHit hit)
    {
        if (hit.transform.tag == "Ladder")
        {
            _lastLadderFrame = _frameCounter;
            _isClimbing = true;
        }
        else if (_lastLadderFrame <= _frameCounter - 5)
        {
            _isClimbing = false;
        }


        if (hit.transform.tag == "Canonball" || hit.transform.tag == "Water" || hit.transform.tag == "Rock" || hit.transform.tag == "Patrol")
        {
               _isHitByEnemy = true;
        }

        if (hit.transform.tag == "Treasure")
        {
            hit.gameObject.GetComponent().IsOpened = true;
        }


    }

    void OnTriggerEnter(Collider other)
    {
        if (other.transform.tag == "Patrol")
        {
            _isHitByEnemy = true;
        }
    }

    private void OnTriggerStay(Collider hit)
    {
        if (hit.transform.tag == "TNT" && (Input.GetButtonDown("AButton") || Input.GetKeyDown(KeyCode.R)) && !_hasTNTPickedUp && _AButtonCooldown <= 0)//pickup TNT if A is pressed
        {
            _pickUpTNT = true;
            _pickedUpTnt = hit.gameObject;
        }
        if (hit.transform.tag == "TNT" && (Input.GetButtonDown("BButton") || Input.GetKeyDown(KeyCode.T)) && !_hasTNTPickedUp)
        {
            _pickedUpTnt = hit.gameObject;
            _difuseTNT = true;
        }

        if (hit.transform.tag == "Water")
        {
            _isHitByEnemy = true;
            if (_hasTNTPickedUp)//destroy tnt if we fall in the water
            {
                _AButtonCooldown = 10;
                _hasTNTPickedUp = false;
                Destroy(_pickedUpTnt.gameObject);
            }
        }
    } 

    private void ResetPosition()
    {
        _hitDelayCounter--;
        if (_isHitByEnemy && _hitDelayCounter <= 0)
        {
            StartCoroutine(FadeOut());
            _hitDelayCounter = 5;
            if (_hasTNTPickedUp)// we need to drop the tnt
            {
                _AButtonCooldown = 10;
                _hasTNTPickedUp = false;
                _pickedUpTnt.transform.parent = null;
                _pickedUpTnt.transform.localScale = new Vector3(1.7f, 1.7f, 1.7f);
                _pickedUpTnt.transform.position = this.transform.position;
            }

            var tempPosition = Vector3.zero;
            var _distanceToCheckpoint = 5000.0f;

            foreach (GameObject gameObject in CheckpointList)
            {
               
                if (gameObject.GetComponent().IsActive)
                {
                    var tempDistance = 0.0f;

                    tempPosition = gameObject.transform.position;
                    tempDistance = Vector3.Distance(tempPosition, _characterController.transform.position);

                    if (tempDistance <= _distanceToCheckpoint)
                    {
                        _distanceToCheckpoint = tempDistance;
                        _nearestCheckpoint = gameObject.transform.position;

                    }
                }
            }

            this.transform.position = _nearestCheckpoint;

            if (_gameManager != null)
            {
                if (_gameManager.GetComponent().LivesLeft >= 1)
                {
                    _gameManager.GetComponent().LivesLeft -= 1;
                }
                else
                {
                    SceneManager.LoadScene("EndScreen");
                }

            }
        }

        _isHitByEnemy = false;

    }

    private static float ClampAngle(float angle, float min, float max)
    {
        if (angle < -360)
            angle += 360;
        if (angle > 360)
            angle -= 360;
        return Mathf.Clamp(angle, min, max);
    }

    public IEnumerator FadeOut()
    {
        float fadeTime = _cameraPivot.GetComponent().BeginFade(1);
        yield return new WaitForSeconds(fadeTime);
        _cameraPivot.GetComponent().BeginFade(-1);
    }
}
								
								

Screenshots


Go back