Inheritance: IPlayerState
Beispiel #1
0
        void Update()
        {
            // jump
            switch (jumpState)
            {
            case JumpState.Jump:
                // 上へ
                collider.transform.Translate(jumpSpeed * Vector2.up * Time.deltaTime);
                if (transform.position.y > jumpHeight)
                {
                    jumpState = JumpState.Fall;
                }
                break;

            case JumpState.Fall:
                // 下へ
                collider.transform.Translate(fallSpeed * Vector2.down * Time.deltaTime);
                if (transform.position.y < 0.01F)
                {
                    // 地面へ
                    collider.transform.transform.position = new Vector3(transform.position.x, 0.0F, transform.position.z);
                    jumpState = JumpState.OnGround;
                    animator.SetBool("IsRunning", true);
                }
                break;

            default:
                // Do Nothing
                break;
            }
        }
 /// <summary>
 /// 模拟Jump控制跳跃
 /// 当前方没有路时,模拟跳跃
 /// </summary>
 private void SimulateControlJump()
 {
     if (m_JumpState == JumpState.Grounded && !IsForwardGrounded)
     {
         m_JumpState = JumpState.PrepareToJump;
     }
 }
Beispiel #3
0
    private void MakeFSM()
    {
        IdleState idle = new IdleState();

        idle.AddTransition(Transition.Walk, StateID.Walk);
        idle.AddTransition(Transition.Jump, StateID.Jump);
        idle.AddTransition(Transition.Die, StateID.Die);

        WalkState walk = new WalkState(path);

        walk.AddTransition(Transition.Idle, StateID.Idle);
        walk.AddTransition(Transition.Jump, StateID.Jump);
        walk.AddTransition(Transition.Die, StateID.Die);

        JumpState jump = new JumpState();

        jump.AddTransition(Transition.Idle, StateID.Idle);
        jump.AddTransition(Transition.Die, StateID.Die);
        DeadState die = new DeadState();

        fsm = new FSMSystem();
        fsm.AddState(idle);
        fsm.AddState(walk);
        fsm.AddState(jump);
        fsm.AddState(die);
    }
Beispiel #4
0
        void UpdateJumpState()
        {
            jump = false;
            switch (jumpState)
            {
            case JumpState.PrepareToJump:
                jumpState = JumpState.Jumping;
                jump      = true;
                stopJump  = false;
                break;

            case JumpState.Jumping:
                if (!IsGrounded)
                {
                    jumpState = JumpState.InFlight;
                }
                break;

            case JumpState.InFlight:
                if (IsGrounded)
                {
                    jumpState = JumpState.Landed;
                }
                break;

            case JumpState.Landed:
                jumpState = JumpState.Grounded;
                break;
            }
        }
Beispiel #5
0
    // Use this for initialization

    void Start()
    {
        Move_parameter_x          = 0;
        Move_parameter_x          = 0;
        playerController          = this;
        AttackTrigger             = 0;
        PlayerAnimation_parameter = 0;
        GhostShadow.ghostShadow.gameObject.GetComponent <GhostShadow>().enabled = false;

        debounce = true;
        CanMove  = true;
        AttackCollider_Small.SetActive(false);
        AttackCollider_Big.SetActive(false);
        AttackCollider_BigSkill.SetActive(false);
        CanAttack             = true;
        CancelAttackCoroutine = null;
        ResetStateCoroutine   = null;
        DoubleClickCoroutine  = null;
        FastRunCoroutine      = null;
        GetUpCoroutine        = null;
        AvoidDistance         = AvoidMaxDistance;
        FixBulletPos          = Bullet_pos.transform.position - transform.position;

        Weapons.transform.parent              = WeaponsBone;//--
        LightAccessoriesUp.transform.parent   = LightAccessoriesUpBone;
        LightAccessoriesDown.transform.parent = LightAccessoriesDownBone;

        attackState         = AttackState.Default;
        moveState           = MoveState.Idle;
        playerAnimatorState = PlayerAnimatorState.Movement;
        avoidState          = AvoidState.Default;
        jumpState           = JumpState.Jump;
    }
        protected override void Update()
        {
            Debug.Log(Input.acceleration.x + ", " + Input.acceleration.y + ", " + Input.acceleration.z);
            var jumpControlDown = Input.GetMouseButtonDown(0); //Input.GetButtonDown("Jump");
            var jumpControlUp   = Input.GetMouseButtonUp(0);   //Input.GetButtonUp("Jump");

            if (controlEnabled)
            {
                //var accValue = Mathf.Clamp(Input.acceleration.x, -maxAccelometerValue, maxAccelometerValue);
                var accValue = Input.acceleration.x;
                accValue = accValue >= minAccelometerValue || accValue <= -minAccelometerValue?Mathf.Sign(accValue) : 0;

                move.x = accValue; //Input.GetAxis("Horizontal");
                if (jumpState == JumpState.Grounded && jumpControlDown)
                {
                    jumpState = JumpState.PrepareToJump;
                }
                else if (jumpControlUp)
                {
                    stopJump = true;
                    Schedule <PlayerStopJump>().player = this;
                }
            }
            else
            {
                move.x = 0;
            }
            UpdateJumpState();
            base.Update();
        }
Beispiel #7
0
        private void UpdateLocalPlayerPosition()
        {
            RotateView();

            // the jump state needs to read here to make sure it is not missed
            if (m_JumpState == JumpState.None)
            {
                if (InputManager.ActiveDevice.Action1.IsPressed ||
                    Input.GetKeyDown(KeyCode.Space))
                {
                    Debug.Log("Jump Pressed");
                    m_JumpState = JumpState.JumpPending;
                }
            }

            if (!m_PreviouslyGrounded && m_CharacterController.isGrounded)
            {
                PlayLandingSound();
                m_MoveDir.y = 0f;
                m_JumpState = JumpState.None;
            }

            if (!m_CharacterController.isGrounded && m_JumpState == JumpState.None && m_PreviouslyGrounded)
            {
                m_MoveDir.y = 0f;
            }

            m_PreviouslyGrounded = m_CharacterController.isGrounded;
        }
Beispiel #8
0
    public PlayerState(IEventManager playerEvent)
    {
        #region Player State Initialization
        _StateIdle              = new IdleState(this);
        _StateWalk              = new WalkState(this);
        _StateSprint            = new SprintState(this);
        _StateFall              = new FallState(this);
        _StateCrouch            = new CrouchState(this);
        _StateJump              = new JumpState(this);
        _StateCrouchWalk        = new CrouchWalkState(this);
        _StateSlide             = new SlideState(this);
        _StateCrouchJump        = new CrouchJumpState(this);
        _StateCrouchFall        = new CrouchFallState(this);
        _StateAirMoveCrouchFall = new AirMoveCrouchFallState(this);
        _StateAirMoveCrouchJump = new AirMoveCrouchJumpState(this);
        _StateAirMoveFall       = new AirMoveFallState(this);
        _StateAirMoveJump       = new AirMoveJumpState(this);
        #endregion

        _ActiveProxies      = new HashSet <IDynamicProxy>();
        _EventPlayer        = playerEvent;
        _CurrentPlayerState = _StateIdle;

        #region State Proxy Initialization
        _MediatorToggleProxy             = new ToggleProxyMediator();
        _ProxySprint                     = new SprintProxy(this, _MediatorToggleProxy);
        _ProxyCrouch                     = new CrouchProxy(this, _MediatorToggleProxy);
        _MediatorToggleProxy.ProxyCrouch = _ProxyCrouch;
        _MediatorToggleProxy.ProxySprint = _ProxySprint;

        _ProxyWalk = new WalkProxy(this, _MediatorToggleProxy);
        _ProxyFall = new FallProxy(this);
        _ProxyJump = new JumpProxy(this, _MediatorToggleProxy);
        #endregion
    }
 void OnCollisionEnter(Collision collision)
 {
     if ((1 << collision.gameObject.layer) == wallLayer)
     {
         jumpState = JumpState.Grounded;
     }
 }
        protected override void Update()
        {
            if (controlEnabled)
            {
                move.x = Input.GetAxis("Horizontal");
                if (jumpState == JumpState.Grounded && Input.GetButtonDown("Jump"))
                {
                    jumpState = JumpState.PrepareToJump;

                    //Sending the event PlayerJumped()
                    deltaDNAManager.PlayerJumped();
                }
                else if (Input.GetButtonUp("Jump"))
                {
                    stopJump = true;
                    Schedule <PlayerStopJump>().player = this;
                }
            }
            else
            {
                move.x = 0;
            }
            UpdateJumpState();
            base.Update();
        }
Beispiel #11
0
 protected override void Update()
 {
     if (controlEnabled)
     {
         move.x = Input.GetAxis("Horizontal");
         if (input_reverse)
         {
             move.x = -move.x;
         }
         if (jumpState == JumpState.Grounded && Input.GetButtonDown("Jump"))
         {
             jumpState = JumpState.PrepareToJump;
         }
         else if (Input.GetButtonUp("Jump"))
         {
             stopJump = true;
             Schedule <PlayerStopJump>().player = this;
         }
     }
     else
     {
         move.x = 0;
     }
     UpdateJumpState();
     base.Update();
 }
Beispiel #12
0
        void UpdateJumpState()
        {
            jump = false;
            switch (jumpState)
            {
            case JumpState.PrepareToJump:
                jumpState = JumpState.Jumping;
                jump      = true;
                stopJump  = false;
                break;

            case JumpState.Jumping:
                if (!IsGrounded)
                {
                    Schedule <PlayerJumped>().player = this;
                    jumpState = JumpState.InFlight;
                }
                break;

            case JumpState.InFlight:
                if (IsGrounded)
                {
                    Schedule <PlayerLanded>().player = this;
                    jumpState = JumpState.Landed;
                }
                break;

            case JumpState.Landed:
                jumpState = JumpState.Grounded;
                break;
            }
        }
