예제 #1
0
    void OnEventTouchTap(System.Object data)
    {
        Hashtable table    = (Hashtable)data;
        Vector2   TouchPos = (Vector2)table["EndPos"];
        Vector2   WorldPos = Camera.main.ScreenToWorldPoint(TouchPos);

        RaycastHit2D[] hits   = Physics2D.RaycastAll(WorldPos, Vector2.zero);
        bool           b_Jump = true;

        foreach (var hit in hits)
        {
            if (hit.collider != null)
            {
                if (hit.collider.tag == "GesturePrefab")
                {
                    iTween.ScaleTo(hit.collider.gameObject, Vector3.zero, 0.75f);
                    Destroy(hit.collider.gameObject, 0.8f);
                    EventHandler.TriggerEvent(EEventID.EVENT_GESTURE_OBJET_DESTROY, null);
                    b_Jump = false;
                    break;
                }
            }
        }

        if ((m_eCurrentState != PLAYER_STATES.JUMP) && b_Jump)
        {
            m_ptrRigidbody.AddForce(new Vector2(0f, JumpMagnitude));
            StartCoroutine(CheckGround());
            m_eCurrentState = PLAYER_STATES.JUMP;
        }
    }
예제 #2
0
 void HandleJumping()
 {
     if (m_jump || m_runningJump)
     {
         m_shoot           = false;
         m_roll            = false;
         m_jumpDelayTimer -= Time.deltaTime;
         if (m_jumpDelayTimer <= 0)
         {
             if (m_grounded)
             {
                 if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.D))
                 {
                     m_running      = true;
                     m_playerStates = PLAYER_STATES.RUNNING_JUMP;
                 }
                 else
                 {
                     m_jogging      = true;
                     m_playerStates = PLAYER_STATES.JUMP;
                 }
             }
             m_jumpDelayTimer = m_maxJumpDelayTimer;
         }
     }
     if (m_runningJump && m_stamina <= 0 || m_jump && m_stamina <= 0)
     {
         m_runningJump = false;
         m_jump        = false;
     }
 }
예제 #3
0
 void Start()
 {
     _mRigidBD       = GetComponent <Rigidbody>();
     _mUiText.text   = "No Parent";
     _mState         = PLAYER_STATES.IDLE;
     _mTouchingFloor = false;
 }
예제 #4
0
 void Start()
 {
     playerState = PLAYER_STATES.IDLE;
     targetPos   = new Vector2(0, 0.7f);
     currentPos  = targetPos;
     this.gameObject.transform.position = targetPos;
 }
예제 #5
0
 void OnCollisionEnter(Collision other)
 {
     // Death
     if (other.collider.tag == "Zombie")
     {
         PlayerPrefs.SetInt("Score", (int)m_scoreScript.GetScore());
         SceneManager.LoadScene("GameOver");
     }
     if (other.collider.tag == "Ground" || other.collider.tag == "Environment")
     {
         m_grounded     = true;
         m_runningJump  = false;
         m_jump         = false;
         m_readyToShoot = false;
         if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.D))
         {
             m_running      = true;
             m_playerStates = PLAYER_STATES.RUN;
         }
         else
         {
             m_jogging      = true;
             m_playerStates = PLAYER_STATES.JOG;
         }
         m_canJump = true;
     }
 }
예제 #6
0
 void Start()
 {
     animator    = this.gameObject.GetComponent <Animator>();
     playerState = PLAYER_STATES.IDLE;
     targetPos   = new Vector2(0, 0.7f);
     currentPos  = targetPos;
     this.gameObject.transform.position = targetPos;
 }
예제 #7
0
 public void InitialisePlayer()
 {
     health      = CONSTANTS.START_HEALTH;
     keys        = 0;
     playerState = PLAYER_STATES.IDLE;
     targetPos   = new Vector2(0, 0.7f);
     currentPos  = targetPos;
     this.gameObject.transform.position = targetPos;
 }
