Exemplo n.º 1
0
    public void MoveAction(Groundy groundy)
    {
        Vector2 moveQuantity = Vector2.right * groundy.moveSpeed * Time.deltaTime;
        Vector3 noZQuantity  = new Vector3(moveQuantity.x, moveQuantity.y, 0f);

        groundy.transform.Translate(noZQuantity);
    }
Exemplo n.º 2
0
    public virtual bool CheckTransitionToMoving(Groundy groundy)
    {
        InvertDirectionIfNeeded(groundy);

        groundy.TransitionToState(groundy.MovingState);
        return(true);
    }
Exemplo n.º 3
0
 public override void Update(Groundy groundy)
 {
     if (CheckTransitionToMoving(groundy))
     {
         return;
     }
     base.MoveAction(groundy);
 }
Exemplo n.º 4
0
    public virtual bool CheckTransitionToDying(Groundy groundy)
    {
        if (groundy.hp <= 0)
        {
            groundy.TransitionToState(groundy.DyingState);
            return(true);
        }

        return(false);
    }
Exemplo n.º 5
0
    public override bool CheckTransitionToMoving(Groundy groundy)
    {
        if (!ThereIsGroundToWalk(groundy) || ReachedObstacle(groundy))
        {
            groundy.needToTurn = true;
            base.CheckTransitionToMoving(groundy);
            return(true);
        }

        return(false);
    }
Exemplo n.º 6
0
    bool ThereIsGroundToWalk(Groundy groundy)
    {
        RaycastHit2D[] groundRay = Physics2D.RaycastAll(groundy.groundTransform.position, Vector2.down, distanceToCheckGround);

        foreach (var obj in groundRay)
        {
            if (obj.collider != null && obj.collider.CompareTag("Ground"))
            {
                return(true);
            }
        }
        return(false);
    }
Exemplo n.º 7
0
 public void InvertDirectionIfNeeded(Groundy groundy)
 {
     if (groundy.needToTurn)
     {
         if (groundy.transform.eulerAngles.y == 0)
         {
             groundy.transform.eulerAngles = new Vector3(0f, 180f, 0f);
         }
         else if (groundy.transform.eulerAngles.y == 180)
         {
             groundy.transform.eulerAngles = new Vector3(0f, 0f, 0f);
         }
     }
     groundy.needToTurn = false;
 }
Exemplo n.º 8
0
    public override void Update(Groundy groundy)
    {
        if (base.CheckTransitionToDying(groundy))
        {
            return;
        }

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

        if (base.CheckTransitionToMoving(groundy))
        {
            return;
        }
    }
Exemplo n.º 9
0
    bool ReachedObstacle(Groundy groundy)
    {
        Vector2 direction = CalculateDirection(groundy);

        RaycastHit2D[] frontRay = Physics2D.RaycastAll(groundy.frontTransform.position, direction, distanceToCheckObstacle);

        foreach (var obj in frontRay)
        {
            if (obj.collider != null)
            {
                bool isWall = obj.collider.CompareTag("Ground");

                bool hasHitObstacle = isWall;
                if (hasHitObstacle)
                {
                    return(true);
                }
            }
        }

        return(false);
    }
Exemplo n.º 10
0
    private void OnTriggerEnter2D(Collider2D other)
    {
        GameObject otherObj = other.gameObject;
        if (otherObj.CompareTag("Groundy")) {
            Groundy groundy = otherObj.GetComponent<Groundy>();

            if (groundy.hp > 0) {
                // groundy.dieParticles.transform.parent = null;
                // groundy.dieParticles.transform.position = groundy.transform.position;
                // groundy.dieParticles.Play();
                hitParticles.transform.parent = null;
                hitParticles.transform.position = transform.position;
                hitParticles.transform.localScale = new Vector3(1, 1, 1);
                hitParticles.Play();
                groundy.TakeDamage();
            }
            Destroy(gameObject);
        }
        else if (otherObj.CompareTag("Fly")) {
            Fly fly = otherObj.GetComponent<Fly>();

            if (fly.hp > 0) {
                hitParticles.transform.parent = null;
                hitParticles.transform.position = transform.position;
                hitParticles.transform.localScale = new Vector3(1, 1, 1);
                hitParticles.Play();
                // fly.dieParticles.transform.parent = null;
                // fly.dieParticles.transform.position = fly.transform.position;
                // fly.dieParticles.Play();
                fly.TakeDamage();
            }
            Destroy(gameObject);
        }
        else if (otherObj.CompareTag("Ground")) {
            // taca partículas
            Destroy(gameObject);
        }
    }
Exemplo n.º 11
0
 public abstract void Update(Groundy groundy);
Exemplo n.º 12
0
 void BeingHitAction(Groundy groundy)
 {
     groundy.rb.velocity          = Vector2.zero;
     groundy.spriteRenderer.color = new Color(1, 0, 0, 1);
 }
Exemplo n.º 13
0
 public override void EnterState(Groundy groundy)
 {
     // Manager.audio.Play("EnemyHit");
     Setup(groundy);
     BeingHitAction(groundy);
 }
Exemplo n.º 14
0
 public override void EnterState(Groundy groundy)
 {
     Manager.audio.Play("enemy_dying");
     groundy.dieParticles.Play();
     Enemy.DieAction(groundy.gameObject);
 }
Exemplo n.º 15
0
 public override void Update(Groundy groundy)
 {
 }
Exemplo n.º 16
0
 public abstract void EnterState(Groundy groundy);
Exemplo n.º 17
0
 void Setup(Groundy groundy)
 {
 }
Exemplo n.º 18
0
 public override void EnterState(Groundy groundy)
 {
     groundy.animator.Play("Walking");
 }
Exemplo n.º 19
0
 public Vector2 CalculateDirection(Groundy groundy)
 {
     return((groundy.moreFrontTransform.position - groundy.frontTransform.position).normalized);
 }