Firstly, we are going to add a second UFO to our existing scene. This UFO must be able to move and rotate using impulses, forces and torques, like the existing UFO.
1. Stay in the
3DInvadersSilverlight
project.2. Open
Ufo.cs
.3. Add the following
public
method to change the position for both the mesh in the 3D world and the 2D body representing the rectangle for this mesh in the 2D physics engine world:public void SetPosition(float x, float y, float z) { _mesh.Position.X = x; _mesh.Position.Y = y; _mesh.Position.Z = z; Body.Position = new Vector2(x, y); }
4. Open
InvadersGame.cs
.5. Add the following
private
variable in thepublic class InvadersGame : RealTimeGame
, to hold the newUfo
instance:private Ufo _ufo2;
6. Add the following lines of code before the end of the
Initialize
method to create anUfo
instance and add this new actor to the game:_ufo2 = new Ufo(this, Scene, _physicsSimulator); AddActor(_ufo2);
7. Add the following lines of code in the
CheckKeyboard...