Ejemplo n.º 1
0
    public override void handle_input(PlayerStateController controller)
    {
        if (Input.GetButtonDown("Fire2"))
        {
            controller.isRetracting = true;
        }

        // Render Hook
        controller.hookLine.SetPosition(0, controller.transform.position);
        controller.hookLine.SetPosition(1, controller.hook.transform.position);


        // Decision to FallingState

        if (controller.isRetracting)
        {
            controller.rb.isKinematic = false;
            // Push to hook
            controller.rb.AddForce(
                (controller.hook.position - controller.transform.position).normalized * controller.hookInertia * Time.deltaTime,
                ForceMode2D.Impulse
                );
            controller.ChangeState(controller.fallingState);
        }

        if (controller.isRetracted)
        {
            controller.rb.isKinematic   = false;
            controller.hookLine.enabled = false;
            controller.hook.parent      = controller.transform;
            controller.isRetracting     = false;
            controller.hook.position    = controller.transform.position;
            controller.ChangeState(controller.fallingState);
        }
    }
Ejemplo n.º 2
0
 // Update is called once per frame
 void Update()
 {
     HandleTimers();
     //can only attack if we're on the ground and not dodging or in knockback
     if (((int)_stateController.state <= 1 || _stateController.state == PlayerState.Aim) && Input.GetButtonDown("Melee"))
     {
         anticipationTimer = anticipationTime;
         _stateController.ChangeState(PlayerState.Attack);
     }
 }
Ejemplo n.º 3
0
 public void Die()
 {
     // TODO: play death animation (in animation controller script)
     AudioManager.instance.PlaySound(deathSound, pitchRange);
     ps_controller.ChangeState(PlayerState.Dead);
     // TODO: put up UI telling player how to restart
 }
Ejemplo n.º 4
0
    public override void handle_input(PlayerStateController controller)
    {
        controller.moveInput = Input.GetAxisRaw("Horizontal");
        controller.Flip();

        if (!controller.isRetracted)
        {
            // Render Hook
            if (controller.hookLine.enabled)
            {
                controller.hookLine.SetPosition(0, controller.transform.position);
                controller.hookLine.SetPosition(1, controller.hook.transform.position);
            }
        }
        else
        {
            controller.hookLine.enabled = false;
            controller.hook.parent      = controller.transform;
            controller.isRetracting     = false;
            controller.hook.position    = controller.transform.position;
        }

        // Decision to MovingState
        if (controller.isGrounded)
        {
            controller.ChangeState(controller.movingState);
        }
    }
Ejemplo n.º 5
0
 public override void handle_input(PlayerStateController controller)
 {
     if (Input.GetButtonDown("Fire2") || Input.GetKeyDown(KeyCode.S))
     {
         Debug.Log("Move");
         controller.ChangeState(controller.movingState);
     }
 }
Ejemplo n.º 6
0
    public override void update(PlayerStateController controller)
    {
        if (!controller.isHooked)
        {
            controller.hook.Translate(_whereToShoot * controller.speedHook * Time.fixedDeltaTime, Space.World);
        }

        // Decision to RetractingState
        if (controller.isRetracting)
        {
            controller.ChangeState(controller.retractingState);
        }

        // Decision to Hooked State
        if (controller.isHooked)
        {
            controller.ChangeState(controller.hookedState);
        }
    }
Ejemplo n.º 7
0
 public override void Update(PlayerStateController state, PlayerController player)
 {
     if (player.IsGrounded && player.Input.Jump.Down)
     {
         state.ChangeState(player.jumpState);
     }
     else if (player.IsGrounded && player.Input.Horizontal.Down)
     {
         state.ChangeState(player.runState);
     }
     else if (player.Input.Shooting.Down)
     {
         player.StartShootingFireBall();
     }
     else if (player.Input.MeleeAttack.Down)
     {
         player.StartMeleeAttack();
     }
 }
Ejemplo n.º 8
0
    public override void handle_input(PlayerStateController controller)
    {
        // Render Hook
        controller.hookLine.SetPosition(0, controller.transform.position);
        controller.hookLine.SetPosition(1, controller.hook.transform.position);

        // Decision
        if (controller.isRetracted)
        {
            Debug.Log("Go to retracting state");
            controller.ChangeState(controller.movingState);
        }
    }
Ejemplo n.º 9
0
    public override void handle_input(PlayerStateController controller)
    {
        controller.moveInput = Input.GetAxisRaw("Horizontal");
        controller.Flip();
        // Decision to jump
        if (controller.isGrounded && Input.GetButtonDown("Jump"))
        {
            controller.ChangeState(controller.jumpingState);
        }

        // Decision to shoot
        if (controller.isGrounded && Input.GetButtonDown("Fire1"))
        {
            controller.ChangeState(controller.shootingState);
        }

        // Decision to hide
        if (controller.isInShadow && (Input.GetButtonDown("Fire2") || Input.GetKeyDown(KeyCode.W)))
        {
            Debug.Log("Hide");
            controller.ChangeState(controller.hidingState);
        }
    }
Ejemplo n.º 10
0
    public override void handle_input(PlayerStateController controller)
    {
        if (Input.GetButtonDown("Fire1"))
        {
            if (controller.hookedObject != null)
            {
                controller.hookedObject.HookAction();
            }
            controller.isRetracting = true;
        }

        if (Input.GetButtonDown("Fire2"))
        {
            controller.isRetracting = true;
        }

        // Render Hook
        controller.hookLine.SetPosition(0, controller.transform.position);
        controller.hookLine.SetPosition(1, controller.hook.transform.position);

        // Decision to PullingState
        if (controller.hookedObject != null)
        {
            Debug.Log(controller.hookedObject.GetTag());
            if (controller.hookedObject.GetTag() == "HookSupport")
            {
                controller.ChangeState(controller.pullingState);
            }
        }


        // Decision to RetractingState
        if (controller.isRetracting)
        {
            controller.ChangeState(controller.retractingState);
        }
    }
