Ejemplo n.º 1
0
    void Update()
    {
        // ragePixel.SetHorizontalFlip(true);
        if (!isAlive)
        {
            this.rigidbody.velocity = new Vector3(0, 0, 0);
            timeAfterDeath         += Time.deltaTime;
            if (timeAfterDeath > 5)
            {
                Destroy(this.gameObject);
            }
            return;
        }

        if (oneDirectionTime <= 0)
        {
            ChangeDirection();
        }
        else
        {
            oneDirectionTime -= Time.deltaTime;
        }

        GameObject Hero = GameObject.FindWithTag("Hero");
        float      d    = Vector3.Distance(Hero.transform.position, this.gameObject.transform.position);

        if (d < 150)
        {
            Vector3 enemyPosition = this.gameObject.transform.position;
            Vector3 heroPosition  = Hero.transform.position;

            Vector3 diff = heroPosition - enemyPosition;

            this.rigidbody.velocity = diff / 5;

            int dir = (int)this.rigidbody.velocity.x;
            switch (dir)
            {
            case 0:
                ragePixel.SetHorizontalFlip(false);
                break;

            case 1:
                ragePixel.SetHorizontalFlip(true);
                break;
            }
        }
    }
Ejemplo n.º 2
0
    void Update()
    {
        if (!isInSafeZone)
        {
            reduceHealth(1);
        }
        //Update Right Stick
        if (!castDirectionSet)
        {
            r_Xaxis = Input.GetAxis("R_XAxis_" + controllerNumber);
            r_Yaxis = -Input.GetAxis("R_YAxis_" + controllerNumber);
        }
        if (Input.GetButtonDown("RB_" + controllerNumber) || (Input.GetKey(KeyCode.Space) && controllerNumber == 1))
        {
            casting = true;
        }

        if (!casting)
        {
            //Check the keyboard state and set the character state accordingly
            if (Input.GetAxis("L_XAxis_" + controllerNumber) < 0)
            {
                state = WalkingState.WalkLeft;
            }
            else if (Input.GetAxis("L_XAxis_" + controllerNumber) > 0)
            {
                state = WalkingState.WalkRight;
            }
            else
            {
                state = WalkingState.Standing;
            }
            if (Input.GetAxis("L_YAxis_" + controllerNumber) < 0)
            {
                if (state == WalkingState.WalkLeft)
                {
                    state = WalkingState.WalkUpLeft;
                }
                else if (state == WalkingState.WalkRight)
                {
                    state = WalkingState.WalkUpRight;
                }
                else
                {
                    state = WalkingState.WalkUp;
                }
            }
            else if (Input.GetAxis("L_YAxis_" + controllerNumber) > 0)
            {
                if (state == WalkingState.WalkLeft)
                {
                    state = WalkingState.WalkDownLeft;
                }
                else if (state == WalkingState.WalkRight)
                {
                    state = WalkingState.WalkDownRight;
                }
                else
                {
                    state = WalkingState.WalkDown;
                }
            }
            if (state == WalkingState.Standing)
            {
                getStandAnimation(lastState);

                ragePixel.PlayNamedAnimation(animation, false);
            }
            else
            {
                switch (state)
                {
                case (WalkingState.WalkLeft):
                    //Flip horizontally. Our animation is drawn to walk right.
                    ragePixel.SetHorizontalFlip(true);
                    //PlayAnimation with forceRestart=false. If the WALK animation is already running, doesn't do anything. Otherwise restarts.

                    ragePixel.PlayNamedAnimation("WALK R", false);

                    //Move direction. X grows right so left is -1.
                    moveDirection = new Vector3(-1f, 0f, 0f);
                    lastState     = LastState.L;
                    break;

                case (WalkingState.WalkRight):
                    //Not flipping horizontally. Our animation is drawn to walk right.
                    //ragePixel.SetHorizontalFlip(false);
                    //PlayAnimation with forceRestart=false. If the WALK animation is already running, doesn't do anything. Otherwise restarts.
                    ragePixel.SetHorizontalFlip(false);
                    ragePixel.PlayNamedAnimation("WALK R", false);
                    //Move direction. X grows right so left is +1.
                    moveDirection = new Vector3(1f, 0f, 0f);
                    lastState     = LastState.R;
                    break;

                case (WalkingState.WalkUp):
                    ragePixel.SetHorizontalFlip(false);
                    moveDirection = new Vector3(0f, 1f, 0f);
                    ragePixel.PlayNamedAnimation("WALK U", false);
                    lastState = LastState.U;
                    break;

                case (WalkingState.WalkDown):
                    ragePixel.SetHorizontalFlip(false);
                    moveDirection = new Vector3(0f, -1f, 0f);
                    ragePixel.PlayNamedAnimation("WALK D", false);
                    lastState = LastState.D;
                    break;

                case (WalkingState.WalkUpLeft):
                    ragePixel.SetHorizontalFlip(true);
                    moveDirection = new Vector3(-1f, 1f, 0f) / Mathf.Pow(2f, 0.5f);
                    ragePixel.PlayNamedAnimation("WALK UR", false);
                    lastState = LastState.UL;
                    break;

                case (WalkingState.WalkUpRight):
                    ragePixel.SetHorizontalFlip(false);
                    moveDirection = new Vector3(1f, 1f, 0f) / Mathf.Pow(2f, 0.5f);
                    ragePixel.PlayNamedAnimation("WALK UR", false);
                    lastState = LastState.UR;
                    break;

                case (WalkingState.WalkDownLeft):
                    ragePixel.SetHorizontalFlip(true);
                    moveDirection = new Vector3(-1f, -1f, 0f) / Mathf.Pow(2f, 0.5f);
                    ragePixel.PlayNamedAnimation("WALK DR", false);
                    lastState = LastState.DL;
                    break;

                case (WalkingState.WalkDownRight):
                    ragePixel.SetHorizontalFlip(false);
                    moveDirection = new Vector3(1f, -1f, 0f) / Mathf.Pow(2f, 0.5f);
                    ragePixel.PlayNamedAnimation("WALK DR", false);
                    lastState = LastState.DR;
                    break;
                }
            }
        }
        else if (!castDirectionSet)
        {
            if ((Input.GetAxis("R_XAxis_" + controllerNumber) == 0 && Input.GetAxis("R_YAxis_" + controllerNumber) == 0))
            {
                //getStandAnimation(lastState);
                if (lastState == LastState.R || lastState == LastState.DR || lastState == LastState.UR)
                {
                    r_Xaxis = 1f;
                }
                else if (lastState == LastState.L || lastState == LastState.DL || lastState == LastState.UL)
                {
                    r_Xaxis = -1f;
                }
                if (lastState == LastState.U || lastState == LastState.UR || lastState == LastState.UL)
                {
                    r_Yaxis = 1f;
                }
                else if (lastState == LastState.D || lastState == LastState.DR || lastState == LastState.DL)
                {
                    r_Yaxis = -1f;
                }
            }
            else
            {
                lastState = getCastAngle();
            }
            getStandAnimation(lastState);
            ragePixel.PlayNamedAnimation(animation, false);
            castDirectionSet = true;
        }


        //Move the sprite into moveDirection at walkingSpeed pixels/sec
        //transform.Translate(moveDirection * Time.deltaTime * walkingSpeed);
        reset();
    }
    public void SetAnimation(float Horizontal, float Vertical)
    {
        //Check the keyboard state and set the character state accordingly
        if (Horizontal < (float)0)
        {
            state = State.WalkLeft;
        }
        else if (Horizontal > (float)0)
        {
            state = State.WalkRight;
        }
        else if (Vertical < 0)
        {
            state = State.WalkToward;
        }
        else if (Vertical > 0)
        {
            state = State.WalkAway;
        }
        else
        {
            switch (state)
            {
            case (State.WalkToward):
                prevState = State.WalkToward;
                break;

            case (State.WalkAway):
                prevState = State.WalkAway;
                break;

            case (State.WalkLeft):
                prevState = State.WalkLeft;
                break;

            case (State.WalkRight):
                prevState = State.WalkRight;
                break;
            }
            state = State.Standing;
        }


        //Debug.Log(Input.GetAxisRaw("Vertical"));

        switch (state)
        {
        case (State.Standing):
            switch (prevState)
            {
            case (State.WalkAway):
                //Reset the horizontal flip for clarity
                ragePixel.SetHorizontalFlip(false);
                ragePixel.PlayNamedAnimation("StayAway", true);
                break;

            case (State.WalkToward):
                //Reset the horizontal flip for clarity
                ragePixel.SetHorizontalFlip(false);
                ragePixel.PlayNamedAnimation("StayToward", true);
                break;

            case (State.WalkRight):
                //Reset the horizontal flip for clarity
                ragePixel.SetHorizontalFlip(false);
                ragePixel.PlayNamedAnimation("StayRight", true);
                break;

            case (State.WalkLeft):
                //Reset the horizontal flip for clarity
                ragePixel.SetHorizontalFlip(true);
                ragePixel.PlayNamedAnimation("StayRight", true);
                break;
            }
            break;

        case (State.WalkLeft):
            //Flip horizontally. Our animation is drawn to walk right.
            ragePixel.SetHorizontalFlip(true);
            //PlayAnimation with forceRestart=false. If the WALK animation is already running, doesn't do anything. Otherwise restarts.
            ragePixel.PlayNamedAnimation("WalkRight", false);
            break;

        case (State.WalkRight):
            //Not flipping horizontally. Our animation is drawn to walk right.
            ragePixel.SetHorizontalFlip(false);
            //PlayAnimation with forceRestart=false. If the WALK animation is already running, doesn't do anything. Otherwise restarts.
            ragePixel.PlayNamedAnimation("WalkRight", false);
            break;

        case (State.WalkToward):
            //Not flipping horizontally. Our animation is drawn to walk right.
            ragePixel.SetHorizontalFlip(false);
            //PlayAnimation with forceRestart=false. If the WALK animation is already running, doesn't do anything. Otherwise restarts.
            ragePixel.PlayNamedAnimation("WalkToward", false);
            break;

        case (State.WalkAway):
            //Not flipping horizontally. Our animation is drawn to walk right.
            ragePixel.SetHorizontalFlip(false);
            //PlayAnimation with forceRestart=false. If the WALK animation is already running, doesn't do anything. Otherwise restarts.
            ragePixel.PlayNamedAnimation("WalkAway", false);
            break;
        }
    }
