Exemplo n.º 1
0
    private Turn turnTrigger; // gets set when we enter a turn trigger

    private void Start()
    {
        previousState            = State.GRUONDED;
        facingDirection          = FacingDir.UP_RIGHT;
        aboutToLandCheckDistance = 20;
        airTimer            = 0;
        dashTimer           = 0;
        deathTimer          = 0;
        groundBufferTimer   = 0;
        groundCheckDistance = 1;
        speed               = 0;
        speedTierTimer      = 0;
        aboutToLand         = false;
        backwardPressed     = false;
        dashPressed         = false;
        forwardPressed      = false;
        leftPressed         = false;
        rightPressed        = false;
        currentAirCharges   = maximumAirCharges;
        currentRunTier      = -1;
        invisWallLayerMask  = 1 << LayerMask.NameToLayer("Invisi Walls");
        vec_down            = new Vector3(0, -1, 0);
        vec_forward         = new Vector3(0, 0, 1);
        vec_turn            = new Vector3(0, 90, 0);
        vec_offset          = new Vector3(0, 1, 0);
        vec_pauseVelocity   = new Vector3();
        vec_wallCheckOffset = new Vector3(0, 1, 0);
        anim        = GetComponent <Animator>();
        rb          = GetComponent <Rigidbody>();
        coll        = GetComponent <BoxCollider>();
        turnTrigger = null;
    }
Exemplo n.º 2
0
            private void DoDash(FacingDir dir)
            {
                if (inDashCooldown)
                {
                    return;
                }

                if (wallStick != null && wallStick.Doing)
                {
                    return;
                }

                if (!physics.Grounded)
                {
                    if (!canAirDash || didAirDash)
                    {
                        return;
                    }
                    horizontalMovement.SetSpeed(dashSpeed);
                }

                StartCoroutine(DashCooldown());
                ChangeState(AbilityStates.Doing);
                curDashTime = 0.0f;
                dashDir     = dir;
            }
Exemplo n.º 3
0
    /**
     * Sets the direction the wolf is facing.
     * Also modifies the camera's position (see cameraFollowing.SetOrientation).
     * @param newDirection The direction the wolf will face.
     */
    public void setFacingDirection(FacingDir newDirection)
    {
        facingDirection = newDirection;

        switch (facingDirection)
        {
        case FacingDir.UP_RIGHT:
            vec_turn.Set(0, 90, 0);
            break;

        case FacingDir.UP_LEFT:
            vec_turn.Set(0, 0, 0);
            break;

        case FacingDir.DOWN_RIGHT:
            vec_turn.Set(0, 180, 0);
            break;

        case FacingDir.DOWN_LEFT:
            vec_turn.Set(0, -90, 0);
            break;
        }

        transform.rotation = Quaternion.Euler(vec_turn);
        GameManager.i().cameraFollowing.SetOrientation(newDirection);
    }
Exemplo n.º 4
0
        public void Tick()
        {
            if (!IsAlive)
            {
                return;
            }

            jumpStartTimer -= Time.deltaTime;
            bool jumpBtn = Input.GetButton("Jump");

            if (jumpBtn && jumpInputDown == false)
            {
                jumpStartTimer = jumpInputLeewayPeriod;
            }
            jumpInputDown = jumpBtn;

            Direction = SpriteHolder.localScale.x == -1 ? FacingDir.Left : FacingDir.Right;

            if (OnCooldown)
            {
                if (CooldownTimer >= InternalCooldown)
                {
                    CooldownTimer = 0;
                    OnCooldown    = false;
                }
                else
                {
                    CooldownTimer += Time.deltaTime;
                }
            }
        }
Exemplo n.º 5
0
 private void JumpInDirBy(FacingDir dir, IntVector2D deltaLoc)
 {
     _currStateInfo.lastLoc = Location;
     Location                       += deltaLoc;
     _currStateInfo.state            = Char2DState.Jumping;
     _currStateInfo.facingDirection  = dir;
     _currStateInfo.fractionComplete = 0f;
 }
