IEnumerator ShootWithAnimation() { GetComponent <AnimateGiant>().PlaySpitAnimation(); speedMultiplier = speedMultiplier / 10f; yield return(new WaitForSeconds(1)); if (pathfinding.target) { Vector2 lookPos = pathfinding.target.transform.position - transform.position; float angle = Mathf.Atan2(lookPos.y, lookPos.x) * Mathf.Rad2Deg; Quaternion shootDir = Quaternion.Euler(0, 0, angle); if (spitParticles) { Instantiate(spitParticles, transform.position, transform.rotation); } yield return(new WaitForSeconds(0.1f)); GameObject _projectile = Instantiate(projectile, transform.position, shootDir, transform.parent); ProjectileAI _projectileAI = _projectile.GetComponent <ProjectileAI>(); _projectileAI.attackDmg = enemy.attackDmg; _projectileAI.range = 50; _projectileAI.friendly = false; } speedMultiplier = speedMultiplier * 10f; }
public override void AI() { ProjectileAI.ExtraAction action = delegate() { try { projectile.frameCounter++; if (projectile.frameCounter >= 15) { projectile.frameCounter = 0; float rotation = (float)(Main.rand.Next(0, 361) * (Math.PI / 180)); Vector2 velocity = new Vector2((float)Math.Cos(rotation), (float)Math.Sin(rotation)); int proj = Projectile.NewProjectile(projectile.Center.X, projectile.Center.Y, velocity.X, velocity.Y, ProjectileID.PinkLaser, 68, 0f); Main.projectile[proj].friendly = true; Main.projectile[proj].hostile = false; Main.projectile[proj].velocity *= 6f; } } catch (Exception e) { Main.NewText(e.Message); } }; ProjectileAI.YoyoAI(projectile.whoAmI, 14, 256f, 13f, 0.39f, action); }
static public Unit CreateUnit( Transform container, Board board, Vector2Int pos, UnitType type) { UnitBehaviour unitBehaviour = Object.Instantiate <UnitBehaviour> (type.Prefab, container); BaseAI ai = null; if (type.AI == UnitType.AIs.HERO) { ai = new HeroAI(); } else if (type.AI == UnitType.AIs.PATTERN) { ai = new PatternAI(type.PatternAIData); } else if (type.AI == UnitType.AIs.PROJECTILE) { ai = new ProjectileAI(); } Unit unit = new Unit(board, unitBehaviour, type, ai, pos); unitBehaviour.UpdateSprite(type.Image); unitBehaviour.UpdatePosition(pos); return(unit); }
protected virtual void FireBullet() { AudioManager.Play_Static(attackSound, true); GameObject _projectile = Instantiate(projectile, transform.position, dir, transform); ProjectileAI _projectileAI = _projectile.GetComponent <ProjectileAI>(); _projectileAI.attackDmg = Mathf.RoundToInt(tower.attackDmg * attackDmgMultiplier); _projectileAI.range = tower.range * rangeMultiplier; }
public override void AI() { ProjectileAI.ExtraAction action = delegate() { if (projectile.localAI[0] % 30 == 0) { Projectile.NewProjectile(projectile.Center.X, projectile.Center.Y, Main.rand.Next(-4, 5), Main.rand.Next(-4, 5), 24, 10, 0, projectile.owner); } }; ProjectileAI.YoyoAI(projectile.whoAmI, 10, 320f, 15f, 0.4f, action); }
private void Die() { if (onDeath != null) { GameObject _onDeath = Instantiate(onDeath, transform.position, Quaternion.identity, transform.parent); ProjectileAI _projectileAI = onDeath.GetComponent <ProjectileAI>(); if (_projectileAI != null && ignore.Count > 0) { _projectileAI.ignore.AddRange(ignore); } } Destroy(gameObject); }
// Update is called once per frame void Update() { //check if the tower is a sence tower if (isSenseTower == false) { //find the first enemy in range GameObject[] enemies = GameObject.FindGameObjectsWithTag("Enemy"); foreach (GameObject target in enemies) { if ((gameObject.transform.position - target.transform.position).sqrMagnitude < TowerRangeSquared) { //check that the tower's cooldown has been complete if (Time.time - lastShot > CoolDownLength) { if (enemies.Length > 0) // { //create a projectile GameObject obj = (GameObject)Instantiate(Projectile, transform.position, this.transform.rotation); ProjectileAI ObjProjectile = (obj.GetComponent("ProjectileAI") as ProjectileAI); //set the projectile's target and damage ObjProjectile.Target = enemies[0]; ObjProjectile.damage = damage + damageUpgrade; //set the tower to cooldown lastShot = Time.time; } } } } } else { //find all towers in range GameObject[] Towers = GameObject.FindGameObjectsWithTag("Tower"); foreach (GameObject Obj in Towers) { if ((gameObject.transform.position - Obj.transform.position).sqrMagnitude < TowerRangeSquared) { //give them a damage upgrade Tower ToUpgrade = Obj.GetComponent <Tower>(); if (ToUpgrade.isSenseTower == false) { ToUpgrade.damageUpgrade += (int)Mathf.Round(ToUpgrade.damage * .25f); } } } } damageUpgrade = 0; // reset damage upgrade for towers }
public override void AI() { ProjectileAI.ExtraAction action = delegate() { try { projectile.frameCounter++; if (projectile.frameCounter >= 30) { projectile.frameCounter = 0; float distance = 2000f; int index = -1; for (int i = 0; i < 200; i++) { float dist = Vector2.Distance(projectile.Center, Main.npc[i].Center); if (dist < distance && dist < 640f && !Main.npc[i].friendly && Main.npc[i].lifeMax > 5 && !Main.npc[i].townNPC) { index = i; distance = dist; } } if (index != -1) { bool check = Collision.CanHit(projectile.position, projectile.width, projectile.height, Main.npc[index].position, Main.npc[index].width, Main.npc[index].height); if (check) { Vector2 vector = Main.npc[index].Center - projectile.Center; float speed = 9f; float mag = (float)Math.Sqrt(vector.X * vector.X + vector.Y * vector.Y); if (mag > speed) { mag = speed / mag; } vector *= mag; Projectile.NewProjectile(projectile.Center.X, projectile.Center.Y, vector.X, vector.Y, 206, 16, 0.5f, projectile.owner); } } } } catch (Exception e) { Main.NewText(e.Message); } }; ProjectileAI.YoyoAI(projectile.whoAmI, 14, 256f, 13f, 0.39f, action); }
IEnumerator SelfDestruct(float timer) { animator.SetFloat("FillSpeed", 1f / enemyAI.enemy.attackRate); yield return(new WaitForSeconds(timer)); if (selfDestructing) { Destroy(gameObject, 0.05f); GameObject _projectile = Instantiate(projectile, transform.position, transform.rotation, transform.parent); ProjectileAI _projectileAI = _projectile.GetComponent <ProjectileAI>(); _projectileAI.attackDmg = explosionDamage; _projectileAI.range = range; _projectileAI.friendly = false; } else { animator.SetFloat("FillSpeed", -1f / enemyAI.enemy.attackRate); } }
protected override void FireBullet() { Quaternion fireDir = dir; if (shots % 2 == 0) { fireDir = Quaternion.Euler(0, 0, dir.eulerAngles.z - scatterDistance / (4f / shots)); } else { fireDir = Quaternion.Euler(0, 0, dir.eulerAngles.z - scatterDistance / (2f / (shots - 1))); } for (int i = 0; i < shots; i++) { GameObject _projectile = Instantiate(projectile, transform.position, fireDir, transform); ProjectileAI _projectileAI = _projectile.GetComponent <ProjectileAI>(); _projectileAI.attackDmg = tower.attackDmg; _projectileAI.range = tower.range; fireDir = Quaternion.Euler(0, 0, fireDir.eulerAngles.z + scatterDistance); } }
public override void OnHitPlayer(Player target, int damage, bool crit) { ProjectileAI.BoomerangOnHitEntity(projectile.whoAmI); }
public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) { ProjectileAI.BoomerangOnHitEntity(projectile.whoAmI); }
public override bool OnTileCollide(Microsoft.Xna.Framework.Vector2 oldVelocity) { return(ProjectileAI.BoomerangTileCollide(projectile.whoAmI, oldVelocity)); }
public override bool PreAI() { ProjectileAI.BoomerangAI(projectile.whoAmI, 30, 20, 1); projectile.spriteDirection = projectile.direction; return(false); }
public override bool PreAI() { ProjectileAI.FlailAI(projectile.whoAmI); return(false); }
public override bool OnTileCollide(Vector2 oldVelocity) { return(ProjectileAI.FlailTileCollide(projectile.whoAmI, oldVelocity)); }
public override bool PreAI(Projectile projectile) { #region Rewriting Yoyo AIs if (projectile.type == 534 || (projectile.type >= 541 && projectile.type <= 555) || (projectile.type >= 562 && projectile.type <= 564) || projectile.type == 603) { switch (projectile.type) { case 534: ProjectileAI.YoyoAI(projectile.whoAmI, 9, 220f, 13); return(false); case 541: ProjectileAI.YoyoAI(projectile.whoAmI, 3, 130f, 9); return(false); case 542: ProjectileAI.YoyoAI(projectile.whoAmI, 7, 195f, 12.5f); return(false); case 543: ProjectileAI.YoyoAI(projectile.whoAmI, 6, 207f, 12); return(false); case 544: ProjectileAI.YoyoAI(projectile.whoAmI, 8, 215f, 13f); return(false); case 545: ProjectileAI.YoyoAI(projectile.whoAmI, 13, 235f, 14f, 045f, delegate() { if (Main.rand.Next(6) == 0) { int num8 = Dust.NewDust(projectile.position, projectile.width, projectile.height, 6, 0f, 0f, 0, default(Color), 1f); Main.dust[num8].noGravity = true; } }); return(false); case 546: ProjectileAI.YoyoAI(projectile.whoAmI, 16, 275f, 17f); return(false); case 547: ProjectileAI.YoyoAI(projectile.whoAmI, -1, 280f, 17f); return(false); case 548: ProjectileAI.YoyoAI(projectile.whoAmI, 5, 170f, 11f); return(false); case 549: ProjectileAI.YoyoAI(projectile.whoAmI, 14, 290f, 16f); return(false); case 550: case 551: ProjectileAI.YoyoAI(projectile.whoAmI, -1, 370f, 16f); return(false); case 552: ProjectileAI.YoyoAI(projectile.whoAmI, 15, 270f, 14f); return(false); case 553: ProjectileAI.YoyoAI(projectile.whoAmI, 12, 275f, 15f, 0.45f, delegate() { if (Main.rand.Next(2) == 0) { int num9 = Dust.NewDust(projectile.position, projectile.width, projectile.height, 6, 0f, 0f, 0, default(Color), 1f); Main.dust[num9].noGravity = true; Main.dust[num9].scale = 1.6f; } }); return(false); case 554: ProjectileAI.YoyoAI(projectile.whoAmI, -1, 340f, 16f); return(false); case 555: ProjectileAI.YoyoAI(projectile.whoAmI, -1, 360f, 16.5f); return(false); case 562: ProjectileAI.YoyoAI(projectile.whoAmI, 8, 235f, 15f); return(false); case 563: ProjectileAI.YoyoAI(projectile.whoAmI, 10, 250f, 12f); return(false); case 564: ProjectileAI.YoyoAI(projectile.whoAmI, 11, 225f, 14f); return(false); case 603: ProjectileAI.YoyoAI(projectile.whoAmI, -1, 400f, 17.5f, 0.45f, delegate() { projectile.localAI[1] += 1f; if (projectile.localAI[1] >= 6f) { float num2 = 400f; Vector2 vector = projectile.velocity; Vector2 vector2 = new Vector2((float)Main.rand.Next(-100, 101), (float)Main.rand.Next(-100, 101)); vector2.Normalize(); vector2 *= (float)Main.rand.Next(10, 41) * 0.1f; if (Main.rand.Next(3) == 0) { vector2 *= 2f; } vector *= 0.25f; vector += vector2; for (int j = 0; j < 200; j++) { if (Main.npc[j].CanBeChasedBy(projectile, false)) { float num3 = Main.npc[j].position.X + (float)(Main.npc[j].width / 2); float num4 = Main.npc[j].position.Y + (float)(Main.npc[j].height / 2); float num5 = Math.Abs(projectile.position.X + (float)(projectile.width / 2) - num3) + Math.Abs(projectile.position.Y + (float)(projectile.height / 2) - num4); if (num5 < num2 && Collision.CanHit(projectile.position, projectile.width, projectile.height, Main.npc[j].position, Main.npc[j].width, Main.npc[j].height)) { num2 = num5; vector.X = num3; vector.Y = num4; vector -= projectile.Center; vector.Normalize(); vector *= 8f; } } } vector *= 0.8f; Projectile.NewProjectile(projectile.Center.X, projectile.Center.Y, vector.X, vector.Y, 604, projectile.damage, projectile.knockBack, projectile.owner, 0f, 0f); projectile.localAI[1] = 0f; } }); return(false); } } #endregion return(true); }