Beispiel #13
0
    private void Jump()
    {
        float jumpVal = Input.GetKeyDown(KeyCode.Space) ? jumpForce : 0.0f;

        switch (_jumpState)
        {
        case JumpState.Grounded:
            if (jumpVal > 0.0f)
            {
                _jumpState = JumpState.Jumping;
                Debug.Log("JumpState: " + _jumpState.ToString());
            }
            break;

        case JumpState.Jumping:
            if (jumpVal > 0.0f)
            {
                _jumpState = JumpState.DoubleJumping;
                Debug.Log("JumpState: " + _jumpState.ToString());
            }
            break;

        case JumpState.DoubleJumping:
            jumpVal = 0.0f;
            break;
        }

        Vector3 jumping = new Vector3(0.0f, jumpVal, 0.0f);

        rb.AddForce(jumping);
    }
Beispiel #14
0
        public static Unit ReadFrom(System.IO.BinaryReader reader)
        {
            var result = new Unit();

            result.PlayerId    = reader.ReadInt32();
            result.Id          = reader.ReadInt32();
            result.Health      = reader.ReadInt32();
            result.Position    = Vec2Double.ReadFrom(reader);
            result.Size        = Vec2Double.ReadFrom(reader);
            result.JumpState   = JumpState.ReadFrom(reader);
            result.WalkedRight = reader.ReadBoolean();
            result.Stand       = reader.ReadBoolean();
            result.OnGround    = reader.ReadBoolean();
            result.OnLadder    = reader.ReadBoolean();
            result.Mines       = reader.ReadInt32();
            if (reader.ReadBoolean())
            {
                result.Weapon = Model.Weapon.ReadFrom(reader);
            }
            else
            {
                result.Weapon = null;
            }
            return(result);
        }
Beispiel #15
0
    private void Jump()
    {
        float JumpVal = Input.GetKeyDown(KeyCode.Space) ? jumpForce : 0.0f;

        switch (_jumpState)
        {
        case JumpState.Grounded:
            if (JumpVal > 0.0f)
            {
                _jumpState = JumpState.Jumping;
            }
            break;

        case JumpState.Jumping:
            if (JumpVal > 0.0f)
            {
                _jumpState = JumpState.DoubleJumping;
            }
            break;

        case JumpState.DoubleJumping:
            JumpVal = 0.0f;
            break;
        }
        Vector3 jump = new Vector3(0.0f, JumpVal, 0.0f);

        rb.AddForce(jump);
    }
        private void Init()
        {
            if (!inited)
            {
                inited = true;
                //初始化
                InitDelegate();

                InitFormatPrefabRectTransform();
                InitCursor();
                InitContentTrans();
                //注册预制体对象池
                RegistObjectPool();
                //注册滚动监听
                ScrollRect.onValueChanged.AddListener(OnValueChanged);
                if (scrollDirection == ScrollDirection.Vertical)
                {
                    onAlignScrollDataAction = AlignScrollDataWhenVertical;
                    onGetDistanceToCenter   = GetDistanceToCenterWhenVeritical;
                    jumpState = new JumpState(this, SetNormalizedPosWhenVertical, GetNormalizedPosWhenVertical);
                }
                else if (scrollDirection == ScrollDirection.Horizontal)
                {
                    onAlignScrollDataAction = SetSingleContentDataWhenHorizontal;
                    onGetDistanceToCenter   = GetDistanceToCenterWhenHorizontal;
                    jumpState = new JumpState(this, SetNormalizedPosWhenHorizontal, GetNormalizedPosWhenHorizontal);
                }
            }
        }
Beispiel #17
0
    void Update()
    {
        if (!HasGroundCollisionInProgress())
        {
            jumpState = JumpState.InAir;
        }

        UpdateInput();
        UpdateJump();

        float dragSpeed = 0;

        if (!isMoving && jumpState == JumpState.Grounded && moveSpeed != 0)
        {
            dragSpeed = -Mathf.Sign(moveSpeed) * dragAcc * Time.fixedDeltaTime;
            if (Mathf.Sign(moveSpeed + dragSpeed) != Mathf.Sign(moveSpeed))
            {
                dragSpeed = -moveSpeed;
            }
        }

        float gravityEnabled = jumpState == JumpState.Grounded ? 0 : 1;

        moveSpeed = Mathf.Clamp(moveSpeed + inputDirection * moveAcc * Time.fixedDeltaTime, -maxSpeed, maxSpeed);
        moveSpeed = moveSpeed + gravityEnabled * gravityDir.x * gravityAcc * Time.fixedDeltaTime;
        moveSpeed = moveSpeed + dragSpeed;

        ySpeed = ySpeed + gravityEnabled * gravityDir.y * gravityAcc * Time.fixedDeltaTime;

        transform.position = transform.position + new Vector3(moveSpeed, ySpeed, 0) * Time.fixedDeltaTime;
    }
Beispiel #18
0
 private void OnCollisionEnter(Collision collision)
 {
     if (collision.transform.tag == "Floor")
     {
         jumpState = JumpState.Grounded;
     }
 }
Beispiel #19
0
    public override CharacterState UpdataState(Character character, InputOrder input)
    {
        CharacterState tempState = this;

        if (!character.OnGround())
        {
            tempState = new JumpState();
        }
        else
        {
            switch (input)
            {
            case InputOrder.stand:
                tempState = new IdleState();
                break;

            case InputOrder.jump:
                character.DoJump();
                tempState = new JumpState();
                break;

            case InputOrder.squat:
                tempState = new SquatState();
                break;
            }
        }

        return(tempState);
    }
Beispiel #20
0
 private void OnCollisionEnter(Collision collision)
 {
     if (jumpState == JumpState.Jumping && collision.gameObject.CompareTag("Ground"))
     {
         jumpState = JumpState.Grounded;
     }
 }
Beispiel #21
0
 private void UpdatePreviousStates()
 {
     previousJumpState     = currentJumpState;
     previouslyWasStrafing = currentlyIsStrafing;
     previousCrouchState   = currentCrouchState;
     previousRunState      = currentRunState;
 }
Beispiel #22
0
 // Start is called before the first frame update
 void Start()
 {
     jumpState = JumpState.OnGround;
     speed     = 0;
     gravity   = 3;
     //height should also be zero.
 }
Beispiel #23
0
 public void Jump()
 {
     if (previousJumpState == JumpState.Grounded)
     {
         currentJumpState = JumpState.Inititated;
     }
 }
Beispiel #24
0
    public void OnUpdate(ref GruntState playerState)
    {
        if (playerState == GruntState.Standing)
        {
            m_body.constraints = RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationZ;
        }


        m_isJumpDown = false;         //= Input.GetButton("Jump");
        //if (Application.platform == RuntimePlatform.Android)
        //	m_isJumpDown = Input.touchCount != 0;

        if (m_isJumpDown && m_jumpState == JumpState.Landed && CanJump(playerState))
        {
            if ((Time.time * 1000.0f) - m_jumpTimer > JumpDelayMS)
            {
                m_jumpTimer = (Time.time * 1000.0f);
                m_body.AddForce(new Vector3(0, PlayerJumpHeight, 0), ForceMode.Impulse);
                m_jumpState      = JumpState.Jumping;
                playerState      = GruntState.Jumping;
                m_collisionState = CollisionState.None;
            }
        }

        if (m_jumpState == JumpState.Jumping && playerState == GruntState.Jumping)
        {
            if ((Time.time * 1000.0f) - m_jumpTimer > 2000.0f)
            {
                playerState = GruntState.FallJumping;
            }
        }
    }
Beispiel #25
0
    void Wave()
    {
        DOTween.Kill("Wave");

        _launchPosition     = _mainCamera.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, -_mainCamera.transform.position.z));
        _rigidbody.velocity = Vector3.zero;

        LaunchRocket();

        Vector3 recoilDirection = transform.position - _launchPosition;

        recoilDirection.z = 0;
        recoilDirection.Normalize();

        _mainCamera.GetComponent <ScreenShakeCamera> ().CameraShaking(FeedbackType.Jump);

        _rigidbody.AddForce(recoilDirection * _waveForce, ForceMode.Impulse);
        _waveForce     = 0;
        WaveForceDebug = 0;

        JumpState = JumpState.InAir;

        if (OnJump != null)
        {
            OnJump();
        }

        _slowMotion.StopSlowMotion();

        WaveState = WaveState.CanWave;
    }
Beispiel #26
0
        public void WriteTo(System.IO.BinaryWriter writer)
        {
            if (writer == null)
                throw new System.ArgumentNullException(nameof(writer));

            writer.Write(PlayerId);
            writer.Write(Id);
            writer.Write(Health);
            Position.WriteTo(writer);
            Size.WriteTo(writer);
            JumpState.WriteTo(writer);
            writer.Write(WalkedRight);
            writer.Write(Stand);
            writer.Write(OnGround);
            writer.Write(OnLadder);
            writer.Write(Mines);

            if (Weapon == null)
                writer.Write(false);
            else
            {
                writer.Write(true);
                Weapon.WriteTo(writer);
            }
        }
Beispiel #27
0
    protected override void ComputeVelocity()
    {
        if (!(isOnEnemy || IsDead))
        {
            if (jumpState == JumpState.PrepareToJump && IsGrounded)
            {
                velocity.y = jumpTakeOffSpeed;
                jumpState  = JumpState.Jumping;
            }

            const float moveEpsilon = 0.01f;

            if (movementVec.x > moveEpsilon && !IsGrabbing && spriteRenderer.flipX)
            {
                spriteRenderer.flipX = false;
            }
            else if (movementVec.x < -moveEpsilon && !IsGrabbing && !spriteRenderer.flipX) // Don't flip when grabbing
            {
                spriteRenderer.flipX = true;
            }
        }

        animator.SetBool("Jumping", jumpState == JumpState.Jumping || jumpState == JumpState.InFlight);
        animator.SetBool("Grounded", IsGrounded);
        animator.SetBool("Grabbing", IsGrabbing);
        animator.SetBool("Dead", isOnEnemy || IsDead);
        animator.SetFloat("VelocityX", Mathf.Abs(velocity.x) / moveSpeed);

        if (!(isOnEnemy || IsDead))
        {
            targetVelocity = movementVec * moveSpeed;
        }
    }