예제 #8
0
 void Start()
 {
     health      = CONSTANTS.START_HEALTH;
     keys        = 0;
     animator    = this.gameObject.GetComponent <Animator>();
     playerState = PLAYER_STATES.IDLE;
     targetPos   = new Vector2(0, 0.7f);
     currentPos  = targetPos;
     this.gameObject.transform.position = targetPos;
 }
예제 #9
0
 void OnEventTouchMoveEnd(System.Object data)
 {
     if (m_eCurrentState != PLAYER_STATES.JUMP)
     {
         m_eCurrentState = PLAYER_STATES.IDLE;
         float NewVelocity = Mathf.MoveTowards(m_ptrRigidbody.velocity.x, 0f, Acceleration * 5f);
         //float NewVelocity = m_ptrRigidbody.velocity.x - (Acceleration * 3f);
         m_ptrRigidbody.velocity = new Vector2(NewVelocity, m_ptrRigidbody.velocity.y);
     }
 }
예제 #10
0
    void Start()
    {
        m_eCurrentState = PLAYER_STATES.IDLE;
        GroundCheck     = transform.GetChild(0);
        GroundColliders = new Collider2D[5];
        m_MoveCamera    = GameObject.FindGameObjectWithTag("InputCamera").GetComponent <Camera>();


        m_ptrRigidbody = GetComponent <Rigidbody2D>();
        b_flipscale    = true;
    }
예제 #11
0
    void Start()
    {
        _mRigidBD  = GetComponent <Rigidbody>();
        _mAnimCTRL = GetComponentInChildren <Animator>();

        _mUiText.text   = "No Parent";
        _mState         = PLAYER_STATES.IDLE;
        _mTouchingFloor = false;

        DetachRopeFromTarget();
    }
예제 #12
0
 public void SetAttackMode(bool val)
 {
     if (val && !chickenOn)
     {
         currentState = PLAYER_STATES.Attack;
         GetComponent <AttackBehaviour>().SetVisibilityCrosshair(true);
     }
     else
     {
         currentState = PLAYER_STATES.Idle;
         GetComponent <AttackBehaviour>().SetVisibilityCrosshair(false);
     }
 }
예제 #13
0
    private IEnumerator MoveToPosition(float timeToMove)
    {
        playerState = PLAYER_STATES.MOVING;
        float t = 0.0f;

        do
        {
            currentPos = this.gameObject.transform.position;
            t         += Time.deltaTime / timeToMove;
            this.gameObject.transform.position = Vector2.MoveTowards(this.gameObject.transform.position, targetPos, t);
            yield return(null);
        } while (t < 1 && currentPos != targetPos);
        playerState = PLAYER_STATES.IDLE;
    }
예제 #14
0
 public void Run()
 {
     if (m_stamina > 0 && m_grounded)
     {
         m_playerStates = PLAYER_STATES.RUN;
         m_jogging      = false;
         m_running      = true;
     }
     else if (m_stamina < 0.1f)
     {
         m_playerStates = PLAYER_STATES.JOG;
         m_running      = false;
         m_jogging      = true;
     }
 }
예제 #15
0
    void OnEventTouchMove(System.Object data)
    {
        Hashtable table          = (Hashtable)data;
        float     TargetVelocity = MaxVelocity;

        if (m_eCurrentState == PLAYER_STATES.IDLE)
        {
            m_eCurrentState = PLAYER_STATES.MOVE;
            TargetVelocity  = MaxVelocity;
        }
        else if (m_eCurrentState == PLAYER_STATES.JUMP)
        {
            TargetVelocity = MaxVelocity / 1.5f;
        }

        Vector2 TouchPos = (Vector2)table["TouchPos"];
        Vector2 WorldPos = m_MoveCamera.ScreenToWorldPoint(TouchPos);

        if (m_vInitialTouchposition.x <= WorldPos.x)
        {
            if (b_flipscale)
            {
                b_flipscale          = false;
                transform.localScale = new Vector3(Mathf.Abs(transform.localScale.x), transform.localScale.y, transform.localScale.z);
                MoveDir = 1;
            }
        }
        else
        {
            if (!b_flipscale)
            {
                b_flipscale          = true;
                transform.localScale = new Vector3(-Mathf.Abs(transform.localScale.x), transform.localScale.y, transform.localScale.z);
                MoveDir = -1;
            }
        }

        float velocity = Mathf.MoveTowards(m_ptrRigidbody.velocity.x, TargetVelocity * MoveDir, Acceleration * Time.fixedDeltaTime);

        m_ptrRigidbody.velocity = new Vector2(velocity, m_ptrRigidbody.velocity.y);
    }