Exemplo n.º 6
0
        public void SetFacingDir(FacingDir dir)
        {
            curFacingDir = dir;
            var newScale = gameObject.transform.localScale;

            newScale.x = dir == FacingDir.Right ? 1 : -1;
            gameObject.transform.localScale = newScale;
        }
Exemplo n.º 7
0
 private void MoveInDirTo(FacingDir dir, IntVector2D dest)
 {
     _currStateInfo.lastLoc = Location;
     Location                        = dest;
     _currStateInfo.state            = Char2DState.Walking;
     _currStateInfo.facingDirection  = dir;
     _currStateInfo.fractionComplete = 0f;
 }
    void SetFaceDir(FacingDir facing, bool moving)
    {
        ani.SetBool("Side", facing == FacingDir.left || facing == FacingDir.right);
        ani.SetBool("Up", facing == FacingDir.up);
        ani.SetBool("Down", facing == FacingDir.down);
        ani.SetBool("IsMoving", moving);
        Debug.Log($"{facing}, {moving}");

        if (facing == FacingDir.left)
        {
            transform.localScale = new Vector2(-playerScale, playerScale);
        }
        else
        {
            transform.localScale = new Vector2(playerScale, playerScale);
        }
    }
Exemplo n.º 9
0
    void makeCrouch()
    {
        // Change fD
        switch (fD)
        {
        case FacingDir.downLeft:
            fD = FacingDir.left;
            break;

        case FacingDir.upLeft:
            fD = FacingDir.left;
            break;

        case FacingDir.downRight:
            fD = FacingDir.right;
            break;

        case FacingDir.upRight:
            fD = FacingDir.right;
            break;

        case FacingDir.down:
            fD = lastDir;
            break;
        }
        //Change position

        Vector3 newPos      = transform.position;
        float   oldHeight   = SliceRight.bounds.size.y;
        float   newHeight   = SliceCrouchRight.bounds.size.y;
        float   scaleChange = newHeight / oldHeight;

        print(scaleChange);
        newPos.y -= scaleChange * this.transform.lossyScale.y / 2;
        this.transform.position = newPos;
        print(newPos.y);

        BoxCollider box      = this.GetComponent <BoxCollider> ();
        Vector3     boxBound = box.size;

        boxBound.y *= scaleChange;
        box.size    = boxBound;
        isCrouching = true;
    }
Exemplo n.º 10
0
    void makeNotCrouch()
    {
        // Make not crouching
        float oldHeight   = SliceRight.bounds.size.y;
        float newHeight   = SliceCrouchRight.bounds.size.y;
        float scaleChange = newHeight / oldHeight;

        Vector3 newPos = transform.position;

        newPos.y += scaleChange * this.transform.lossyScale.y / 2;
        this.transform.position = newPos;

        BoxCollider box      = this.GetComponent <BoxCollider> ();
        Vector3     boxBound = box.size;

        boxBound.y *= 1f / scaleChange;
        box.size    = boxBound;

        isCrouching = false;
        fD          = lastDir;
    }
Exemplo n.º 11
0
    private tnUICharacter SpawnCharacter(tnCharacterData i_CharacterData, FacingDir i_Facing, Color i_TeamColor, Sprite i_Flag)
    {
        tnUICharacter character = null;

        if (m_CharactersPool.Count > 0)
        {
            character = m_CharactersPool[m_CharactersPool.Count - 1];
            m_CharactersPool.RemoveAt(m_CharactersPool.Count - 1);
            character.gameObject.SetActive(true);
        }
        else
        {
            if (m_CharacterPrefab == null)
            {
                return(null);
            }

            character = GameObject.Instantiate <tnUICharacter>(m_CharacterPrefab);
            character.transform.SetParent(transform, false);
        }

        character.SetBaseColor(i_TeamColor);
        character.SetFlagSprite(i_Flag);

        if (i_Facing == FacingDir.FacingRight)
        {
            character.SetCharacterSprite(i_CharacterData.uiIconFacingRight);
        }
        else // Facing Left
        {
            character.SetCharacterSprite(i_CharacterData.uiIconFacingLeft);
        }

        character.SetName(i_CharacterData.displayName);

        character.SetAvailable();
        character.Deselect();

        return(character);
    }
