SilverTile: Another progress report

17. desember 2009

It's time I posted another progress report.

Since my last progress report I have implemented most of the features from my feature list. I'm not entirely happy about the Xaml support for level design, and I am still missing the support for per-pixel collision detection, but the game engine works well enough that I have implemented a VERY simple game using it. 

The game, available here, lets you control your character on a field throwing swords at some monsters. You get points for how many monsters you kill and if you are touched by a monster you die. 

Hunting monsters

Hunting monsters

As simple as it is the game demonstrates the features needed for a proper game:

  • We have collision detection - both between moving sprites (character, monster, sword) and between sprites and background (you cannot walk across mountains). 
  • We have animation support and an animated sprite can have many animations that we can choose.
  • The game area and all game assets are defined in Xaml. 
  • Graphics are reused between sprites. This means that two identical monsters share the same bitmaps in memory.

The engine is still missing some features. The most obvious one is the pixel perfect collision detection. This is a simple feature to add, but I fear that it will be a real performance killer so I postpone it until I really need it. Apart from that I feel that the framework surrounding game setup needs some work.

The current implementation lets you define one or many GameAreaGrid objects. The GameAreaGrid lets you place one rectangular sprite in each cell. You then tell the Viewport to load the grid and it will be setup as the background area of your game. To change maps you tell the viewport to load another GameAreaGrid object.

While this works well enough I would like it to be even simpler to use.

The idea is to add support for area transitions to cells in the GameAreaGrid so that when the player enters one of these we automatically loads the new grid and places the player at the new location. This should allow us to setup an entire game world using only Xaml. I'm not entirely sure what would be the best way to define an area transition but I think it would be nice to add an AreaTransitions collection property to the GameAreaGrid where each object in the collection described a transition that would be performed when the player enters a given cell. A transition would be from a cell (grid row and column) to a new cell in another GameAreaGrid. The reference to the GameAreaGrid would be a regular object reference that could be modeled as a binding to a StaticResource in Xaml. This still gives us the option of designing the GameAreaGrid in Xaml or in code if we prefer. 

I would also like to allow random placement of enemies in a GameAreaGrid. Either completely random or by identifying cells where mosnters can spawn. The types of monsters, the number of monsters and how often they spawn would also have to be specified.

So that will be my plan for the week until christmas. Implementing more support for game mechanics, paving the way for a complete game engine :-)

kick it on

.NET, Silverlight , ,

SilverTile: Old-school gaming on a modern platform - progress report

8. desember 2009

It's time for a progress report.

The last week I have been adding basic features to SilverTile. The first feature was to add basic rendering support. My first attempt used Array-copy functions to copy pixel data from the sprite to the viewport. This worked well, but it did not support alpha blending (transparency) of pixel data. To improve this I added some code from the Silverlight Games 101 blog that allowed rendering of bitmap data from one WriteableBitmap to another. I modified the code somewhat to support rendering of data from any IRenderable and then I had the rendering support I needed.

The intial architecture of SilverTile defined each sprite object as having its own pixel data. This is fine as long as you have only a few sprites or if each sprite have an unique appearance, but in most cases you will have many sprites using the same image. One example is the walls of a game area. I model each wall segment as an unique sprite, but each is built up of the same image. So instead of having each sprite have its own pixel data I refactored out the pixel data into a Frame object that could be reused between sprites. This also lay the ground for animation support later.

Zelda walking

Link walking!

To set up a game area I want to support two modes. One mode should be building game areas in code by using the AddBackgroundSprite() method of the Viewport class. This lets you add one sprite at a time at the desired location. While building the game area in code works well, I wanted to support using Xaml to describe the game area and the graphical resources used by a game. Since Silverlight only allows classes that inherit from UIElement to be named (given the x:Name and x:key attributes) in Xaml I had a choice of either letting the Sprite classes derive from UIElement or using a separate set of classes to describe the game area. I cholse the latter option and built a set of classes that can be instansiated in Xaml and that describes a game area, a game tile and a frame. I then added a SetGameArea helper method to the viewport that reads the GameArea data and performs the setup.

Finally I added support for animated sprites. An animation is a list of IFrame objects in combination with a frame rate. Each time the Update method of the animated sprite is called, we check if the elapsed time is greater than the time a frame should last and if it is we switch frames to the next frame. When we reach the last frame in the animation we go back to the first frame again. Although I will need for sprites to support multiple animations (like walk left and walk right), this is a good starting point.

On top of all this I have written tests for everything. This really helped me when refactoring the code to use IFrame and the bitmap blitting.

If you have the Silverlight 4 beta installed you can watch a live demo here: (Try clicking on the game area!) Or you can download the source code here:


kick it on

.NET, Silverlight , ,

SilverTile: Old-school gaming on a modern platform (part 2)

3. desember 2009

I will try to keep SilverTile simple with just the features needed to get my game running.

At the very least SilverTile will support the following:

  • Rendering to a surface (WriteableBitmap)
    • I think this is the fastest way to render pixel graphics in Silverlight (done)
  • Support both tiles for background / terrain, and moveable sprites
    • Sprites should support animation (done)
    • Sprites should support transparent pixels (done)
  • XAML for game level setup
    • Support using XAML to setup the game levels/maps (done)
    • SUpport using XAML to define sprites and animated sprites (done)
  • Collision detection
    • Tiles should support bounding-box collision detection (done)
    • Sprites should support bounding-box collision detection (done) and possibly per-pixel collision detection (not yet)
  • Input control
    • Keyboard input should be handled in a structured way
  • Game infrastructure support
    • Support for transitions between levels/maps defined in XAML (done)

In addition I think SilverTile needs a way to handle the game and a game session as an entity, but that can wait until later. This is implemented in the SilverTileGameWorld class.

Any comments? Did I forget anything essential? I will update this page with any new features and with some progress information as soon as I have anything to report.

.NET, Silverlight , ,