示例#1
0
    void Start()
    {
        _spacedeath        = false;
        dead               = false;
        initialDrag        = rb.drag;
        lastInstructionPos = transform.position;

        instructionHandler = GameObject.Find("InstructionHandler").GetComponent <InstructionHandler>();
        instructionHandler.AddNextPlayerInstruction(transform.position);
    }
示例#2
0
    public override void Update()
    {
        base.Update();

        if (inSpace)
        {
            return;
        }
        if (dead)
        {
            // Yep, no input here as well
            return;
        }

        if (hurtCooldownCount > 0)
        {
            hurtCooldownCount -= Time.deltaTime;
        }

        // State transitions
        switch (state)
        {
        case PlayerState.Walking:

            dashCooldownCount -= Time.deltaTime;
            if (Input.GetButtonDown("Dash") && dashCooldownCount <= 0)
            {
                _dashaudio.Play();
                state     = PlayerState.Dashing;
                dashCount = DashTime;     // something?
                StopAllCoroutines();
                StartCoroutine(SpriteColor(invincibleColor, DashInvincibleTime));
            }
            break;

        case PlayerState.Dashing:
            dashCount -= Time.deltaTime;
            if (dashCount <= 0)
            {
                state             = PlayerState.Walking;
                dashCooldownCount = DashCooldownTime;
                // TODO? Update the player input so the gravity and such makes sense?
            }
            break;
        }

        moveDir = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
        if (moveDir.sqrMagnitude > 0.4)
        {
            dashDir = moveDir.normalized;
        }

        // Walk SFX
        if (WalkSfxCount > 0)
        {
            WalkSfxCount -= Time.deltaTime;
        }
        if (moveDir.sqrMagnitude > 0.1)
        {
            if (WalkSfxCount <= 0)
            {
                WalkSfxCount = WalkSfxTime;
                _walkaudio.Play();
            }
        }

        _anim.SetFloat("MoveSpeed", moveDir.sqrMagnitude);
        _anim.SetBool("Roll", state == PlayerState.Dashing);

        // Instruction updating
        const int instructionDist = 10;

        if ((transform.position - lastInstructionPos).sqrMagnitude > instructionDist * instructionDist)
        {
            instructionHandler.AddNextPlayerInstruction(transform.position);
            lastInstructionPos = transform.position;
        }
    }