Time for action – the basic flying saucer
To add a flying saucer to Mars Runner, perform the following steps:
1. Add a new class file called
EnemySaucer.cs
to theMars Runner
project.2. Add the following
using
directives at the beginning of theEnemySaucer
class file:using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics;
3. Modify the declaration of the
EnemySaucer
class to inherit from theGameEntity
class. The new declaration should read as follows:class EnemySaucer : GameEntity
4. Add a constructor for the
EnemySaucer
class as follows:#region Constructor public EnemySaucer(GraphicsDevice device, Model model, Vector3 position) : base(device, model, position) { scale = 0.0025f; yaw = MathHelper.ToRadians(180); } #endregion
5. In the
Fields
region of theMarsRunnerPlayScreen
class, add a new field for our enemy saucer as follows:EnemySaucer enemy;
6. In the
LoadContent()
method of theMarsRunnerPlayScreen
class, initializeenemy
as follows:enemy = new EnemySaucer...