Ejemplo n.º 11
0
 public override void Update(PlayerStateController state, PlayerController player)
 {
     if (player.IsGrounded && player.MoveVector.y < 0)
     {
         state.ChangeState(player.idleState);
     }
     else if (player.Input.MeleeAttack.Down)
     {
         player.StartMeleeAttack();
     }
     else if (player.Input.Shooting.Down)
     {
         player.StartShootingFireBall();
     }
 }
Ejemplo n.º 12
0
    public void ResetPositionsAndStates()
    {
        for (int i = 0; i < teamAgents.Count; i++)
        {
            GameObject obj = (GameObject)teamAgents[i];

            obj.transform.position = (Vector3)originalPositions[i];
            PlayerStateController PScontroller = obj.GetComponent <PlayerStateController>();
            PScontroller.ChangeState(PlayerStateController.PlayerState.idle);
            obj.GetComponent <FlagCarrierSM>().HasFlag = false;
            obj.GetComponent <MovementBehaviour>().CharacterVelocity = Vector3.zero;
            print("WARNING RESET THE TAGGER AND UNTAGGER STATES! ");
        }
        //todo that !
    }
Ejemplo n.º 13
0
    public override void handle_input(PlayerStateController controller)
    {
        controller.moveInput = Input.GetAxisRaw("Horizontal");
        controller.Flip();
        if (_jumping)
        {
            if (Input.GetButton("Jump"))
            {
                _isPressingJump = true;
            }
            else
            {
                _canJump        = false;
                _isPressingJump = false;
            }

            if (_jumpTimeCounter > 0)
            {
                _jumpTimeCounter -= Time.deltaTime;
            }
            else
            {
                _canJump = false;
            }
        }


        // Decision to MovingState
        if (controller.isGrounded)
        {
            //_isPressingJump = false;
            //_canJump = true;
            //_jumping = false;

            controller.ChangeState(controller.movingState);
        }
    }
Ejemplo n.º 14
0
 /// <summary>
 /// change player to the aiming state
 /// </summary>
 void StartAiming()
 {
     facingRightInitially = playerMove.facingRight;
     //Debug.Log("StartAiming");
     _stateController.ChangeState(PlayerState.Aim);
 }
Ejemplo n.º 15
0
    /// <summary>
    /// update all the timers we're keeping track of
    /// </summary>
    void UpdateTimers()
    {
        if (coyoteTimer > 0)
        {
            coyoteTimer -= Time.deltaTime;
        }
        //if we're dodging and we were on the ground in our last state, set coyote time
        if (_stateController.state == PlayerState.Dodge &&
            ((int)_stateController.previousState <= 1 ||
             _stateController.previousState == PlayerState.Attack ||
             _stateController.previousState == PlayerState.Aim))
        {
            coyoteTimer = coyoteTimeDodge;
        }
        //knockback timer
        if (knockbackTimer > 0)
        {
            knockbackTimer -= Time.deltaTime;
            if (knockbackTimer < 0 && _stateController.state != PlayerState.Dead)
            {
                if (_controller.isGrounded)
                {
                    _stateController.ChangeState(0);
                }
                else
                {
                    _stateController.ChangeState(PlayerState.Fall);
                }
            }
        }
        //invincibility timer
        if (invTimer > 0)
        {
            invTimer -= Time.deltaTime;
            if (_stateController.state != PlayerState.Dead)
            {
                Flash();
            }

            if (invTimer <= 0)
            {
                m_spriteRenderer.enabled = true;
            }
        }
        #region dodgeTimers
        if (dodgeInvTimer > 0)
        {
            dodgeInvTimer -= Time.deltaTime;
            if (dodgeInvTimer <= 0)
            {
                m_spriteRenderer.color = dodgeCooldownTint;
            }
        }
        if (dodgeCooldownTimer > 0)
        {
            dodgeCooldownTimer -= Time.deltaTime;
            //clamp dodge cooldown timer to 0 so we don't get weird stuff in the lerp
            dodgeCooldownTimer     = Mathf.Max(dodgeCooldownTimer, 0);
            m_spriteRenderer.color = Color.Lerp(m_initialColor, dodgeCooldownTint, dodgeCooldownTimer / dodgeCooldownTime);
            if (dodgeCooldownTimer == 0)
            {
                m_spriteRenderer.color = m_initialColor;
            }
        }
        //dodge timer
        if (dodgeTimer > 0)
        {
            dodgeTimer -= Time.deltaTime;
            if (dodgeTimer <= 0)
            {
                //if we can undodge
                if (CeilingCheck())
                {
                    //if we're grounded, change state to idle, otherwise change state to fall
                    if (_controller.isGrounded)
                    {
                        _stateController.ChangeState(0);
                    }
                    //if we're falling, change state to falling
                    else if (_velocity.y < 0)
                    {
                        _stateController.ChangeState(3);
                    }
                    //if we're moving up, change state to jumping
                    else
                    {
                        _stateController.ChangeState(2);
                    }
                    dodgeCooldownTimer = dodgeCooldownTime;
                }
                else
                {
                    //add a small amount of time to the dodge timer so we check next frame
                    dodgeTimer = 0.01f;
                }
            }
        }
        #endregion
    }