Beispiel #28
0
        private void UpdateJumpState()
        {
            m_IsJumped = false;

            switch (m_JumpState)
            {
            case JumpState.PrepareToJump:
            {
                m_IsJumped  = true;
                m_JumpState = JumpState.Jumping;
            }
            break;

            case JumpState.Jumping:
            {
                m_JumpState = JumpState.InFlight;
            }
            break;

            case JumpState.InFlight:
            {
                if (IsGrounded)
                {
                    m_JumpState = JumpState.Landed;
                }
            }
            break;

            case JumpState.Landed:
            {
                m_JumpState = JumpState.Grounded;
            }
            break;
            }
        }
Beispiel #29
0
 // Update is called once per frame
 void Update()
 {
     SetScoreText();
     if (Input.GetKey(KeyCode.UpArrow) && CanJump)
     {
         jumpState = JumpState.Animating;
         StartCoroutine(Jump(0));
     }
     if (Input.GetKey(KeyCode.RightArrow))
     {
         if ((branch == -1 || branch == 0) && CanJump)
         {
             jumpState = JumpState.Animating;
             StartCoroutine(Jump(1));
         }
     }
     if (Input.GetKey(KeyCode.LeftArrow))
     {
         if ((branch == 0 || branch == 1) && CanJump)
         {
             jumpState = JumpState.Animating;
             StartCoroutine(Jump(-1));
         }
     }
 }
Beispiel #30
0
 private void OnCollisionEnter(Collision collision)
 {
     if ((_jumpState == JumpState.Jumping || _jumpState == JumpState.DoubleJumping) && collision.gameObject.CompareTag("Ground"))
     {
         _jumpState = JumpState.Grounded;
     }
 }
Beispiel #31
0
 public void StartJump()
 {
     if (jumpState == JumpState.NO_JUMP)
     {
         currJumpHeight = 0;
         currFlyingDistance = 0;
         jumpState = JumpState.GOING_UP;
     }
 }
Beispiel #32
0
 public Skater()
     : base()
 {
     this.spriteName = "boy_skate";
     maxJumpHeight = 40;
     currJumpHeight = 0;
     maxFlyingDistance = 20;
     jumpState = JumpState.NO_JUMP;
 }
Beispiel #33
0
 //    void OnTap (TapGesture gesture)
 //    {
 //        Debug.Log(gesture.Recognizer.name);
 //        if(playerMotorState != PlayerMotorState.disabled)
 //        {
 //            Jump ();
 //        }
 //    }
 public void Jump()
 {
     if(jumpState == JumpState.grounded)
     {
         jumpState = JumpState.jumping;
         m_JumpHeight = GetJumpHeight();
         this.GetComponent<Rigidbody2D>().velocity = new Vector2 (walkingSpeed, m_JumpHeight);
         StartCoroutine(JumpAnimation());
     }
 }
Beispiel #34
0
    public void TrackUserYPosition(float yPosition, float timestamp)
    {
        if (oldYPos != -10)
            yVelocity = (yPosition - oldYPos)/(timestamp - oldPosTimestamp);
        float x = Mathf.Pow(0.2f, timestamp - oldPosTimestamp);
        // TODO: Consider a system of adjusting this based on crouch or jump
        lowPassY = x*lowPassY + (1-x)*(yPosition);
        oldYPos = yPosition;
        oldPosTimestamp = timestamp;

        jumpState = JumpState.STANDING;
        if (yVelocity > jumpVelThreshold) jumpState = JumpState.JUMPING;
        if (yPosition < lowPassY - crouchThreshold) jumpState = JumpState.CROUCHING;
    }
Beispiel #35
0
	// Update is called once per frame
	void Update () 
	{

		if (combat.turn == TurnState.ENEMYSTART)
		{
			jumpState = JumpState.FORWARD;
		}
		if (jumpState == JumpState.FORWARD)
		{
			JumpForward();
		}
		else if (jumpState == JumpState.KNOCKBACK)
		{
			Knockback();
		}
	}
