Example #1
0
    float SetDragonPower()
    {
        float GoldLevel = Manager_Reference.GetComponent <EntityManager>().Player_Ref.GetComponent <Player>().Gold;

        DragonPower = (GoldLevel % 5) + 1;

        return(DragonPower);
    }
Example #2
0
    // Update is called once per frame
    void Update()
    {
        MovementTimer = MovementTimer <= 0 ? 0 : MovementTimer - Time.deltaTime;
        // rotate towards
        float      GetAngle = Mathf.Atan2(Direction.y, Direction.x) * Mathf.Rad2Deg;
        Quaternion Rotator  = Quaternion.AngleAxis(GetAngle, Vector3.forward);

        if (MovementTimer == 0 && !CanSeePlayer)
        {
            // Should have just made a function for this.
            NewLocation.x = Random.Range(Manager_Reference.GetComponent <EntityManager>().Min_Point.transform.position.x, Manager_Reference.GetComponent <EntityManager>().Max_Point.transform.position.x);
            NewLocation.y = Random.Range(Manager_Reference.GetComponent <EntityManager>().Min_Point.transform.position.y, Manager_Reference.GetComponent <EntityManager>().Max_Point.transform.position.y);

            gameObject.transform.rotation = Quaternion.Slerp(Muzzle.transform.rotation, Rotator, Time.deltaTime * DragonPower);

            MovementTimer = Reset_MovementTimer;
        }

        UserAxis.SetX(NewLocation.x < transform.position.x ? NewLocation.x == transform.position.x ? 0 : -1 : 1);
        UserAxis.SetY(NewLocation.y < transform.position.y ? NewLocation.y == transform.position.x ? 0 : -1 : 1);

        Move(UserAxis);
        ///

        TargetLocation = Manager_Reference.GetComponent <EntityManager>().Player_Ref.transform;

        Direction = TargetLocation.position - transform.position;
        RaycastHit RayHit;

        if (Physics.Raycast(Body.transform.position, Direction, out RayHit, 1000f, LayerMask.NameToLayer("Player")))
        {
            CanSeePlayer = true;
            NewLocation  = Manager_Reference.GetComponent <EntityManager>().Player_Ref.transform.position;
            LaunchAttack(Head.transform.rotation, Head.transform.position, Head.transform.position, Attack, AttackSpeed + 10);

            // Checking line of site to the player before attacking.
        }
        else
        {
            CanSeePlayer = false;
        }

        // Rotate the muzzle towards the player.

        Muzzle.transform.rotation = Quaternion.Slerp(Muzzle.transform.rotation, Rotator, Time.deltaTime * DragonPower);

        AttackTimer = AttackTimer <= 0 ? 0 : AttackTimer - Time.deltaTime;
        if (AttackTimer == 0)
        {
            if (!CanSeePlayer)
            {
                LaunchAttack(Muzzle.transform.rotation, Direction, Muzzle.transform.position, Attack, DragonPower + 10);
            }
            AttackTimer = ResetAttackTimer;
        }
    }
Example #3
0
 void OnCollisionEnter2D(Collision2D col)
 {
     if (col.gameObject.layer == LayerMask.NameToLayer("EnemyProjectile"))
     {
         Health -= 1;
         if (Health <= 0)
         {
             Alive = false;
         }
     }
     if (col.gameObject.layer == LayerMask.NameToLayer("Pickup"))
     {
         Gold += col.gameObject.GetComponent <Gold>().GoldValue;
         Manager_Reference.GetComponent <EntityManager>().SetPowerState();
         Destroy(col.gameObject);
     }
 }
Example #4
0
    // Update is called once per frame
    void Update()
    {
        #region Movement

        /* Movement
         *                      W
         *                      1
         *      A	-1		1	D
         *                      -1
         *                      S
         */

        this.transform.rotation = new Quaternion();

        if (KeyDown(KeyCode.W))
        {
            UserAxis.SetX(1);
        }

        else if (KeyDown(KeyCode.S))
        {
            UserAxis.SetX(-1);
        }

        else if (Input.GetKeyUp(KeyCode.W) || Input.GetKeyUp(KeyCode.S))
        {
            UserAxis.SetX(0);                                                                     // Could be done better
        }
        ////
        /////
        ////
        if (KeyDown(KeyCode.A))
        {
            UserAxis.SetY(-1);
        }

        else if (KeyDown(KeyCode.D))
        {
            UserAxis.SetY(1);
        }

        else if (Input.GetKeyUp(KeyCode.A) || Input.GetKeyUp(KeyCode.D))
        {
            UserAxis.SetY(0);                                                                      // Could be done better
        }
        Move(UserAxis);

        #endregion

        #region Aiming and combat
        // Get location of the cursor on the screen
        PointerDirection = RaycastOut(Cam_reference.ScreenPointToRay(Input.mousePosition));
        // Rotate the body of the wizard towards the cursor.
        Vector3    NewLookDirection = PointerDirection - TopSprite.transform.position;
        float      GetAngle         = Mathf.Atan2(NewLookDirection.y, NewLookDirection.x) * Mathf.Rad2Deg;
        Quaternion Rotator          = Quaternion.AngleAxis(GetAngle, Vector3.forward);
        TopSprite.transform.rotation = Quaternion.Slerp(TopSprite.transform.rotation, Rotator, Time.deltaTime * RotateTowardsSpeed);
        //

        MaxCharge = Gold_Strength * Gold * 10;

        CoolDownTimer = CoolDownTimer <= 0 ? 0 : CoolDownTimer - Time.deltaTime;

        if (Input.GetMouseButton(0) && CoolDownTimer == 0)
        {
            ChargeCounter = ChargeCounter <= MaxCharge ? (ChargeCounter += (Gold_Strength * Gold) * Time.deltaTime) + 1 : MaxCharge;
        }

        if (Input.GetMouseButtonUp(0) && CoolDownTimer == 0)
        {
            LaunchAttack(TopSprite.transform.rotation, Vector2.zero, WandSprite.transform.position, Attack, ChargeCounter);

            ChargeCounter = 0;
            CoolDownTimer = ResetCoolDownTimer;
        }

        #endregion


        if (Alive == false)
        {
            Manager_Reference.GetComponent <EntityManager>().RestartGame();
        }
    }