public override void CardFixedUpdate() { if (simp == null) { return; } if (RetroBullet != null) { RetroBullet.transform.position = transform.position; } if (accelerating) { if (transform.position.x < -14 || transform.position.x > 14 || transform.position.y < -2.8f || transform.position.y > 23.37f) { accelerating = false; simp.UpdateAcceleration(0, 0); rb.velocity = Vector2.zero; User.transform.position = new Vector2(Mathf.Clamp(transform.position.x, -13.99f, 13.99f), Mathf.Clamp(transform.position.y, -2.7f, 23.3f)); StageController.AudioManager.PlaySFX(BigShot, 0.6f); StageController.AudioManager.PlaySFX(BigShotEcho, 0.4f); } } else if (!stopping) { StartCoroutine(AccelerateToPlayer()); } }
public IEnumerator SpawnEnemies(string enemy, float hp, int count, float timeBetween, float x, float y, float vx, float vy, float ax = 0.0f, float ay = 0.0f, string args = "") { for (int i = 0; i < count; i++) { GameObject newEnemy = Instantiate(EnemyLibrary[enemy], new Vector3(x, y, 0), Quaternion.identity); Enemies.Add(newEnemy); SimpleMovement enemyMovement = newEnemy.GetComponent <SimpleMovement>(); EnemyShot shot = newEnemy.GetComponent <EnemyShot>(); newEnemy.GetComponent <Shootable>().StartingHealth = hp; enemyMovement.UpdateVelocity(vx, vy); enemyMovement.UpdateAcceleration(ax, ay); if (shot != null && !string.IsNullOrWhiteSpace(args)) { shot.args = args; } yield return(new WaitForSeconds(timeBetween)); } }
public void Destroy(GameObject obj) { if (!obj.activeSelf) { return; // Don't re-destroy an object } PooledObject o = obj.GetComponent <PooledObject>(); if (o == null) { Object.Destroy(obj); return; // Don't try and pool non-poolables. } obj.SetActive(false); Boundary.WarpCount.Remove(obj); if (obj.GetComponent <Rigidbody2D>() != null) { obj.GetComponent <Rigidbody2D>().gravityScale = 0; } string ptag = o.Tag; Pool p = Pools.Find(x => x.tag == ptag); if (p == null) { Debug.LogWarning($"There is no pool for bullet {o.Tag}!"); return; } SpriteRenderer ospr = obj.GetComponent <SpriteRenderer>(); SpriteRenderer pspr = p.prefab.GetComponent <SpriteRenderer>(); if (ospr != null && pspr != null) { ospr.color = pspr.color; // reset color. } o.transform.localScale = p.prefab.transform.localScale; // Reset scale SimpleMovement sm = p.prefab.GetComponent <SimpleMovement>(); SimpleMovement osm = obj.GetComponent <SimpleMovement>(); if (sm != null && osm != null) { osm.UpdateAcceleration(sm.XAcceleration, sm.YAcceleration); } foreach (Component comp in obj.GetComponents(typeof(Component))) { if (p.prefab.GetComponent(comp.GetType()) == null) { Destroy(comp); } } if (o != null) { PoolDict[o.Tag].Enqueue(obj); } }
public override IEnumerator StartSpell() { while (User.IsMoving()) { yield return(new WaitForSeconds(0.0001f)); } StageController.AudioManager.PlaySFX(Alert, 0.9f); const int MAX_LVL = 5; const float BORDER_SPEED = 20; List <Vector2> bulletLocations = new List <Vector2>(); for (int level = 0; level < MAX_LVL; level++) { for (int x = -14; x <= 14; x++) { for (int y = -3; y <= 23; y++) { if ((x % 2 == 0 && y % 2 == 0) || (Mathf.Abs(x % 2) == 1 && Mathf.Abs(y % 2) == 1)) { continue; } bulletLocations.Add(new Vector2(x, y)); } } int c = 0; StageController.AudioManager.PlaySFX(BigShot, 0.6f); StageController.AudioManager.PlaySFX(BigShotEcho, 0.6f); foreach (Vector2 pos in bulletLocations) { if (Random.Range(0, 9) < 5) { if (c++ % 35 == 0) { ShootSFX(); } StartCoroutine(WarnSpawn(pos, level)); yield return(new WaitForSeconds(0.0005f)); } } bulletLocations.Clear(); while (bulletSpawns > 0) { yield return(new WaitForSeconds(0.0001f)); } for (int i = 0; i < 20; i++) { if (i % 2 == 0) { ShootSFX(); } GameObject bullet = ObjectPooler.Spawn("BubbleGreen", new Vector3(-13.5f, -1.5f, 0), Quaternion.identity); GameObject bullet2 = ObjectPooler.Spawn("BubbleGreen", new Vector3(-13.5f, -1.5f, 0), Quaternion.identity); GameObject bullet3 = ObjectPooler.Spawn("BubbleGreen", new Vector3(12.5f, 21.5f, 0), Quaternion.identity); GameObject bullet4 = ObjectPooler.Spawn("BubbleGreen", new Vector3(12.5f, 21.5f, 0), Quaternion.identity); bullet.transform.localScale = new Vector3(3.5f, 3.5f, 1); bullet2.transform.localScale = new Vector3(3.5f, 3.5f, 1); bullet3.transform.localScale = new Vector3(3.5f, 3.5f, 1); bullet4.transform.localScale = new Vector3(3.5f, 3.5f, 1); bullet.GetComponent <Rigidbody2D>().velocity = new Vector2(0, BORDER_SPEED); bullet2.GetComponent <Rigidbody2D>().velocity = new Vector2(BORDER_SPEED, 0); bullet3.GetComponent <Rigidbody2D>().velocity = new Vector2(0, -BORDER_SPEED); bullet4.GetComponent <Rigidbody2D>().velocity = new Vector2(-BORDER_SPEED, 0); bullet.GetComponent <Rigidbody2D>().angularVelocity = Random.Range(90.0f, 110.0f); bullet2.GetComponent <Rigidbody2D>().angularVelocity = Random.Range(90.0f, 110.0f); bullet3.GetComponent <Rigidbody2D>().angularVelocity = Random.Range(90.0f, 110.0f); bullet4.GetComponent <Rigidbody2D>().angularVelocity = Random.Range(90.0f, 110.0f); yield return(new WaitForSeconds(0.05f)); } yield return(new WaitForSeconds(1.0f)); StageController.AudioManager.PlaySFX(Boon, 0.6f); foreach (GameObject bullet in Bullets) { Vector2 dir = (StageController.Player.transform.position - bullet.transform.position).normalized * 1; SimpleMovement sm = bullet.GetComponent <SimpleMovement>(); sm.UpdateAcceleration(dir.x, dir.y); } yield return(new WaitForSeconds(10.0f - level)); } }