Exemplo n.º 12
0
    /**
     * Turns the wolf so now they are running in a new direction based on current inputs
     * and the turnTrigger we're currently inside.
     * @see Turn.cs for more information.
     */
    private void turn()
    {
        if (turnTrigger == null)
        {
            Debug.LogWarning("A call to turn, but no turnTrigger object is set!");
            return;
        }

        FacingDir newDirection = FacingDir.UP_RIGHT;

        switch (facingDirection)
        {
        case FacingDir.UP_RIGHT:   newDirection = leftPressed ? FacingDir.UP_LEFT : FacingDir.DOWN_RIGHT; break;

        case FacingDir.UP_LEFT:    newDirection = leftPressed ? FacingDir.DOWN_LEFT : FacingDir.UP_RIGHT; break;

        case FacingDir.DOWN_RIGHT: newDirection = leftPressed ? FacingDir.UP_RIGHT : FacingDir.DOWN_LEFT; break;

        case FacingDir.DOWN_LEFT:  newDirection = leftPressed ? FacingDir.DOWN_RIGHT : FacingDir.UP_LEFT; break;
        }

        if (!turnTrigger.allowsDirection(newDirection))
        {
            return;
        }

        setFacingDirection(newDirection);
        if (turnTrigger.centerOnTurn)
        {
            setPosition(turnTrigger.transform.position, true);
        }

        if (turnTrigger.onlyTurnOnce)
        {
            turnTrigger = null;
        }
    }
Exemplo n.º 13
0
    private void UpdatePortrait(int i_TeamIndex)
    {
        if (!IsValidIndex(i_TeamIndex))
        {
            return;
        }

        tnCharacterPortrait portrait         = m_Portraits[i_TeamIndex];
        GameObject          currentSelection = m_CurrentSlots[i_TeamIndex];

        ClearPortrait(i_TeamIndex);
        SetPortraitEnable(i_TeamIndex, false);

        if (portrait != null && currentSelection != null)
        {
            tnUICharacterSlot slot = currentSelection.GetComponent <tnUICharacterSlot>();
            if (slot != null)
            {
                int characterId = slot.characterId;
                if (characterId != Hash.s_NULL)
                {
                    tnCharacterData characterData = tnGameData.GetCharacterDataMain(characterId);
                    if (characterData != null)
                    {
                        SetPortraitEnable(i_TeamIndex, true);

                        FacingDir facing = m_Facing[i_TeamIndex];

                        Sprite characterSprite = (facing == FacingDir.FacingLeft) ? characterData.uiIconFacingLeft : characterData.uiIconFacingRight;

                        portrait.SetCharacterPortrait(characterSprite);
                        portrait.SetName(characterData.displayName);
                    }
                }
            }
        }
    }
Exemplo n.º 14
0
    private void FixedUpdate()
    {
        CheckIfGrounded();

        float inputVector = 0.0f;

        inputVector += Input.GetAxisRaw("Horizontal");
        if (inputVector > 0.0f)
        {
            CurrentFacing      = FacingDir.Right;
            playerSprite.flipX = true;

            _anim.ResetTrigger("Idle");
            _anim.SetTrigger("Walk");
        }
        else if (inputVector < 0.0f)
        {
            CurrentFacing      = FacingDir.Left;
            playerSprite.flipX = false;

            _anim.ResetTrigger("Idle");
            _anim.SetTrigger("Walk");
        }
        else
        {
            _anim.ResetTrigger("Walk");
            _anim.SetTrigger("Idle");
        }

        bool doJump = false;

        doJump = Input.GetButton("Jump");



        MovementWithFriction(inputVector, doJump);
    }
