Developing Casual Games with Silverlight 2 – Part 6
Author: Joel Neubeck – Director of Technology / Silverlight MVP
subscribe nowto get yours.
In this series of articles, we explored the process of designing and building a casual online game in Silverlight. Throughout the series we targeted the interactive developer, as we construct our own version of the classic 1980s game Sabotage.
Module 6: Advanced Topics
In this last and final module, we will explore some of the more advanced concepts we see in today’s online casual games. Requirements such as the use of advanced physics or the incorporation of multiple players don’t necessarily fit within the type of game we built throughout this series. Nonetheless, numerous developers within the community have given us great examples of how these concepts can be incorporated within a Silverlight game. In this article I will help point you towards these sources and give you some direction as to how they can take your game to the next level.
To a very small extent, the game we constructed had some simple 2D physics. When our gun shot a cannon ball from its turret, the projectile exhibited signs of gravity, deceleration and weight. As it collided with the ground, we saw a bit more as the ball exhibited an elastic collision with the ground and bounced a few times until it came to rest. These behaviors are pretty simple forms of 2D physics that are easily written into our logic for movement and collision detection. Now, what if we didn’t stop there and the entire game needed to exhibit 2D physics?
Thankfully, a member of the Silverlight community, Bill Reiss, ported one of the most popular XNA 2D physics engines, the Farseer Physics Engine, to Silverlight. If you want to incorporate true physics into your game, this engine is the way to go. It’s completely open-source and very simple to use.
To get started, go to
CodePlex and download the
Farseer Physics Engine 2.1.1 and the
Farseer Physics Engine Simple Samples. If you open up the solution and compile it, you will be presented with seven different examples. The best way to get your head around how the engine behaves is to run the samples and set some break points. My favorite example is demo 4, from which I show a screen capture in Figure 2. If you get your head around how this example works, you can use these techniques in just about any physics-based game. This one is quite impressive because it demonstrates motion and collision that takes into account speed and direction. I think you will be surprised at how little code it takes to build this example.
Figure 2. Demo 4 - Stacked Bodies
To see some great examples of games that have been created with the Farseer engine, take a look at any of the following websites.
This site is created by Jeff Weber, the original author of the Farseer Physics Engine for XNA. Jeff is one of the co-owners the Farseer project on CodePlex.
The site highlights some of the games he has created to demonstrate the power of the engine. There are a few examples that I think every developer should take a look at. The first is called Water Demo and demonstrates some interesting physics around density, rotation and the effect that motion can have on a series of objects (cubes bobbing in the ocean with waves). Trust me that if you tried to create all of these behaviors yourself, you would be writing code for quite some time. The Farseer engine takes care of the entire heavy lifting, letting you focus on keeping your players engaged. The best part about this demo is that Jeff provides complete source.
The second demo is a game Jeff created called Diver. This game demonstrates how, through the use of momentum, rotation, and gravity, we can create an almost life-like visualization of a diver jumping off of a cliff. The game is hard to master, but quite fun.
Lastly, make sure to check out the video Jeff posted for his current game development project, Krashlander. This game looks amazing and will certainly be packed full of 2D physics. I am not sure when he plans to release it, but I am sure it will be worth the wait.
This next site is created by Andy Beaulieu, a Silverlight MVP and amazing game developer. When it comes to using physics in Silverlight games, Andy has created some of the best. One of my favorite games is called Boss Launch, a hilarious game where you catapult your “boss” through the air hoping he collides with a set of targets (Pizza boxes, etc). The entire game is built upon the Farseer Physics Engine combined with an open- source helper library called
Physics Helper. Andy created this helper library to take away some of the challenges of designing sprites in Blend that ultimately become physics objects. If you are interested in incorporating physics in your game, Andy is a great source of expertise.
I love 2D physics and believe that, with selective use, physics can take a game from interesting to truly addictive.
Is Silverlight Ready for Multiplayer?
I am certain that, with the release of Silverlight 3, we can all expect to see a whole new breed of casual games done in Silverlight. One of the areas in Silverlight games we have not seen much focus on is in the area of multiplayer. About a year ago I got the privilege to speak at XNA Gamefest with Bill Reiss, Tim Heuer, and Mike Snow. Mike did a great presentation where he showed a simple way to leverage sockets and a custom policy server as a way to allow multiple players to participate in a single Silverlight game. See how on Mike's blog:
http://silverlight.net/blogs/msnow/archive/2008/06/26/full-implementation-of-a-silverlight-policy-server.aspx. If you have not checked out Mike’s site, I strongly recommend it. Mike is a great developer and true game expert. Just recently mike published an entire book on writing games in Silverlight.
Is WCF an Option for Multiplayer?
Depending on the complexity of your game, one option for multiplayer games is the use of WCF services. In Silverlight 3 we have new features that will certainly help improve performance when leveraging WCF in our multiplayer game.
In SL 2 the only form of binding was Basic HTTP, which encoded messages as clear text. As you can imagine, this created the potential for quite a bit of performance concern if we needed to send large payloads of data back and forth with a server. In 3.0 we now have the ability to encode our messages as binary. This will reduce the size of the payload and improve its performance. If we choose to consume WCF from Silverlight, binary is the new default for message encoding.
Sorry, No UDP support in Silverlight 3
For the hard-core game developer, when they think of designing a great multiplayer games one has to consider the use of UDP instead of TCP-IP. Unfortunately, for security reasons, no version of Silverlight so far has allowed for UDP support.
After a year and six articles, this completes our series on building causal games in Silverlight. I hope that I have sparked your interest in using the power and flexibility of Silverlight to build the next addictive game. I just can’t wait to see the future of casual games.
Joel Neubeck, Silverlight MVP