public void Firemode1() { Vector2 newpos1 = rigidbody2d.position + Vector2.down * 0.3f + Vector2.right * 0.1f; Vector2 newpos2 = rigidbody2d.position + Vector2.down * 0.3f + Vector2.left * 0.1f; Vector2 newpos3 = rigidbody2d.position + Vector2.down * 0.3f + Vector2.right * 0.2f; Vector2 newpos4 = rigidbody2d.position + Vector2.down * 0.3f + Vector2.left * 0.2f; GameObject projectileObject1 = Instantiate(bullet, newpos1, Quaternion.identity); EnemyBullet projectile1 = projectileObject1.GetComponent <EnemyBullet>(); GameObject projectileObject2 = Instantiate(bullet, newpos2, Quaternion.identity); EnemyBullet projectile2 = projectileObject2.GetComponent <EnemyBullet>(); GameObject projectileObject4 = Instantiate(bullet, newpos1, Quaternion.identity); EnemyBullet projectile4 = projectileObject4.GetComponent <EnemyBullet>(); GameObject projectileObject5 = Instantiate(bullet, newpos2, Quaternion.identity); EnemyBullet projectile5 = projectileObject5.GetComponent <EnemyBullet>(); GameObject projectileObject6 = Instantiate(bullet, newpos3, Quaternion.identity); EnemyBullet projectile6 = projectileObject6.GetComponent <EnemyBullet>(); GameObject projectileObject7 = Instantiate(bullet, newpos4, Quaternion.identity); EnemyBullet projectile7 = projectileObject7.GetComponent <EnemyBullet>(); projectile1.Launch(Vector2.down + Vector2.right * 0.2f, 4); projectile2.Launch(Vector2.down + Vector2.left * 0.2f, 4); projectile4.Launch(Vector2.down + Vector2.right * 0.6f, 4); projectile5.Launch(Vector2.down + Vector2.left * 0.6f, 4); projectile6.Launch(Vector2.down + Vector2.right * 0.9f, 4); projectile7.Launch(Vector2.down + Vector2.left * 0.9f, 4); }
/// <summary> /// 当たり判定 /// </summary> private void hitJudge() { // 自機弾→敵機 if (Bullet.Left < Enemy.Right && Bullet.Top < Enemy.Bottom && Bullet.Right > Enemy.Left && Bullet.Bottom >= Enemy.Top) { // 敵機消滅 Enemy.Image = null; Enemy.Hide(); initEnemy(); // 敵機初期化 Bullet.Hide(); // 弾非表示 initBullet(); // 自機弾初期化 myShootFlg = false; // 発射フラグを戻す } // 敵機弾→自機 if (Player.Left < EnemyBullet.Right && Player.Top < EnemyBullet.Bottom && Player.Right > EnemyBullet.Left && Player.Bottom > EnemyBullet.Top) { // タイマー停止 myTimer.Stop(); retryButton.Show(); // 自機消滅 Player.Image = null; Player.Hide(); EnemyBullet.Hide(); } }
// f:弾生成時にパラメータを渡せるInstantiate関数 public static EnemyBullet Instantiate(EnemyBullet _bullet, EnemyBulletParam _param, Transform _transform) { EnemyBullet bullet = Instantiate(_bullet, _transform.position + _param.initialPosition, _transform.rotation) as EnemyBullet; SetupBullet(bullet, _param, _transform); return(bullet); }
//if bullet hits ship void OnTriggerEnter2D(Collider2D collider) { PlayerBullet pBullet = collider.gameObject.GetComponent <PlayerBullet>(); // if ship hit by own bullet (bullet hell) EnemyBullet eBullet = collider.gameObject.GetComponent <EnemyBullet>(); // if ship hit by enemy bullet BossBullet bBullet = collider.gameObject.GetComponent <BossBullet>(); // if ship hit by boss bullet BossLeft bLeft = collider.gameObject.GetComponent <BossLeft>(); // if ship hits boss left gun BossRight bRight = collider.gameObject.GetComponent <BossRight>(); // if ship hits boss right gun BossCore bCore = collider.gameObject.GetComponent <BossCore>(); // if ship hits boss core Upgrade upgrade = collider.gameObject.GetComponent <Upgrade>(); // if ship hits an upgrade if (pBullet || eBullet || bBullet || bLeft || bRight || bCore) { laserCount--; AudioSource.PlayClipAtPoint(deathSound, transform.position); if (laserCount == 0) { Destroy(gameObject); GameObject shipExploding = Instantiate(explosion, transform.position, Quaternion.identity) as GameObject; Destroy(shipExploding, 1.0f); canvas.SetActive(true); } } if (upgrade) { laserCount++; } }
public void RangeBulletEliminate(Vector3 centerPos, float range, bool getPoint) { float rangeSq = range * range; List <BattleObject> bulletList = GetObjectList(BattleObjectType.EnemyBullet); if (bulletList == null) { return; } for (int i = bulletList.Count - 1; i >= 0; --i) { BattleObject bulletObj = bulletList[i]; Vector3 disVec = bulletObj.transform.position - centerPos; if (disVec.sqrMagnitude < rangeSq) { EnemyBullet bullet = bulletObj as EnemyBullet; if (bullet != null) { bullet.Eliminate(); if (getPoint) { GameObject pointItem = BattleStageManager.Instance.SpawnObject("Item/PointItem"); pointItem.transform.position = bullet.transform.position; } } } } }
private void ShootTimer_timeout() { GetNode <Timer>("ShootTimer").Stop(); if (_canShoot) { EnemyBullet bullet = (EnemyBullet)_bulletScene.Instance(); GD.Print(Position); bullet.Speed = 105; bullet.Position = Position; bullet.Direction = new Vector2(_player.Position.x - Position.x, _player.Position.y - Position.y).Normalized(); GetParent().AddChild(bullet); if (++_shots == 20) { _shots = 0; GetNode <Timer>("ShootTimer").WaitTime = (float)(_random.NextDouble() * (2.0 - .85) + .85); GetNode <Timer>("ShootTimer").Start(); } else { GetNode <Timer>("ShootTimer").WaitTime = (float)(_random.NextDouble() * (.4 - .1) + .1); GetNode <Timer>("ShootTimer").Start(); } } else { GetNode <Timer>("ShootTimer").WaitTime = (float)(_random.NextDouble() * (.15 - .1) + .1); GetNode <Timer>("ShootTimer").Start(); } }
// Shooting towards target position private void ShootAtPlayer() { EnemyBullet bullet = Instantiate(bulletPrefab); bullet.transform.position = transform.position; bullet.GetComponent <Rigidbody2D>().velocity = TargetDirection() * bulletSpeed; }
public void AddEnemyBulletModel(Vector3 position, Vector3 direction) { Vector3 bulletPosition = new Vector3(position.X + direction.X * 3, position.Y + direction.Y * 3, position.Z + direction.Z * 3); DrawableModel newDModel = new EnemyBullet(enemyBulletModel, Matrix.CreateTranslation(bulletPosition.X, bulletPosition.Y, bulletPosition.Z), direction); octreeRoot.Add(newDModel); }
void shootBullet(Vector3 playerPos) { if (timeSinceShoot >= 1.0 / fireRatePerSecond) { bulletSound.volume = PlayerPrefs.GetFloat("Sound") / 100.0f; bulletSound.Play(); timeSinceShoot = 0; GameObject bulletClone = Instantiate(enemyBullet, enemyBullet.transform.position, enemyBullet.transform.rotation); bulletClone.SetActive(true); EnemyBullet bullet = new EnemyBullet(bulletClone, playerPos); bullets.Add(bullet); } else { timeSinceShoot += Time.deltaTime; } foreach (EnemyBullet bullet in bullets) { float step = bulletSpeed * Time.deltaTime; Vector3 pos = bullet.enemyBullet.transform.position; bullet.enemyBullet.transform.position = Vector3.MoveTowards(pos, bullet.playerPos, step); if (bullet.reachedDistance()) { bullet.dead = true; Destroy(bullet.enemyBullet); } } bullets.RemoveAll(bullet => bullet.dead); }
void Start() { bullets = new GameObject[8]; int i = 0; Transform[] childs = GetComponentsInChildren <Transform>(); foreach (Transform child in childs) { if (child.name.Contains("pike")) { bullets[i] = child.gameObject; i++; } } // bullets = GetComponentsInChildren<GameObject>(); int index = 0; foreach (GameObject e in bullets) { EnemyBullet eb = e.GetComponent <EnemyBullet>(); ebs[index] = eb; index++; e.SetActive(false); } eType = "PufferFish"; health = 1; bobTimer = 0; rb2d = GetComponent <Rigidbody2D>(); //rb2d.isKinematic = false; }
public override EnemyBullet[] GetBullets(Vector3 enemyFirePos) { var bullet = PoolManager.Instance.EnemyBulletPool.Get <TankEnemyBullet>(enemyFirePos); int varianceIndex = FireCounter + NumBulletsPerBurst; float variance = varianceIndex * SpeedVariancePerBullet; float velocityX = FireXFlip * RandomUtil.Float(0, variance); FireXFlip *= -1f; bullet.Velocity = new Vector2(velocityX, bullet.Speed); bullet.OnSpawn(); FireCounter++; if (FireCounter != 0) { FireTimer.ActivationInterval = FireSpeed; } else { FireTimer.ActivationInterval = ReloadSpeed; FireCounter = -NumBulletsPerBurst; } var ret = new EnemyBullet[] { bullet }; return(ret); }
public void Fire() { Vector2 newpos1 = rigidbody2d.position + Vector2.down * 0.3f + Vector2.right * 0.1f; Vector2 newpos2 = rigidbody2d.position + Vector2.down * 0.3f + Vector2.left * 0.1f; Vector2 newpos3 = rigidbody2d.position + Vector2.down * 0.3f; GameObject projectileObject1 = Instantiate(bullet2, newpos1, Quaternion.identity); EnemyBullet projectile1 = projectileObject1.GetComponent <EnemyBullet>(); GameObject projectileObject2 = Instantiate(bullet2, newpos2, Quaternion.identity); EnemyBullet projectile2 = projectileObject2.GetComponent <EnemyBullet>(); GameObject projectileObject3 = Instantiate(bullet2, newpos3, Quaternion.identity); EnemyBullet projectile3 = projectileObject3.GetComponent <EnemyBullet>(); GameObject projectileObject4 = Instantiate(bullet2, newpos1, Quaternion.identity); EnemyBullet projectile4 = projectileObject4.GetComponent <EnemyBullet>(); GameObject projectileObject5 = Instantiate(bullet2, newpos2, Quaternion.identity); EnemyBullet projectile5 = projectileObject5.GetComponent <EnemyBullet>(); projectile1.Launch(Vector2.down + Vector2.right * 0.4f, 3); projectile2.Launch(Vector2.down + Vector2.left * 0.4f, 3); projectile4.Launch(Vector2.down + Vector2.right * 0.9f, 3); projectile5.Launch(Vector2.down + Vector2.left * 0.9f, 3); projectile3.Launch(Vector2.down, 3); Vector2 firePoint1 = rigidbody2d.position + Vector2.down * 0.2f + Vector2.right * 0.3f; Vector2 firePoint2 = rigidbody2d.position + Vector2.down * 0.2f + Vector2.left * 0.3f; Vector2 target = gameCtr.player.position; Vector2 dir1 = target - firePoint1; Vector2 dir2 = target - firePoint2; GameObject projectileObject6 = Instantiate(bullet3, firePoint1, Quaternion.identity); EnemyBullet projectile6 = projectileObject6.GetComponent <EnemyBullet>(); GameObject projectileObject7 = Instantiate(bullet3, firePoint2, Quaternion.identity); EnemyBullet projectile7 = projectileObject7.GetComponent <EnemyBullet>(); projectile6.Launch(dir1, 2f); projectile7.Launch(dir2, 2f); }
public void Fire() { EnemyBullet newBullet = Instantiate <EnemyBullet>(this.bulletPrefab, this.transform.position, Quaternion.identity); newBullet.angle = this.currentAngle; newBullet.speed = this.currentBulletSpeed; }
private void Shoot() { Vector2 dir = target.position - transform.position; EnemyBullet bullet = Instantiate(bulletPref, shootPos.transform.position, Quaternion.identity, WorldManager.Instance.currentRoom.transform); bullet.Shoot(dir, attackForce, bulletDamage); }
public override void Shoot() { degrees += variation; //Obtengo el GameManager var Manager = GameModelManager.instance; Debug.Log(transform.forward); for (int i = 1; i < 360; i += 360 / numberOfBullets) { //Chequea esto. EnemyBullet bullets = Manager.EnemyBulletPool.GetObjectFromPool().GetComponent <EnemyBullet>(); Vector3 direction; direction.x = Mathf.Sin((i + degrees) * Mathf.Deg2Rad); direction.y = 0; direction.z = Mathf.Cos((i + degrees) * Mathf.Deg2Rad); bullets.transform.forward = direction; bullets.degrees = degrees; bullets.radians = radians; bullets.radiusX = radiusX; bullets.radiusY = radiusY; bullets.center = canon.position; bullets.speedOscilation = speedOscilation; bullets.Movement += () => Moving(bullets); //Debug Debug.DrawRay(transform.position, bullets.transform.forward, Color.green); } }
public void ShootWeapon() { EnemyBullet bullet = BulletController.instance.EnemyShootABullet(); bullet.transform.position = new Vector3(this.transform.position.x + 0.5f, this.transform.position.y, this.transform.position.z); bullet.transform.rotation = Quaternion.Euler(this.transform.rotation.eulerAngles.x, this.transform.rotation.eulerAngles.y, this.transform.rotation.eulerAngles.z + 15); bullet.Move(); }
void checkIfTimeToFire() { if (Time.time > nextFire) { EnemyBullet new_bullet = Instantiate(bullet, transform.position, Quaternion.Euler(CalculateRotation())); nextFire = Time.time + fireRate; } }
void OnCollisionEnter2D(Collision2D collision) { if (collision.gameObject.tag == "Enemybullet" && shield == false) { EnemyBullet enemybullet = collision.gameObject.GetComponent <EnemyBullet>(); TakeDamage(enemybullet.damage); } }
public void fire() { for (int i = 0; i < firepoints.Length; i++) { EnemyBullet newBullet = Instantiate(bullet, firepoints[i].position, transform.rotation) as EnemyBullet; newBullet.damage = power; } }
private void Shoot(Transform startPoint)//Transform startPoint { EnemyBullet newBullet = Instantiate(bullet, transform.position, startPoint.rotation) as EnemyBullet; newBullet.damage = damage; //newBullet.speed = bulletSpeed; newBullet.target = Input.mousePosition - Camera.main.WorldToScreenPoint(transform.position); }
public void Fire() { GameObject projectileObject = Instantiate(bullet, rigidbody2d.position + Vector2.down * 0.2f, Quaternion.identity); EnemyBullet projectile = projectileObject.GetComponent <EnemyBullet>(); projectile.Launch(Vector2.down, 3); }
/// <summary> /// Выстрел снарядом /// </summary> protected override void Shoot() { GameObject bulletEnemy = PoolManager.GetObject(PoolManager.NamePrefab.EnemyBullet, _weapon.transform.position, Quaternion.identity); EnemyBullet bulletScript = bulletEnemy.GetComponent <EnemyBullet>(); _audioSourceFire.Play(); bulletScript.SetSpeedBullet(-gameObject.transform.up * _speedBullet); }
private void Shoot() { currentShootTime = 0f; Vector2 dir = spawnPoint.position - spawnPointGo.transform.position; EnemyBullet bullet = Instantiate(bulletPrefab, spawnPointGo.transform.position, Quaternion.identity, WorldManager.Instance.currentRoom.transform); bullet.Shoot(dir, attackForce, attackDamage); }
public void AddFree(EnemyBullet _bullet) { //_bullet.ResetChild(); freeList.Add(_bullet); usedList.Remove(_bullet); _bullet.gameObject.SetActive(false); freeNum++; }
public virtual void RestorePosition() { Lives = 1; Position = StartPosition; onWindowPosition = null; direction = DOWN_DIRECTION; blinkTickStart = 0; bullet = null; }
public EnemyBullet NewEnemyBullet() { EnemyBullet bullet = new EnemyBullet(Info); int positionY = Position.Y + 30; int positionX = Position.X + 15; bullet.Position = new Point(positionX, positionY); bullet.Load(); return bullet; }
public EnemyBullet CreateEnemyBullet(Ship2 ship) { var enbullet = new EnemyBullet(Info); int positionY = ship.Position.Y + 26; int positionX = ship.Position.X + 12; enbullet.Position = new Point(positionX, positionY); enbullet.Load(); return enbullet; }
void OnTriggerEnter2D(Collider2D other) { EnemyBullet bullet = GetComponent <EnemyBullet>(); if (bullet != null) { HurtPlayer(); } }
protected void CreateBullet(float direction, float speed, float damage) { EnemyBullet bullet = Instantiate(bulletToUse, bulletSpawner.transform.position, Quaternion.identity); bullet.Speed = speed; bullet.Direction = direction; bullet.SetDamage(damage); //bullet.SetOwnerTag(tag); // Indicate the shooter of the bullet }
public EnemyBullet NewEnemyBullet(Enemy1ForLevelTwo spaceship) { EnemyBullet bullet = new EnemyBullet(Info); int positionY = spaceship.Position.Y + 30; int positionX = spaceship.Position.X + 15; bullet.Position = new Point(positionX, positionY); bullet.Load(); return bullet; }
void attack() { bullet = new EnemyBullet(this.x + 70f, this.y + 50f, 10); if (hasStoped) { Game.main.AddChild(bullet); } }
protected override void AttackPlayer() { if (bulletTimer == 0) { GameObject shot = (GameObject)Instantiate(bullet, transform.position, transform.rotation); EnemyBullet shotBehaviour = shot.GetComponent <EnemyBullet>(); shotBehaviour.SetDirection(direction); } }
public virtual EnemyBullet GetBullet(IBasePlayer player, IBaseMap gameMap) { var bullet = new EnemyBullet(this.Position, 0); bullet.direction = this.Direction; bullet.Owner = this; //this.Reloaded = false; return(bullet); }
public EnemyBullet CreateBullet() { EnemyBullet enemyBullet = new EnemyBullet(Info); { Position = Position; }; enemyBullet.Load(); return enemyBullet; }
public EnemyBullet CreatEnemyBullet() { var enemybullet = new EnemyBullet(Info); int positionY = Position.Y + 20; int positionX = Position.X + 20; enemybullet.Position = new Point(positionX, positionY); enemybullet.Load(); return enemybullet; }
IEnumerator EnemyBulletPat1(Enemy e) { EnemyBullet[] enemyBullets = new EnemyBullet[8]; for(int i = 0; i < 8; i++) { enemyBullets[i] = new EnemyBullet(); enemyBullets[i].M.Muki = 45 * i; enemyBullets[i].M.Speed = 3; enemyBullets[i].Position = e.Position; enemyBullets[i].Sprite = 0; enemyBullets[i].Size = 1; enemyBullets[i].Color = 1; EnemyBullets.EnemyBulletList.Add(enemyBullets[i]); } yield return new WaitForEndOfFrame(); }
IEnumerator EnemyBulletPat2(Enemy e) { EnemyBullet[] enemyBullets = new EnemyBullet[16]; for (int i = 0; i < 8; i++) { enemyBullets[i] = new EnemyBullet(); enemyBullets[i].M.Muki = enemyBullets[i].Atan()-(22.5f*(i-3.5f))+180; enemyBullets[i].M.Speed = 3; enemyBullets[i].Position = e.Position; enemyBullets[i].Sprite = 0; enemyBullets[i].Size = 1; enemyBullets[i].Color = 1; EnemyBullets.EnemyBulletList.Add(enemyBullets[i]); } yield return new WaitForSeconds(0.7f); for (int i = 0; i < 8; i++) { enemyBullets[i].M.Muki = enemyBullets[i].Atan(); } }
public BaseActor Shoot() { h_startShootTimer(); var bullet = new EnemyBullet(Info, this); bullet.Load(); return bullet; }
private void b_shots() { if (shot.ElapsedMilliseconds < 1000) return; var enbull = new EnemyBullet(this); var enlis = Actors.Where((actor) => actor is Ship).ToList(); if (enlis.Count() > 0) { Random rd = new Random(); int a = rd.Next(enlis.Count()); var mission = enlis[a].Position; enbull.Position = new Point(mission.X, mission.Y + 10); enbull.Load(); Actors.Add(enbull); shot.Restart(); } }
void IncomingBulletUI(EnemyBullet bullet) { var camPos = Camera.main.transform.position; var diff = bullet.transform.position - camPos; if (Physics.RaycastAll(camPos, diff, diff.magnitude).Any(x => x.collider.gameObject.name == "Planet")) return; var ssPos = camera.WorldToScreenPoint(bullet.transform.position); //Debug.Log("x = " + ssPos.x + ", y = " + ssPos.y); var spacing = 25 * globalScale; var arrowDirection = Vector3.zero; if (ssPos.x < spacing) arrowDirection.x -= 1; if (ssPos.x > Screen.width - spacing) arrowDirection.x += 1; if (ssPos.y < spacing) arrowDirection.y -= 1; if (ssPos.y > Screen.height - spacing) arrowDirection.y += 1; arrowDirection.Normalize(); ssPos.x = Mathf.Clamp(ssPos.x, spacing, Screen.width - spacing); ssPos.y = Mathf.Clamp(ssPos.y, spacing, Screen.height - spacing); GL.Color(Color.white); // Make backing circle for (int i = 0; i < Segments; i++) { var thisA = i / Segments * Mathf.PI * 2; var nextA = (i + 1) / Segments * Mathf.PI * 2; GL.Vertex3(ssPos.x, ssPos.y, 0); GL.Vertex3(ssPos.x + (float)Math.Cos(thisA) * InnerRadius, ssPos.y + (float)Math.Sin(thisA) * InnerRadius, 0); GL.Vertex3(ssPos.x + (float)Math.Cos(nextA) * InnerRadius, ssPos.y + (float)Math.Sin(nextA) * InnerRadius, 0); } var power = bullet.Power; var bulletColor = ColorHelper.ColorFromHSV(bullet.Hue, 1, 1); var bgColor = new Color(36 / 255f, 34 / 255f, 34 / 255f); //var bgColor = Color.Lerp(new Color(36 / 255f, 34 / 255f, 34 / 255f), bulletColor, Mathf.Clamp01(Mathf.FloorToInt(power) / 5f)); GL.Color(bgColor); // Make backing circle for (int i = 0; i < Segments; i++) { var thisA = i / Segments * Mathf.PI * 2; var nextA = (i + 1) / Segments * Mathf.PI * 2; GL.Vertex3(ssPos.x, ssPos.y, 0); GL.Vertex3(ssPos.x + (float)Math.Cos(thisA) * InnerMaskRadius, ssPos.y + (float)Math.Sin(thisA) * InnerMaskRadius, 0); GL.Vertex3(ssPos.x + (float)Math.Cos(nextA) * InnerMaskRadius, ssPos.y + (float)Math.Sin(nextA) * InnerMaskRadius, 0); } //bulletColor = Color.Lerp(new Color(36 / 255f, 34 / 255f, 34 / 255f), bulletColor, 1 - Mathf.Clamp01(Mathf.FloorToInt(power) / 5f)); GL.Color(bulletColor); // Make smaller circle for (int i = 0; i < Segments; i++) { var thisA = i / Segments * Mathf.PI * -2 * Mathf.Clamp01(power / 4f) + Mathf.PI / 2; var nextA = (i + 1) / Segments * Mathf.PI * -2 * Mathf.Clamp01(power / 4f) + Mathf.PI / 2; GL.Vertex3(ssPos.x, ssPos.y, 0); GL.Vertex3(ssPos.x + (float)Math.Cos(thisA) * CoreRadius * 1.25f, ssPos.y + (float)Math.Sin(thisA) * CoreRadius * 1.25f, 0); GL.Vertex3(ssPos.x + (float)Math.Cos(nextA) * CoreRadius * 1.25f, ssPos.y + (float)Math.Sin(nextA) * CoreRadius * 1.25f, 0); } // Make arrow? if (arrowDirection != Vector3.zero) DrawArrow(arrowDirection, ssPos); }
private void TimeEnemyBul() { if (BullShotTime.ElapsedMilliseconds < 2000) return; var enemyBullet = new EnemyBullet(this); var enemyList = Actors.Where((actor) => actor is Ship || actor is ShipNew).ToList(); if (enemyList.Count > 0) { Random rnd = new Random(); int qq = rnd.Next(enemyList.Count); var target = enemyList[qq].Position; enemyBullet.Position = new Point(target.X, target.Y); enemyBullet.Load(); Actors.Add(enemyBullet); BullShotTime.Restart(); } }
protected void processEnemies() { //Initialize List<FNode> Deads = new List<FNode>(); List<float> deadTimerIndex = new List<float>(); //For each child in the container for (int i = 0; i < m_Enemies.GetChildCount(); i++) { //Get enemy Enemy enemy = m_Enemies.GetChildAt(i) as Enemy; if (enemy != null) { //Move enemy.x -= ENEMY_SPEED; enemy.UpdateDuration(Time.deltaTime); m_EnemyShootTimer[i] -= Time.deltaTime; if (m_EnemyShootTimer[i] <= 0) { //Shoot bullet m_EnemyShootTimer[i] = ENEMY_SHOOT_INTERVAL; EnemyBullet bullet = new EnemyBullet(enemy.GetPosition().x - 10, enemy.GetPosition().y); bullet.SetTarget(m_Exa.GetPosition()); m_EnemyBullets.AddChild(bullet); //Animate enemy enemy.Attack(); //Log //logConsole("[LOG] Enemy: Shooting bullet"); } if (enemy.ShouldBeDead()) { //Log logConsole("[ERROR] Memory Leak: Enemy not deleted " + (m_Error + 1) + "/" + ERROR_MAX); incrementError(); } if (enemy.x + (enemy.getWidth() / 2) < 0) { Deads.Add(enemy); deadTimerIndex.Add(m_EnemyShootTimer[i]); //Log logConsole("[LOG] Enemy: OutOfScreen"); } } } //Remove dead coins for (int i = 0; i < Deads.Count; i++) m_Enemies.RemoveChild(Deads[i]); foreach(float f in deadTimerIndex) m_EnemyShootTimer.Remove(f); //Spawn m_EnemyTimer -= Time.deltaTime; if (m_EnemyTimer <= 0f) { //Create float X = Constants.UNITY_CANVAS_RIGHT + 61.0f; //Hardcode width / 2 float Y = Constants.UNITY_CANVAS_BOTTOM + (Constants.UNITY_CANVAS_HEIGHT / 12.0f * (float)(Random.Range(3, 10))); Enemy enemy = new Enemy(X,Y); //Add m_Enemies.AddChild(enemy); m_EnemyShootTimer.Add(ENEMY_FIRST_SHOOT_INTERVAL); //Reset m_EnemyTimer = Random.Range(1, 9) / 2.0f; if (m_EnemyTimer > 1) m_EnemyTimer -= 1; //Log //logConsole("[LOG] Enemy: Spawned"); } }
public void BulletShot() { if (BullShot.ElapsedMilliseconds < 1000 ) return; var enbul = new EnemyBullet(this); var enemyList = Actors.Where((actor) => actor is Ship || actor is Ship1).ToList(); if (enemyList.Count > 0) { Random rnd = new Random(); int qq = rnd.Next(enemyList.Count); var target = enemyList[qq].Position; enbul.Position = new Point(target.X, target.Y + 10); enbul.Load(); Actors.Add(enbul); SoundPlayer lazershot2 = new SoundPlayer(@"Media\Lazer2.wav"); lazershot2.Play(); BullShot.Restart(); } }