Getting started

It’s about time I started blogging again.

There’s been a fair amount of interest in this – I’ve been making a 2D game engine in Borland Delphi, and I’ve had some people ask me to blog about the design and coding process. So that’s what I intend to do. The engine should be fairly capable, and is built around classes designed to handle one part of rendering a game. 

The design is simple – a 2D game is (usually) a room or level, which consists of tiles which make up the background and sprites which can collide with eachother and with the background. To this end, here’s the structure of the classes:

TGameEngine – the overall wrapper for the game. This contains:

TTileManager –

Manages lists of tiles. Each tileset is of a given size (say 16×16, or 32×32) and the tile manager is responsible for drawing each tile to a given DIB. Tiles have two masks – a collision mask (currently 1bpp) and an alpha mask for blending. The alpha mask is used when rendering to the DIB.

The tile manager also contains mechanisms for referring to tilesets by name rather than by index. More on how this is done later. You can add or remove tilesets using the methods provided. Each tile can have two callbacks associated with it for pre-and-post-processing – you can, for example, render the tile yourself and add say a blurring effect after it’s been rendered, or if you want to modify the DIB before it’s rendered then you are free to do so.

TLayerManager –

This class handles layers. Layers can be any size, and made of tiles from any tileset that share the same dimensions. Each cell in the layer can have a callback associated both pre-and-post render, as with tiles. The Manager is responsible for maintaining a list of layers that are used to create a TLevel. It is the part of the engine that renders a layer to a specified place in a DIB – or, rather it renders a layer to a DIB by centreing on a specified point in the layer. 

TLevelManager –

This manages a list of TLevel classes. The TLevel contains a list of layers used in a level, sprites utilised by that layer and certain flags – if the layer can be collided with, if the layer scrolls (and at what speed if so), various callbacks associated with pre-and-post layer rendering etc.

TSpriteManager –

This manages and draws sprites, maintaining a list of sprites and their masks and animations. Like tiles, sprites have both a collision mask and an alpha blending mask, used to render them. Unlike tiles, they can be any size and can appear on any layer. When drawn, they can trigger callbacks to notify the user that they have been drawn, and also (if set able to collide) when they intersect with certain tiles and other sprites. They can have any number of animations (all of which must be of the same size, like a TTileset).

 

That then, is as far as I have got so far. I’ve put a demo up – here’s a picture of it:

 

A demo of Layers being used for parallax scrolling, and also demoing the post-processing callbacks of TLevel.

A demo of Layers being used for parallax scrolling, and also demoing the post-processing callbacks of TLevel.

 

You can find the demo at http://paul.dunn.googlepages.com/TestGame2.rar

Yes, it’s a bit Ghosts’n’Goblins, and I’m probably the worst pixel artist in the world… But it does illustrate the points above. Use up/down/left/right to move around. There’s no sprites yet, just layers. As each layer is drawn, a post-processing blur and darken is added to the DIB used to draw the display. This isn’t the final engine method, as it relies on crappy windows timers. You can see where I’m heading here.

 

I hope to port this to fpc, so I can develop for the new Pandora console due out any time now. Let’s see how far I get :)

Next up though is getting the sprites in, and then collisions. It’s going to be interesting to do proper collision (a doddle to see if something has collided, but not so easy to determine if something will collide, and how much it can move before it does… when you have sprites flying around at more than one pixel per frame, it’s easy to get things stuck in the scenery, or worse – fly right through it!

All things I shall have to address in time. God help me.

Advertisements

2 Responses to “Getting started”

  1. Nice one Dunny, good to see you writing this blog. It’ll be interesting for all beginning coders and experienced coders alike, :)

    Looks like I better dust of a version of Delphi to play with. Which version do you use?

    Well done…

    John

  2. Currently using Delphi 5 – if you eventually want to play with this, you’ll need a copy of FastLib (very fast graphics package for Delphi that utilises windows DIBs properly, unlike TImage).

    I’m probably going to aim for a .dll version too, so other languages can use it.

    D.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: