IEnumerator chargeAndFire(ShipAi enermyAI, ShipSpawner cl)
    {
        AttackHandeler ah = enermyAI.GetComponent <AttackHandeler>();

        ah.ChargeUp();
        for (int i = 0; i < FixedUpdateFramesChargedFor; i++)
        {
            yield return(new WaitForFixedUpdate());

            if (enermyAI == null || ah == null || ah.spawnPoint == null)
            {
                yield break;
            }
            var hit = Physics2D.Raycast(ah.spawnPoint.transform.position, enermyAI.transform.up, 10);
            Debug.DrawRay(ah.spawnPoint.transform.position, enermyAI.transform.up * 10);
            if (hit)
            {
                Debug.Log("hit", hit.transform);
                Debug.Log("by", enermyAI.transform);
                var other_team = hit.transform.GetComponent <TeamHandeler>();
                var my_team    = enermyAI.GetComponent <TeamHandeler>();
                if (!my_team.Equals(other_team))
                {
                    if (ah.charged)
                    {
                        ah.Fire();
                    }
                }
            }
        }
        ah.Discharge();
    }
 private void OnTriggerEnter(Collider other)                        // when the cannonball collides with something
 {
     if (other.tag == "Player")                                     // if object colliding with is a player
     {
         ShipBehavior player = other.GetComponent <ShipBehavior>(); // gets the player script
         if (player == null)
         {
             return;
         }
         player.shipHealth -= damage; // subtracts damage from the health of the player
         Debug.Log("PlayerHealth: " + player.shipHealth);
     }
     else if (other.tag == "AI") // if object colliding with is an ai
     {
         CannonFireAI    cannonFireAI    = other.GetComponent <CannonFireAI>();
         RespawnBehavior respawnBehavior = other.GetComponent <RespawnBehavior>();
         ShipAi          shipAi          = other.GetComponent <ShipAi>(); // grabs the ai script
         if (shipAi == null)
         {
             return;
         }
         shipAi.health -= damage; // subtracts damge from the health of the ai
         if (shipAi.health <= 0.0f)
         {
             respawnBehavior.Respawn();
             shipAi.health = 100.0f;
             // Delete Below Later (Once Nathan is done with the AI code, implment that there
             userStatistics.addFood(Random.Range(1, 100));
             userStatistics.addGold(Random.Range(1, 25));
         }
         Debug.Log("AIHealth: " + shipAi.health);
     }
 }
    internal override void go(ShipAi enermyAI, ShipSpawner cl)
    {
        if (cl)
        {
            Camera cam        = cl.cam;
            var    bottomLeft = cam.ScreenToWorldPoint(Vector3.zero);
            var    topRight   = cam.ScreenToWorldPoint(new Vector3(
                                                           cam.pixelWidth, cam.pixelHeight));

            var cameraRect = new Rect(
                bottomLeft.x,
                bottomLeft.y,
                topRight.x - bottomLeft.x,
                topRight.y - bottomLeft.y);
            if (cameraRect.Contains(enermyAI.transform.position))
            {
                enermyAI.StartCoroutine(chargeAndFire(enermyAI, cl));
            }
        }
    }
Example #4
0
 internal virtual void go(ShipAi enermyAI, ShipSpawner cl)
 {
     throw new NotImplementedException();
 }
Example #5
0
 internal override void go(ShipAi enermyAI, ShipSpawner cl)
 {
     enermyAI.xDirection = movement;
 }