Windows 8 Game Development using C#, XNA and MonoGame 3.0: Building a Shooter Game Walkthrough – Part 6: Creating Enemies and Detecting Collisions
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!
- private void WrapTextureToLeft(int index)
- // If the textures are scrolling to the left, when the tile wraps, it should be put at the
- // one pixel to the right of the tile before it.
- int prevTexture = index - 1;
- if (prevTexture < 0)
- prevTexture = _positions.Length - 1;
- _positions[index].X = _positions[prevTexture].X + _texture.Width;
- private void WrapTextureToRight(int index)
- // If the textures are scrolling to the right, when the tile wraps, it should be
- //placed to the left of the tile that comes after it.
- int nextTexture = index + 1;
- if (nextTexture == _positions.Length)
- nextTexture = 0;
- _positions[index].X = _positions[nextTexture].X - _texture.Width;
Now on with the tutorial. Let's just into how to create enemies for the game and animate the enemy graphic.