Beispiel #36
0
	public ParticleSystem	explosion; //the particle system that makes the ninja explode

	// Use this for initialization

	void Start () 
	{
		//initialize variables
		jumpState = JumpState.GROUNDED;
		jumpPointNumber = jumpPoints.Count;
		currentJumpPoint = jumpPointNumber - 1;
		for (int i = 0; i < jumpPointNumber; i += 1)
		{
			Vector3 temp = jumpPoints[i].position;
			temp.z = transform.position.z;
			jumpPoints[i].position = temp;
		}
		turnCounter = GetComponentInChildren<TextMesh>();
		turnCounter.text = currentJumpPoint.ToString ();

		combat = GameObject.Find("CombatController").GetComponent<CombatController>();
	}
    // Update is called once per frame
    void Update()
    {
        if(!pulling && Input.GetMouseButtonDown(0))
        {
            //ground and air jump logic.

            //if body must be grounded to jump
            if(requireGrounded)
            {
                //if body is currently not grounded
                if(!grounded)
                {
                    //first jump occured or am currently air jumping and havnet performed the max number of air jumps
                    if((jumpState == JumpState.FirstJumpOccured || jumpState == JumpState.AirJumping) && numAirJumpsPreformed < numAirJumps)
                    {
                        jumpState = JumpState.AirJumping; //i am air jumping
                        numAirJumpsPreformed++; //increase the number of air jumps performed
                    }
                    else
                    {
                        //i am unable to jump. exit.
                        jumpState = JumpState.Unable;
                        return;
                    }
                }
                else
                {
                    //i am grounded and performed my first jump
                    jumpState = JumpState.FirstJumpOccured;
                }
            }

            //Process the input!
            StartCoroutine(ProcessPull());
        }
    }
 public void SetLedgeGrabState(CEntityPlayer player, PlayerState state)
 {
     if (state == PlayerState.LedgeHang)
     {
         m_velocity = 0;
         player.SetPlayerState(PlayerState.LedgeHang);
         m_body.constraints = RigidbodyConstraints.FreezeAll;
         m_jumpState = JumpState.Landed;
     }
 }
    public void OnUpdate(ref PlayerState playerState)
    {
        if (playerState == PlayerState.Standing)
            m_body.constraints = RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationZ;

        m_isJumpDown = Input.GetButton("Jump");
        if (Application.platform == RuntimePlatform.Android)
            m_isJumpDown = Input.touchCount != 0;

        if (m_isJumpDown && m_jumpState == JumpState.Landed && CanJump(playerState))
        {
            if ((Time.time * 1000.0f) - m_jumpTimer > JumpDelayMS)
            {
                m_jumpTimer = (Time.time * 1000.0f);
                m_body.AddForce(new Vector3(0, PlayerJumpHeight, 0), ForceMode.Impulse);
                m_jumpState = JumpState.Jumping;
                playerState = PlayerState.Jumping;
                m_collisionState = CollisionState.None;
            }
        }

        if (m_jumpState == JumpState.Jumping && playerState == PlayerState.Jumping)
        {
            if ((Time.time * 1000.0f) - m_jumpTimer > 2000.0f)
            {
                playerState = PlayerState.FallJumping;
            }
        }

        if (m_ladderClimb.State != LadderState.None)
        {
            if (m_ladderClimb.State != LadderState.JumpOff)
            {
                playerState = PlayerState.UpALadder;
                m_collisionState = CollisionState.None;
                m_ladderClimb.CallOnUpdate(m_collisionState);
            }
            else
                playerState = PlayerState.Jumping;

            if (m_ladderClimb.State == LadderState.JumpOff && m_jumpState != JumpState.Jumping)
            {
                if (Input.GetAxis("Horizontal") == 0.0f)
                {
                    m_ladderClimb.State = LadderState.AtMiddle;
                    m_collisionState = CollisionState.None;
                    playerState = PlayerState.UpALadder;
                    return;
                }

                m_jumpTimer = (Time.time * 1000.0f);
                m_body.AddForce(new Vector3(0, PlayerJumpHeight, 0), ForceMode.Impulse);
                m_jumpState = JumpState.Jumping;
                playerState = PlayerState.Jumping;
                m_velocity = Input.GetAxis("Horizontal") * -2.0f;
                m_body.constraints = RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationZ;
                m_velocityLockTimer = (Time.time * 1000.0f);
            }
        }
    }
 public void MakeJump()
 {
     m_fakeJump = true;
     m_jumpTimer = ((Time.time) * 1000.0f);
     m_jumpState = JumpState.Jumping;
     CEntityPlayer.GetInstance().SetPlayerState(PlayerState.Jumping);
     m_collisionState = CollisionState.None;
 }
    /*
     * \brief Called on player update
    */
    public void OnFixedUpdate(ref PlayerState playerState)
    {
        if (playerState == PlayerState.FallingFromTower)
            return;

        ////////////////////////

        bool wasJump = m_isJumpDown;
        m_isJumpDown = Input.GetButtonDown("Jump");

        if (Application.platform == RuntimePlatform.Android)
            m_isJumpDown = Input.touchCount != 0;

        if (m_isJumpDown && !wasJump)
        {
            m_canJumpFromLedge = true;
        }
        else
        {
            m_canJumpFromLedge = false;
        }

        if (m_isJumpDown && m_jumpState == JumpState.Landed && CanJump(playerState))
        {
            if ((Time.time * 1000.0f) - m_jumpTimer > JumpDelayMS)
            {
                m_jumpTimer = (Time.time * 1000.0f);
                m_body.AddForce(new Vector3(0, PlayerJumpHeight, 0), ForceMode.Impulse);
                m_jumpState = JumpState.Jumping;
                playerState = PlayerState.Jumping;
                m_collisionState = CollisionState.None;
            }
        }

        if (m_jumpState == JumpState.Jumping && playerState == PlayerState.Jumping)
        {
            if ((Time.time * 1000.0f) - m_jumpTimer > 2000.0f)
            {
                playerState = PlayerState.FallJumping;
                if (!m_fakeJump && ((Time.time * 1000.0f) - m_jumpTimer > 3000.0f))
                {
                    m_player.PushPlayerFromTower();
                }
            }
        }

        if (m_isJumpDown == true && (GetLadder.state == LadderState.OnMiddle || GetLadder.state == LadderState.OnTop))
        {
            GetLadder.state = LadderState.JumpingOff;
            m_jumpTimer = (Time.time * 1000.0f);
            m_body.velocity = Vector3.zero;
            m_body.AddForce(new Vector3(0, PlayerJumpHeight, 0), ForceMode.Impulse);
            m_jumpState = JumpState.Jumping;
            playerState = PlayerState.Jumping;
            m_collisionState = CollisionState.None;
            rigidbody.constraints = RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationZ;
        }

        ////////////////////////

        float velocity = (Input.GetAxis("Horizontal") * MaxSpeed) * m_invert;
        if (Application.platform == RuntimePlatform.Android)
            velocity = Input.acceleration.y;

        if (playerState == PlayerState.OnLadder || playerState == PlayerState.LedgeClimb || playerState == PlayerState.LedgeClimbComplete)
            velocity = 0.0f;

        if (m_player.PullingLever(false))
            velocity = 0.0f;

        if ((Time.time * 1000.0f) - m_velocityLockTimer < 350)
        {
            velocity = m_velocity;
        }

        if (velocity != 0.0f && (m_ladder.state != LadderState.AtBase && m_ladder.state != LadderState.JumpingOff))
        {
            m_ladder.state = LadderState.None;
        }

        int direction = isNearly(velocity, 0.0f, 0.1f) ? 0 : velocity > 0 ? 1 : -1;

        //platform update
        if (m_platform && m_collisionState == CollisionState.OnFloor) {
            m_platformVelocity += m_platform.DeltaA;
            m_platform.resetDeltaA();
        }

        // Ledge hanging code start
        if (playerState == PlayerState.LedgeHang || playerState == PlayerState.LedgeClimb || playerState == PlayerState.LedgeClimbComplete) {

            m_velocity = 0.0f;

            // If we are trying to move in the opposite way of the wall, fall off the wall
            if (direction != 0 && direction != m_movingDirection) {
                m_velocity = velocity * 4.0f;
                playerState = PlayerState.Walking;
                m_jumpState = JumpState.Landed;
                m_body.constraints = RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationZ;
                m_movingDirection *= -1;
                m_direction *= -1;
                m_collisionState = CollisionState.None;

                Transform t = m_ledgeGrabBox.transform;
                t.localPosition = new Vector3(m_direction > 0 ? -0.18f : 0.18f, t.localPosition.y, t.localPosition.z);
                return;
            }

            // if the player is not already climbing the wall, check keys
            if (playerState != PlayerState.LedgeClimb)
            {
                // if the user pressed up, climb the wall
                if (Input.GetAxis("Vertical") > 0 && playerState != PlayerState.LedgeClimbComplete) {
                    playerState = PlayerState.LedgeClimb;
                    m_jumpState = JumpState.Landed;
                }
                // if the user pressed space, jump off the wall
                else if (m_isJumpDown && m_canJumpFromLedge) {
                    m_body.constraints = RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationZ;
                    m_velocity = -(m_movingDirection) * 4.0f; // kick it away from the wall
                    m_body.AddForce(new Vector3(0, PlayerJumpHeight * 0.25f, 0), ForceMode.Impulse);
                    playerState = PlayerState.Jumping;
                    m_collisionState = CollisionState.None;
                    m_movingDirection *= -1;
                    m_direction *= -1;

                    Transform t = m_ledgeGrabBox.transform;
                    t.localPosition = new Vector3(m_direction > 0 ? -0.18f : 0.18f, t.localPosition.y, t.localPosition.z);
                }
                return;
            }

            return;
        }
        // Ledge hanging code end

        if (playerState == PlayerState.WallJumpStart)
        {
            if (Time.time - m_wallJump.StartHangTime > 1.0f) {
                m_body.constraints = RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationZ;
                m_velocity = -m_wallJump.WallJumpDirection;
                playerState = PlayerState.Walking;
                m_jumpState = JumpState.Landed;
                m_collisionState = CollisionState.None;
            } else if (Input.GetButton("Jump") && (direction != 0 && direction != m_wallJump.WallJumpDirection)) {
                m_body.constraints = RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationZ;
                m_velocity = -(m_wallJump.WallJumpDirection * 0.5f); // kick it away from the wall
                m_velocityLockTimer = (Time.time * 1000.0f) + 50;
                m_body.AddForce(new Vector3(0, PlayerJumpHeight * 1.1f, 0), ForceMode.Impulse);
                playerState = PlayerState.Jumping;
                m_jumpState = JumpState.Jumping;
                m_jumpTimer = (Time.time * 1000.0f);
                m_collisionState = CollisionState.None;
                m_movingDirection = m_wallJump.WallJumpDirection;
                m_direction = m_wallJump.WallJumpDirection;
            }
            return;
        }

        if (!(m_collisionState == CollisionState.OnWall && m_jumpState == JumpState.Jumping))
            m_velocity = velocity;

        int lastDirection = m_direction;
        int lastMovingDirection = m_movingDirection;

        if (playerState != PlayerState.Turning)
        {
            m_direction = direction;
            if (m_direction != 0) m_movingDirection = m_direction;
        }

        if (m_collisionState != CollisionState.None && m_jumpState != JumpState.Jumping)
        {
            if (m_direction == 0 && playerState != PlayerState.Turning)
            {
                if (playerState != PlayerState.OnLadder && !m_player.PullingLever(false))
                {
                    playerState = PlayerState.Standing;
                }
            }
            else
            {
                if (playerState == PlayerState.Turning)
                {
                    m_velocity = 0.0f;
                    return;
                }

                // are we tuning round?
                if (lastDirection != direction && ((Time.time * 1000.0f) - m_turnLockTimer > 1000.0f))
                {
                    playerState = PlayerState.Walking;
                    if (m_velocity != 0.0f && lastMovingDirection != m_direction)
                    {
                        playerState = PlayerState.Turning;
                        m_velocity = 0.0f;
                        m_turnLockTimer = Time.time * 1000.0f;
                    }
                }
                else
                    playerState = PlayerState.Walking;
            }
        }
    }
    /// <summary>
    /// Initialize controlling state machine
    /// </summary>
    private void InitializeStateMachine()
    {
        Debug.Log("Init state machine");

        // States
        IdleState idleState = new IdleState();
        idleState.Parent = this;
        mStateMachine.AddState(idleState);

        SkiState skiState = new SkiState();
        skiState.Parent = this;
        mStateMachine.AddState(skiState);

        CrouchState crouchState = new CrouchState();
        crouchState.Parent = this;
        mStateMachine.AddState(crouchState);

        JumpState jumpState = new JumpState();
        jumpState.Parent = this;
        mStateMachine.AddState(jumpState);

        InAirState inAirState = new InAirState();
        inAirState.Parent = this;
        mStateMachine.AddState(inAirState);

        LandingState landState = new LandingState();
        landState.Parent = this;
        mStateMachine.AddState(landState);

        FallDownState fallDownState = new FallDownState();
        fallDownState.Parent = this;
        mStateMachine.AddState(fallDownState);
        // Transitions ///////////////////

        // Grounded states
        mStateMachine.AddTransition( CharacterEvents.To_Ski, idleState, skiState);
        mStateMachine.AddTransition( CharacterEvents.To_Idle, skiState, idleState);

        // Jump / Land states
        mStateMachine.AddTransition( CharacterEvents.To_Crouch, skiState, crouchState);
        mStateMachine.AddTransition( CharacterEvents.To_Jump, crouchState, jumpState);
        mStateMachine.AddTransition( CharacterEvents.To_InAir, jumpState, inAirState);
        mStateMachine.AddTransition( CharacterEvents.To_Landing, inAirState, landState);
        mStateMachine.AddTransition( CharacterEvents.To_Ski, landState, skiState);

        // Ramp states
        mStateMachine.AddTransition( CharacterEvents.To_InAir, skiState, inAirState);

        // for initialization
        mStateMachine.AddTransition( CharacterEvents.To_InAir, idleState, inAirState);

        // for fall down
        mStateMachine.AddTransition( CharacterEvents.To_FallDown, idleState, fallDownState);
        mStateMachine.AddTransition( CharacterEvents.To_FallDown, skiState, fallDownState);
        mStateMachine.AddTransition( CharacterEvents.To_FallDown, crouchState, fallDownState);

        // character starts in a spawn in state
        mStateMachine.StartState = idleState;

        mStateMachine.Activate(null);

        DeactivateRagdoll();
    }
