Physics Powered Games Logo
games  |  blog  |  about

Any good game development platform needs a game engine to extract away some of the repetitive, less exciting work required to build a game.

I have been wondering if anyone would build such an engine for Silverilght.  Well, someone is/has.

That person is John Kanalakis and company over at Envy Games. The game engine is called PlayBits.

I’ve been in brief contact with John and it sounds like they are very close to releasing at least a limited beta version.

It’s impossible to know right now how useful the PlayBits engine will be for making games, but judging just by the feature list, it certainly looks promising. (see below. This is copied from Envy Games website)

<snip>

The PlayBits Game Engine for Silverlight 2.0

Looking for an easy way to create Games for the Web using the C# programming languag? The PlayBits Game Engine for Silverlight 2.0 is the answer. The PlayBits engine uses Microsoft’s Silverlight Web plug-in for Internet Explorer, Safari, and Firefox to render rich Web games. Your game code is implemented entirely in C# and XAML (the markup language used by Silverlight and WPF). The PlayBits game engine features rich support for making 2D games with 3D games on the way.

Features

High-Speed Render Loop and Fixed-Step Game Update Loop
Powerful Scene Graph with Scene Loading & Unloading
Component System for Modular Game Design
Physics System with Rigid Collision Support and Math Helpers
An Efficient Resource Manager for Keeping Memory Consumption Down
Multi-Layered Rendering with dynamic Sort Ordering
Connect Scene Objects Together with Object Mounting
Flexible Particle Effect System
Dynamic Input Manager to Dynamically Shift Game Control
Flexible Input Support for Keyboard, Mouse, and Ink
Event Scheduler and SceneObject Trigger
Seamlessly Integrate Silverlight Graphical User Interface Elements
Integrated Event Logging with Framerate Metrics Capture
Custom SceneObject Type Assignment and Comparison
Rich Media Support for Integrated Photos and Videos
Multiplayer Networking Support
Localization and Multiplatform Support via Silverlight
Local Data Storage for Saved Game States
Optional High Score and Game Data Cloud Storage Support

Game Objects

Static Sprites, Animated Sprited, Scrolling Sprites
Object Templates and Spawners
Tilemap and Tiles
Chase, Avoid, and Path-Following AI

Game Types

Create a wide variety of game types, including:
Arcade Classic Games
Side-Scrolling Games
Isometric Games
Racing Games
Sports Games
RPG-Adventure Games
Real-Time Strategy Games

Game Level Design

Game level design is accomplished with Microsoft Expression Blend 2.5 for Windows XP /Vista and Mac OS. Game code is written within Microsoft Visual Studio 2008, or it’s FREE counterpart Visual C# Express 2008.

Developer Support

Primary Developer Support is available via online Forums. Product documentation and Developer Articles & Resources will be free available online at EnvyGames.com

Availability

Spring 2009
$299 Retail Price

</snip>

-Jeff Weber

 

WeAreBugsLogo (click to play)


My Mix 10k Challenge entry, We Are Bugs, didn’t win any prizes, but I had a lot of fun developing it and thought others might enjoy  tinkering with it themselves or might be able to learn from seeing how a simple Silverlight game is put together.

I have spent a fair amount of time completely refactoring the source code for We Are Bugs to make it more structured and easier to understand.  (The original code was optimized for size and not pretty.)

For this refactored version I used a simple Model-View-Controller pattern, similar to what Joel Neubeck describes in his Developing a casual game with Silverlight 2 articles.  I also used the state pattern to keep the different game states organized.

I’ve released the code for the refactored version of We Are Bugs on Codeplex. You can find it here: http://www.codeplex.com/WeAreBugs

Following are some of the areas in code worth mentioning briefly.

Controller

The controller controls the navigation between game screens, owns the render loop which runs continuously to update the bug positions, and controls transitions between the various game states. If you want to follow through the code execution, this is the place to start.

Here is the class view for the controller

CropperCapture[7] 

Bug Models, AgentModel, and the DynamicModel base class

The bugs in the game all derive from AgentModel, which in turn derives from DynamicModel. As you can see in the class diagram below, the “food” also derives from AgentModel.  This is because at some point I think I will want the food to animate in some fashion or another. Possibly the “food” is another small bug that tries not to be eaten.

CropperCapture[12]

The DynamicModel base contains all the basic functionality for managing position and orientation. It uses a set of matices for this purpose and exposes a single RenderTransform that can be used by the Views to update themselves.(see below)

From the EnemyView:

public void Update()
{
    RenderTransform = _enemyModel.RenderTransform;
    UpdateEnemyExcitement();
}

One of the key things required for the bug movement was the ability to align a bugs forward direction with its velocity. To do this, I added a “Front” property to the DynamicModel.

The front property is a normalized vector that determines what direction the bug is facing.  With this, every update step, I can just set the Front property equal to the AgentModel’s velocity vector to get the affect I needed.