Exemplo n.º 15
0
    // Update is called once per frame
    void Update()
    {
        //Handle respawning
        if (isDead && ((deathTime + 1f) < Time.time))
        {
            if (lives > -1)
            {
                respawn(didIFall, deathPos);
            }
        }

        if (lives < 0)
        {
            Application.LoadLevel("_Scene_StartScreen");
        }

        //Reset Burst Fire
        if (Time.time > nextBurst)
        {
            numFired = 0;
        }

        updateSprite();

        // Bullet-time
        if (Input.GetKeyDown(KeyCode.R))
        {
            if (Application.loadedLevelName == "_Scene_0")
            {
                return;
            }
            if (!bulletTime)
            {
                speed         *= 2f;
                vel.x         *= 2f;
                fireRate      *= .5f;
                burstRate     *= .5f;
                Time.timeScale = (1f / 3f);
                bulletTime     = true;
            }
            else
            {
                speed         /= 2f;
                vel.x         /= 2f;
                fireRate      /= .5f;
                burstRate     /= .5f;
                Time.timeScale = 1f;
                bulletTime     = false;
            }
        }

        // Left Button
        if (Input.GetKeyDown(KeyCode.A) || Input.GetKeyDown(KeyCode.LeftArrow))
        {
            if (isCrouching)
            {
                makeNotCrouch();
                fD = FacingDir.downLeft;
            }
            else
            {
                fD = FacingDir.left;
            }
            lastDir = FacingDir.left;
            vel.x  += -speed;
        }
        if (Input.GetKeyUp(KeyCode.A) || Input.GetKeyUp(KeyCode.LeftArrow))
        {
            vel.x += speed;
        }

        // Right Button
        if (Input.GetKeyDown(KeyCode.D) || Input.GetKeyDown(KeyCode.RightArrow))
        {
            if (isCrouching)
            {
                makeNotCrouch();
                fD = FacingDir.downRight;
            }
            else
            {
                fD = FacingDir.right;
            }
            lastDir = FacingDir.right;
            vel.x  += speed;
        }
        if (Input.GetKeyUp(KeyCode.D) || Input.GetKeyUp(KeyCode.RightArrow))
        {
            vel.x += -speed;
        }

        // Down Button
        if (Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.DownArrow))
        {
            if (vel.x == 0 && vel.y == 0 && !isCrouching)
            {
                makeCrouch();
            }
            else if (vel.x == 0 && vel.y != 0)
            {
                fD = FacingDir.down;
            }
            else if (vel.x > 0)
            {
                fD = FacingDir.downRight;
            }
            else if (vel.x < 0)
            {
                fD = FacingDir.downLeft;
            }
        }

        if (Input.GetKeyUp(KeyCode.S) || Input.GetKeyUp(KeyCode.DownArrow))
        {
            if (isCrouching)
            {
                makeNotCrouch();
            }
            else if (fD == FacingDir.downLeft)
            {
                fD = FacingDir.left;
                spriteRend.sprite = SliceLeft;
            }
            else if (fD == FacingDir.downRight)
            {
                spriteRend.sprite = SliceRight;
                fD = FacingDir.right;
            }
            else if (fD == FacingDir.down)
            {
                fD = lastDir;
            }
        }

        // Up Button
        if (Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.UpArrow))
        {
            if (vel.x == 0)
            {
                if (fD == FacingDir.left || fD == FacingDir.upLeft || fD == FacingDir.downLeft || fD == FacingDir.upFaceLeft)
                {
                    fD = FacingDir.upFaceLeft;
                }
                else
                {
                    fD = FacingDir.upFaceRight;
                }
            }
            else if (vel.x > 0)
            {
                fD = FacingDir.upRight;
            }
            else if (vel.x < 0)
            {
                fD = FacingDir.upLeft;
            }
        }
        if (Input.GetKeyUp(KeyCode.W) || Input.GetKeyUp(KeyCode.UpArrow))
        {
            if (fD == FacingDir.upFaceLeft || fD == FacingDir.upLeft)
            {
                fD = FacingDir.left;
            }
            else
            {
                fD = FacingDir.right;
            }
        }


        // Jump Button
        if (Input.GetKeyDown(KeyCode.X) || Input.GetKeyDown(KeyCode.Period))
        {
            if (vel.y == 0 && !isCrouching && !isInWater)             // Jump
            {
                vel.y += jumpSpeed;
                makeJump();
                isInAir = true;
            }
            else if (isCrouching)                // Drop below
            {
                makeNotCrouch();
                // Fall through platforms
                Physics.IgnoreLayerCollision(LayerMask.NameToLayer("Character"), LayerMask.NameToLayer("Platforms"), true);
                layerTimerCrouch = Time.time;
            }
        }

        // Shoot Button
        //Machine Gun fire
        if ((Input.GetKey(KeyCode.Z) || Input.GetKey(KeyCode.Comma)) && gunType == GunType.machineGun)
        {
            shootBullet();
        }
        //Normal  fire
        if (Input.GetKeyDown(KeyCode.Z) || Input.GetKeyDown(KeyCode.Comma))
        {
            shootBullet();
        }
    }