Beispiel #43
0
 /// <summary>
 /// Resets all relevant properties to their "fresh"/initial states.
 /// Used for when the player enters rooms, spawns/respawns, or starts
 /// a new game.
 /// </summary>
 /// <param name="direction">The direction the player should face.</param>
 public void ResetActionStates(XDirection direction)
 {
     isOnGround = true;
     isGravityAffected = true;
     PlayerJumpState = JumpState.NotAllowed;
     PlayerXFacing = direction;
     midairJumps = MAX_MIDAIR_JUMPS;
     dashes = INFINITE_DASHES;
     if (rightBtnFlag == true && leftBtnFlag == false)
         LatestXArrow = XDirection.Right;
     else if (leftBtnFlag == true && rightBtnFlag == false)
         LatestXArrow = XDirection.Left;
     else
         LatestXArrow = XDirection.None;
     WallSlideDirection = XDirection.None;
     dashStatus = DASH_NOT_ALLOWED;
     velocityY = 0;
     velocityX = 0;
     accelerationX = 0;
     accelerationY = 0;
     drawnLastFrame = true;
 }
    public void OnUpdate(ref GruntState playerState)
    {
        if (playerState == GruntState.Standing)
            m_body.constraints = RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationZ;

        m_isJumpDown = false; //= Input.GetButton("Jump");
        //if (Application.platform == RuntimePlatform.Android)
        //	m_isJumpDown = Input.touchCount != 0;

        if (m_isJumpDown && m_jumpState == JumpState.Landed && CanJump(playerState))
        {
            if ((Time.time * 1000.0f) - m_jumpTimer > JumpDelayMS)
            {
                m_jumpTimer = (Time.time * 1000.0f);
                m_body.AddForce(new Vector3(0, PlayerJumpHeight, 0), ForceMode.Impulse);
                m_jumpState = JumpState.Jumping;
                playerState = GruntState.Jumping;
                m_collisionState = CollisionState.None;
            }
        }

        if (m_jumpState == JumpState.Jumping && playerState == GruntState.Jumping)
        {
            if ((Time.time * 1000.0f) - m_jumpTimer > 2000.0f)
            {
                playerState = GruntState.FallJumping;
            }
        }
    }
    /*
     * \brief Called whilst a collision is taking place
    */
    public void CallOnCollisionStay(Collision collision, ref GruntState playerState, ref float playerAlpha)
    {
        m_collisionState = CollisionState.None;

        foreach (ContactPoint contact in collision)
        {
            Debug.DrawRay(contact.point, contact.normal);
            //
            if (contact.otherCollider != null && contact.otherCollider.gameObject != null)
            {
                CSceneObjectPlatform platform = contact.otherCollider.gameObject.GetComponent<CSceneObjectPlatform>();
                if (platform != null && m_platform == null) {
                    m_platform = platform;
                    m_platform.resetDeltaA();
                }
            }

            //
            CSceneObject obj = null;
            if (contact.otherCollider)
            {
                obj = contact.otherCollider.gameObject.GetComponent<CSceneObject>();
                if (obj == null && contact.otherCollider.gameObject.transform.parent != null) {
                    GameObject parent = contact.otherCollider.gameObject.transform.parent.gameObject;
                    if (parent != null) {
                        obj = parent.GetComponent<CSceneObject>();
                    }
                }
            }

            // floor check
            else if (isNearly(contact.normal.y, 1.0f, 0.8f))
            {
                m_collisionState = CollisionState.OnFloor;
                if (!isNearly(contact.normal.y, 1.0f, 0.15f) && collision.contacts.Length == 1)
                {
                    m_velocity = (m_movingDirection * 0.15f);
                    m_velocityLockTimer = (Time.time * 1000.0f);
                }
                if(contact.otherCollider)
                {
                    // are we on a special material?
                    m_footMaterial = FootMaterial.Stone;
                    if (contact.otherCollider.tag == "Wood Object")
                        m_footMaterial = FootMaterial.Wood;
                    else if (contact.otherCollider.tag == "Metal Object")
                        m_footMaterial = FootMaterial.Metal;
                }
            }
            // head check
            else if (isNearly(contact.normal.y, -1.0f, 0.1f))
            {
                m_collisionState = CollisionState.OnRoof;
            }
            // wall check
            else
            {
                if (isFacingCollision(m_movingDirection, m_body.transform.position, contact.point, playerAlpha)) {
                    m_collisionState = CollisionState.OnWall;
                    break;
                }
            }
        }

        if (m_collisionState == CollisionState.OnWall && m_jumpState == JumpState.Jumping && playerState != GruntState.WallJumpStart)
        {
            m_velocity = -(m_movingDirection * 0.15f);
        }

        if (m_collisionState == CollisionState.OnFloor && ((Time.time * 1000.0f) - m_jumpTimer > 200.0f))
        {
            m_jumpState = JumpState.Landed;

            if (m_grunt.GetGruntState() != GruntState.Turning) m_grunt.SetGruntState(GruntState.Standing);
        }
    }
Beispiel #46
0
 /// <summary>
 /// Changes all of the player's relevant properties to reflect that
 /// the left or right side of its collision box has just hit a wall
 /// or a horizontal edge of the map.
 /// </summary>
 public override void CollideX()
 {
     if (dashStatus >= DASH_HELD)
     {
         dashStatus = DASH_LAG_START;
         isGravityAffected = true;
         velocityY = 0;
         if (jumpBtnFlag == true)
             PlayerJumpState = JumpState.NotAllowed;
         else
             PlayerJumpState = JumpState.Allowed;
     }
     if (currentHealth < 0)
     {
         accelerationX = 0;
         velocityX *= -0.5f;
     }
     else
         base.CollideX();
 }
Beispiel #47
0
 /// <summary>
 /// Changes all of the player's relevant properties to reflect that
 /// the top end of its collision box has just hit a ceiling.
 /// </summary>
 public override void HitCeiling()
 {
     if (jumpBtnFlag == false)
         PlayerJumpState = JumpState.Allowed;
     else
         PlayerJumpState = JumpState.NotAllowed;
     base.HitCeiling();
 }
Beispiel #48
0
        /// <summary>
        /// Changes all of the player's relevant properties to reflect that
        /// the bottom side of its collision box has just hit a floor.
        /// </summary>
        public override void Land()
        {
            soundEngine.Play(AudioEngine.SoundEffects.Land);
            if (jumpBtnFlag == false)
                PlayerJumpState = JumpState.Allowed;
            else
                PlayerJumpState = JumpState.NotAllowed;

            if (dashStatus >= DASH_HELD)
            {
                dashStatus = DASH_NOT_ALLOWED;
                isGravityAffected = true;
            }

            if (dashBtnFlag == false)
                dashStatus = DASH_ALLOWED;
            else
                dashStatus = DASH_NOT_ALLOWED;

            midairJumps = MAX_MIDAIR_JUMPS;
            dashes = INFINITE_DASHES;

            if (currentHealth > 0)
                base.Land();
            else
            {
                isOnGround = true;
                accelerationY = 0;
                if (DisplacementY <= 2)
                    velocityY = 0;
                else
                    velocityY *= -0.5f;
            }
        }
Beispiel #49
0
	//move ninja to a previous jump point
	void Knockback()
	{
		transform.position = Vector3.MoveTowards(transform.position, jumpPoints[currentJumpPoint].position, jumpSpeed * 2 * Time.deltaTime);
		if (transform.position == jumpPoints[currentJumpPoint].position)
		{
			jumpState = JumpState.GROUNDED;
		}
	}
Beispiel #50
0
    void Start()
    {
        personCtrl = this.GetComponent<HeroCtrl>();
        heroStateActVer = new IdleStateActVer(this.gameObject);
        heroStateMoveVer = new IdleStateMoveVer(this.gameObject);
        inputArgs = new InputEventArgs("", "", "");
        hero_act_state[0] = new IdleStateActVer(this.gameObject);
        hero_act_state[1] = new ActState(this.gameObject);
        hero_act_state[2] = new DefenseState(this.gameObject);

        hero_move_state[0] = new IdleStateMoveVer(this.gameObject);
        hero_move_state[1] = new MoveState(this.gameObject);
        hero_move_state[2] = new JumpState(this.gameObject);

        InputTran += new InputEventHandler(heroStateActVer.handleInput);
        InputTran += new InputEventHandler(heroStateMoveVer.handleInput);
    }
Beispiel #51
0
 public void setJumpState(JumpState state)
 {
     this.jumpState = state;
 }
    public void OnUpdate(ref PlayerState playerState)
    {
        if (playerState == PlayerState.Standing)
        {
            m_body.constraints = RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationZ;
            m_fakeJump = false;

            if (GetLadder.state != LadderState.AtBase)
            {
                // standing, we can't be on a ladder
                GetLadder.state = LadderState.None;
                GetLadder.offset = 0.0f;
                GetLadder.moving = false;
                GetLadder.direction = 0.0f;
            }
        }

        bool wasJump = m_isJumpDown;
        m_isJumpDown = Input.GetButtonDown("Jump");

        if (Application.platform == RuntimePlatform.Android)
            m_isJumpDown = Input.touchCount != 0;

        if (m_isJumpDown && !wasJump)
        {
            m_canJumpFromLedge = true;
        }
        else
        {
            m_canJumpFromLedge = false;
        }

        if (m_isJumpDown && m_jumpState == JumpState.Landed && CanJump(playerState))
        {
            if ((Time.time * 1000.0f) - m_jumpTimer > JumpDelayMS)
            {
                m_jumpTimer = (Time.time * 1000.0f);
                m_body.AddForce(new Vector3(0, PlayerJumpHeight, 0), ForceMode.Impulse);
                m_jumpState = JumpState.Jumping;
                playerState = PlayerState.Jumping;
                m_collisionState = CollisionState.None;
            }
        }

        if (m_jumpState == JumpState.Jumping && playerState == PlayerState.Jumping)
        {
            if ((Time.time * 1000.0f) - m_jumpTimer > 2000.0f)
            {
                playerState = PlayerState.FallJumping;
                if (!m_fakeJump && ((Time.time * 1000.0f) - m_jumpTimer > 3000.0f))
                {
                    m_player.PushPlayerFromTower();
                }
            }
        }

        if (m_isJumpDown == true && (GetLadder.state == LadderState.OnMiddle || GetLadder.state == LadderState.OnTop))
        {
            GetLadder.state = LadderState.JumpingOff;
            m_jumpTimer = (Time.time * 1000.0f);
            m_body.velocity = Vector3.zero;
            m_body.AddForce(new Vector3(0, PlayerJumpHeight, 0), ForceMode.Impulse);
            m_jumpState = JumpState.Jumping;
            playerState = PlayerState.Jumping;
            m_collisionState = CollisionState.None;
            rigidbody.constraints = RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationZ;
        }

        // LADDER CODE

        float updown = (Input.GetAxis("Vertical") * 0.001f);
        if (updown > 0.0f)
        {
            if (GetLadder.state == LadderState.AtBase)
            {
                if (m_jumpState == JumpState.Jumping) {
                    GetLadder.state = LadderState.OnMiddle;
                } else {
                    GetLadder.state = LadderState.OnBase;
                }
                playerState = PlayerState.OnLadder;
                m_collisionState = CollisionState.None;
                m_jumpState = JumpState.Landed;
            }
            else if (GetLadder.state == LadderState.OnBase || GetLadder.state == LadderState.OnMiddle)
            {
                GetLadder.offset = (updown * 10.0f);
                GetLadder.moving = true;
                GetLadder.direction = 1.0f;
            }
            else if (GetLadder.state == LadderState.OnTop)
            {
                GetLadder.moving = false;
                GetLadder.direction = 0.0f;
                GetLadder.offset = 0.0f;
            }
        }
        else if (updown < 0.0f)
        {
            if (GetLadder.state == LadderState.OnBase)
            {
                GetLadder.state = LadderState.AtBase;
                playerState = PlayerState.Standing;
                rigidbody.constraints = RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationZ;
                rigidbody.AddForce(0, 0.1f, 0);
            }
            else if (GetLadder.state == LadderState.OnBase || GetLadder.state == LadderState.OnMiddle || GetLadder.state == LadderState.OnTop)
            {
                GetLadder.offset = (updown * 10.0f);
                GetLadder.moving = true;
                GetLadder.direction = -1.0f;
            }
        }

        if (updown == 0.0f && GetLadder.state != LadderState.None)
        {
            GetLadder.moving = false;
            GetLadder.direction = 0.0f;
            GetLadder.offset = 0.0f;
        }
    }
