Adding a Starfield

Given the way that you've created your particles and your particle engine, you're perfectly set up for creating a field of stars in the background to make this look more like outer space. To do this, you'll need to create a new version of your ParticleExplosion class that treats the particles a little bit differently. For example, the particles you use for stars in the background won't move around the screen the way the ones in the explosions do. You also won't be deleting stars from the list of stars to draw, nor will your star particle engine die out at some time—the stars will be the same at the end of the game as they were at the beginning.

Add a new class to your project by right-clicking the solution and selecting Add → Class.... Name the class ParticleStarSheet:

Replace the code in the file that is generated with the following: using System; using System.Collections.Generic; using System.Text; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; namespace _3D_Game { class ParticleStarSheet { //Particles Particle[] particles; //Behavior variables Vector3 maxPosition; int maxParticles; Vector2 textureSize; static Random rnd = new Random(); //Graphics related variables VertexDeclaration vertexDeclaration; GraphicsDevice graphicsDevice; ParticleSettings particleSettings; public ParticleStarSheet(GraphicsDevice graphicsDevice, Vector3 maxPosition, int maxParticles, Vector2 textureSize, ParticleSettings particleSettings) { this.maxPosition ...

Get Learning XNA 3.0 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.