Exemplo n.º 16
0
    // Update is called once per frame
    void Update()
    {
        switch (enemyType)
        {
        case EnemyType.Chase:
            patrol.enabled = false;
            aiDestinationSetter.enabled = true;
            if (hybrid)
            {
                Hybrid();
            }
            break;

        case EnemyType.Patrol:
            aiDestinationSetter.enabled = false;
            patrol.enabled = true;
            if (hybrid)
            {
                Hybrid();
            }
            break;
        }
        if (aiPath.desiredVelocity.y > 0)
        {
            if (aiPath.desiredVelocity.x > 0)
            {
                facingDir = FacingDir.Right;
            }
            else if (aiPath.desiredVelocity.x < 0)
            {
                facingDir = FacingDir.Left;
            }
            else
            {
                facingDir = FacingDir.Up;
            }
        }
        else
        {
            if (aiPath.desiredVelocity.x > 0)
            {
                facingDir = FacingDir.Right;
            }
            else if (aiPath.desiredVelocity.x < 0)
            {
                facingDir = FacingDir.Left;
            }
            else
            {
                facingDir = FacingDir.Down;
            }
        }

        switch (facingDir)
        {
        case FacingDir.Down:
            animator.SetFloat("MoveDir", 4);
            break;

        case FacingDir.Up:
            animator.SetFloat("MoveDir", 1);
            break;

        case FacingDir.Left:
            animator.SetFloat("MoveDir", 2);
            break;

        case FacingDir.Right:
            animator.SetFloat("MoveDir", 3);
            break;
        }
    }