Beispiel #53
0
	//when hit by the foot or Tommy (not currently working, which is fine; easy fix)
	void OnTriggerEnter2D (Collider2D coll)
	{
		if (jumpState == JumpState.GROUNDED &&
		    coll.gameObject.tag == "Foot" && coll.gameObject.GetComponent<Foot>().attackState == AttackState.SHOOTING)
		{
			Foot foot = coll.gameObject.GetComponent<Foot>();
			Rigidbody2D footRB = coll.gameObject.GetComponent<Rigidbody2D>();

			if (footRB.velocity.magnitude / foot.shotSpeedOriginal <= .3f)
			{
				Instantiate(explosion, transform.position, Quaternion.identity);
				Destroy(this.gameObject);
			} 
			else
			{
				jumpState = JumpState.KNOCKBACK;
			}
		}
		else if (coll.gameObject.tag == "Player")
		{
			jumpState = JumpState.KNOCKBACK;
		}
	}
Beispiel #54
0
        private void JumpBehavior()
        {
            /* * JUMP * */

            if (jumpState == JumpState.grounded)
            {
                //On the ground
                if ((playerControl == true)) //&& (inputRef.jumpDown == true))
                {
                    jumpState = JumpState.impulse;
                    impulseTime = 0f;
                }
                if (touchingGround == false)
                {
                    jumpState = JumpState.falling;
                }
            }
            if (jumpState == JumpState.impulse)
            {
                //move upward while button is held down, up to max impulse time
                velocity = new Vector3(velocity.x, jumpSpeed, 0f);
                impulseTime += Time.deltaTime;
                if ( /*(inputRef.jumpPressed == false) ||*/ (impulseTime >= impulseLength))
                {
                    jumpState = JumpState.cresting;
                }
                if (touchingCeiling == true)
                {
                    //hit ceiling
                    velocity = new Vector3(velocity.x, 0f, 0f);
                    jumpState = JumpState.falling;
                }
            }
            if (jumpState == JumpState.cresting)
            {
                //gravity is slowing the player's ascent
                velocity = new Vector3(velocity.x, velocity.y - gravity * Time.deltaTime, 0f);
                if (velocity.y < 0f)
                {
                    jumpState = JumpState.falling;
                }
                if (touchingCeiling == true)
                {
                    //hit ceiling
                    velocity = new Vector3(velocity.x, 0f, 0f);
                    jumpState = JumpState.falling;
                }
            }
            if (jumpState == JumpState.falling)
            {
                //gravity is pulling the player downwards
                velocity = new Vector3(velocity.x, velocity.y - gravity * Time.deltaTime, 0f);
                if (velocity.y <= -fallSpeed)
                {
                    jumpState = JumpState.terminal;
                }
                if ((touchingGround == true) && (velocity.y < 0f))
                {
                    velocity = new Vector3(velocity.x, 0f, 0f);
                    jumpState = JumpState.grounded;
                }
            }
            if (jumpState == JumpState.terminal)
            {
                //terminal velocity
                velocity = new Vector3(velocity.x, -fallSpeed, 0f);
                if (touchingGround == true)
                {
                    velocity = new Vector3(velocity.x, 0f, 0f);
                    jumpState = JumpState.grounded;
                }
            }
        }
