Esempio n. 1
0
    public void Attack()
    {
        IsAttacking = true;
        Animate.ChangeAnimationState("Attacking", animator, currentDirection);

        PrepareAttackHitboxes(currentDirection);
    }
Esempio n. 2
0
 void StoppedAttactingAlert()
 {
     Debug.Log("Stoped attacking");
     Animate.ChangeAnimationState("Idle", animator, currentDirection);
     IsIdle      = true;
     IsAttacking = false;
 }
 public void OnTriggerEnter2D(Collider2D collision)
 {
     if (collision.GetType() == typeof(PolygonCollider2D))
     {
         //We are hit by an attack!!!
         Debug.Log("ai hit by an attack!!!!");
         Animate.ChangeAnimationState("Hit", AIMovementHandler.animator, AIMovementHandler.currentDirection);
     }
 }
Esempio n. 4
0
    public void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.GetType() == typeof(PolygonCollider2D))
        {
            //We are hit by an attack!!!
            Debug.Log("character got hit by an attack!!!!");
            Animate.ChangeAnimationState("Hit", animator, currentDirection);

            TakeDamage(collision.gameObject.GetComponent <AIVariables>().AttackDamage);
        }
    }
Esempio n. 5
0
    void StartCasting()
    {
        CastingLocationChangedEvent e = new CastingLocationChangedEvent();

        e.go = gameObject;
        e.FireEvent();

        StartedCastingEvent ev = new StartedCastingEvent();

        ev.FireEvent();

        Animate.ChangeAnimationState("Casting", animator, currentDirection);
        casting = true;
    }
Esempio n. 6
0
    void StopCasting()
    {
        Animate.ChangeAnimationState("Idle", animator, currentDirection);
        casting = false;
        Destroy(CastingCircleProjection);
        CastingCircleProjection = null;
        CastingProjectionDestroyedEvent e = new CastingProjectionDestroyedEvent();

        e.FireEvent();
        castingLocationChanged = false;

        StoppedCastingEvent ev = new StoppedCastingEvent();

        ev.FireEvent();
    }
Esempio n. 7
0
    void SetAnimationDirection(Vector2 dir)
    {
        float angle = Vector2.SignedAngle(dir, new Vector2(1, 0));

        if (Mathf.Abs(angle) <= rightAngle)
        {
            if (currentDirection != Direction.EAST)
            {
                currentDirection = Direction.EAST;

                //animator.SetTrigger("Walking_Right");
                Animate.ChangeAnimationState("Walk", animator, currentDirection);
            }
        }
        else if (Mathf.Abs(angle) >= leftAngle)
        {
            if (currentDirection != Direction.WEST)
            {
                currentDirection = Direction.WEST;

                //animator.SetTrigger("Walking_Left");
                Animate.ChangeAnimationState("Walk", animator, currentDirection);
            }
        }
        else if (angle > 0)
        {
            if (currentDirection != Direction.SOUTH)
            {
                currentDirection = Direction.SOUTH;

                //animator.SetTrigger("Walking_Down");
                Animate.ChangeAnimationState("Walk", animator, currentDirection);
            }
        }
        else
        {
            if (currentDirection != Direction.NORTH)
            {
                currentDirection = Direction.NORTH;
                Animate.ChangeAnimationState("Walk", animator, currentDirection);
            }
        }
    }
