void makeCircle(int number, EnemyShot type, float offset, float vel, float accel, float minv, float maxv, int tickrate, bool decelYN, int moveFx, float incr) { float betAng = 360 / number; //Creates number of bullets for (int i = 0; i < number + 1; i++) { EnemyShot circBullet = Instantiate(type, transform.position, Quaternion.identity) as EnemyShot; circBullet.mvtFxn = moveFx; circBullet.velocity = vel; circBullet.acceleration = accel; circBullet.minvelocity = minv; circBullet.maxvelocity = maxv; circBullet.ticks = tickrate; circBullet.direction = GlobalFxns.ToVect(betAng * i + offset); circBullet.increment = incr; if (decelYN) { circBullet.decelerating = true; } else { circBullet.decelerating = false; } } }
//Nonspell 1 void Nonspell1() { if (currentStg == 1) { if (timer == 5) { playSnd(1); } if (timer == 10) { playSnd(1); } if (timer > 15) { playSnd(1); EnemyShot a = (Instantiate(bulletA, transform.position, Quaternion.Euler(GlobalFxns.ToVect(0 + rotation))) as EnemyShot); EnemyShot b = (Instantiate(bulletA, transform.position, Quaternion.Euler(GlobalFxns.ToVect(120 + rotation))) as EnemyShot); EnemyShot c = (Instantiate(bulletA, transform.position, Quaternion.Euler(GlobalFxns.ToVect(240 + rotation))) as EnemyShot); a.direction = (GlobalFxns.ToVect(0 + rotation)); b.direction = (GlobalFxns.ToVect(120 + rotation)); c.direction = (GlobalFxns.ToVect(240 + rotation)); a.transform.eulerAngles = new Vector3(0, 0, GlobalFxns.ToAng(a.direction) + 90); b.transform.eulerAngles = new Vector3(0, 0, GlobalFxns.ToAng(b.direction) + 90); c.transform.eulerAngles = new Vector3(0, 0, GlobalFxns.ToAng(c.direction) + 90); a.setParameters(1, .05f, 0, .05f, .05f, 1, false); b.setParameters(1, .05f, 0, .05f, .05f, 1, false); c.setParameters(1, .05f, 0, .05f, .05f, 1, false); rotation += 10; timer = 0; } } }
new void makeCircle(int number, float offset, float vel, float accel, float minv, float maxv, int tickrate, bool decelYN, int sndVer) { float betAng = 360 / number; //Creates number of bullets for (int i = 0; i < number + 1; i++) { EnemyShot circBullet = Instantiate(bulletA, transform.position, Quaternion.identity) as EnemyShot; circBullet.mvtFxn = 2; circBullet.velocity = vel; circBullet.acceleration = accel; circBullet.minvelocity = minv; circBullet.maxvelocity = maxv; circBullet.ticks = tickrate; circBullet.direction = GlobalFxns.ToVect(betAng * i + offset); circBullet.transform.eulerAngles = new Vector3(0, 0, betAng * i + offset + 90); if (decelYN) { circBullet.decelerating = true; } else { circBullet.decelerating = false; } } }
void AimShot() { if (shotTimer > shotDelay) { float deviation = Random.Range(-variance, variance); float tempX = Controller.Instance.player.transform.position.x; float tempY = Controller.Instance.player.transform.position.y; Vector3 rota = (new Vector3(tempX - this.transform.position.x, tempY - this.transform.position.y, 0)); EnemyShot aimed = Instantiate(bullet, transform.position, Quaternion.identity); bullet.mvtFxn = 2; shotTimer = 0; aimed.playerX = tempX; aimed.playerY = tempY; Vector3 dir = rota; if (indirect) { float ang = GlobalFxns.ToAng(dir.normalized); aimed.direction = GlobalFxns.ToVect(ang + deviation); } else { aimed.direction = dir.normalized; } playSnd(1); } }
/// <summary> /// 弾を発射する関数 /// </summary> /// <param name="angleBase"></param> /// <param name="angleRange"></param> /// <param name="speed"></param> /// <param name="count"></param> private void ShootNWay(float angleBase, float angleRange, float speed, int count) { // var pos = transform.position + transform.forward; // プレイヤーの位置 var pos = canonPos.position; var rot = transform.rotation; // プレイヤーの向き // 弾を複数発射する場合 if (1 < count) { // 発射する回数分ループする for (int i = 0; i < count; ++i) { // 弾の発射角度を計算する var angle = angleBase + angleRange * ((float)i / (count - 1) - 0.5f); // 発射する弾を生成する var shot = EnemyShot.Add(this.gameObject.tag, pos.x, pos.y, pos.z, player); // 弾を発射する方向と速さを設定する shot.Init(angle, speed, gm); } } // 弾を 1 つだけ発射する場合 else if (count == 1) { // 発射する弾を生成する var shot = EnemyShot.Add(this.gameObject.tag, pos.x, pos.y, pos.z, player); // 弾を発射する方向と速さを設定する shot.Init(angleBase, speed, gm); shot.StartShotEffect(); } }
void CheckEnemyAttack() { if (levelActive && Time.time >= lastEnemyAttack + enemyAttackInterval) { float enemyFireAngle = Random.Range(0, 360); if (Mathf.Abs(enemyFireAngle - lastEnemyShotAngle) <= 45f) { enemyFireAngle -= 180f; } enemyFireAngle = enemyFireAngle > 360f ? enemyFireAngle - 360f : enemyFireAngle < 0f ? enemyFireAngle + 360f : enemyFireAngle; Vector2 esshotangle = Vector2.zero; esshotangle.x = Mathf.Cos(enemyFireAngle * Mathf.Deg2Rad); esshotangle.y = Mathf.Sin(enemyFireAngle * Mathf.Deg2Rad); enemyShip.selfTransform.localRotation = Quaternion.FromToRotation(Vector3.down, esshotangle); lastEnemyAttack = Time.time; lastEnemyShotAngle = enemyFireAngle; if (enemyShotPool != null) { Transform estrans = enemyShotPool.Spawn(); EnemyShot es = estrans.GetComponent <EnemyShot>(); es.EnemyShotStart(this); estrans.position = enemyShip.selfTransform.position; es.moving = true; es.movementSpeed = enemyShotSpeed; es.directedTowardsPlayer = true; es.movementDirection = esshotangle; es.selfTransform.localRotation = Quaternion.FromToRotation(Vector3.up, esshotangle); } } }
void GetAndSetCompoents() { _collider = GetComponent <QuadtreeCollider>(); _life = GetComponent <Life>(); _shot = GetComponent <EnemyShot>(); _move = GetComponent <EnemyMove>(); }
void Spell1() { if (timer > 100 && !chrgAnim) { anim.Play("Mokou"); playSnd(3); chrgAnim = !chrgAnim; } if (timer > 120) { float tempX = Controller.Instance.player.transform.position.x; float tempY = Controller.Instance.player.transform.position.y; Vector3 rota = (new Vector3(tempX - this.transform.position.x, tempY - this.transform.position.y, 0)); float angle = GlobalFxns.ToAng(rota); EnemyShot ph = Instantiate(phoenix, transform.position, Quaternion.identity) as EnemyShot; ph.mvtFxn = 2; ph.velocity = .05f; ph.minvelocity = .05f; ph.maxvelocity = .05f; ph.ticks = 20; ph.playerX = tempX; ph.playerY = tempY; ph.transform.eulerAngles = new Vector3(0, 0, angle + 90); Vector3 dir = rota; ph.direction = dir.normalized; timer = 0; makeCircle(10, offset, .05f, 0, .05f, .05f, 20, false, 1); offset += 5; playSnd(1); chrgAnim = !chrgAnim; } }
void Shoot() { float timeGuess = (player.position - transform.position).magnitude / shotSpeed; timeGuess *= predictionCorrectionCoefficient; timeGuess = timeGuess + Random.Range(timeGuess - predictionFuzzFactor * timeGuess, timeGuess + predictionFuzzFactor * timeGuess); shots++; Debug.Log("Ranged enemy shot"); Vector3 targetPosition = new Vector3(player.position.x, player.position.y + predictionYOffset, player.position.z) + playerRigidbody.velocity * timeGuess; Quaternion targetRotation = Quaternion.LookRotation(targetPosition - shotOrigin.position, Vector3.up); shotOrigin.rotation = targetRotation; GameObject shotObject = Instantiate(shotPrefab, shotOrigin.position, shotOrigin.rotation) as GameObject; EnemyShot shotComponent = shotObject.GetComponent <EnemyShot>(); audioSource.Play(); shotComponent.shooter = this; }
// Update is called once per frame void Update() { if (active) { if (!dead) { //Fire! if (fireTime > 1 / fireRate) { fireTime = 0; EnemyShot shotClone = Instantiate(shot, gun.transform.position + velocity + transform.up * 0.0f, gun.transform.rotation); shotClone.speed = shotSpeed; } else { fireTime += Time.deltaTime; } MovePath(); } Move(); } else { CheckActive(); } }
private void EnemyShotMessageReceived(EnemyShot enemyShot) { pendingActions.Enqueue(() => { enemyManager.ShootEnemy(false, enemyShot.enemyId, enemyShot.damage); }); }
void Shoot() { muzzleFLash.Play(); ak47.Play(); currentAmmo--; ammoTest.ammo = currentAmmo; Vector3 point = new Vector3(playerCam.pixelWidth / 2, playerCam.pixelHeight / 2, 0); Ray ray = playerCam.ScreenPointToRay(point); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { GameObject hitObject = hit.transform.gameObject; EnemyShot target = hitObject.GetComponent <EnemyShot>(); if (target != null) { target.GotShot(damage); GameObject enemyBlood = Instantiate(enemyHitEffect, hit.point, Quaternion.LookRotation(hit.normal)); Destroy(enemyBlood, 2f); } else { GameObject impact = Instantiate(impactEffect, hit.point, Quaternion.LookRotation(hit.normal)); Destroy(impact, 2f); } } }
void Spell1() { if (timer == 30) { makeCircle(24, coinA, offset, .075f, 0, .075f, .075f, 1, false); makeCircle(24, coinB, offset2, .075f, 0, .075f, .075f, 1, false); offset += 12; offset2 -= 12; timer = 0; timer2++; playSnd(1); } if (timer2 == 2) { float tempX = Controller.Instance.player.transform.position.x; float tempY = Controller.Instance.player.transform.position.y; Vector3 rota = (new Vector3(tempX - this.transform.position.x, tempY - this.transform.position.y, 0)); float angle = GlobalFxns.ToAng(rota); EnemyShot targeted = Instantiate(spirit, transform.position, Quaternion.identity); targeted.setParameters(1, .05f, 0, .05f, .05f, 1, false); targeted.transform.eulerAngles = new Vector3(0, 0, angle + 90); Vector3 dir = rota; targeted.direction = dir.normalized; timer2 = 0; } }
// LIFE UI // Image life; // public float max_time = 5f; -> max_life // float time_left; -> life left void Start() { hero = GameObject.Find("Hero"); anim = GetComponent <Animator>(); rb.velocity = -speed * transform.right; shootGenerator = FindObjectOfType <EnemyShot>(); lastShotTime = Time.time; }
public static EnemyShot Add(string tag_name, float x, float y, float z) { // Enemyインスタンスの取得 EnemyShot es = parent.Add(x, y, z); es.SetTagName(tag_name); return(es); }
void Nonspell2() { if (timer == 60) { if (timer2 == 0) { float shotSpd = .05f; for (int i = 0; i < 54; i++) { EnemyShot coin = Instantiate(coinA, transform.position, Quaternion.identity); coin.direction = GlobalFxns.ToVect(0 + rotation + offset); coin.setParameters(1, shotSpd, 0, shotSpd, shotSpd, 1, false); rotation -= 10; shotSpd += .003f; } rotation = 0; timer2 = 1; timer3++; } else if (timer2 == 1) { float shotSpd = .05f; for (int i = 0; i < 54; i++) { EnemyShot coin = Instantiate(coinB, transform.position, Quaternion.identity); coin.direction = GlobalFxns.ToVect(180 + rotation + offset); coin.setParameters(1, shotSpd, 0, shotSpd, shotSpd, 1, false); rotation += 10; shotSpd += .003f; } rotation = 0; timer2 = 0; timer3++; } playSnd(2); } if (timer > 90) { if (timer3 > 3) { float streamSpd = .05f; float tempX = Controller.Instance.player.transform.position.x; float tempY = Controller.Instance.player.transform.position.y; for (int i = 0; i < 3; i++) { Vector3 rota = (new Vector3(tempX - this.transform.position.x, tempY - this.transform.position.y, 0)); float angle = GlobalFxns.ToAng(rota); makeCircle(20, coinA, angle, streamSpd, 0, streamSpd, streamSpd, 1, false); streamSpd += .005f; playSnd(1); } timer3 = 0; } timer = 0; } }
public void Run() { const int NUM_ENEMIES = 4; ConsoleKeyInfo userkey; Spaceship ship = new Spaceship(); MovingBackground back = new MovingBackground(); Scoreboard sb = new Scoreboard(); Enemy[] enemies = new Enemy[NUM_ENEMIES]; enemies[0] = new EnemyLevel1(); enemies[1] = new EnemyLevel2(); enemies[2] = new EnemyLevel3(); enemies[3] = new EnemyLevel4(); Mothership ms = new Mothership(); PlayerShot shot1 = new PlayerShot(20, 10); EnemyShot shot2 = new EnemyShot(15, 1); while (true) { // Update elements position and appearance back.Update(); ms.Update(); ship.Update(); foreach (Enemy e in enemies) { e.Update(); } shot1.Update(); shot2.Update(); // Screen update Console.Clear(); back.Draw(); sb.Draw(); ms.Draw(); ship.Draw(); foreach (Enemy e in enemies) { e.Draw(); } shot1.Draw(); shot2.Draw(); // Get user input userkey = Console.ReadKey(true); switch (userkey.Key) { case ConsoleKey.A: ship.MoveLeft(); break; case ConsoleKey.D: ship.MoveRight(); break; case ConsoleKey.Escape: return; } } }
public override void Initialize(EnemyShot shot) { base.Initialize(shot); rigidBody = Owner.GetComponent <Rigidbody2D>(); Way = 2; AngleSpan = 30; ShotSpeed = 200; ShotTimeSpan = 0.5f; moveSubscription = null; }
void OnTriggerEnter2D(Collider2D trigger) { EnemyShot laserHit = trigger.GetComponent <EnemyShot> (); if (laserHit) { TakeDamage(laserHit.getDamage()); laserHit.killMe(); } }
//0.5f - For not start shoting private IEnumerator WaitForActiveShot() { yield return(new WaitForSeconds(initialAnimationTime + 0.5f)); EnemyShot enemyShot = GetComponent <EnemyShot>(); if (enemyShot != null) { enemyShot.Active = true; } }
void Spell2() { if (timer > 100 && !chrgAnim) { anim.Play("Mokou"); chrgAnim = !chrgAnim; playSnd(3); } if (timer > 120) { for (int i = 0; i < 5 + 1; i++) { float tempX = Controller.Instance.player.transform.position.x; float tempY = Controller.Instance.player.transform.position.y; Vector3 start = new Vector3(-4 + .8f * i, 16.5f + .4f * i, 0); EnemyShot stream = Instantiate(bulletA, start, Quaternion.identity) as EnemyShot; Vector3 rota = (new Vector3(tempX - stream.transform.position.x, tempY - stream.transform.position.y, 0)); float angle = GlobalFxns.ToAng(rota); Vector3 dir = rota; stream.direction = dir.normalized; stream.transform.eulerAngles = new Vector3(0, 0, angle + 90); stream.setParameters(1, .05f, 0, .05f, .05f, 1, false); } for (int i = 0; i < 4 + 1; i++) { float tempX = Controller.Instance.player.transform.position.x; float tempY = Controller.Instance.player.transform.position.y; Vector3 start = new Vector3(-4.5f - .8f * i, 16.9f + .4f * i, 0); EnemyShot stream = Instantiate(bulletA, start, Quaternion.identity) as EnemyShot; Vector3 rota = (new Vector3(tempX - stream.transform.position.x, tempY - stream.transform.position.y, 0)); float angle = GlobalFxns.ToAng(rota); Vector3 dir = rota; stream.direction = dir.normalized; stream.transform.eulerAngles = new Vector3(0, 0, angle + 90); stream.setParameters(1, .05f, 0, .05f, .05f, 1, false); } timer = 0; chrgAnim = !chrgAnim; playSnd(5); } if (timer2 > 15) { float random = Random.Range(-11f, 3f); Vector3 startLoc = new Vector3(random, 19, 0); EnemyShot rain = Instantiate(bulletB, startLoc, Quaternion.identity); rain.setParameters(1, .2f, -.0001f, .01f, 0, 1, false); rain.direction = new Vector3(0, -.1f, 0); timer2 = 0; playSnd(4); } }
private void OnCollisionEnter2D(Collision2D collision) { GameObject go = collision.gameObject; EnemyShot es = go.GetComponent <EnemyShot>(); if (es) { if (es.isAlive == true)// play death explosion { gm.EndGame(); Destroy(gameObject, 0.5f); } } }
public override void OnInspectorGUI() { EnemyShot script = target as EnemyShot; script.BulletID = EditorGUILayout.TextField("Bullet ID", script.BulletID); script.BulletHue = EditorGUILayout.ColorField("Bullet Hue", script.BulletHue); script.Shot = (EnemyShot.ShotType)EditorGUILayout.EnumPopup("Shot Type", script.Shot); script.Frequency = EditorGUILayout.FloatField("Frequency", Mathf.Max(0.001f, script.Frequency)); script.Velocity = EditorGUILayout.FloatField("Velocity", script.Velocity); switch (script.Shot) { case EnemyShot.ShotType.DIRECT: script.DirectOffset = EditorGUILayout.Slider("Shot Angle (Deg)", script.DirectOffset, 0, 360); break; case EnemyShot.ShotType.CIRCLE: script.NumInCircle = EditorGUILayout.IntField("Bullets per circle", Mathf.Max(0, script.NumInCircle)); script.CircleCount = EditorGUILayout.IntField("Circles Per Wave", Mathf.Max(0, script.CircleCount)); script.Count = EditorGUILayout.IntField("Wave Count", Mathf.Max(-1, script.Count)); script.WaveDelay = EditorGUILayout.FloatField("Time Between Circles", Mathf.Max(0, script.WaveDelay)); break; case EnemyShot.ShotType.RANDOM: script.Count = EditorGUILayout.IntField("Bullet Count", script.Count); script.GravScale = EditorGUILayout.FloatField("Bullet Gravity Scale", script.GravScale); break; case EnemyShot.ShotType.TARGET: script.Left = EditorGUILayout.Toggle("Aim Left", script.Left); script.Direct = EditorGUILayout.Toggle("Aim Directly", script.Direct); script.Right = EditorGUILayout.Toggle("Aim Right", script.Right); if (script.Left) { script.LeftOffset = EditorGUILayout.Slider("Left Offset (Deg)", script.LeftOffset, 0, 180); } if (script.Right) { script.RightOffset = EditorGUILayout.Slider("Right Offset (Deg)", script.RightOffset, 0, 180); } break; case EnemyShot.ShotType.SPIRAL: break; } }
public void Attack() { //これはanimationから呼ばれる Debug.Log("Armor__Attack"); ShotPosition = this.transform.position; ShotPosition.x -= 0.3f; //この下の一行の存在を忘れて永遠に止まっていた許さんぞ過去の俺(許す // Instantiate(ArmorShot,ShotPosition ,Quaternion.identity); NowEnemyShot = Instantiate(ArmorShot, this.transform.position, this.transform.rotation) as GameObject; if (ArmorShot != null) { EnemyShot S = NowEnemyShot.GetComponent <EnemyShot>(); S.Create(360, -ShotSpeed); } }
private void OnTriggerEnter(Collider col) { EnemyHealth enemyHealth = col.gameObject.GetComponent <EnemyHealth>(); if (enemyHealth != null) { enemyHealth.takeDamage(damage); PlayerShotPool.Instance.ReturnToPool(this); } EnemyShot enemyShot = col.gameObject.GetComponent <EnemyShot>(); if (enemyShot != null) { PlayerShotPool.Instance.ReturnToPool(this); } }
private void LoadShotCompleteCB(GameObject gameObj, System.Guid uid, params object[] param) { if (gameObj != null) { GameObject createObj = Instantiate(gameObj) as GameObject; createObj.transform.parent = GameManager.Instance. rootArray[(int)GameManager.eRootType.Type_Object].transform; createObj.transform.position = effectDummy.position; createObj.transform.localScale = gameObj.transform.localScale; EnemyShot shot = createObj.GetComponent <EnemyShot>(); if (shot != null) { shot.Init((int)param[0], (EnemyTable.TableRow)param[1], (Vector3)param[2], (Vector3)param[3]); } } }
private void SetShot() { int hashID = Animator.StringToHash(enemyStatus.table.attackEffectPath); Vector3 targetPos = GameManager.Instance.GetEnemyEndPos(enemyStatus.floorIndex); EnemyShot shot = null; if (PoolManager.Instance != null && PoolManager.Instance.GetEnemyShotFromPool(hashID, out shot)) { shot.Init(hashID, enemyStatus.table, effectDummy.position, targetPos); } else { LoadAssetbundle.LoadPrefabCB loadPrefabCB = new LoadAssetbundle.LoadPrefabCB(LoadShotCompleteCB); PrefabManager.Instance.LoadPrefab(enemyStatus.table.attackEffectPath, System.Guid.NewGuid(), loadPrefabCB, hashID, enemyStatus.table, effectDummy.position, targetPos); } }
private void OnCollisionEnter2D(Collision2D collision) { GameObject go = collision.gameObject; EnemyShot es = go.GetComponent <EnemyShot>(); if (es) { if (es.isAlive == true) { es.DoDamageToShot(3); if (es.isAlive == false) { mainPlayer.ScoreIncrease(1); } } } Destroy(gameObject, 0.2f); }
// Start is called before the first frame update void Start() { enemy = gameObject.transform.parent.GetComponent <EnemyShot>(); target = enemy.target; gameObject.transform.parent = null; targetpos = target.transform.position; if (transform.position.y > targetpos.y) { targetpos.y += 0.5f; } else { targetpos.y -= 0.5f; } rad = Mathf.Atan2( target.transform.position.y - transform.position.y, target.transform.position.x - transform.position.x); vec = (targetpos - transform.position).normalized; }
void AimShotgun() { if (shotTimer > shotDelay) { float tempX = Controller.Instance.player.transform.position.x; float tempY = Controller.Instance.player.transform.position.y; Vector3 rota = (new Vector3(tempX - this.transform.position.x, tempY - this.transform.position.y, 0)); float angle = GlobalFxns.ToAng(rota); EnemyShot aimed1 = Instantiate(bulletGroupA, transform.position, Quaternion.identity); aimed1.mvtFxn = 2; shotTimer = 0; aimed1.playerX = tempX; aimed1.playerY = tempY; Vector3 dir = rota; aimed1.direction = dir.normalized; aimed1.transform.eulerAngles = new Vector3(0, 0, angle + 90); playSnd(1); } }