Beispiel #55
0
    void Update()
    {
        //Raycast in front of the player from three different heights to see if a wall is in front of the player
        leftWalled = (Physics2D.Raycast (midWallCheck.position, -Vector2.right, .75f, whatIsWall)
                      || Physics2D.Raycast (midTopWallCheck.position, -Vector2.right, .75f, whatIsWall)
                      || Physics2D.Raycast (midBotWallCheck.position, -Vector2.right, .75f, whatIsWall)
                      || Physics2D.Raycast (topWallCheck.position, -Vector2.right, .75f, whatIsWall)
                      || Physics2D.Raycast (botWallCheck.position, -Vector2.right, .75f, whatIsWall));
        rightWalled = (Physics2D.Raycast (midWallCheck.position, Vector2.right, .75f, whatIsWall)
                       || Physics2D.Raycast (midTopWallCheck.position, Vector2.right, .75f, whatIsWall)
                       || Physics2D.Raycast (midBotWallCheck.position, Vector2.right, .75f, whatIsWall)
                       || Physics2D.Raycast (topWallCheck.position, Vector2.right, .75f, whatIsWall)
                       || Physics2D.Raycast (botWallCheck.position, Vector2.right, .75f, whatIsWall));

        //Debug.Log ("WALLED: " + leftWalled + rightWalled);

        switch (Jump) {

        case JumpState.GROUNDED:
            if((Input.GetKey(KeyCode.Space) || Input.GetAxis ("LTrig") > 0.1) && isGrounded()) {
                Jump = JumpState.JUMPING;
                animator.SetBool ("Jump", true); //Switch to jump animation
                animator.SetBool ("Hit", false);
            }
            break;

        case JumpState.JUMPING:
            if((Input.GetKey(KeyCode.Space) || Input.GetAxis ("LTrig") > 0.1) && CurrJumpForce < MaxJumpForce) {
                var timeDiff = Time.deltaTime * 100;
                var forceToAdd = PlusJumpForce*timeDiff;
                CurrJumpForce += forceToAdd;
                r.AddForce(new Vector2(0, forceToAdd));
            }
            else {
                Jump = JumpState.FALLING;
                CurrJumpForce = 0;
            }
            break;

        case JumpState.FALLING:
            if (isGrounded() && r.velocity.y <= 0) {
                //Debug.Log("Grounded"); Use this to debug jump issues
                Jump = JumpState.GROUNDED;
                animator.SetBool ("Jump", false); //End jump animation
            }
            break;

        }
    }
    /*
     * \brief Works out if a value is almost another value (for floating point accuracy)
    */
    public void CallOnCollisionEnter(Collision collision)
    {
        m_collisionState = CollisionState.None;

        foreach (ContactPoint contact in collision)
        {
            m_platform = contact.otherCollider.gameObject.GetComponent<CSceneObjectPlatform>();
            if (m_platform != null) {
                m_platform.resetDeltaA();
            }
            if (isNearly(contact.normal.y, 1.0f, 0.2f))
            {
                m_collisionState = CollisionState.OnFloor;

                // are we on a special material?
                m_footMaterial = FootMaterial.Stone;
                if (contact.otherCollider.tag == "Wood Object")
                    m_footMaterial = FootMaterial.Wood;
                else if (contact.otherCollider.tag == "Metal Object")
                    m_footMaterial = FootMaterial.Metal;

            }
            else if (isNearly(contact.normal.y, -1.0f, 0.2f))
            {
                m_collisionState = CollisionState.OnRoof;
            }
            else
            {
                m_collisionState = CollisionState.OnWall;
                m_ladderClimb.State = LadderState.None;
            }
        }

        if (m_collisionState == CollisionState.OnFloor)
        {
            if (m_jumpState != JumpState.Landed)
                m_player.GetPlayerAnimation().PlayFootstepAudio(m_footMaterial);

            m_jumpState = JumpState.Landed;
            m_ladderClimb.State = LadderState.None;

            if (m_player.GetPlayerState() != PlayerState.Turning) m_player.SetPlayerState(PlayerState.Standing);

            //m_ledgeGrabBox.collider.enabled = true;
        }
    }
    /*
     * \brief Called whilst a collision is taking place
    */
    public void CallOnCollisionStay(Collision collision, ref PlayerState playerState, ref float playerAlpha)
    {
        m_collisionState = CollisionState.None;

        foreach (ContactPoint contact in collision)
        {
            Debug.DrawRay(contact.point, contact.normal);

            //
            if (contact.otherCollider != null && contact.otherCollider.gameObject != null)
            {
                CSceneObjectPlatform platform = contact.otherCollider.gameObject.GetComponent<CSceneObjectPlatform>();
                if (platform != null && m_platform == null) {
                    m_platform = platform;
                    m_platform.resetDeltaA();
                }
            }

            //
            CSceneObject obj = null;
            if (contact.otherCollider)
            {
                obj = contact.otherCollider.gameObject.GetComponent<CSceneObject>();
                if (obj == null && contact.otherCollider.gameObject.transform.parent != null) {
                    GameObject parent = contact.otherCollider.gameObject.transform.parent.gameObject;
                    if (parent != null) {
                        obj = parent.GetComponent<CSceneObject>();
                    }
                }
            }

            if (contact.thisCollider != null && contact.thisCollider.gameObject != null && contact.thisCollider.gameObject.name == "Ledge_Grab_Detection" && (obj == null || obj.CanLedgeGrab))
            {
                if(CSceneObject.CheckLedgeGrab(collision))
                    continue;
            }

            if (contact.otherCollider != null && contact.otherCollider.gameObject != null && contact.otherCollider.gameObject.name == "Ledge_Grab_Detection" && (obj == null || obj.CanLedgeGrab))
            {
                if (CSceneObject.CheckLedgeGrab(collision))
                    continue;
            }

            // wall jumping
            if (obj != null && obj.CanWallJump == true && m_jumpState != JumpState.Landed && !isNearly(contact.normal.y, 1.0f, 0.2f) && !isNearly(contact.normal.y, -1.0f, 0.1f))
            {
                m_collisionState = CollisionState.OnWall;
                playerState = PlayerState.WallJumpStart;
                m_jumpTimer = (Time.time * 1000.0f);
                m_body.constraints = RigidbodyConstraints.FreezeAll;
                m_velocity = 0.0f;
                m_wallJump.StartHangTime = Time.time * 1000.0f;
            }
            // floor check
            else if (isNearly(contact.normal.y, 1.0f, 0.8f))
            {
                m_collisionState = CollisionState.OnFloor;
                if (!isNearly(contact.normal.y, 1.0f, 0.15f) && collision.contacts.Length == 1)
                {
                    m_velocity = (m_movingDirection * 0.15f);
                    m_velocityLockTimer = (Time.time * 1000.0f);
                }

                // are we on a special material?
                m_footMaterial = FootMaterial.Stone;
                if (contact.otherCollider.tag == "Wood Object")
                    m_footMaterial = FootMaterial.Wood;
                else if (contact.otherCollider.tag == "Metal Object")
                    m_footMaterial = FootMaterial.Metal;
            }
            // head check
            else if (isNearly(contact.normal.y, -1.0f, 0.1f))
            {
                m_collisionState = CollisionState.OnRoof;
            }
            // wall check
            else
            {
                if (isFacingCollision(m_movingDirection, m_body.transform.position, contact.point, playerAlpha)) {
                    m_collisionState = CollisionState.OnWall;
                    break;
                }
            }
        }

        if (m_collisionState == CollisionState.OnWall && m_jumpState == JumpState.Jumping && playerState != PlayerState.WallJumpStart)
        {
            m_velocity = -(m_movingDirection * 0.15f);
        }

        if (m_collisionState == CollisionState.OnFloor && ((Time.time * 1000.0f) - m_jumpTimer > 200.0f))
        {
            m_jumpState = JumpState.Landed;

            if (m_ladderClimb.State != LadderState.AtBase)
            {
                m_ladderClimb.State = LadderState.None;
            }
            else
            {
                playerState = PlayerState.UpALadder;
            }

            if (m_player.GetPlayerState() != PlayerState.Turning) m_player.SetPlayerState(PlayerState.Standing);
            //m_ledgeGrabBox.collider.enabled = true;
        }
    }
    /*
     * \brief Called on player update
    */
    public void OnFixedUpdate(ref PlayerState playerState)
    {
        if (playerState == PlayerState.FallingFromTower)
            return;

        float velocity = (Input.GetAxis("Horizontal") * MaxSpeed) * m_invert;
        if (Application.platform == RuntimePlatform.Android)
            velocity = Input.acceleration.y;

        if ((Time.time * 1000.0f) - m_velocityLockTimer < 100)
        {
            velocity = m_velocity;
        }

        if (m_ladderClimb.State == LadderState.AtMiddle || m_ladderClimb.State == LadderState.AtTop)
            velocity = 0;

        int direction = isNearly(velocity, 0.0f, 0.1f) ? 0 : velocity > 0 ? 1 : -1;

        //platform update
        if (m_platform && m_collisionState == CollisionState.OnFloor) {
            m_platformVelocity += m_platform.DeltaA;
            m_platform.resetDeltaA();
        }

        // Ledge hanging code start
        if (playerState == PlayerState.LedgeHang || playerState == PlayerState.LedgeClimb || playerState == PlayerState.LedgeClimbComplete) {

            m_velocity = 0.0f;

            // If we are trying to move in the opposite way of the wall, fall off the wall
            if (direction != 0 && direction != m_movingDirection) {
                m_velocity = velocity * 4.0f;
                playerState = PlayerState.Walking;
                m_jumpState = JumpState.Landed;
                m_body.constraints = RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationZ;
            //	m_ledgeGrabBox.collider.enabled = true;
                m_movingDirection *= -1;
                m_direction *= -1;
                m_collisionState = CollisionState.None;

            //	Transform t = m_ledgeGrabBox.transform;
            //	t.localPosition = new Vector3(m_direction > 0 ? -0.18f : 0.18f, t.localPosition.y, t.localPosition.z);
                return;
            }

            // if the player is not already climbing the wall, check keys
            if (playerState != PlayerState.LedgeClimb)
            {
                // if the user pressed up, climb the wall
                if (Input.GetAxis("Vertical") > 0 && playerState != PlayerState.LedgeClimbComplete) {
                    playerState = PlayerState.LedgeClimb;
                    m_jumpState = JumpState.Landed;
                //	m_ledgeGrabBox.collider.enabled = false;
                }
                // if the user pressed space, jump off the wall
                else if (m_isJumpDown) {
                    m_body.constraints = RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationZ;
                    m_velocity = -(m_movingDirection) * 4.0f; // kick it away from the wall
                    m_body.AddForce(new Vector3(0, PlayerJumpHeight * 0.25f, 0), ForceMode.Impulse);
                    playerState = PlayerState.Jumping;
                    m_collisionState = CollisionState.None;
                    m_movingDirection *= -1;
                    m_direction *= -1;
                //	m_ledgeGrabBox.collider.enabled = true;

                //	Transform t = m_ledgeGrabBox.transform;
                //	t.localPosition = new Vector3(m_direction > 0 ? -0.18f : 0.18f, t.localPosition.y, t.localPosition.z);
                }
                return;
            }

            return;
        }
        // Ledge hanging code end

        if (playerState == PlayerState.WallJumpStart)
        {
            if ((Time.time * 1000.0f) - m_wallJump.StartHangTime > m_wallJump.WallHangTime) {
                m_body.constraints = RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationZ;
                m_velocity = -m_movingDirection;
                playerState = PlayerState.Walking;
                m_jumpState = JumpState.Landed;
            } else if (m_isJumpDown && direction != 0 && direction != m_movingDirection) {
                m_body.constraints = RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationZ;
                m_velocity = -(m_movingDirection); // kick it away from the wall
                m_body.AddForce(new Vector3(0, PlayerJumpHeight * 1.1f, 0), ForceMode.Impulse);
                playerState = PlayerState.Jumping;
                m_jumpTimer = (Time.time * 1000.0f);
                m_collisionState = CollisionState.None;
                m_movingDirection *= -1;
                m_direction *= -1;
            }
            return;
        }

        if (!(m_collisionState == CollisionState.OnWall && m_jumpState == JumpState.Jumping))
            m_velocity = velocity;

        int lastDirection = m_direction;
        int lastMovingDirection = m_movingDirection;

        if (playerState != PlayerState.Turning)
        {
            m_direction = direction;
            if (m_direction != 0) m_movingDirection = m_direction;
        }

        if (m_collisionState != CollisionState.None && m_jumpState != JumpState.Jumping)
        {
            if (m_direction == 0 && playerState != PlayerState.Turning)
            {
                playerState = PlayerState.Standing;
            }
            else
            {
                if (playerState == PlayerState.Turning)
                {
                    m_velocity = 0.0f;
                    return;
                }

                // are we tuning round?
                if (lastDirection != direction && ((Time.time * 1000.0f) - m_turnLockTimer > 1000.0f))
                {
                    playerState = PlayerState.Walking;
                    if (m_velocity != 0.0f && lastMovingDirection != m_direction)
                    {
                        playerState = PlayerState.Turning;
                        m_velocity = 0.0f;
                        m_turnLockTimer = Time.time * 1000.0f;
                    }
                }
                else
                    playerState = PlayerState.Walking;
            }
        }
    }
