private void Start() { bossAttack = GetComponent <BossAttack>(); bossAnimations = GetComponent <BossAnimations>(); audioSystem = GameObject.FindWithTag("AudioSystem").GetComponent <AudioSystem>(); scoreSystem = GameObject.FindWithTag("ScoreSystem").GetComponent <ScoreSystem>(); }
private void Start() { anim = GetComponent <BossAnimations>(); transform.position = new Vector2(minX, yPos); bossAi = GetComponent <BossAI>(); bossRend = FindObjectOfType <BossRend>(); transform.eulerAngles = new Vector3(transform.rotation.x, 0f, transform.rotation.z); }
//wake up boss public static void WakeUp() { bossAnimation = BossAnimations.stoneToIdle; bossAnimations[(int)bossAnimation].Reset(); rightWingAnimation = WingAnimations.stoneToIdle; leftWingAnimation = WingAnimations.stoneToIdle; rightWingAnimations[(int)rightWingAnimation].Reset(); leftWingAnimations[(int)leftWingAnimation].Reset(); MediaPlayer.Play(SoundEffects.FinaBossSoundTrack); MediaPlayer.IsRepeating = true; }
//reset all variables to what they are before the boss fight public static void Reset() { elapsedRecoveryTime = 0; elapsedAttackAnimationTime = 0; YSpeed = 0; bossAnimation = BossAnimations.stone; rightWingAnimation = WingAnimations.stoneIdle; leftWingAnimation = WingAnimations.stoneIdle; rightWingTexture = WingTextures.stone; leftWingTexture = WingTextures.stone; currentPhase = Phases.one; bossColor = Color.White; frameCount = 0; bossInitialMidPoint = new Vector2(fireballsCenter.X, fireballsCenter.Y - 13); bossHP = maxBossHp; rightWingHP = maxWingHP; leftWingHP = maxWingHP; bossMidPoint = bossInitialMidPoint + new Vector2(0, 5); }
public static void Update(float elapsedTime) { if (dead || bossAnimation == BossAnimations.stone) { return; //do not update if boss is dead } if (bossAnimation != BossAnimations.stone && bossAnimation != BossAnimations.stoneToIdle && bossAnimation != BossAnimations.falling) { //oscillatory motion bossMidPoint.Y += YSpeed; YSpeed += (bossInitialMidPoint.Y - bossMidPoint.Y) * 0.2f * elapsedTime; } bossAnimations[(int)bossAnimation].Update(elapsedTime); rightWingAnimations[(int)rightWingAnimation].Update(elapsedTime); leftWingAnimations[(int)leftWingAnimation].Update(elapsedTime); if (!bossAnimations[(int)bossAnimation].Active) {//if an animation has stopped playing because the last frame was reached //decide what animation should be played next if (bossAnimation == BossAnimations.startRecovering) { bossAnimation = BossAnimations.recovering; rightWingAnimation = WingAnimations.flap; leftWingAnimation = WingAnimations.flap; bossAnimations[(int)bossAnimation].Reset(); rightWingAnimations[(int)rightWingAnimation].Reset(); leftWingAnimations[(int)leftWingAnimation].Reset(); } else { bossAnimation = BossAnimations.idle; rightWingAnimation = WingAnimations.idle; leftWingAnimation = WingAnimations.idle; if (rightWingTexture == WingTextures.stone || leftWingTexture == WingTextures.stone) { rightWingTexture = WingTextures.healthy; leftWingTexture = WingTextures.healthy; } bossAnimations[(int)bossAnimation].Reset(); rightWingAnimations[(int)rightWingAnimation].Reset(); leftWingAnimations[(int)leftWingAnimation].Reset(); } } //finate state machine determing the boss AI switch (bossAnimation) { case BossAnimations.stone: break; case BossAnimations.stoneToIdle: break; case BossAnimations.idle: //if the boss is in th eidle state, then it is ready to attack //the attacks available depend on the phace of the battle //the battle progresses to the next phase each time a wing is hit if (!bossAnimations[(int)bossAnimation].IsLastFrame()) { break; } switch (currentPhase) { case Phases.one: { if (bossHP <= 0) { bossAnimation = BossAnimations.startRecovering; bossAnimations[(int)BossAnimations.startRecovering].Reset(); LavaGeyserManager.Reset(); FireBallsManager.Reset(); rightWingAnimation = WingAnimations.spread; leftWingAnimation = WingAnimations.spread; rightWingAnimations[(int)rightWingAnimation].Reset(); leftWingAnimations[(int)leftWingAnimation].Reset(); break; } if (FireBallsManager.NumberOfActiveFireballs > 0 || LavaGeyserManager.ActiveLavaGeysers > 0) { break; } int attack = rand.Next(4); if (attack == 0) { FireBallsManager.ThrowAtPlayer((int)MathHelper.Lerp(3, 6, 1 - (float)bossHP / maxBossHp), 2 + (float)rand.NextDouble(), 1f); bossAnimation = BossAnimations.attack; bossAnimations[(int)BossAnimations.attack].Reset(); rightWingAnimations[(int)rightWingAnimation].Reset(); leftWingAnimations[(int)leftWingAnimation].Reset(); } else if (attack == 1) { FireBallsManager.ThrowInAllDirections((int)MathHelper.Lerp(3, 7, 1 - (float)bossHP / maxBossHp), FireBall.radialShootingVelocity, (float)(0.5 + rand.NextDouble())); bossAnimation = BossAnimations.attack; bossAnimations[(int)BossAnimations.attack].Reset(); rightWingAnimations[(int)rightWingAnimation].Reset(); leftWingAnimations[(int)leftWingAnimation].Reset(); } else if (attack == 2) { int num = (int)MathHelper.Lerp(2, 4, 1 - (float)bossHP / maxBossHp); int[] platforms = new int[num]; for (int i = 0; i < num; i++) { int nextPlatform = rand.Next(PlatformsManager.platformsRoomManagers[(int)RoomsManager.CurrentRoom].movingPlatforms.Length - 1); while (platforms.Contains(nextPlatform)) { nextPlatform = (nextPlatform + 1) % (PlatformsManager.platformsRoomManagers[(int)RoomsManager.CurrentRoom].movingPlatforms.Length - 1); } platforms[i] = nextPlatform; } FireBallsManager.TargetPlatform(platforms, 6, 2); FireBallsManager.AddGhostFireball(7); bossAnimation = BossAnimations.attack; bossAnimations[(int)BossAnimations.attack].Reset(); rightWingAnimations[(int)rightWingAnimation].Reset(); leftWingAnimations[(int)leftWingAnimation].Reset(); } else { FireBallsManager.Sweep((float)(0.4 + 0.2 * rand.NextDouble()), rand.Next(3, 5)); bossAnimation = BossAnimations.attack; bossAnimations[(int)BossAnimations.attack].Reset(); rightWingAnimations[(int)rightWingAnimation].Reset(); leftWingAnimations[(int)leftWingAnimation].Reset(); } SoundEffects.FinalBossAttack.Play(); break; } case Phases.two: { if (bossHP <= 0) { bossAnimation = BossAnimations.startRecovering; bossAnimations[(int)BossAnimations.startRecovering].Reset(); LavaGeyserManager.Reset(); FireBallsManager.Reset(); rightWingAnimation = WingAnimations.spread; leftWingAnimation = WingAnimations.spread; rightWingAnimations[(int)rightWingAnimation].Reset(); leftWingAnimations[(int)leftWingAnimation].Reset(); break; } if (FireBallsManager.NumberOfActiveFireballs > 0 || LavaGeyserManager.ActiveLavaGeysers > 0) { break; } int attack = rand.Next(3); if (attack == 0) { attack = rand.Next(2); if (attack == 0) { FireBallsManager.ThrowAtPlayer((int)MathHelper.Lerp(4, 9, 1 - (float)bossHP / maxBossHp), (float)(3 + rand.NextDouble()), 1f); } else { FireBallsManager.ThrowInAllDirections(6, FireBall.radialShootingVelocity, (float)(1 + rand.NextDouble())); } int num = (int)MathHelper.Lerp(2, 4, 1 - (float)bossHP / maxBossHp); int[] platforms = new int[num]; for (int i = 0; i < num; i++) { int nextPlatform = rand.Next(PlatformsManager.platformsRoomManagers[(int)RoomsManager.CurrentRoom].movingPlatforms.Length - 1); while (platforms.Contains(nextPlatform)) { nextPlatform = (nextPlatform + 1) % (PlatformsManager.platformsRoomManagers[(int)RoomsManager.CurrentRoom].movingPlatforms.Length - 1); } platforms[i] = nextPlatform; } FireBallsManager.TargetPlatform(platforms, 6, 2); FireBallsManager.AddGhostFireball(7); bossAnimation = BossAnimations.attack; bossAnimations[(int)BossAnimations.attack].Reset(); rightWingAnimations[(int)rightWingAnimation].Reset(); leftWingAnimations[(int)leftWingAnimation].Reset(); } else if (attack == 1) { float angle = MathHelper.Lerp(90, 180, 1 - (float)bossHP / maxBossHp); FireBallsManager.TrowWithinCircularSector( (int)(angle / 6), FireBall.radialShootingVelocity * 0.8f, (float)(0.25 + 0.5 * rand.NextDouble()), angle); bossAnimation = BossAnimations.attack; bossAnimations[(int)BossAnimations.attack].Reset(); rightWingAnimations[(int)rightWingAnimation].Reset(); leftWingAnimations[(int)leftWingAnimation].Reset(); } else { FireBallsManager.RandomSweep((float)(1.0f + 0.2 * rand.NextDouble()), 2, 4); bossAnimation = BossAnimations.attack; bossAnimations[(int)BossAnimations.attack].Reset(); rightWingAnimations[(int)rightWingAnimation].Reset(); leftWingAnimations[(int)leftWingAnimation].Reset(); } SoundEffects.FinalBossAttack.Play(); break; } case Phases.three: { if (bossHP <= 0) { bossAnimation = BossAnimations.startRecovering; bossAnimations[(int)BossAnimations.startRecovering].Reset(); LavaGeyserManager.Reset(); FireBallsManager.Reset(); rightWingAnimation = WingAnimations.spread; leftWingAnimation = WingAnimations.spread; rightWingAnimations[(int)rightWingAnimation].Reset(); leftWingAnimations[(int)leftWingAnimation].Reset(); break; } if (FireBallsManager.NumberOfActiveFireballs > 0 || LavaGeyserManager.ActiveLavaGeysers > 0) { break; } int attack = rand.Next(4); if (attack == 0) { attack = rand.Next(2); if (attack == 0) { int num = 2; int[] platforms = new int[num]; for (int i = 0; i < num; i++) { int nextPlatform = rand.Next(PlatformsManager.platformsRoomManagers[(int)RoomsManager.CurrentRoom].movingPlatforms.Length - 1); while (platforms.Contains(nextPlatform)) { nextPlatform = (nextPlatform + 1) % (PlatformsManager.platformsRoomManagers[(int)RoomsManager.CurrentRoom].movingPlatforms.Length - 1); } platforms[i] = nextPlatform; } FireBallsManager.TargetPlatform(platforms, 6, 2); FireBallsManager.AddGhostFireball(7); } else { FireBallsManager.ThrowAtPlayer(4, (float)(3 + rand.NextDouble()), 1f); } LavaGeyserManager.ShootGeyser( new float[] { rand.Next((int)fireballsCenter.X - 200, (int)fireballsCenter.X + 200), rand.Next((int)fireballsCenter.X - 200, (int)fireballsCenter.X + 200), }, 3); bossAnimation = BossAnimations.attack; bossAnimations[(int)BossAnimations.attack].Reset(); rightWingAnimations[(int)rightWingAnimation].Reset(); leftWingAnimations[(int)leftWingAnimation].Reset(); } else if (attack == 1) { int num = 3; int[] platforms = new int[num]; for (int i = 0; i < num; i++) { int nextPlatform = rand.Next(PlatformsManager.platformsRoomManagers[(int)RoomsManager.CurrentRoom].movingPlatforms.Length - 1); while (platforms.Contains(nextPlatform)) { nextPlatform = (nextPlatform + 1) % (PlatformsManager.platformsRoomManagers[(int)RoomsManager.CurrentRoom].movingPlatforms.Length - 1); } platforms[i] = nextPlatform; } FireBallsManager.TargetPlatform(platforms, 6, 5); FireBallsManager.TrowWithinCircularSector( 20, FireBall.radialShootingVelocity * 0.8f, (float)(0.5 + 0.1 * rand.NextDouble()), 120); bossAnimation = BossAnimations.attack; bossAnimations[(int)BossAnimations.attack].Reset(); rightWingAnimations[(int)rightWingAnimation].Reset(); leftWingAnimations[(int)leftWingAnimation].Reset(); } else if (attack == 2) { FireBallsManager.Spiral(30, 20, MathHelper.Lerp(0.3f, 0.5f, (float)bossHP / maxBossHp), FireBall.radialShootingVelocity * 0.4f); bossAnimation = BossAnimations.attack; bossAnimations[(int)BossAnimations.attack].Reset(); rightWingAnimations[(int)rightWingAnimation].Reset(); leftWingAnimations[(int)leftWingAnimation].Reset(); } else { LavaGeyserManager.EquallySpaced(LavaGeyser.size * 7, 2, 0); bossAnimation = BossAnimations.attack; bossAnimations[(int)BossAnimations.attack].Reset(); rightWingAnimations[(int)rightWingAnimation].Reset(); leftWingAnimations[(int)leftWingAnimation].Reset(); } SoundEffects.FinalBossAttack.Play(); break; } case Phases.four: { if (bossHP <= 0) { bossAnimation = BossAnimations.startRecovering; bossAnimations[(int)BossAnimations.startRecovering].Reset(); LavaGeyserManager.Reset(); FireBallsManager.Reset(); rightWingAnimation = WingAnimations.spread; leftWingAnimation = WingAnimations.spread; rightWingAnimations[(int)rightWingAnimation].Reset(); leftWingAnimations[(int)leftWingAnimation].Reset(); break; } if (FireBallsManager.NumberOfActiveFireballs > 0 || LavaGeyserManager.ActiveLavaGeysers > 0) { break; } int attack = rand.Next(3); if (attack == 0) { FireBallsManager.Sweep((float)(0.4 + 0.2 * rand.NextDouble()), 10); LavaGeyserManager.SweepAcross( 1, 0.5f, (int)MathHelper.Lerp(4, 10, (float)bossHP / maxBossHp), 244, 524, rand.Next(2) == 0); bossAnimation = BossAnimations.attack; bossAnimations[(int)BossAnimations.attack].Reset(); rightWingAnimations[(int)rightWingAnimation].Reset(); leftWingAnimations[(int)leftWingAnimation].Reset(); } else if (attack == 1) { FireBallsManager.TrowWithinCircularSector( (int)(20), FireBall.radialShootingVelocity * 0.8f, (float)(0.25 + 0.5 * rand.NextDouble()), 120); LavaGeyserManager.EquallySpaced(LavaGeyser.size * 6, 2, LavaGeyser.size * 6 * (float)rand.NextDouble()); bossAnimation = BossAnimations.attack; bossAnimations[(int)BossAnimations.attack].Reset(); rightWingAnimations[(int)rightWingAnimation].Reset(); leftWingAnimations[(int)leftWingAnimation].Reset(); } else { LavaGeyserManager.ShootGeyser( new float[] { rand.Next((int)fireballsCenter.X - 200, (int)fireballsCenter.X + 200), rand.Next((int)fireballsCenter.X - 200, (int)fireballsCenter.X + 200), }, 3); FireBallsManager.Spiral(30, 20, 0.3f, FireBall.radialShootingVelocity * 0.4f); bossAnimation = BossAnimations.attack; bossAnimations[(int)BossAnimations.attack].Reset(); rightWingAnimations[(int)rightWingAnimation].Reset(); leftWingAnimations[(int)leftWingAnimation].Reset(); } SoundEffects.FinalBossAttack.Play(); break; } } break; case BossAnimations.attack: //the boss is attacking elapsedAttackAnimationTime += elapsedTime; if (elapsedAttackAnimationTime >= attackAnimationTime) { elapsedAttackAnimationTime = 0; bossAnimation = BossAnimations.idle; bossAnimations[(int)BossAnimations.idle].Reset(); bossAnimations[(int)BossAnimations.endRecovering].Reset(); rightWingAnimations[(int)rightWingAnimation].Reset(); leftWingAnimations[(int)leftWingAnimation].Reset(); } break; case BossAnimations.startRecovering: break; case BossAnimations.recovering: //the boss is recovering and its wings can be hit { if (bossAnimations[(int)bossAnimation].FrameIndex == 0 && bossAnimations[(int)bossAnimation].FreviousFrameIndex != 0) { SoundEffects.FinalBossRecover.Play(); } else if (bossAnimations[(int)bossAnimation].FrameIndex == 2 && bossAnimations[(int)bossAnimation].FreviousFrameIndex != 2) { SoundEffects.FinalBossAwaken.Play(); } elapsedRecoveryTime += elapsedTime; if (elapsedRecoveryTime >= recoveryTime) { bossAnimation = BossAnimations.endRecovering; if (rightWingHP > 0) { rightWingAnimation = WingAnimations.withdraw; } else { rightWingAnimation = WingAnimations.withdrawDead; } if (leftWingHP > 0) { leftWingAnimation = WingAnimations.withdraw; } else { leftWingAnimation = WingAnimations.withdrawDead; } bossAnimations[(int)BossAnimations.endRecovering].Reset(); rightWingAnimations[(int)rightWingAnimation].Reset(); leftWingAnimations[(int)leftWingAnimation].Reset(); elapsedRecoveryTime = 0; bossHP = maxBossHp / 2; break; } switch (currentPhase) { case Phases.one: if (rightWingHP + leftWingHP == 3) { bossHP = maxBossHp; elapsedRecoveryTime = 0; currentPhase = Phases.two; bossAnimation = BossAnimations.endRecovering; if (rightWingHP > 0) { rightWingAnimation = WingAnimations.withdraw; } else { rightWingAnimation = WingAnimations.withdrawDead; } if (leftWingHP > 0) { leftWingAnimation = WingAnimations.withdraw; } else { leftWingAnimation = WingAnimations.withdrawDead; } bossAnimations[(int)BossAnimations.attack].Reset(); bossAnimations[(int)BossAnimations.endRecovering].Reset(); rightWingAnimations[(int)rightWingAnimation].Reset(); leftWingAnimations[(int)leftWingAnimation].Reset(); SoundEffects.FinalBossHurt.Play(); FireBallsManager.AddGhostFireball(3); } break; case Phases.two: if (rightWingHP + leftWingHP == 2) { bossHP = maxBossHp; elapsedRecoveryTime = 0; currentPhase = Phases.three; bossAnimation = BossAnimations.endRecovering; if (rightWingHP > 0) { rightWingAnimation = WingAnimations.withdraw; } else { rightWingAnimation = WingAnimations.withdrawDead; } if (leftWingHP > 0) { leftWingAnimation = WingAnimations.withdraw; } else { leftWingAnimation = WingAnimations.withdrawDead; } bossAnimations[(int)BossAnimations.attack].Reset(); bossAnimations[(int)BossAnimations.endRecovering].Reset(); rightWingAnimations[(int)rightWingAnimation].Reset(); leftWingAnimations[(int)leftWingAnimation].Reset(); SoundEffects.FinalBossHurt.Play(); FireBallsManager.ThrowAtPlayer(20, 2, 0.1f); CollectablesManager.collectablesRoomManagers[(int)RoomsManager.CurrentRoom].AddCollectableToMap( new Collectable(new Point(374, 475), Collectable.ItemType.heart)); } break; case Phases.three: if (rightWingHP + leftWingHP == 1) { bossHP = maxBossHp; elapsedRecoveryTime = 0; currentPhase = Phases.four; bossAnimation = BossAnimations.endRecovering; if (rightWingHP > 0) { rightWingAnimation = WingAnimations.withdraw; } else { rightWingAnimation = WingAnimations.withdrawDead; } if (leftWingHP > 0) { leftWingAnimation = WingAnimations.withdraw; } else { leftWingAnimation = WingAnimations.withdrawDead; } bossAnimations[(int)BossAnimations.attack].Reset(); bossAnimations[(int)BossAnimations.endRecovering].Reset(); rightWingAnimations[(int)rightWingAnimation].Reset(); leftWingAnimations[(int)leftWingAnimation].Reset(); SoundEffects.FinalBossHurt.Play(); LavaGeyserManager.SweepAcross(1, 0f, 100, 159, 609, true); CollectablesManager.collectablesRoomManagers[(int)RoomsManager.CurrentRoom].AddCollectableToMap( new Collectable(new Point(378, 475), Collectable.ItemType.heart)); } break; case Phases.four: if (rightWingHP + leftWingHP == 0) { if (Player.CollisionRectangle.Right > bossMidPoint.X) { rightWingAnimation = WingAnimations.withdraw; leftWingAnimation = WingAnimations.withdrawDead; } else { rightWingAnimation = WingAnimations.withdrawDead; leftWingAnimation = WingAnimations.withdraw; } bossAnimation = BossAnimations.falling; bossAnimations[(int)BossAnimations.attack].Reset(); rightWingAnimations[(int)rightWingAnimation].Reset(); leftWingAnimations[(int)leftWingAnimation].Reset(); elapsedRecoveryTime = 0; SoundEffects.FinalBossHurt.Play(); FireBallsManager.Reset(); LavaGeyserManager.Reset(); } break; } break; } case BossAnimations.endRecovering: break; case BossAnimations.falling: //when the boss dies, it falls out of the screen { bossMidPoint.Y += YSpeed * elapsedTime; YSpeed += Gravity.gravityAcceleration * elapsedTime; if (BossDrawRectangle.Y > MapsManager.maps[(int)RoomsManager.CurrentRoom].RoomHeightPx) { dead = true; LoadSaveManager.SaveGameProgress(); MediaPlayer.Stop(); } break; } } }