Esempio n. 8
0
    // Update is called once per frame
    void Update()
    {
        Horizontal = Input.GetAxisRaw("Horizontal");
        Vertical   = Input.GetAxisRaw("Vertical");

        if (casting && Input.GetKeyUp("space"))
        {
            StopCasting();
        }

        if (Input.GetKeyDown("space"))
        {
            StartCasting();
        }

        if (IsAttacking)
        {
            Debug.Log("update loop stooped cause attacting");
            return;
        }

        if (Input.GetKeyDown(KeyCode.Period))
        {
            IsAttacking = true;
            Animate.ChangeAnimationState("Attacking", animator, currentDirection);

            PrepareAttackHitboxes(currentDirection);

            Horizontal = 0;
            Vertical   = 0;
        }



        //TODO: dont want to be doing this, but i must for now, means when holding space (casting) you cant move
        else if (Input.GetKey(KeyCode.Space) == false)
        {
            if (Vertical != 0 && Horizontal == 0)
            {
                if (Vertical > 0)
                {
                    if (currentDirection != Direction.NORTH || IsIdle)
                    {
                        currentDirection = Direction.NORTH;
                        Animate.ChangeAnimationState("Walk", animator, currentDirection);
                    }
                }
                else
                {
                    if (currentDirection != Direction.SOUTH || IsIdle)
                    {
                        currentDirection = Direction.SOUTH;
                        Animate.ChangeAnimationState("Walk", animator, currentDirection);
                    }
                }

                IsIdle = false;
            }
            else if (Horizontal != 0)
            {
                if (Horizontal > 0)
                {
                    if (currentDirection != Direction.EAST || IsIdle)
                    {
                        currentDirection = Direction.EAST;
                        Animate.ChangeAnimationState("Walk", animator, currentDirection);
                    }
                    //Flip();
                }
                else if (Horizontal < 0)
                {
                    if (currentDirection != Direction.WEST || IsIdle)
                    {
                        currentDirection = Direction.WEST;
                        Animate.ChangeAnimationState("Walk", animator, currentDirection);
                    }

                    //Flip();
                }

                IsIdle = false;
            }
            else
            {
                if (IsIdle == false)
                {
                    Animate.ChangeAnimationState("Idle", animator, currentDirection);
                    //currentDirection = Direction.IDLE;
                    IsIdle = true;
                }
            }

            //Vector3 tempVect = new Vector3(Horizontal, Vertical, 0);
            //tempVect = tempVect.normalized * speed * Time.deltaTime;

            //this.transform.position += tempVect;
        }
        else if (casting)
        {
            // character is currently casting
            float h = Input.GetAxis("Horizontal");
            float v = Input.GetAxis("Vertical");

            if (h != 0 || v != 0)
            {
                if (castingLocationChanged == false)
                {
                    //We are wanting to move the casting projection, so lets see if we need to instantiate it
                    if (CastingCircleProjection == null)
                    {
                        CastingCircleProjection = Instantiate(CastingCircleProjectionPrefab, this.transform.position, Quaternion.identity);
                        CastingProjectionCreatedEvent e = new CastingProjectionCreatedEvent();
                        e.castingProjection = CastingCircleProjection;
                        e.FireEvent();
                    }

                    CastingCircleProjection.transform.position += new Vector3(h, v).normalized *speed *Time.deltaTime;
                }
            }
        }

        if (Input.GetKeyDown("f"))
        {
            if (CastingCircleProjection != null)
            {
                CastingLocationChangedEvent e = new CastingLocationChangedEvent();
                e.go = CastingCircleProjection;
                e.FireEvent();
                castingLocationChanged = true;
                Destroy(CastingCircleProjection);
                CastingCircleProjection = null;
            }
        }

        if (Input.GetKeyDown("j"))
        {
            SpellCastCall e = new SpellCastCall();
            e.FireEvent();
            //CrawlController.instance.ConsumeCrawl(transform.position, consumeAmount, consumePixelsPerFrame);
        }
        if (Input.GetKeyDown("p"))
        {
            Vector2 bottom = transform.position;
            crawlController.CreateCrawl(bottom);
        }

        if (Input.GetKeyDown("r"))
        {
            Vector2 bottom = transform.position;
            crawlController.AddFire(bottom);
            //animator.SetBool("Casting", true);
        }

        if (Input.GetKeyDown("q"))
        {
            Vector2 bottom = transform.position;

            WaterControllerScript.instance.AddWater(bottom, 100);
        }

        //if (Input.GetKeyDown("e"))
        //{

        //    if(runningCrawl == null)
        //    {
        //        runningCrawl = crawlController.CreateCrawl(transform.position);
        //        runningStartPosition = transform.position;
        //        runningStartTime = Time.time;
        //    }

        //} else if(runningCrawl != null)
        //{

        //    if (Time.time - runningStartTime >= 3)
        //    {
        //        runningCrawl = null;

        //    }
        //    else
        //    {
        //        int startingPixel = crawlController.GetWidth()/2;

        //        int startX = startingPixel + (int)transform.position.x;
        //        int startY = startingPixel + (int)transform.position.y;


        //        runningCrawl.GrowByPosition(new Vector2(startX, startY));
        //    }

        //}


        //void Flip()
        //{
        //    facingRight = !facingRight;
        //    Vector3 theScale = transform.localScale;
        //    theScale.x *= -1;
        //    transform.localScale = theScale;
        //}
    }
Esempio n. 9
0
 public void SetIdle()
 {
     Debug.Log("Setting idle");
     IsIdle = true;
     Animate.ChangeAnimationState("Idle", animator, currentDirection);
 }
Esempio n. 10
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            //targetPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);


            //hasTarget = true;
            //Vector2 testPos = Camera.main.ScreenToWorldPoint(transform.position);
            //float angle = Vector2.SignedAngle(testPos, (Vector2)transform.position - targetPosition);
            //isIdle = false;
        }

        if (IsAttacking)
        {
            Debug.Log("update loop stooped cause attacting");
            return;
        }

        if (hasTarget)
        {
            Vector2 dir;

            if (turning)
            {
                if (timeElapsed < turnRate)
                {
                    timeElapsed += Time.deltaTime;
                    dir          = Vector3.Lerp(previousDirection, (targetPosition - (Vector2)transform.position).normalized, timeElapsed / turnRate);
                }
                else
                {
                    dir     = (targetPosition - (Vector2)transform.position).normalized;
                    turning = false;
                }
            }
            else
            {
                dir = (targetPosition - (Vector2)transform.position).normalized;
            }

            SetAnimationDirection(dir);

            float frameSpeed = speed * Time.deltaTime;

            if (Vector2.Distance(transform.position, targetPosition) <= frameSpeed)
            {
                //we will be at destination after this is done
                //so lets set is postion to target and set target to null
                transform.position = targetPosition;
                hasTarget          = false;
                //animator.SetTrigger("Idle");

                Animate.ChangeAnimationState("Idle", animator, currentDirection);
                isIdle = true;
            }
            else
            {
                transform.position += (Vector3)(dir * frameSpeed);
            }
        }
    }