Ejemplo n.º 4
0
    void Update()
    {
        //Check the keyboard state and set the character state accordingly
        if (Input.GetKey(KeyCode.LeftArrow))
        {
            state = WalkingState.WalkLeft;
        }
        else if (Input.GetKey(KeyCode.RightArrow))
        {
            state = WalkingState.WalkRight;
        }
        else
        {
            state = WalkingState.Standing;
        }

        Vector3 moveDirection = new Vector3();

        switch (state)
        {
        case (WalkingState.Standing):
            //Reset the horizontal flip for clarity
            ragePixel.SetHorizontalFlip(false);
            ragePixel.PlayNamedAnimation("STAY", false);
            if (arrowLeft != null)
            {
                arrowLeft.SetTintColor(Color.gray);
            }
            if (arrowRight != null)
            {
                arrowRight.SetTintColor(Color.gray);
            }
            break;

        case (WalkingState.WalkLeft):
            //Flip horizontally. Our animation is drawn to walk right.
            ragePixel.SetHorizontalFlip(true);
            //PlayAnimation with forceRestart=false. If the WALK animation is already running, doesn't do anything. Otherwise restarts.
            ragePixel.PlayNamedAnimation("WALK", false);
            //Move direction. X grows right so left is -1.
            moveDirection = new Vector3(-1f, 0f, 0f);
            if (arrowLeft != null)
            {
                arrowLeft.SetTintColor(Color.white);
            }
            if (arrowRight != null)
            {
                arrowRight.SetTintColor(Color.gray);
            }
            break;

        case (WalkingState.WalkRight):
            //Not flipping horizontally. Our animation is drawn to walk right.
            ragePixel.SetHorizontalFlip(false);
            //PlayAnimation with forceRestart=false. If the WALK animation is already running, doesn't do anything. Otherwise restarts.
            ragePixel.PlayNamedAnimation("WALK", false);
            //Move direction. X grows right so left is +1.
            moveDirection = new Vector3(1f, 0f, 0f);
            if (arrowLeft != null)
            {
                arrowLeft.SetTintColor(Color.gray);
            }
            if (arrowRight != null)
            {
                arrowRight.SetTintColor(Color.white);
            }
            break;
        }

        //Move the sprite into moveDirection at walkingSpeed pixels/sec
        transform.Translate(moveDirection * Time.deltaTime * walkingSpeed);
    }
 void Start()
 {
     ragePixel = GetComponent <RagePixelSprite>();
     ragePixel.SetHorizontalFlip(false);
     ragePixel.PlayNamedAnimation("StayToward", false);
 }