예제 #16
0
    private void StateController()
    {
        switch (currentState)
        {
        case PLAYER_STATES.Idle:
            if (!onFloor)
            {
                currentState = PLAYER_STATES.Jump;
            }
            if (rig.velocity.x != 0)
            {
                currentState = PLAYER_STATES.Running;
            }
            break;

        case PLAYER_STATES.Running:
            if (!onFloor)
            {
                currentState = PLAYER_STATES.Jump;
            }
            if (Mathf.Abs(rig.velocity.x) <= 0.1)
            {
                currentState = PLAYER_STATES.Idle;
            }
            break;

        case PLAYER_STATES.Jump:
            if (onFloor)
            {
                currentState = PLAYER_STATES.Idle;
            }
            break;

        default:
            break;
        }
    }
예제 #17
0
    IEnumerator CheckGround()
    {
        yield return(new WaitForFixedUpdate());

        yield return(new WaitForFixedUpdate());

        System.Array.Clear(GroundColliders, 0, GroundColliders.Length);
        while (true)
        {
            Physics2D.OverlapCircleNonAlloc(GroundCheck.position, 0.2f, GroundColliders);
            foreach (Collider2D collider in GroundColliders)
            {
                if (collider != null)
                {
                    if (collider.tag == "Ground")
                    {
                        m_eCurrentState = PLAYER_STATES.IDLE;
                        yield break;
                    }
                }
            }
            yield return(new WaitForFixedUpdate());
        }
    }
예제 #18
0
    void SetAnimations()
    {
        // Set the enum PLAYER_STATES
        if (m_jogging && !m_jump && !m_roll && !m_runningJump && !m_shoot && !m_running && m_grounded)
        {
            m_playerStates = PLAYER_STATES.JOG;
        }
        else if (m_jogging && m_jump || m_jump && m_grounded)
        {
            m_playerStates = PLAYER_STATES.JUMP;
        }
        else if (m_running && !m_runningJump && !m_roll && !m_jump && !m_shoot && !m_jogging)
        {
            if (m_stamina > 0 && !m_jump || m_stamina > 0 && !m_runningJump && m_grounded)
            {
                m_playerStates = PLAYER_STATES.RUN;
            }
            else if (m_stamina <= 0 && !m_jump || m_stamina <= 0 && !m_runningJump && m_grounded)
            {
                m_playerStates = PLAYER_STATES.JOG;
            }
        }
        else if (m_running && m_runningJump || m_runningJump || m_runningJump && m_jogging)
        {
            m_playerStates = PLAYER_STATES.RUNNING_JUMP;
        }
        else if (m_shoot)
        {
            m_playerStates = PLAYER_STATES.SHOOT;
        }
        else if (m_roll && m_jogging || m_roll && m_running)
        {
            m_playerStates = PLAYER_STATES.ROLL;
        }
        else if (m_stamina <= 0 && m_jump)
        {
            m_playerStates = PLAYER_STATES.JUMP;
        }
        else if (m_stamina <= 0 && m_runningJump)
        {
            m_playerStates = PLAYER_STATES.RUNNING_JUMP;
        }
        else if (m_jogging && m_runningJump)
        {
            m_playerStates = PLAYER_STATES.RUNNING_JUMP;
        }

        // Set the Parameters in the Animator based on the enum PLAYER_STATES
        switch (m_playerStates)
        {
        case PLAYER_STATES.JOG:
            m_animator.SetBool("jogging", true);
            m_animator.SetBool("running", false);
            m_animator.SetBool("runningJump", false);
            m_animator.SetBool("jump", false);
            break;

        case PLAYER_STATES.RUN:
            m_animator.SetBool("running", true);
            m_animator.SetBool("jump", false);
            m_animator.SetBool("runningJump", false);
            m_animator.SetBool("jogging", false);
            break;

        case PLAYER_STATES.JUMP:
            m_animator.SetBool("jump", true);
            m_animator.SetBool("runningJump", false);
            m_animator.SetBool("running", false);
            m_animator.SetBool("jogging", false);
            break;

        case PLAYER_STATES.RUNNING_JUMP:
            m_animator.SetBool("runningJump", true);
            m_animator.SetBool("jump", false);
            m_animator.SetBool("jogging", false);
            m_animator.SetBool("running", false);
            break;

        case PLAYER_STATES.ROLL:
            m_animator.SetBool("roll", true);
            break;

        case PLAYER_STATES.SHOOT:
            m_animator.SetBool("shoot", true);
            m_animator.SetBool("running", false);
            m_animator.SetBool("jump", false);
            m_animator.SetBool("runningJump", false);
            m_animator.SetBool("jogging", false);
            break;
        }
        if (!m_shoot)
        {
            m_animator.SetBool("shoot", false);
        }
        if (!m_roll)
        {
            m_animator.SetBool("roll", false);
        }
    }