Exemplo n.º 17
0
    // INTERNAL

    private void Internal_SetupTeam(int i_TeamIndex, tnTeamDescription i_TeamDescription)
    {
        if (!IsValidIndex(i_TeamIndex))
        {
            return;
        }

        if (i_TeamDescription == null)
        {
            return;
        }

        int        teamId   = i_TeamDescription.teamId;
        tnTeamData teamData = tnGameData.GetTeamDataMain(teamId);

        if (teamData == null)
        {
            return;
        }

        List <int> lineUp = teamData.GetDefaultLineUp(i_TeamDescription.charactersCount);

        if (lineUp == null)
        {
            return;
        }

        SetTeamInfo(i_TeamIndex, teamData);

        // Lineup.

        {
            tnUITeamAnchors teamAnchors = m_TeamAnchorsSets[i_TeamIndex];

            tnUIAnchorsSet anchorsSet = null;

            if (teamAnchors != null)
            {
                anchorsSet = teamAnchors.GetAnchorsSetBySize(i_TeamDescription.charactersCount);
            }

            if (anchorsSet != null)
            {
                for (int index = 0; index < anchorsSet.anchorsCount && index < lineUp.Count; ++index)
                {
                    RectTransform anchor = anchorsSet.GetAnchorByIndex(index);
                    if (anchor != null)
                    {
                        int characterId = lineUp[index];

                        if (!teamData.Contains(characterId))
                        {
                            continue;
                        }

                        tnCharacterData characterData = tnGameData.GetCharacterDataMain(characterId);

                        if (characterData == null)
                        {
                            continue;
                        }

                        FacingDir facingDir = m_Facing[i_TeamIndex];

                        Color  teamColor = i_TeamDescription.teamColor;
                        Sprite flag      = teamData.baseSprite;

                        tnUICharacter character = SpawnCharacter(characterData, facingDir, teamColor, flag);

                        tnUICharacterSlot slot = SpawnCharacterSlot();
                        slot.transform.position = anchor.position;
                        slot.character          = character;
                        slot.characterId        = characterId;

                        bool isHuman = m_Humans[i_TeamIndex, index];
                        if (isHuman)
                        {
                            Color playerColor = m_PlayersColors[i_TeamIndex, index];
                            slot.SetPlayerColor(playerColor);
                        }
                        else
                        {
                            slot.ClearPlayerColor();
                        }

                        SlotList slotList = m_LineUp[i_TeamIndex];
                        slotList.Add(slot);
                    }
                }
            }

            m_TeamAnchors[i_TeamIndex] = anchorsSet;
        }

        // Bench.

        {
            tnUIBench bench = m_TeamAnchorsBench[i_TeamIndex];

            int lastBenchIndexUsed = -1;
            for (int index = 0; index < bench.entriesCount && index < teamData.charactersCount; ++index)
            {
                tnUIBenchEntry benchEntry = bench.GetEntryByIndex(index);
                if (benchEntry != null && benchEntry.anchor != null)
                {
                    int characterId = Hash.s_NULL;

                    for (int characterIndex = lastBenchIndexUsed + 1; characterIndex < teamData.charactersCount; ++characterIndex)
                    {
                        int id = teamData.GetCharacterKey(characterIndex);
                        if (!lineUp.Contains(id))
                        {
                            characterId        = id;
                            lastBenchIndexUsed = characterIndex;
                            break;
                        }
                    }

                    tnCharacterData characterData = tnGameData.GetCharacterDataMain(characterId);

                    if (characterData == null)
                    {
                        continue;
                    }

                    FacingDir facingDir = m_Facing[i_TeamIndex];

                    Color  teamColor = i_TeamDescription.teamColor;
                    Sprite flag      = teamData.baseSprite;

                    tnUICharacter character = SpawnCharacter(characterData, facingDir, teamColor, flag);

                    tnUICharacterSlot slot = SpawnCharacterSlot();
                    slot.transform.position = benchEntry.anchor.position;
                    slot.character          = character;
                    slot.characterId        = characterId;
                    slot.ClearPlayerColor();

                    SlotList slotList = m_Bench[i_TeamIndex];
                    slotList.Add(slot);
                }
            }
        }
    }
