/// <summary> /// Creates all the beehives and bees. /// </summary> private void CreateBeehives() { // Init position parameters Vector2 scorebarPosition = new Vector2(18, beehiveTexture.Height - 15); Vector2[] beehivePositions = new Vector2[5] { new Vector2(83, 8), new Vector2(347, 8), new Vector2(661, 8), new Vector2(83, 201), new Vector2(661, 201) }; // Create the beehives for (int beehiveCounter = 0; beehiveCounter < beehivePositions.Length; beehiveCounter++) { ScoreBar scoreBar = new ScoreBar(ScreenManager.Game, 0, 100, beehivePositions[beehiveCounter] + scorebarPosition, 10, 68, Color.Green, ScoreBar.ScoreBarOrientation.Horizontal, 100, this, false); ScreenManager.Game.Components.Add(scoreBar); Beehive beehive = new Beehive(ScreenManager.Game, this, beehiveTexture, scoreBar, beehivePositions[beehiveCounter]); beehive.AnimationDefinitions = animations; ScreenManager.Game.Components.Add(beehive); beehives.Add(beehive); scoreBar.DrawOrder = beehive.DrawOrder; } for (int beehiveIndex = 0; beehiveIndex < beehivePositions.Length; beehiveIndex++) { // Create the Soldier bees for (int SoldierBeeCounter = 0; SoldierBeeCounter < amountOfSoldierBee; SoldierBeeCounter++) { SoldierBee bee = new SoldierBee(ScreenManager.Game, this, beehives[beehiveIndex]); bee.AnimationDefinitions = animations; ScreenManager.Game.Components.Add(bee); bees.Add(bee); } // Creates the worker bees for (int workerBeeCounter = 0; workerBeeCounter < amountOfWorkerBee; workerBeeCounter++) { WorkerBee bee = new WorkerBee(ScreenManager.Game, this, beehives[beehiveIndex]); bee.AnimationDefinitions = animations; ScreenManager.Game.Components.Add(bee); bees.Add(bee); } } }
/// <summary> /// Handle the interaction of the bees with other game components. /// </summary> /// <param name="gameTime">Game time information.</param> /// <param name="isBeeKeeperCollideWithVat">Whether the beekeeper is currently touching the vat.</param> /// <param name="isBeeKeeperCollideWithBeehive">Whether the beekeeper is currently touching a beehive.</param> private void HandleBeeInteractions(GameTime gameTime, bool isBeeKeeperCollideWithVat, bool isBeeKeeperCollideWithBeehive) { // Goes over all the bees foreach (Bee bee in bees) { // Check for smoke collisions SmokePuff intersectingPuff = beeKeeper.CheckSmokeCollision(bee.Bounds); if (intersectingPuff != null) { bee.HitBySmoke(intersectingPuff); } // Check for vat collision if (vat.Bounds.HasCollision(bee.Bounds)) { bee.Collide(vat.Bounds); } // Check for beekeeper collision if (beeKeeper.Bounds.HasCollision(bee.Bounds)) { if (!bee.IsBeeHit && !isBeeKeeperCollideWithVat && !beeKeeper.IsStung && !beeKeeper.IsFlashing && !isBeeKeeperCollideWithBeehive) { jar.DecreaseHoneyByPercent(20); beeKeeper.Stung(gameTime.TotalGameTime); AudioManager.PlaySound("HoneyPotBreak"); AudioManager.PlaySound("Stung"); } bee.Collide(beeKeeper.Bounds); } // Soldier bee chase logic if (bee is SoldierBee) { SoldierBee SoldierBee = bee as SoldierBee; SoldierBee.DistanceFromBeeKeeper = (Vector2.Distance(beeKeeper.Bounds.GetVector(), SoldierBee.Bounds.GetVector())); SoldierBee.BeeKeeperVector = beeKeeper.Bounds.GetVector() - SoldierBee.Bounds.GetVector(); } } }
/// <summary> /// Creates all the beehives and bees. /// </summary> private void CreateBeehives(Rectangle safeArea, HoneyJar jar) { Vector2 scaleVector = ScreenManager.SpriteBatch.ScaleVector; // Init position parameters Vector2 scorebarPosition = new Vector2(beehiveTexture.Width * scaleVector.X / 4, beehiveTexture.Height * scaleVector.Y * 9 / 10); Vector2[] beehivePositions = new Vector2[5] { // top left new Vector2(safeArea.Left + UIConstants.BeehiveLeftMargin, safeArea.Top + UIConstants.BeehiveTopMargin), // top middle new Vector2(safeArea.Center.X - beehiveTexture.Width * scaleVector.X / 2, safeArea.Top + UIConstants.BeehiveTopMargin), // top right new Vector2(safeArea.Right - beehiveTexture.Width * scaleVector.X - UIConstants.BeehiveRightMargin, safeArea.Top + UIConstants.BeehiveTopMargin), // left new Vector2(safeArea.Left + UIConstants.BeehiveLeftMargin, safeArea.Center.Y - beehiveTexture.Height * scaleVector.Y / 2 + UIConstants.BeehiveMiddleOffset), // right new Vector2(safeArea.Right - beehiveTexture.Width * scaleVector.X - UIConstants.BeehiveRightMargin, safeArea.Center.Y - beehiveTexture.Height * scaleVector.Y / 2 + UIConstants.BeehiveMiddleOffset) }; // Create the beehives for (int beehiveCounter = 0; beehiveCounter < beehivePositions.Length; beehiveCounter++) { ScoreBar scoreBar = new ScoreBar(ScreenManager.Game, 0, 100, beehivePositions[beehiveCounter] + scorebarPosition, (int)(beehiveTexture.Height * scaleVector.Y / 10), (int)(beehiveTexture.Width * scaleVector.X / 2), Color.Green, ScoreBar.ScoreBarOrientation.Horizontal, 100, this, false); ScreenManager.Game.Components.Add(scoreBar); Beehive beehive = new Beehive(ScreenManager.Game, this, beehiveTexture, scoreBar, beehivePositions[beehiveCounter]); beehive.AnimationDefinitions = animations; ScreenManager.Game.Components.Add(beehive); beehives.Add(beehive); scoreBar.DrawOrder = beehive.DrawOrder; } for (int beehiveIndex = 0; beehiveIndex < beehivePositions.Length; beehiveIndex++) { // Create the Soldier bees for (int SoldierBeeCounter = 0; SoldierBeeCounter < amountOfSoldierBee; SoldierBeeCounter++) { SoldierBee bee = new SoldierBee(ScreenManager.Game, this, beehives[beehiveIndex]); bee.AnimationDefinitions = animations; ScreenManager.Game.Components.Add(bee); bees.Add(bee); } // Creates the worker bees for (int workerBeeCounter = 0; workerBeeCounter < amountOfWorkerBee; workerBeeCounter++) { WorkerBee bee = new WorkerBee(ScreenManager.Game, this, beehives[beehiveIndex]); bee.AnimationDefinitions = animations; ScreenManager.Game.Components.Add(bee); bees.Add(bee); } } }