private void Start() { collider = gameObject.GetComponent <Collider2D>(); rigidbody = gameObject.GetComponent <Rigidbody2D>(); if (collider == null) { throw new System.Exception("The player does not have a 2D collider attached."); } if (rigidbody == null) { throw new System.Exception("The player does not have a 2D rigidbody attached."); } ship = transform.Find("Ship").gameObject; Health3 = GameObject.Find("Health3").gameObject; Health2 = GameObject.Find("Health2").gameObject; Health1 = GameObject.Find("Health1").gameObject; spawner = gameObject.GetComponent <Spawner>(); bullet = new PatternSpawn(0f, new LineSpawn(SpawnPattern.Single(10f), 3, Vector2.left * 0.2f + Vector2.down * 0.1f, 0f), new LineSpawn(SpawnPattern.Single(10f), 3, Vector2.right * 0.2f + Vector2.down * 0.1f, 0f)); fireSound = Resources.Load <GameObject>("Prefabs/Laser"); damageSound = Resources.Load <GameObject>("Prefabs/PlayerDamage"); deathSound = Resources.Load <GameObject>("Prefabs/Death"); }
/// <summary> /// /// </summary> /// <param name="child">The pattern to spawn in a line.</param> /// <param name="projectileCount">The number of projectiles to spawn</param> /// <param name="offsetPerSpawn">The positional offset of each bullet</param> /// <param name="delayPerSpawn">Time delay per bullet spawn</param> /// <param name="deltaSpeedPerSpawn">The increase in speed per spawn</param> /// <param name="center">If true, the position will represent the center of the line, instead of the end</param> public LineSpawn(BulletSpawnDefinition child, int projectileCount, Vector2 offsetPerSpawn, float delayPerSpawn = 0f, float deltaSpeedPerSpawn = 0f, bool center = false) : base(child) { this.projectileCount = projectileCount; this.offsetPerSpawn = offsetPerSpawn; this.delayPerSpawn = delayPerSpawn; this.deltaSpeedPerSpawn = deltaSpeedPerSpawn; this.center = center; }
/// <summary> /// Spawns the child bullet pattern in a fan /// </summary> /// <param name="child">The base pattern to use for the fan</param> /// <param name="projectileCount">The number of projectiles to spawn in the fan</param> /// <param name="deltaAnglePerSpawn">The angle difference per spawn</param> /// <param name="delayPerSpawn">The delay per spawn</param> /// <param name="deltaSpeedPerSpawn">The change in speed per spawn</param> /// <param name="center">If true, the spawn will fan out from the center, instead of the edge</param> public FanSpawn(BulletSpawnDefinition child, int projectileCount, float deltaAnglePerSpawn, float delayPerSpawn = 0f, float deltaSpeedPerSpawn = 0f, bool center = true) : base(child) { this.projectileCount = projectileCount; this.deltaAnglePerSpawn = deltaAnglePerSpawn; this.delayPerSpawn = delayPerSpawn; this.deltaSpeedPerSpawn = deltaSpeedPerSpawn; this.center = center; }
private DropInOut Init(Vector2 startPos, Vector2 enterPos, Vector2 exitPos, float speed, BulletSpawnDefinition pattern, Vector2 target) { this.startPos = startPos; this.enterPos = enterPos; this.exitPos = exitPos; this.speed = speed; this.pattern = pattern; this.target = target; return(this); }
protected void ShootUpdate(bool isPlayerClose) { if (waves.Length == 0 || (!repeat && currentWaveIndex >= waves.Length)) { return; } elapsedTime = Mathf.Clamp(elapsedTime + timeHandler.DeltaTime, 0, waves[waves.Length - 1].timeToSpawn); if (timeHandler.GameSpeed <= 0) { while (currentWaveIndex > 0 && elapsedTime >= waves[currentWaveIndex].timeToSpawn) { --currentWaveIndex; } return; } if (elapsedTime >= waves[currentWaveIndex].timeToSpawn && isPlayerClose) { BulletSpawnDefinition definition = waves[currentWaveIndex]; SpawnWave(definition.wave); ++currentWaveIndex; if (repeat && currentWaveIndex >= waves.Length) { ResetShot(); } else if (currentWaveIndex >= waves.Length) { hasFinishedShooting = true; } } }
public static BulletSpawnDefinition AcceleratingFan(float anglePerBullet, int bulletsPerLine, int linesPerVolley, float speedGrowthPerBullet, BulletSpawnDefinition baseDefinition) { return(new FanSpawn(new LineSpawn(baseDefinition, linesPerVolley, Vector2.zero, 0f, speedGrowthPerBullet), linesPerVolley, anglePerBullet)); }
/// <summary> /// Creates a fan blade with two bursts, with bullets interleaved. /// </summary> /// <param name="fanAngle"></param> /// <param name="bulletsPerVolley"></param> /// <param name="delay"></param> /// <param name="baseDefinition"></param> /// <returns></returns> public static BulletSpawnDefinition InterleavedFan(float fanAngle, int bulletsPerVolley, float delay, BulletSpawnDefinition baseDefinition) { return(new PatternSpawn(delay, new FanSpawn(baseDefinition, bulletsPerVolley, fanAngle), new FanSpawn(baseDefinition, bulletsPerVolley - 1, fanAngle))); }
public static DropInOut Create(GameObject prefab, Vector2 startPos, Vector2 enterPos, Vector2 exitPos, float speed, BulletSpawnDefinition pattern, Vector2 target) { return(Instantiate(prefab).GetComponent <DropInOut>().Init(startPos, enterPos, exitPos, speed, pattern, target)); }
protected BulletSpawnDefinition(BulletSpawnDefinition child) { this.child = child; }
public void MirrorDropInSpawnLeave(BulletSpawnDefinition defA, BulletSpawnDefinition defB, Vector2 targetAVec, Vector2 targetBVec, Vector2 targetCVec, Vector2 targetDVec) { DropInSpawnLeave(transform.position, transform.position + Vector3.right * 10f, Vector2.down * 10f, targetAVec, targetBVec, defA, defB); DropInSpawnLeave(transform.position + Vector3.right * 10f + Vector3.down * 30f, transform.position + Vector3.down * 30f, Vector3.up * 10f, targetCVec, targetDVec, defA, defB); }
public void DropInSpawnLeave(Vector2 posA, Vector2 posB, Vector2 moveDelta, Vector2 targetDeltaA, Vector2 targetDeltaB, BulletSpawnDefinition defA, BulletSpawnDefinition defB) { Vector2 AMovePos = posA + moveDelta; Vector2 BMovePos = posB + moveDelta; Vector2 ATargetPos = AMovePos + targetDeltaA; Vector2 BTargetPos = BMovePos + targetDeltaB; DropInOut.Create(dropInOutPrefab, posA, AMovePos, posA, 10f, defA, ATargetPos); DropInOut.Create(dropInOutPrefab, posB, BMovePos, posB, 10f, defB, BTargetPos); }
public RepeatSpawn(BulletSpawnDefinition child, int repeatCount, float timeDelayPerSpawn) : base(child) { this.repeatCount = repeatCount; this.timeDelayPerSpawn = timeDelayPerSpawn; }