O'Reilly logo

3D Game Development with Microsoft Silverlight 3 Beginner's Guide by Gastón C. Hillar

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action—adding a second UFO

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 the public class InvadersGame : RealTimeGame, to hold the new Ufo instance:
    private Ufo _ufo2;
    
  6. Add the following ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required