Windows 8 Game Development using C#, XNA and MonoGame 3.0: Building a Shooter Game Walkthrough – Part 6: Creating Enemies and Detecting Collisions

 

Overview

Last time we met in Part 5 of this blog series, we created an animation to bring the ship to life by simulation of movement and propulsion. We also created and added a more realistic background to the game by the creation of a parallaxing background by layering three distinct images and moving them in and/or of the game screen's view by simulate the sky with clouds moving as the ship flies through the background. In the comments of Part 5, we got some great feedback on the variations of how people handled the Parallaxing background screen refresh on various machines and would not have a smooth jitter. One such comment and example was well throughout and I want to share it with you all so that you can update your game accordingly if desired. Tim Eicher ( teicher) updated the Shooter parallaxing background by creating a function WrapTextureToLeft and WrapTextureToRight (shown below) and changing the position and scale variables (see full code at https://bitbucket.org/teicher/shootertutorial. Thanks Tim for sharing this Excellent code update with us all!

  1. private void WrapTextureToLeft(int index)
  2. {
  3. // If the textures are scrolling to the left, when the tile wraps, it should be put at the
  4. // one pixel to the right of the tile before it.
  5. int prevTexture = index - 1;
  6. if (prevTexture < 0)
  7. prevTexture = _positions.Length - 1;
  8.  
  9. _positions[index].X = _positions[prevTexture].X + _texture.Width;
  10. }
  11.  
  12. private void WrapTextureToRight(int index)
  13. {
  14. // If the textures are scrolling to the right, when the tile wraps, it should be
  15. //placed to the left of the tile that comes after it.
  16.  
  17. int nextTexture = index + 1;
  18. if (nextTexture == _positions.Length)
  19. nextTexture = 0;
  20.  
  21. _positions[index].X = _positions[nextTexture].X - _texture.Width;
  22. }

 

Now on with the tutorial. Let's just into how to create enemies for the game and animate the enemy graphic.

See the Complete Post Here