What is ZXLIB?

Hogweed Software’s ZXLIB is an object-orientated C++ library for writing 2D games of the sort which used to abound on the ZX Spectrum and its contemporaries, while taking advantage of the vast increase in memory and graphical ability of machines today. If like me you grew up with those computers and always enjoyed the old classics like Manic Miner, Jet Set Willy, and Atic Atac, the quirkiness of characters like Hungry Horace and Miner Willy, and the countless variations on the old arcade games like Space Invaders, Asteroids and the like, and thought it would be even more fun writing your own similar games on the PC in a modern programming language, then ZXLIB is the library for you. Likewise if you want to program your own completely new and original 2D game for the PC. If on the other hand you want to be merely a cog in the wheel working on on a “cutting edge” (but maybe not that original) game for 15 year old “serious gamers” which requires astrophysics PhDs and artists of the ability of Leonardo to write, as well as 128MB of RAM and a 2 gigahertz processor to run, then you’d best look elsewhere… 🙂


Running on Linux and Windows, and potentially a whole range of other systems, ZXLIB is based on SDL, a very good cross platform multimedia library which allows low-level graphical manipulation. You should know something about SDL before starting to use ZXLIB; however, ZXLIB allows you to bypass the low-level details of manipulating graphics memory and concentrate on the higher-level entities in your game. It contains classes for the following:

  • Sprites, Creatures and Monsters. A sprite is a movable graphic in your game, such as the hero of the game (like Pacman, Miner Willy or Hungry Horace), the monsters (invaders, ghosts, flying pigs, Maria the housekeeper…) or inanimate objects like bullets or arrows. What makes a sprite special compared to a regular graphic is that it can be drawn on the screen without erasing what’s underneath. A creature is a sprite that’s alive, i.e. Pacman and the ghosts are creatures, but a bullet isn’t. It differs from a plain sprite in that it has a given number of lives. A monster is a further-specialised creature, which can chase another!
  • The game Arena. The arena encapsulates the actual screen when you’re playing the game. Like a real arena – like a football ground or concert hall for instance – it contains not only the playing area itself, but also room for scores and other status information. The arena provides the bounds which limit where the sprites can move, and you can also load a background image as “wallpaper” for your arena.
  • The game itself.As well as encapsulating the creatures in your game and the arena, with ZXLIB the actual game itself is encapsulated as an object. To write your own game you derive your own game class from the base Game class which provides the basic functionality for a game, and override methods to respond to keyboard and mouse input, to provide the actual action and to refresh the screen. For those of you very happy with object-orientated programming, and in particular, GUI programming, this provides a nice way to program which allows you to skip the basic mechanics of how a game runs; but it is perfectly possible to use the sprite and arena classes without using the game class at all. More on this in lesson 2 of the tutorial.
  • Simple font classes To allow you to write text on the screen, ZXLIB contains simple classes for bitmapped fonts (those represented as pixel grids with all characters of equal width), and truetype fonts (those which appear on the screen as they would on print, with unequal widths for different characters, e.g. Times and the like).

What you should know

To start using ZXLIB you should be comfortable with programming in C++, including classes, objects and inheritance, as well as error handling with exceptions. You should also know the basics of the SDL library, though anything you don’t understand you can always look up in that library’s documentation.

Go back to hogweed.org