예제 #1
0
    public virtual void Cast(Vector3 start, EnumManager.Face face)
    {
        Vector3 end = new Vector3(start.x, start.y, start.z);

        if (face == EnumManager.Face.Up)
        {
            end += new Vector3(0, range * 1f, 0);
        }
        else if (face == EnumManager.Face.Down)
        {
            end += new Vector3(0, range * -1f, 0);
        }
        else if (face == EnumManager.Face.Left)
        {
            end += new Vector3(range * -1f, 0, 0);
        }
        else if (face == EnumManager.Face.Right)
        {
            end += new Vector3(range * 1f, 0, 0);
        }

        RaycastHit2D hit = Physics2D.Linecast(start, end, blockingLayer);

        if (hit.transform != null)
        {
            StartCoroutine(move(hit.point, hit.transform));
        }
        else
        {
            StartCoroutine(move(end, null));
        }
    }
예제 #2
0
 public override void Cast(Vector3 start, EnumManager.Face face)
 {
     gameObject.SetActive(true);
     GetComponent <SpriteRenderer>().enabled = false;
     GetComponent <Animator>().enabled       = false;
     base.Cast(start, face);
 }
예제 #3
0
    public override void Cast(Vector3 start, EnumManager.Face face)
    {
        gameObject.SetActive(true);

        if (face == EnumManager.Face.Left && NEED_FLIP)
        {
            GetComponent <SpriteRenderer>().flipX = !(GetComponent <SpriteRenderer>().flipX);
        }

        base.Cast(start, face);
    }
예제 #4
0
 void moveAnim(EnumManager.Face nextState)
 {
     if (nextState == face || nextState == EnumManager.Face.Down ||
         nextState == EnumManager.Face.Up)
     {
         animator.SetTrigger("Moving");
     }
     else if (nextState != animFace)
     {
         animator.SetTrigger("Swap");
     }
 }
예제 #5
0
 public void castFirst(Vector3 start, EnumManager.Face face)
 {
     GetComponentInParent <Player>().Mana -= currSpell.GetComponent <Spell>().Cost;
     if (GetComponentInParent <Player>().Mana < 0)
     {
         Debug.Log("Unable to cast spell! Need more mana!");
         GetComponentInParent <Player>().Mana += currSpell.GetComponent <Spell>().Cost;
         return;
     }
     currSpell.transform.position = transform.position;
     currSpell.GetComponent <Spell>().Cast(start, face);
     Debug.Log("Current Mana: " + this.GetComponentInParent <Player>().Mana);
 }
예제 #6
0
    void changeAnim(EnumManager.Face nextState)
    {
        if (face != nextState)
        {
            face = nextState;

            if (face != EnumManager.Face.Down && face != EnumManager.Face.Up &&
                animFace != nextState)
            {
                animator.SetTrigger("Change");
                animFace = nextState;
            }
        }
    }
예제 #7
0
    //Simple calculation between two objects. Sends out where the enemy is relative to the object that calls this method
    public virtual float distFrom(GameObject go, out EnumManager.Face face)
    {
        float myX    = transform.position.x;
        float myY    = transform.position.y;
        float otherX = go.transform.position.x;
        float otherY = go.transform.position.y;

        float dist = Mathf.Sqrt(Mathf.Pow(myX - otherX, 2) + Mathf.Pow(myY - otherY, 2));

        float xDist = myX - otherX;         //Positive if to the left, negative if to the right
        float yDist = myY - otherY;         //Positive if below, negative if above

        if (Mathf.Abs(xDist) > Mathf.Abs(yDist))
        {
            if (xDist > 0)
            {
                face = EnumManager.Face.Left;
            }
            else
            {
                face = EnumManager.Face.Right;
            }
        }
        else
        {
            if (yDist > 0)
            {
                face = EnumManager.Face.Down;
            }
            else
            {
                face = EnumManager.Face.Up;
            }
        }

        return(dist);
    }
예제 #8
0
    // Update is called once per frame
    protected void Update()
    {
        if (!GameManager.instance.playerTurn)
        {
            return;
        }

        if (!GameManager.instance.TargetControl)
        {
            if (Input.GetKeyDown(KeyCode.A))                   //Left
            {
                if (attemptMove <Unit>(-1, 0))
                {
                    moveAnim(EnumManager.Face.Left);
                }
                face     = EnumManager.Face.Left;
                animFace = EnumManager.Face.Left;
            }
            else if (Input.GetKeyDown(KeyCode.D))                   //Right
            {
                if (attemptMove <Unit>(1, 0))
                {
                    moveAnim(EnumManager.Face.Right);
                }
                face     = EnumManager.Face.Right;
                animFace = EnumManager.Face.Right;
            }
            else if (Input.GetKeyDown(KeyCode.W))                   //Up
            {
                if (attemptMove <Unit>(0, 1))
                {
                    moveAnim(face);
                }
                face = EnumManager.Face.Up;
            }
            else if (Input.GetKeyDown(KeyCode.S))                   //Down
            {
                if (attemptMove <Unit>(0, -1))
                {
                    moveAnim(face);
                }
                face = EnumManager.Face.Down;
            }
            else if (Input.GetKeyDown(KeyCode.Q))
            {
                GetComponent <BoxCollider2D>().enabled = false;
                spellbook.castFirst(transform.position, face);
                GetComponent <BoxCollider2D>().enabled = true;
            }
            else if (Input.GetKeyDown(KeyCode.E))
            {
                spellbook.nextSpell();
            }
            else if (Input.GetKeyDown(KeyCode.LeftArrow))
            {
                changeAnim(EnumManager.Face.Left);
            }
            else if (Input.GetKeyDown(KeyCode.RightArrow))
            {
                changeAnim(EnumManager.Face.Right);
            }
            else if (Input.GetKeyDown(KeyCode.UpArrow))
            {
                changeAnim(EnumManager.Face.Up);
            }
            else if (Input.GetKeyDown(KeyCode.DownArrow))
            {
                changeAnim(EnumManager.Face.Down);
            }
        }
    }
예제 #9
0
 public float distFrom(GameObject go, out EnumManager.Face face)
 {
     face = EnumManager.Face.None; return(-1f);
 }                                                                                                                   //Walls don't do much
예제 #10
0
 /**
  * Method that is called immediately after a player casts a spell. Removes controls from all units and gives
  * control to this object for targeting. Creates both moving and still tiles based on the spells aoe and range
  * respectively.
  *
  * param start: current location of the user casting
  * param face: current direction of the user casting
  */
 public virtual void Cast(Vector3 start, EnumManager.Face face)
 {
     GameManager.instance.TargetControl = true;
     createMovingTarget(AoE);
     createStillTarget(range);
 }
예제 #11
0
    public override void Cast(Vector3 start, EnumManager.Face face)
    {
        GetComponent <SpriteRenderer>().flipX = false;

        base.Cast(start, face);
    }