SHARE
TWEET

Swarm Source Code Sound

SuperLemrick Mar 30th, 2015 259 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ////////////////////////////////////////////////////////////////
  2. // Copyright 2013, CompuScholar, Inc.
  3. //
  4. // This source code is for use by the students and teachers who
  5. // have purchased the corresponding TeenCoder or KidCoder product.
  6. // It may not be transmitted to other parties for any reason
  7. // without the written consent of CompuScholar, Inc.
  8. // This source is provided as-is for educational purposes only.
  9. // CompuScholar, Inc. makes no warranty and assumes
  10. // no liability regarding the functionality of this program.
  11. //
  12. ////////////////////////////////////////////////////////////////
  13.  
  14. using System;
  15. using System.Collections.Generic;
  16. using System.Linq;
  17. using Microsoft.Xna.Framework;
  18. using Microsoft.Xna.Framework.Audio;
  19. using Microsoft.Xna.Framework.Content;
  20. using Microsoft.Xna.Framework.GamerServices;
  21. using Microsoft.Xna.Framework.Graphics;
  22. using Microsoft.Xna.Framework.Input;
  23. using Microsoft.Xna.Framework.Media;
  24. using Microsoft.Xna.Framework.Net;
  25. using Microsoft.Xna.Framework.Storage;
  26.  
  27. using SpriteLibrary;
  28.  
  29. namespace Swarm
  30. {
  31.     /// <summary>
  32.     /// This is the main type for your game
  33.     /// </summary>
  34.     public class Swarm : Microsoft.Xna.Framework.Game
  35.     {
  36.         GraphicsDeviceManager graphics;
  37.         SpriteBatch spriteBatch;
  38.        
  39.         // the following constants control how many of each type of sprite are possible
  40.         const int NUM_COLS = 5;
  41.         const int NUM_BEES_PER_COL = 4;
  42.         const int MAX_BEE_SHOTS = 5;
  43.         const int MAX_SMOKE_SHOTS = 2;
  44.  
  45.         const int NUM_HIVES = 3;
  46.         const int NUM_HONEYCOMBS = 20;
  47.  
  48.         // initialize a new random number generator
  49.         Random randomNumGen = new Random(DateTime.Now.Millisecond);
  50.  
  51.         // font used to display user messages
  52.         SpriteFont gameFont;
  53.  
  54.         // textures used in the game
  55.         Texture2D beeTexture;
  56.         Texture2D beeShotTexture;
  57.         Texture2D beeStripTexture;
  58.         Texture2D hive1Texture;
  59.         Texture2D hive2Texture;
  60.         Texture2D smokeTexture;
  61.         Texture2D smokeSprayerTexture;
  62.         Texture2D smokeSprayerStripTexture;
  63.         Texture2D smokeStripTexture;
  64.  
  65.  
  66.         // the following members form the Game State for this program!
  67.  
  68.         // this sprite represents the player at the bottom
  69.         Sprite smokeSprayer;
  70.        
  71.         // these sprites represent the smoke balls fired from the smoke gun
  72.         LinkedList<Sprite> smokeShots = new LinkedList<Sprite>();
  73.  
  74.         // these sprites represent the individual honeycomb sections of the hive bunkers
  75.         LinkedList<Sprite> hiveSections = new LinkedList<Sprite>();
  76.  
  77.         // these sprites represent the bees in the swarm
  78.         LinkedList<Sprite> bees = new LinkedList<Sprite>();
  79.  
  80.         // these sprites represent the stinger shots fired from the bees
  81.         LinkedList<Sprite> beeShots = new LinkedList<Sprite>();
  82.  
  83.         // the time the most recent bee shot was fired
  84.         double lastBeeShotFired = 0;
  85.  
  86.         // the current bee movement speed
  87.         float beeSpeed = 1.0f;
  88.  
  89.         // if true, the current game is over
  90.         bool gameOver = false;
  91.  
  92.         // this string contains the message that is currently displayed to the user
  93.         String displayMessage = "";
  94.  
  95.         // previous keyboard state
  96.         KeyboardState oldKeyboardState;
  97.  
  98.         //previous Xbox controller state
  99.         GamePadState oldGamePadState;
  100.  
  101.         SoundEffect stingerSound;
  102.         SoundEffect smokeSound;
  103.         SoundEffect explodeSound;
  104.         SoundEffect buzzSound;
  105.         SoundEffectInstance buzzSoundInstance;
  106.  
  107.         public Swarm()
  108.         {
  109.             graphics = new GraphicsDeviceManager(this);
  110.             Content.RootDirectory = "Content";
  111.         }
  112.  
  113.         /// <summary>
  114.         /// Allows the game to perform any initialization it needs to before starting to run.
  115.         /// This is where it can query for any required services and load any non-graphic
  116.         /// related content.  Calling base.Initialize will enumerate through any components
  117.         /// and initialize them as well.
  118.         /// </summary>
  119.         // This method is provided fully complete as part of the activity starter.
  120.         protected override void Initialize()
  121.         {
  122.             // call base.Initialize() first to get LoadContent called
  123.             // (and therefore all textures initialized) prior to starting game!
  124.             base.Initialize();
  125.  
  126.             startGame();
  127.         }
  128.  
  129.         // This method is provided partially complete as part of the activity starter.
  130.         private void startGame()
  131.         {
  132.             // reset game over flag
  133.             gameOver = false;
  134.  
  135.             // create new smoke sprayer, bees, and hives
  136.             initializeSmokeSprayer();
  137.             initializeBees();
  138.             initializeHives();
  139.  
  140.             // clear all prior shots
  141.             smokeShots.Clear();
  142.             beeShots.Clear();
  143.            
  144.             if (buzzSound != null)
  145.             {
  146.                 buzzSoundInstance = buzzSound.CreateInstance();
  147.  
  148.                 buzzSoundInstance.Volume = 0.06f;
  149.                 buzzSoundInstance.IsLooped = true;
  150.                 buzzSoundInstance.Play();
  151.             }
  152.         }
  153.  
  154.  
  155.         // The student will complete this function as part of an activity
  156.         private void initializeSmokeSprayer()
  157.         {
  158.             smokeSprayer = new Sprite();
  159.  
  160.             smokeSprayer.SetTexture(smokeSprayerTexture);
  161.  
  162.             int startingX = GraphicsDevice.Viewport.Width / 2;
  163.             int startingY = GraphicsDevice.Viewport.Height - smokeSprayer.GetHeight() - 20;
  164.             smokeSprayer.UpperLeft = new Vector2(startingX, startingY);
  165.  
  166.             smokeSprayer.IsAlive = true;
  167.         }
  168.  
  169.         // This method is provided fully complete as part of the activity starter.
  170.         private void initializeHives()
  171.         {
  172.             // this method will initialize all of the little hive sections as
  173.             // individual sprites that can be destroyed by shots and bees
  174.             hiveSections.Clear();
  175.  
  176.             // pick starting Y location
  177.             float hiveStartingY = GraphicsDevice.Viewport.Height - 150;
  178.             if (smokeSprayer != null)
  179.                 hiveStartingY = smokeSprayer.UpperLeft.Y - 100;
  180.            
  181.             // spacing between hives
  182.             float hiveSpacing = 200;
  183.  
  184.             // for each hive
  185.             for (int i = 0; i < NUM_HIVES; i++)
  186.             {
  187.                 // for each honeycomb in the hive
  188.                 for (int j = 0; j < NUM_HONEYCOMBS; j++)
  189.                 {
  190.                     // create a new sprite
  191.                     Sprite hiveSection = new Sprite();
  192.  
  193.                     // alternate the colors on odd/even blocks
  194.                     if (j % 2 == 0)
  195.                         hiveSection.SetTexture(hive1Texture);
  196.                     else
  197.                         hiveSection.SetTexture(hive2Texture);
  198.  
  199.                     // first 8 squares go along the bottom
  200.                     if (j < 8)
  201.                     {
  202.                         hiveSection.UpperLeft.Y = hiveStartingY + 3 * hiveSection.GetHeight();
  203.                         hiveSection.UpperLeft.X = ((hiveSpacing * (i + 1)) + (j * hiveSection.GetWidth()));
  204.                     }
  205.                     // next 6 squares go along the middle
  206.                     else if (j < 14)
  207.                     {
  208.                         hiveSection.UpperLeft.Y = hiveStartingY + 2 * hiveSection.GetHeight();
  209.                         hiveSection.UpperLeft.X = ((hiveSpacing * (i + 1)) + ((j - 7) * hiveSection.GetWidth()));
  210.                     }
  211.                     // next 4 squares along the top
  212.                     else if (j < 18)
  213.                     {
  214.                         hiveSection.UpperLeft.Y = hiveStartingY + hiveSection.GetHeight();
  215.                         hiveSection.UpperLeft.X = ((hiveSpacing * (i + 1)) + ((j - 12) * hiveSection.GetWidth()));
  216.                     }
  217.                     // small group of squares at the peak
  218.                     else
  219.                     {
  220.                         hiveSection.UpperLeft.Y = hiveStartingY;
  221.                         hiveSection.UpperLeft.X = ((hiveSpacing * (i + 1)) + ((j - 15) * hiveSection.GetWidth()));
  222.                     }
  223.  
  224.                     // set hive section to alive and add to list
  225.                     hiveSection.IsAlive = true;
  226.  
  227.                     hiveSections.AddLast(hiveSection);
  228.                 }
  229.             }
  230.         }
  231.  
  232.  
  233.         // The student will complete this function as part of an activity
  234.         private void initializeBees()
  235.         {
  236.             bees.Clear();
  237.  
  238.             for (int i = 0; i < NUM_COLS; i++)
  239.             {
  240.                 for (int j = 0; j < NUM_BEES_PER_COL; j++)
  241.                 {
  242.                     Sprite bee = new Sprite();
  243.  
  244.                     bee.UpperLeft = new Vector2((i + 1) * 100.0f, j * 75.0f);
  245.  
  246.                     bee.SetTexture(beeStripTexture, 5);
  247.                     bees.AddLast(bee);
  248.                     bee.SetSpeedAndDirection(beeSpeed, 0);
  249.                 }
  250.             }
  251.         }
  252.  
  253.         // The student will complete this function as part of an activity
  254.         private void stopGame(bool won, String message)
  255.         {
  256.             displayMessage = message;
  257.             gameOver = true;
  258.  
  259.             if (won)
  260.             {
  261.                 beeSpeed += 0.3f;
  262.             }
  263.             else
  264.             {
  265.                 beeSpeed -= 0.3f;
  266.                 if (beeSpeed < 0.3f)
  267.                     beeSpeed = 0.3f;
  268.             }
  269.  
  270.             if (buzzSoundInstance != null)
  271.             {
  272.                 buzzSoundInstance.Stop();
  273.             }
  274.         }
  275.  
  276.  
  277.  
  278.         /// <summary>
  279.         /// LoadContent will be called once per game and is the place to load
  280.         /// all of your content.
  281.         /// </summary>
  282.         // This method is provided partially complete as part of the activity starter.
  283.         protected override void LoadContent()
  284.         {
  285.             // Create a new SpriteBatch, which can be used to draw textures.
  286.             spriteBatch = new SpriteBatch(GraphicsDevice);
  287.  
  288.             // load all textures used in the game
  289.             beeTexture = Content.Load<Texture2D>("Images\\Bee");
  290.             beeShotTexture = Content.Load<Texture2D>("Images\\BeeShot");
  291.             beeStripTexture = Content.Load<Texture2D>("Images\\BeeStrip");
  292.             hive1Texture = Content.Load<Texture2D>("Images\\Hive1");
  293.             hive2Texture = Content.Load<Texture2D>("Images\\Hive2");
  294.             smokeTexture = Content.Load<Texture2D>("Images\\Smoke");
  295.             smokeSprayerTexture = Content.Load<Texture2D>("Images\\SmokeSprayer");
  296.             smokeSprayerStripTexture = Content.Load<Texture2D>("Images\\SmokeSprayerStrip");
  297.             smokeStripTexture = Content.Load<Texture2D>("Images\\SmokeStrip");
  298.  
  299.             // load all fonts used in the game
  300.             gameFont = Content.Load<SpriteFont>("GameFont");
  301.  
  302.             stingerSound = Content.Load<SoundEffect>("Audio\\stingerShot");
  303.             smokeSound = Content.Load<SoundEffect>("Audio\\smokeShot");
  304.             explodeSound = Content.Load<SoundEffect>("Audio\\explosion");
  305.             buzzSound = Content.Load<SoundEffect>("Audio\\buzz");
  306.  
  307.         }
  308.  
  309.         /// <summary>
  310.         /// UnloadContent will be called once per game and is the place to unload
  311.         /// all content.
  312.         /// </summary>
  313.         // This method is provided fully complete as part of the activity starter.
  314.         protected override void UnloadContent()
  315.         {
  316.             // TODO: Unload any non ContentManager content here
  317.         }
  318.  
  319.         /// <summary>
  320.         /// Allows the game to run logic such as updating the world,
  321.         /// checking for collisions, gathering input, and playing audio.
  322.         /// </summary>
  323.         /// <param name="gameTime">Provides a snapshot of timing values.</param>
  324.         // This method is provided fully complete as part of the activity starter.
  325.         protected override void Update(GameTime gameTime)
  326.         {
  327.             // Allows the game to exit
  328.             if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
  329.                 this.Exit();
  330.  
  331.             // if the game is still going on
  332.             if (!gameOver)
  333.             {
  334.                 // check to see if the player has beaten all the bees
  335.                 if (bees.Count == 0)
  336.                 {
  337.                     stopGame(true,"You have defeated the swarm!");
  338.                 }
  339.                 else
  340.                 {
  341.  
  342.                     // see if any more bee stingers need to be fired
  343.                     checkBeeShots(gameTime);
  344.  
  345.                     // move the bees
  346.                     moveBees(gameTime);
  347.  
  348.                     // move any bee shots that are on the screen
  349.                     moveBeeShots();
  350.  
  351.                     // move any smoke shots that are on the screen
  352.                     moveSmokeShots(gameTime);
  353.  
  354.                     // handle all collisions
  355.                     checkCollisions();
  356.                 }
  357.             }
  358.  
  359.             // if the smoke sprayer is currently animating, advance the frame
  360.             if (smokeSprayer != null)
  361.                 if (smokeSprayer.IsAnimating())
  362.                         smokeSprayer.Animate(gameTime);
  363.  
  364.             // handle all user input
  365.             handleKeyPress();
  366.  
  367.             // Optionally handle Xbox gamepad
  368.             handleXboxGamepad();
  369.            
  370.             base.Update(gameTime);
  371.         }
  372.  
  373.         // The student will complete this function as part of an activity
  374.         private void checkBeeShots(GameTime gameTime)
  375.         {
  376.             if (gameTime.TotalGameTime.TotalMilliseconds > (lastBeeShotFired + 1000))
  377.             {
  378.                 fireBeeShot();
  379.  
  380.                 lastBeeShotFired = gameTime.TotalGameTime.TotalMilliseconds;
  381.             }
  382.         }
  383.  
  384.         // The student will complete this function as part of an activity
  385.         private void fireBeeShot()
  386.         {
  387.             if (beeShots.Count < MAX_BEE_SHOTS)
  388.             {
  389.                 int beeNumber = randomNumGen.Next(0, bees.Count);
  390.                 Sprite bee = bees.ElementAt(beeNumber);
  391.  
  392.                 Sprite newBeeShot = new Sprite();
  393.                 newBeeShot.SetTexture(beeShotTexture);
  394.  
  395.                 newBeeShot.SetVelocity(0, 2);
  396.                 newBeeShot.IsAlive = true;
  397.  
  398.                 newBeeShot.UpperLeft.X = bee.UpperLeft.X + (bee.GetCenter().X - newBeeShot.GetWidth() / 2);
  399.                 newBeeShot.UpperLeft.Y = bee.UpperLeft.Y + bee.GetHeight();
  400.  
  401.                 beeShots.AddLast(newBeeShot);
  402.                 stingerSound.Play(0.15f, 0, 0);
  403.             }
  404.         }
  405.  
  406.         // This method is provided fully complete as part of the activity starter.
  407.         private Sprite findEdgeBee(bool leftSide)
  408.         {
  409.             // create variable to trach the bee we think is on the edge
  410.             Sprite edgeSprite = null;
  411.  
  412.             // check all remaining bees
  413.             foreach (Sprite bee in bees)
  414.             {
  415.                 // if this is the first bee, just save it as current edge bee
  416.                 if (edgeSprite == null)
  417.                     edgeSprite = bee;
  418.                 else
  419.                 {
  420.                     // if we are looking for the leftmost bee
  421.                     if (leftSide)
  422.                     {
  423.                         // if this bee is to left of current edge bee
  424.                         if (bee.UpperLeft.X < edgeSprite.UpperLeft.X)
  425.                             edgeSprite = bee;   // we have a new edge bee
  426.                     }
  427.                     else // we are looking for the rightmost bee
  428.                     {
  429.                         // if this bee is to right of current edge bee
  430.                         if (bee.UpperLeft.X > edgeSprite.UpperLeft.X)
  431.                             edgeSprite = bee;   // we have a new edge bee
  432.                     }
  433.                 }
  434.             }
  435.            
  436.             // return the edge bee we found
  437.             return edgeSprite;
  438.         }
  439.  
  440.         // The student will complete this function as part of an activity
  441.         private void moveSmokeShots(GameTime gameTime)
  442.         {
  443.             foreach (Sprite smokeShot in smokeShots)
  444.             {
  445.                 smokeShot.Animate(gameTime);
  446.                 smokeShot.MoveAndVanish(GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height);
  447.             }
  448.         }
  449.  
  450.         // The student will complete this function as part of an activity
  451.         private void moveBeeShots()
  452.         {
  453.             foreach (Sprite beeShot in beeShots)
  454.             {
  455.                 beeShot.MoveAndVanish(GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height);
  456.             }
  457.         }
  458.  
  459.         // The student will complete this function as part of an activity
  460.         private void moveBees(GameTime gameTime)
  461.         {
  462.             Sprite leftmostBee = findEdgeBee(true);
  463.             Sprite rightmostBee = findEdgeBee(false);
  464.             if ((leftmostBee == null) || (rightmostBee == null))
  465.             {
  466.                 return;
  467.             }
  468.  
  469.             if (((leftmostBee.UpperLeft.X) < 0) ||
  470.                  ((rightmostBee.UpperLeft.X + rightmostBee.GetWidth()) > GraphicsDevice.Viewport.Width))
  471.             {
  472.                 foreach (Sprite bee in bees)
  473.                 {
  474.                     Vector2 velocity = bee.GetVelocity();
  475.                     velocity.X *= -1;
  476.                     bee.SetVelocity(velocity.X,velocity.Y);
  477.  
  478.                     bee.UpperLeft.Y += 25;
  479.                 }
  480.             }
  481.             foreach (Sprite bee in bees)
  482.             {
  483.                 bee.Animate(gameTime);
  484.                 bee.Move();
  485.  
  486.                 if (bee.UpperLeft.Y >= smokeSprayer.UpperLeft.Y)
  487.                 {
  488.                     stopGame(false, "The bees have reached you!");
  489.                 }
  490.             }
  491.         }
  492.  
  493.         // The student will complete this function as part of an activity
  494.         private void checkCollisions()
  495.         {
  496.             foreach (Sprite bee in bees)
  497.             {
  498.                 foreach (Sprite smokeShot in smokeShots)
  499.                 {
  500.                     if (smokeShot.IsCollided(bee))
  501.                     {
  502.                         bee.IsAlive = false;
  503.                         smokeShot.IsAlive = false;
  504.                         explodeSound.Play();
  505.                     }
  506.                 }
  507.             }
  508.             foreach (Sprite hiveSection in hiveSections)
  509.             {
  510.                 foreach (Sprite beeShot in beeShots)
  511.                 {
  512.                     if (beeShot.IsCollided(hiveSection))
  513.                     {
  514.                         hiveSection.IsAlive = false;
  515.                         beeShot.IsAlive = false;
  516.                         explodeSound.Play();
  517.                     }
  518.                 }
  519.                 foreach (Sprite smokeShot in smokeShots)
  520.                 {
  521.                     if (smokeShot.IsCollided(hiveSection))
  522.                     {
  523.                         hiveSection.IsAlive = false;
  524.                         smokeShot.IsAlive = false;
  525.                         explodeSound.Play();
  526.                     }
  527.                 }
  528.                 foreach (Sprite bee in bees)
  529.                 {
  530.                     if (bee.IsCollided(hiveSection))
  531.                     {
  532.                         hiveSection.IsAlive = false;
  533.                         explodeSound.Play();
  534.                     }
  535.                 }
  536.             }
  537.             foreach (Sprite beeShot in beeShots)
  538.             {
  539.                 if (beeShot.IsCollided(smokeSprayer))
  540.                 {
  541.                     explodeSound.Play();
  542.                     smokeSprayer.StartAnimationShort(1, 4, 4);
  543.                     stopGame(false, "You have been stung!");
  544.                 }
  545.             }
  546.             // remove all dead sprites from their lists
  547.             pruneList(beeShots);
  548.             pruneList(smokeShots);
  549.             pruneList(bees);
  550.             pruneList(hiveSections);
  551.         }
  552.  
  553.         // The student will complete this function as part of an activity
  554.         private void handleKeyPress()
  555.         {
  556.             KeyboardState currentKeyboard = Keyboard.GetState();
  557.             if (oldKeyboardState == null)
  558.                 oldKeyboardState = currentKeyboard;
  559.  
  560.             if (!oldKeyboardState.IsKeyDown(Keys.Space) &&
  561.                 (currentKeyboard.IsKeyDown(Keys.Space)))
  562.             {
  563.                 if (gameOver)
  564.                 {
  565.                     startGame();
  566.                 }
  567.                 else
  568.                 {
  569.                     shootSmokeSprayer();
  570.                 }
  571.             }
  572.  
  573.             if (!gameOver)
  574.             {
  575.                 if (currentKeyboard.IsKeyDown(Keys.Right))
  576.                 {
  577.                     if (smokeSprayer.UpperLeft.X <
  578.                         GraphicsDevice.Viewport.Width - smokeSprayer.GetWidth())
  579.                         smokeSprayer.UpperLeft.X += 2;
  580.                 }
  581.  
  582.                 if (currentKeyboard.IsKeyDown(Keys.Left))
  583.                 {
  584.                     if (smokeSprayer.UpperLeft.X > smokeSprayer.GetWidth())
  585.                         smokeSprayer.UpperLeft.X -= 2;
  586.                 }
  587.             }
  588.  
  589.             oldKeyboardState = currentKeyboard;
  590.         }
  591.  
  592.         //*************************************************************************************************************
  593.         // OPTIONAL: If the student is using Xbox gamepads, they can optionally complete this method
  594.         // If not, they should complete the handleKeyPress() method mentioned above.
  595.  
  596.         private void handleXboxGamepad()
  597.         {
  598.            
  599.         }
  600.         //*****************************************************************************************************************
  601.  
  602.  
  603.  
  604.         // The student will complete this function as part of an activity
  605.         private void shootSmokeSprayer()
  606.         {
  607.             if (smokeShots.Count < MAX_SMOKE_SHOTS)
  608.             {
  609.                 Sprite newSmokeShot = new Sprite();
  610.  
  611.                 newSmokeShot.SetTexture(smokeStripTexture, 4);
  612.  
  613.                 newSmokeShot.SetVelocity(0, -4);
  614.                 newSmokeShot.IsAlive = true;
  615.  
  616.                 newSmokeShot.UpperLeft.X = smokeSprayer.UpperLeft.X + (smokeSprayer.GetCenter().X - newSmokeShot.GetWidth() / 2);
  617.                 newSmokeShot.UpperLeft.Y = smokeSprayer.UpperLeft.Y;
  618.  
  619.                 smokeShots.AddLast(newSmokeShot);
  620.             }
  621.         }
  622.  
  623.         /// <summary>
  624.         /// This is called when the game should draw itself.
  625.         /// </summary>
  626.         /// <param name="gameTime">Provides a snapshot of timing values.</param>
  627.         // The student will complete this function as part of an activity
  628.         protected override void Draw(GameTime gameTime)
  629.         {
  630.             GraphicsDevice.Clear(Color.SkyBlue);
  631.  
  632.             spriteBatch.Begin();
  633.  
  634.             // draw the smoke sprayer
  635.             if (smokeSprayer != null)
  636.                 smokeSprayer.Draw(spriteBatch);
  637.  
  638.             // draw all active smoke shots
  639.             foreach (Sprite smokeShot in smokeShots)
  640.             {
  641.                 smokeShot.Draw(spriteBatch);
  642.             }
  643.  
  644.             // draw all active bee shots
  645.             foreach (Sprite beeShot in beeShots)
  646.             {
  647.                 beeShot.Draw(spriteBatch);
  648.             }
  649.  
  650.             // draw all active bees
  651.             foreach (Sprite bee in bees)
  652.             {
  653.                 bee.Draw(spriteBatch);
  654.             }
  655.  
  656.             // draw all remaining hive sections
  657.             foreach (Sprite hiveSection in hiveSections)
  658.             {
  659.                 hiveSection.Draw(spriteBatch);
  660.             }
  661.  
  662.             //*****************************************************************
  663.             // Student will add some "game over" logic here in an activity
  664.             if (gameOver)
  665.             {
  666.                 spriteBatch.DrawString(gameFont, displayMessage, new Vector2(200, 20), Color.Blue);
  667.             }
  668.             //*****************************************************************
  669.  
  670.             spriteBatch.End();
  671.  
  672.             base.Draw(gameTime);
  673.         }
  674.  
  675.  
  676.         // This method is provided fully complete as part of the activity starter.
  677.         private void pruneList(LinkedList<Sprite> spriteList)
  678.         {
  679.             // clip out any sprites from the list where IsAlive = false
  680.             for (int i = spriteList.Count - 1; i >= 0; i--)
  681.             {
  682.                 Sprite s = spriteList.ElementAt(i);
  683.                 if (!s.IsAlive)
  684.                 {
  685.                     spriteList.Remove(s);
  686.                 }
  687.             }
  688.         }
  689.     }
  690. }
RAW Paste Data
Want to get better at C#?
Learn to code C# in 2017
Pastebin PRO Summer Special!
Get 40% OFF on Pastebin PRO accounts!
Top