예제 #19
0
 public void Jog()
 {
     m_playerStates = PLAYER_STATES.JOG;
     m_running      = false;
     m_jogging      = true;
 }
예제 #20
0
    void FixedUpdate()
    {
        _mTouchingFloor = IsTouchingFloor();
        UpdateRope();


        if (!_mTouchingFloor /* && DistanceToFloor() > 0.25f*/)
        {
            _mState = PLAYER_STATES.AIRBOURNE;
            _mRigidBD.AddForce(_mArtificialVelocity);
        }
        else if (Input.GetKey(KeyCode.Space) && _mTouchingFloor)
        {
            _mState = PLAYER_STATES.AIRBOURNE;
            _mRigidBD.AddForce(Vector3.up * _mJumpStreangth);
            _mRigidBD.AddForce(_mArtificialVelocity);
        }
        else if (Input.GetAxis("Horizontal") != 0 || Input.GetAxis("Vertical") != 0)
        {
            if (Input.GetKey(KeyCode.LeftShift))
            {
                _mState = PLAYER_STATES.RUN;
                _mArtificialVelocity = FlattenMovementVectorAgainstFloor(CalculateHorizontalMovementVecotor(_mRunningSpeed));
            }
            else
            {
                _mState = PLAYER_STATES.WALK;
                _mArtificialVelocity = FlattenMovementVectorAgainstFloor(CalculateHorizontalMovementVecotor(_mWalkingSpeed));
            }
            Vector3 heading = _mArtificialVelocity;
            heading.y = 0;
            heading.Normalize();
            TurnPlayerAvatar(heading);
        }
        else
        {
            _mState = PLAYER_STATES.IDLE;

            if (_mArtificialVelocity.magnitude > 0.01f)
            {
                Vector3 subTraction = _mArtificialVelocity * _mArtificalVelocityMagDegredation;
                _mArtificialVelocity -= subTraction * Time.deltaTime;
            }
            else if (_mArtificialVelocity.magnitude != 0)
            {
                _mArtificialVelocity = Vector3.zero;
            }
        }

        if (_mState.Equals(PLAYER_STATES.AIRBOURNE))
        {
            _mRigidBD.drag = 0.5f;
            //AssignTansformParent(null);
        }
        else
        {
            _mRigidBD.drag = Mathf.Infinity;
            GameObject floor = GetFloor().collider.gameObject;
            if (floor != null)
            {
                AssignTansformParent(floor);
            }
        }

        _mRigidBD.MovePosition(transform.position + _mArtificialVelocity);
        UpdateAnimCTRL();
    }