Beispiel #59
0
        /// <summary>
        /// Determines the player's intended x and y velocities based on the most recent user input,
        /// while updating other action-related properties.
        /// </summary>
        /// <param name="time">The amount of gametime that has elapsed since the last frame.</param>
        public override void Update(GameTime time)
        {
            float totalTime = (float)(time.ElapsedGameTime.TotalSeconds);

            if (damageStatus >= INVINCIBLE_END)
            {
                damageStatus = VULNERABLE;
            }
            else if (damageStatus >= STUN_END)
            {
                if (rightBtnFlag == true && leftBtnFlag == false)
                    LatestXArrow = XDirection.Right;
                else if (leftBtnFlag == true && rightBtnFlag == false)
                    LatestXArrow = XDirection.Left;
                else
                    LatestXArrow = XDirection.None;
            }

            if (currentHealth > 0 && (damageStatus < INVINCIBLE_START || damageStatus >= STUN_END))
            {
                if (dashStatus < DASH_HELD)
                {
                    if (LatestXArrow == XDirection.Left && PlayerXFacing == XDirection.Right)
                        PlayerXFacing = XDirection.Left;
                    else if (LatestXArrow == XDirection.Right && PlayerXFacing == XDirection.Left)
                        PlayerXFacing = XDirection.Right;
                }

                if (isOnGround == false && velocityY >= 0)
                {
                    if (wallOnRight && rightBtnFlag)
                    {
                        if (WallSlideDirection == XDirection.None)
                        {
                            soundEngine.Play(AudioEngine.SoundEffects.WallLand);
                            if (jumpBtnFlag == false)
                                PlayerJumpState = JumpState.Allowed;
                            else
                                PlayerJumpState = JumpState.NotAllowed;
                            if (!dashBtnFlag)
                                dashStatus = DASH_ALLOWED;
                            else
                                dashStatus = DASH_NOT_ALLOWED;
                        }
                        WallSlideDirection = XDirection.Right;
                    }
                    else if (wallOnLeft && leftBtnFlag == true)
                    {
                        if (WallSlideDirection == XDirection.None)
                        {
                            soundEngine.Play(AudioEngine.SoundEffects.WallLand);
                            if (jumpBtnFlag == false)
                                PlayerJumpState = JumpState.Allowed;
                            else
                                PlayerJumpState = JumpState.NotAllowed;
                            if (!dashBtnFlag)
                                dashStatus = DASH_ALLOWED;
                            else
                                dashStatus = DASH_NOT_ALLOWED;
                        }
                        WallSlideDirection = XDirection.Left;
                    }
                    else
                        WallSlideDirection = XDirection.None;
                }
                else
                    WallSlideDirection = XDirection.None;

                if (PlayerJumpState == JumpState.NotAllowed && jumpBtnFlag == false)
                    PlayerJumpState = JumpState.Allowed;

                if (jumpBtnFlag == true && PlayerJumpState == JumpState.Allowed &&
                    (isOnGround || midairJumps > 0 || wallOnLeft || wallOnRight))
                {
                    if (isOnGround == false)
                    {
                        if (wallOnRight || wallOnLeft)
                        {
                            velocityY = WALL_JUMP_V_Y;
                            velocityX = WALL_JUMP_V_X;
                            if (wallOnLeft)
                            {
                                velocityX *= -1;
                                PlayerXFacing = XDirection.Right;
                            }
                            else
                            {
                                PlayerXFacing = XDirection.Left;
                            }
                            WallSlideDirection = XDirection.None;
                            soundEngine.Play(AudioEngine.SoundEffects.WallJump);
                        }
                        else
                        {
                            midairJumps = (byte)Math.Max(0, midairJumps - 1);
                            velocityY = JUMP_V;
                            soundEngine.Play(AudioEngine.SoundEffects.WallJump);
                        }
                    }
                    else
                    {
                        LeaveGround();
                        velocityY = JUMP_V;
                        soundEngine.Play(AudioEngine.SoundEffects.Jump);
                    }
                    if (dashStatus >= DASH_HELD)
                    {
                        dashStatus = DASH_LAG_START;
                        isGravityAffected = true;
                    }
                    PlayerJumpState = JumpState.Holding;
                    accelerationY = 0;
                }

                if (!isOnGround)
                {
                    if (PlayerJumpState == JumpState.Holding)
                    {
                        if (jumpBtnFlag == false)
                        {
                            PlayerJumpState = JumpState.Allowed;
                            if (velocityY <= 0)
                            {
                                accelerationY = JUMP_DECAY;
                                velocityLimitY = 0;
                            }
                        }
                    }
                    else if (WallSlideDirection != XDirection.None)
                    {
                        accelerationY = WALL_FRICTION_DEC;
                        velocityLimitY = MAX_WALL_SLIDE_V;
                    }
                    else if (velocityY >= 0)
                    {
                        accelerationY = 0;
                    }
                }

                if (dashStatus == DASH_ALLOWED && dashBtnFlag == true &&
                    (dashes != 0 || WallSlideDirection != XDirection.None))
                {
                    dashStatus = DASH_HELD;
                    accelerationX = 0;
                    if (WallSlideDirection == XDirection.Right)
                    {
                        velocityX = -DASH_V;
                        PlayerXFacing = XDirection.Left;
                    }
                    else if (WallSlideDirection == XDirection.Left)
                    {
                        velocityX = DASH_V;
                        PlayerXFacing = XDirection.Right;
                    }
                    else
                    {
                        if (dashes > 0)
                            dashes--;
                        if (PlayerXFacing == XDirection.Right)
                        {
                            velocityX = DASH_V;
                            velocityLimitX = DASH_V;
                        }
                        else
                        {
                            velocityX = -DASH_V;
                            velocityLimitX = -DASH_V;
                        }
                    }
                    if (!isOnGround)
                    {
                        isGravityAffected = false;
                        velocityY = 0;
                        accelerationY = 0;
                    }
                    soundEngine.Play(AudioEngine.SoundEffects.Dash);
                }
                else if (dashStatus < DASH_NOT_ALLOWED)
                    dashStatus = Math.Min(dashStatus + totalTime, DASH_NOT_ALLOWED);
                else if (dashStatus == DASH_NOT_ALLOWED && dashBtnFlag == false)
                    dashStatus = DASH_ALLOWED;

                if (dashStatus >= DASH_HELD)
                {
                    dashStatus += totalTime;
                    if (dashStatus > MAX_DASH_TIME || dashBtnFlag == false)
                    {
                        if (LatestXArrow == XDirection.Right)
                            velocityX = MAX_RUN_V;
                        else if (LatestXArrow == XDirection.Left)
                            velocityX = -MAX_RUN_V;
                        else
                            velocityX = 0;
                        isGravityAffected = true;
                        dashStatus = DASH_LAG_START;
                    }
                }
                else
                {
                    if (LatestXArrow == XDirection.Right)
                    {
                        if (velocityX < 0)
                        {
                            accelerationX = BRAKE_DEC;
                            velocityLimitX = 0;
                        }
                        else if (velocityX <= MAX_RUN_V)
                        {
                            accelerationX = RUN_ACC;
                            velocityLimitX = MAX_RUN_V;
                        }
                        else
                        {
                            accelerationX = TOO_FAST_DEC;
                            velocityLimitX = MAX_RUN_V;
                        }
                    }
                    else if (LatestXArrow == XDirection.Left)
                    {
                        if (velocityX > 0)
                        {
                            accelerationX = -BRAKE_DEC;
                            velocityLimitX = 0;
                        }
                        else if (velocityX >= -MAX_RUN_V)
                        {
                            accelerationX = -RUN_ACC;
                            velocityLimitX = -MAX_RUN_V;
                        }
                        else
                        {
                            accelerationX = -TOO_FAST_DEC;
                            velocityLimitX = -MAX_RUN_V;
                        }
                    }
                    else if (velocityX != 0)
                    {
                        if (velocityX > MAX_RUN_V)
                        {
                            accelerationX = TOO_FAST_DEC;
                            velocityLimitX = MAX_RUN_V;
                        }
                        else if (velocityX > 0)
                        {
                            accelerationX = STOP_DEC;
                            velocityLimitX = 0;
                        }
                        else if (velocityX < -MAX_RUN_V)
                        {
                            accelerationX = -TOO_FAST_DEC;
                            velocityLimitX = -MAX_RUN_V;
                        }
                        else if (velocityX < 0)
                        {
                            accelerationX = -STOP_DEC;
                            velocityLimitX = 0;
                        }
                    }
                }
            }

            if ((damageStatus >= SWITCH_TO_DEAD_FRAME) && (damageStatus <= deathSequenceEndTime) &&
                (currentFrame == 0))
            {
                SwitchToDeathCollision();
                currentFrame++;
            }

            if (damageStatus >= INVINCIBLE_START)
                damageStatus += totalTime;
            else if (damageStatus < deathSequenceEndTime)
                damageStatus = Math.Min(deathSequenceEndTime, damageStatus + totalTime);

            if (PlayerXFacing == XDirection.Right)
            {
                if (currentHealth <= 0)
                    currentAnimation = currentAnimation = (int)PlayerAnimations.DyingRight;
                else if (damageStatus >= INVINCIBLE_START && damageStatus < STUN_END)
                    currentAnimation = (int)PlayerAnimations.DamageRight;
                else if (dashStatus >= DASH_HELD)
                    currentAnimation = (int)PlayerAnimations.DashRight;
                else if (WallSlideDirection == XDirection.Right)
                    currentAnimation = (int)PlayerAnimations.WallSlideRight;
                else if (!isOnGround)
                    currentAnimation = (int)PlayerAnimations.JumpRight;
                else
                {
                    currentAnimation = (int)PlayerAnimations.WalkRight;
                    if (damageStatus >= STUN_END)
                        animationSpeed[currentAnimation] = 2 * velocityX / MAX_RUN_V;
                    else
                        animationSpeed[currentAnimation] = velocityX / MAX_RUN_V;
                }
            }
            else
            {
                if (currentHealth <= 0)
                    currentAnimation = currentAnimation = (int)PlayerAnimations.DyingLeft;
                else if (damageStatus >= INVINCIBLE_START && damageStatus < STUN_END)
                    currentAnimation = (int)PlayerAnimations.DamageLeft;
                else if (dashStatus >= DASH_HELD)
                    currentAnimation = (int)PlayerAnimations.DashLeft;
                else if (WallSlideDirection == XDirection.Left)
                    currentAnimation = (int)PlayerAnimations.WallSlideLeft;
                else if (!isOnGround)
                    currentAnimation = (int)PlayerAnimations.JumpLeft;
                else
                {
                    currentAnimation = (int)PlayerAnimations.WalkLeft;
                    if (damageStatus >= STUN_END)
                        animationSpeed[currentAnimation] = 2 * -velocityX / MAX_RUN_V;
                    else
                        animationSpeed[currentAnimation] = -velocityX / MAX_RUN_V;
                }
            }
            if (velocityX == 0 && currentHealth > 0)
                currentFrame = 0;

            if (currentAnimation == (int)PlayerAnimations.DashLeft || currentAnimation == (int)PlayerAnimations.DashRight ||
                currentAnimation == (int)PlayerAnimations.DyingLeft || currentAnimation == (int)PlayerAnimations.DyingRight)
                looping = false;
            else
                looping = true;

            base.Update(time);
        }
    /*
     * \brief Works out if a value is almost another value (for floating point accuracy)
    */
    public void CallOnCollisionEnter(Collision collision)
    {
        m_collisionState = CollisionState.None;

        foreach (ContactPoint contact in collision)
        {
            m_platform = contact.otherCollider.gameObject.GetComponent<CSceneObjectPlatform>();
            if (m_platform != null) {
                m_platform.resetDeltaA();
            }
            if (isNearly(contact.normal.y, 1.0f, 0.2f))
            {
                m_collisionState = CollisionState.OnFloor;

                if (m_player.GetPlayerState() == PlayerState.OnLadder)
                {
                    GetLadder.state = LadderState.AtBase;
                    m_player.SetPlayerState(PlayerState.Standing);
                }

                // are we on a special material?
                m_footMaterial = FootMaterial.Stone;
                if (contact.otherCollider.tag == "Wood Object")
                    m_footMaterial = FootMaterial.Wood;
                else if (contact.otherCollider.tag == "Metal Object")
                    m_footMaterial = FootMaterial.Metal;

            }
            else if (isNearly(contact.normal.y, -1.0f, 0.2f))
            {
                m_collisionState = CollisionState.OnRoof;
                if (contact.otherCollider != null && contact.otherCollider.GetComponent<CSceneObjectPlatform>() != null)
                {
                    m_player.PushPlayerFromTower();
                }
            }
            else
            {
                if (m_player.GetPlayerState() != PlayerState.OnLadder)
                    m_collisionState = CollisionState.OnWall;
            }
        }

        if (m_collisionState == CollisionState.OnFloor)
        {
            if (m_jumpState != JumpState.Landed)
                m_player.GetPlayerAnimation().PlayFootstepAudio(m_footMaterial);

            m_jumpState = JumpState.Landed;

            if (GetLadder.state == LadderState.JumpingOff)
                GetLadder.state = LadderState.None;

            if (m_player.GetPlayerState() != PlayerState.Turning && m_player.GetPlayerState() != PlayerState.OnLadder && !m_player.PullingLever(false))
            {
                m_player.SetPlayerState(PlayerState.Standing);
            }
        }
    }