From the AgentModel.Update() method:

Front = Mathematics.Normalize(velocity);

During the update tick a little bit of matrix trickery aligns the bug with the direction of the Front vector.

The AgentModel class contains some higher level movement concepts like SteeringForce, Velocity, and MaxSpeed.  It also contains a list of Behaviors.

These Behaviors are often referred to as Steering Behaviors and are described in great detail with examples here: http://www.red3d.com/cwr/steer/

The Behaviors in We Are Bugs all implement a common interface called IBehavior. (see below)

CropperCapture[13]

As you can see above, We Are Bugs only uses 3 steering behaviors.

SeekPointBehavior is used to make the Bug chase the mouse pointer.

PursueAgentBehavior is used to make the enemy bugs chase the “good” bug.

SeperationBehavior is used to keep all the enemy bugs from bunching up and overlapping eachother.

The bug Models themselves are very light weight as they get almost all there functionality from the AgentModel and DynamicModel base classes.  In fact, the EnemyModel is the only bug model that has any additional properties.

The EnemyModel has a single “Excitement” property which is set by the GameModel.Update() method. The value of the property is based on how close the enemy is to the bug it’s chasing.  The EnemyView then uses this Excitement property to turn the Enemy red when it gets close to the “good” bug.

Game Model and Game States

One of the largest challenges I have when developing a game is keeping the core game object from blowing-up in complexity.  There are usually a lot of game-states to manage and more often then not the core game object ends up a big pile of stink!

For We Are Bugs, I decided to try and hold back some of the code-stench by using the state pattern.  (I won’t go into this in detail you can learn about it here: http://www.dofactory.com/Patterns/PatternState.aspx)

The GameStates in We Are Bugs can kind of be thought of as mini-controllers for the GameModel.  They contain a reference back to the GameModel and use this reference to make the GameModel do what it(the GameState) requires.

CropperCapture[14]

As can be seen above, the State base class contains 3 methods (not counting the constructor): Enter, Exit, and Update.

Enter allows the state to set things up as it becomes the active state.

Update is what gives the State dynamic, ongoing control of the GameModel during render time.

Exit allows the state to clean house when it’s finished.

GameStates are set by calling SetState on the GameModel class and passing in a State object. (see below)

public void SetState(State state)
{
    if (_state != null)
    {
        _state.Exit();
    }
     _state = state;
     _state.Enter();
 }

We Are Bugs has 4 games states.

Note: The textual display of information is not considered part of what I’m calling game states.  The game state really just entails what the “bugs” are doing in the background. The text on the screen is actually overlaid on to the game.

StartState is what you see when the game first loads up. In this state, there is a single bug that randomly moves about the screen by itself (no user input)

ReadyState centers the bug and prevents movement while the instructions for the game are displayed.

PlayState (suprise, suprise) is the state where the core game-play takes  place

GameOverState starts as soon as you are eaten by one of the bad bugs.

Final Words

This post does not describe the We Are Bugs code in complete detail, but hopefully it can act as a small guide as you look at the actual source.

As mentioned above you can download the source here: http://www.codeplex.com/WeAreBugs

Source Code Terms of Use

Feel free to do pretty much whatever you want with the source.  Learn from it, extend the game, make derivative games, etc…  I don’t require anything specific, but a shout-out to Farseer Games is always nice. :-)

Also, if you do something interesting with the code please shoot me an email and let me know. I’d love to see it.

-Jeff Weber

Just notice that my latest game Tire Storm was accepted on the Silverlight.Net showcase site.

Sweet!

-Jeff

Tire Storm is my latest physics driven Silverlight game. It is a fun, casual, 5 to 10 minute time-waster.

You are a tire (yep, a tire!) floating adrift on a log in the middle of the ocean. Your goal is to stay on the log as long as possible as a storm rolls in and the ocean waves get crazy.

That's it, simple but fun.

Tire Storm also has a high score system so you can compete against other...ummm.. tires. 

Here is the direct link: Tire Storm

Here are some screenshots:

TireStormScreen1 TireStormScreen2 TireStormScreen3

Here is a YouTube video:

If you like this game, support Farseer Games by spreading the word to any and all of your internet communities.

Enjoy!

Jeff Weber

www.farseergames.com

Just ran accross this:  Anatomy of a Silverlight Game

Looks like a  very good read.   

  

 

FarseerGamesWhiteBG_300X200

A few of you may remember when I changed the name of my website from “Farseer Games” to “Physics Powered Games”.

Well, I decided to change it back to “Farseer Games”

I won’t go into all the reasons why. Suffice it to say “Farseer Games” just feels right and “Physics Powered Games” never did.

This will be my last name change. It’s a pain the ass to switch names.

Sorry for any confusion

-Jeff Weber