Book Image

3D Game Development with Microsoft Silverlight 3: Beginner's Guide

By : Gaston C. Hillar
Book Image

3D Game Development with Microsoft Silverlight 3: Beginner's Guide

By: Gaston C. Hillar

Overview of this book

Microsoft Silverlight is a programmable web browser plug-in that enables the animation, vector graphics, and audio-video playback features that characterize Rich Internet Applications. Silverlight is a great (and growing) RIA platform and games are the next level to exploit in it. But it doesn't offer 3D capabilities out of the box and integrating a 3D engine can involve lot of complex mathematics and matrix algebra. This book will help C# developers to get their fingers on the pulse of 3D in Silverlight. This book uses Balder, an open source 3D engine offering 3D capabilities for Silverlight 3. It leaves out boring matrix algebra and complex 3D mathematics. By the end of the book you will have explored the entire engine, and will be able to design and program your own 3D games with ease! The book begins by introducing you to the fundamental concepts of 2D games and then drives you into the 3D world, using easy-to-follow, step-by-step examples. The book employs amazing graphics and impressive performance, and increasingly adds more features to a 3D game giving you a rich interactive experience. By following the practical examples in this book, you will learn the important concepts, from the creation of the initial models, up to the addition of physics and artificial intelligence. The book helps you to provide realistic behaviors for 3D characters by enveloping models with different textures, using lights to create effects, animating multiple 3D characters using a physics engine (Farseer Physics Engine), and simulating real-life physics. Videos, music, and sounds associated with specific events offer the final touches to the 3D game development learning experience.
Table of Contents (21 chapters)
3D Game Development with Microsoft Silverlight 3
Credits
About the Author
Acknowledgement
About the Reviewer
Preface
Pop quiz—Answers

Time for action—using evasion algorithms


You created a very good chase algorithm. It is time to make the other UFO evade its hunter.

Now, we are going to add more AI to the game in order to make one UFO run away from the other:

  1. 1. Stay in the 3DInvadersSilverlight project.

  2. 2. Open Ufo.cs.

  3. 3. Replace the AIEvade method with the following:

    protected void AIEvade(Ufo enemy)
    {
    Vector2 distance = (Body.Position - enemy.Body.Position);
    if ((Math.Abs(distance.X) < (Width * 2)) ||
    (Math.Abs(distance.Y) < (Height * 2)))
    {
    // The Ufo can wander without problems because the enemy is
    too far
    _state = UfoAIState.Wandering;
    AIWander();
    }
    _state = UfoAIState.Evading;
    if ((Math.Abs(distance.X)) > (Math.Abs(distance.Y)))
    {
    if (distance.X > 0)
    Body.ApplyImpulse(new Vector2(0.2f, 0));
    else
    Body.ApplyImpulse(new Vector2(-0.2f, 0));
    }
    else
    {
    if (distance.Y > 0)
    Body.ApplyImpulse(new Vector2(0, 0.2f));
    else
    Body.ApplyImpulse(new Vector2(0, -0.2f));
    }
    }
    
  4. 4. Build and run the solution. The default web...