Category: Ideas

How to implement a Roguelike

How to implement a Roguelike

Roguelike dungeon
From Wikimedia

A roguelike is a character based fantasy game. By character I mean @^! not an individual as such! A question on the C SubReddit had asked about Project ideas for simple applications and someone had suggested a Roguelike. It’s not a bad idea but probably quite a bit more than just a simple project.

So I suggested breaking it down into stages. Here’s what I said.

Rather than a roguelike in one go (that’s a actually quite a bit of code) so do it in these stages.

  1. A Dungeon level generator. Create rooms and link them by corridors.

  2. Generate a bunch of levels – link them via randomly stairs, pits, transporters.

  3. Add random monsters and treasures in rooms.

  4. Implement a moving player able to navigate through the levels.

  5. Add combat. Weapons, range weapons, spell casting. Add monster hit points.

  6. Turn it into a polished game. Add everything else needed. Permadeath, collecting treasures. Moving monsters.

  7. (Optional) Make it multiplayer and allow PvP.

PvP means allow Player v Player combat. Doing it multiplayer is actually quite a lot of work which is why I made it an option. Rogues are often created using simple ASCII chars for monsters and treasures. Some programmers have used graphics and there are plenty of free graphics sets for 8 x 8 or 16 x 16 pixel sized monsters etc. like the microrogue set. Shown in action below. micro rogue set in action

I am tempted to make this the 3rd game idea for the Raspi game book. 30 years ago I created a multiplayer postal game Quest that is still running albeit on the web not by post. That included a dungeon generator. It wasn’t in C but it’s easy enough to translate Turbo Pascal to C.

Ingenious games in just 13KB of JavaScript

Ingenious games in just 13KB of JavaScript

Last Spartan screenshotI’m not fond of JavaScript but I am still in awe at the ingenuity of people who created a HTML5 game in JavaScript in just 13KB. There’s an annual competition called Js13K and this year there were 220 entries and prizes of $20,000 in total.

When you think that many graphics are way bigger than 13KB this is even more of an accomplishment. It means those games have to mostly draw their own. graphics rather than use prerendered graphical images. It helps that HTML5 includes a canvas drawing area and instructions in JavaScript to draw into it.

The GitHub Blog featured the top ten from this years competition. The picture comes from The Last Spartan which I really liked. Ironically the screen grab image was 121KB, almost eight x the size of the actual game!

If you are ever stuck for ideas for games, take a look at these. Being JavaScript, you can right-click in your browser and View Source (Chrome) or View Page Source (Firefox). Of course, to achieve 13KB, many of them have been minified which means getting rid of all spaces, carriage returns and renders it rather unreadable. This is what it looks like.

Screenshot of last Spartan source code

However the internet taketh and the internet giveth. If you paste this (or any of the source listings) into an online deminifier (aka beautifier) such as then you get all 1622 lines laid out in immaculately indented glory.  It’s actually 73KB in size as a normal listing and still very impressive.

There’s no reason why games can’t be done this way i.e. drawing graphics in C+SDL2 though I doubt I’d get them down to 13KB. My asteroids game which was 2200 lines of C generates a 96 KB exe. But when you add in images, SDL code and sounds etc it comes out at just under 35 MB.

Why C and not C++?

Why C and not C++?

C++ LogoConfession, I can program in C++ though I’m a bit rusty and my C++ knowledge stops short of creating template classes but I can use them.  But given that probably most games these days are programmed in C++ why is this site about C?

Well it’s been mostly personal preference. I like C; it is a heck of a lot simpler than C++ (understatement!) and compilations are very fast! I know most of C though to my chagrin I admit I got include guards wrong for quite a while. I was using them in .c files rather than .h.

Plus, I haven’t really looked into WebAssembly enough. I know it will work with both C and C++. But it has to be said that there is probably only so much you can write about C, so I will be including C++ in the future. I’d planned to do a C++ conversion of my Ebook(s).

Besides which if you google for something involving C, you’d be amazed how many C++ and even C# websites are in the results!



SSSnakes – a game for the next Ebook

SSSnakes – a game for the next Ebook

Screenshot of snake gameI’ve done a snake game in the past for About. That’s the picture and today I’ve uploaded it complete with source to Github. The thing with snake is, everyone knows it, its old hat and not particularly exciting.

Back in the early 80s the same was true about Breakout games. It was a common trope for game programming, bouncing a ball off a bat to break through a wall.

But then in 1987 along came the Arkanoid game which could be best described as Breakout re-imagined.  More balls, special bricks when when hit gave different features. It made Breakout games cool again for a few years.

So Ssnakes, is my name for a re-imagined snake game.  We’ll throw away losing your life when the snake hits a wall or itself. Only if your snake runs out of space is it dead, or if it is killed by an enemy. And as it travels around it picks up food which gives it energy. You can burn this energy is making it longer, moving faster or .. spawn off a new snake! Also you can attack enemy snakes – spitting venom directly ahead or sinking fangs into an enemy body if  your snake’s head is next to it.

Having 2, 3 or 4 snakes on the go will make it a bit more stressful to control. You only lose a life when you only have one snake left in play and you lose it.

Plus instead of a plain empty arena there will be a few static objects in it.


My next Book – Match three

My next Book – Match three

I’ve been thinking about doing a 3rd book – something like ‘More C Games, design and programming’ which would have three games, each with a design and then implemented with explanations and bits of source code and all on Github.  The first game is possibly going to be a Match Three game.

Match tree gameMatch Three games have been around for the best part of a decade and have a basic mechanic of swapping two adjacent pieces to make a line up of three, four or five pieces which get removed.

What makes it more challenging and interesting is the almost limitless number of mechanisms you can build on. For instance when you clear four or five you get special items that when swapped with another special item do something interesting. Or could be you have to get a set of special items and so on.

Or you might have special levels where you have to clear all of one particular shape within a time or Boss levels where the baddy is continually adding hard to remove pieces that clog up the game, or you might have a rotate button that flips the board 90 degrees so you can get rid of hard to remove pieces by having them drop into special buckets beneath the board.

Now I just have to come up with two more games. Suggestions welcomed!