Ejemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        float width = (float)health / (float)400;

        healthbar.rectTransform.sizeDelta = new Vector2(width * 600, 40);

        switch (state)
        {
        case LegStates.following:
            Vector3 direction = (player.transform.position - transform.position).normalized;
            direction.y = 0;
            gameObject.transform.position += direction * speed * Time.deltaTime;
            gameObject.transform.LookAt(transform.position + direction);

            animator.SetBool("Walking", true);

            if ((player.transform.position - transform.position).magnitude <= 5)
            {
                state = LegStates.kicking;
                animator.SetBool("Walking", false);
                animator.SetBool("Kicking", true);
                kicking = true;
            }
            break;

        case LegStates.kicking:

            cooldownTimer -= Time.deltaTime;
            if (cooldownTimer <= 0)
            {
                playerkicked = false;
                kicking      = false;
                animator.SetBool("Kicking", false);
                state         = LegStates.cooldown;
                cooldownTimer = 5;
            }
            break;

        case LegStates.cooldown:
            cooldownTimer -= Time.deltaTime;

            if (cooldownTimer <= 0)
            {
                state         = LegStates.following;
                cooldownTimer = 1;
            }
            break;
        }
    }
Ejemplo n.º 2
0
        public void Update(float dtime, InputHelper input)
        {
            HandleInput(input);

            Tangent.X = (float)Math.Cos(BodyTorso.Rotation);
            Tangent.Y = (float)Math.Sin(BodyTorso.Rotation);
            Normal.X = -Tangent.Y;
            Normal.Y = Tangent.X;

            if (LegState == LegStates.Leaping && BodyTorso.LinearVelocity.Y > 0 && IsLandable)
            {
                LegState = LegStates.Squatting;
            }

            if (LegState != LegStateOld)
            {
                switch (LegState)
                {
                    case LegStates.Standing:
                        SpriteLeg.Texture = TextureStanding;
                        break;
                    case LegStates.Squatting:
                        SpriteLeg.Texture = TextureSquatting;
                        break;
                    case LegStates.Leaping:
                        SpriteLeg.Texture = TextureLeaping;
                        break;
                    case LegStates.Walking1:
                        SpriteLeg.Texture = TextureWalking1;
                        break;
                    case LegStates.Walking2:
                        SpriteLeg.Texture = TextureWalking2;
                        break;
                    case LegStates.Walking3:
                        SpriteLeg.Texture = TextureWalking3;
                        break;
                    default:
                        break;
                }
            }
            LegStateOld = LegState;
        }
Ejemplo n.º 3
0
 public void Hop()
 {
     LegState = LegStates.Leaping;
     BodyTorso.ApplyForce(Normal * HopForce * -1);
     IsLandable = false;
     timerLandable.Start();
 }
Ejemplo n.º 4
0
 public void Stand()
 {
     LegState = LegStates.Standing;
     physicsSimulator.Add(GeomLegsStanding);
 }
Ejemplo n.º 5
0
 public void Squat()
 {
     LegState = LegStates.Squatting;
     BodyTorso.ApplyForce(Normal * JumpForce);
     physicsSimulator.Remove(GeomLegsStanding);
 }
Ejemplo n.º 6
0
        private bool OnCollision(Geom geom1, Geom geom2, ContactList contactList)
        {
            bool result = true;

            IsGrounded = true;

            if (geom1 == GeomLegsStanding && IsLandable && !IsWalking)
            {
                LegState = LegStates.Standing;
            }

            return result;
        }
Ejemplo n.º 7
0
 void timerWalking_Elapsed(object sender, ElapsedEventArgs e)
 {
     if (IsGrounded)
     {
         if (LegState == LegStates.Walking1) LegState = LegStates.Walking2;
         else if (LegState == LegStates.Walking2) LegState = LegStates.Walking3;
         else if (LegState == LegStates.Walking3) LegState = LegStates.Walking1;
         else LegState = LegStates.Walking1;
     }
 }