Exemplo n.º 18
0
    override protected void ResolveCollisionWith(PE_Obj that)
    {
        switch (that.coll)
        {
        case PE_Collider.platform:
            // In Progress
            Vector3 thatP = that.transform.position;
            Vector3 delta = (pos1 - this.transform.lossyScale / 2) - (thatP - that.transform.lossyScale / 2);
            if (isInWater)
            {
                if (!isClimbing)
                {
                    climbTimer = Time.time;
                    isClimbing = true;
                }
                Vector3 newPos = transform.position;

                //Take a quarter of a second to climb up ledge
                if (Time.time > climbTimer + .15f)
                {
                    isInWater  = false;
                    isClimbing = false;
                    RepositionToTop(that);
                    break;
                }
                newPos = transform.position;
                if (transform.position.x > thatP.x)
                {
                    newPos.x = thatP.x + (that.transform.lossyScale.x / 2);
                }
                else if (transform.position.x < thatP.x)
                {
                    newPos.x = thatP.x - (that.transform.lossyScale.x / 2);
                }
                this.transform.position = newPos;
            }
            else if (delta.y >= 0)                                         // Top
            {
                if (vel.y <= 0)
                {
                    // Landed!
                    if (isInAir)
                    {
                        isInAir = false;
                        makeNotJump();
                    }
                    if (fD == FacingDir.down)
                    {
                        fD = lastDir;
                    }
                    RepositionToTop(that);
                }
            }
            break;


        //TODO Change this to handle sprites properly
        case PE_Collider.water:
            //If you are in the water then you can no longer jump
            isInWater = true;
            if (isInAir)
            {
                isInAir = false;
                makeNotJump();
            }

            RepositionToTop(that);
            break;

        case PE_Collider.enemyBullet:
            if (!isDead)
            {
                death(false, transform.position);
            }
            break;

        case PE_Collider.powerup:
            PowerupType pt = that.GetComponent <PE_Powerup>().powerupType;
            print("You got a powerup of type: " + pt);
            switch (pt)
            {
            case PowerupType.rapidFire:
                fireRate  *= .85f;
                burstRate *= .85f;
                break;

            case PowerupType.machineGun:
                gunType   = GunType.machineGun;
                fireRate  = .12f;
                burstRate = .15f;
                break;

            case PowerupType.spreadGun:
                gunType   = GunType.spreadGun;
                fireRate  = normFireRate;
                burstRate = normBurstRate;
                break;

            case PowerupType.laser:
                gunType   = GunType.laser;
                fireRate  = 1f;
                burstRate = 1f;
                break;

            case PowerupType.flame:
                gunType   = GunType.flame;
                fireRate  = .3f;
                burstRate = 1f;
                break;
            }
            // Remove powerup from game
            PhysEngine.objs.Remove(that.GetComponent <PE_Obj>());
            Destroy(that.gameObject);
            break;
        }
    }
Exemplo n.º 19
0
    void Update()
    {
        if (!levelController.paused && gameController.gameStart)
        {
            movement.x = Input.GetAxisRaw("Horizontal");
            movement.y = Input.GetAxisRaw("Vertical");

            animator.SetFloat("Horizontal", movement.x);
            animator.SetFloat("Vertical", movement.y);
            animator.SetFloat("Speed", movement.sqrMagnitude);

            if (Input.GetButtonDown("Horizontal"))
            {
                if (Input.GetButtonDown("Vertical"))
                {
                    if (movement.y > 0)
                    {
                        facingDir = FacingDir.Up;
                    }
                    else
                    {
                        facingDir = FacingDir.Down;
                    }
                }
                else
                {
                    if (movement.x > 0)
                    {
                        facingDir = FacingDir.Right;
                    }
                    else
                    {
                        facingDir = FacingDir.Left;
                    }
                }
            }
            else
            {
                if (Input.GetButtonDown("Vertical"))
                {
                    if (movement.y > 0)
                    {
                        facingDir = FacingDir.Up;
                    }
                    else
                    {
                        facingDir = FacingDir.Down;
                    }
                }
            }
        }

        switch (facingDir)
        {
        case FacingDir.Up:
            animator.SetFloat("IdleType", 3);
            break;

        case FacingDir.Down:
            animator.SetFloat("IdleType", 0);
            break;

        case FacingDir.Left:
            animator.SetFloat("IdleType", 1);
            break;

        case FacingDir.Right:
            animator.SetFloat("IdleType", 2);
            break;
        }

        if (progressBar)
        {
            slider.value += Time.deltaTime;
        }
    }
Exemplo n.º 20
0
 public bool IsFacing(FacingDir dir)
 {
     return(curFacingDir == dir);
 }
Exemplo n.º 21
0
 public void DashInDirection(FacingDir dir)
 {
     DoDash(dir);
 }