Category: Ebook

More thoughts on the design of Rogue like

More thoughts on the design of Rogue like

Unicorn hackSometimes I walk up around 3:00 AM and my mind is abuzz with things like this. Last night was one such night. The first thought was I should stop calling it a Roguelike. There’s a certain set of conventions with those and I don’t want to be limited by that.

For instance here’s an article about things you should or shouldn’t do in designing Roguelikes.

The game (for the next Ebook) is not going to be an all singing all dancing version but will be an MVP in the parlance. That’s Minimum Viable Product,

So if I’m going to divert away from the ‘standard’ then it needs a name. Something evocative like Dungeon Trawler but shorter more catchy.  So I’m going with V.O.R. (Vaults of Ruin) or maybe just Vor,

So onto design aspects. Here’s a list of the features:

  • 10-15 different Monster types with differing melee, range weapons and magic. Can have packs of them, not just one. There is only one player. Should be fun!
  • Simple set of castable spells using a Mana value. It is used up casting spells but regenerates slowly as you move. It can be replenished quicker by consuming potions.
  • No food or water but the character has an energy rating. This is depleted by movement and fighting. Rest or sleep oe rating food replenishes it but I don’t want it to be a major thing. I’m not having deep dungeons with 25 or more levels, but 12 levels maximum.
  • Weapons are sword, dagger or bow. Can switch between them.
  • A few powerful magical treasures.
  • Turn based not real-time. Asteroids is real-time but movement will be restricted to so many squares for you and monsters. You probably won’t be able to outrun the faster moving monsters.
  • Limited visibility can make things interesting. It means the game has to calculate what squares are visible each move.

I was tempted to do away with grid movement; for instance in the Asteroids game, they can move at any angle and velocity and are not tied to a grid. But that might be a bit too complicated so movement will be grid limited and Up/Down, Left/Right and maybe diagonal.

The screenshot is from an open source (.NET Core/C#) web rogue game called Unicornhack.

 

 

Restarting the Raspberry PI C Games tutorials

Restarting the Raspberry PI C Games tutorials

Raspberry Pi 4I believe that the Raspberry PI, especially the 4B is a great and very low cost machine for not only running games but for developing them as well. Of course, if you have a PC, Linux or Mac then you can use that as a development machine but if you haven’t, it costs less than £100 (when you count the system, case, cables, SD-Card) to get up and running.

So I’m reworking my original eBook for the Raspberry Pi, using software running on the Pi and developing a 2nd ebook. Along the way I’ll publish longer excerpts from it here. Probably one a week.

 

 

Essential C – Free 45 page PDF

Essential C – Free 45 page PDF

Essentail C Front pageThis was compiled between 1996 and 2003 by Nick Parlante at Stanford college. It’s a 45 page PDF that summaries all the basic features of C.

It saves having to search online or through a reference book (I have the excellent O’Reilly C book as well). It has a few pitfalls to show you things to avoid and lots of short source examples.

A free C Book – “C Programming Notes for Professionals”

A free C Book – “C Programming Notes for Professionals”

C Notes for Professionals Book coverThis has nothing to do with my ebook and was produced entirely by the Goalkicker.com project which produces free and very professional looking ebooks, I came across it just a few days ago.

The C Programming Note for Professionals is currently 327 pages long, a 2.4 MB download. It’s nicely laid out and professionally done. I’ve only flicked through it but it looks an excellent piece of work with 63 chapters currently. You can leave your email address and they’ll notify you of any changes.

There are almost 50 ebooks in total covering topics like Android, .NET, Xamarion Forms, Perl, PHP, MySQL, PostgreSQL and may other topics. This is an excellent library.  I don’t know who is behind this project but they deserve to be bought a lot of coffees…

Back writing book two

Back writing book two

Hexagons
Image by Clker-Free-Vector-Images from Pixabay

This time it’s about Learning to program games in C on the Raspberry Pi. Most of the books I’ve seen are about programming in Python, but C combined with SDL2 gives you an edge. I already know that I can get 150 frames per second in Asteroids on a Raspberry Pi 4B.

The three games for the book are

  1. Asteroids. Fully developed
  2. MatchThree. About 1/2 developed.
  3. Empire type game. Map generator plus large scrolling hexagon map with fog-of-war shrouding and computer AI opponents. This will be based on the existing Empire code.

The third game is one I originally wrote thirty-three years ago (Dark Empire) in Z80 assembler for the Zx Spectrum. I then converted all 5000 lines of code into CBM-64 6502 assembly in one month working seven all-nighters, with the last three on three successive days. That one wasn’t in hexagons but squares and of course there was no mouse.

On the morning after the last all-nighter I drove across Manchester to deliver the tape master copy to a railway station to be sent to the publisher in London and when I got home, I slept for 24 hours solid. I doubt I could do an all-nighter now, but 33 years ago …

 

Slight change of pace

Slight change of pace

Networking
Image by Gordon Johnson from Pixabay

I’ve managed one blog entry per day for the last 134 days but a change in side project (I was writing a book to be published, not an Ebook)  but that has to be delayed by at least a year because of an issue at the publisher. In fact I may just publish what I’ve done as my 2nd Ebook.

I’m currently working on networking on a Raspberry Pi. Unfortunately it has to be in C# not C. Networking is a lot easier in C#- you have OOP, task parallel library (far easier than threads), thread pools,. concurrency with async/await and a lot more.  And I can use C# with .NET core or Mono on the Pi.

That said, I will still continue on with game development on the PI. I’ve got my Match Three game half done; I’m quite proud of it and want to get it finished. But I may switch to a slightly less frequent blog posting schedule…

 

Thrusting in different directions

Thrusting in different directions

Trigonometry
Image by dognamedseven from Pixabay

When you press the control key, the player’s ship will accelerate in whatever direction (0-23) it is facing. To make this possible, I pre-populated a couple of float arrays with values x and y for thrust in any of the 24 directions.

This function populate the two arrays. These are declared as

float thrustx[24];
float thrusty[24];

void InitThrustAngles() {
    const float pi = 3.14159265f;
    const float degreeToRad = pi / 180.0f;
    float degree = 0.0f;
    for (int i = 0; i<24; i++) {
        float radianValue = degree * degreeToRad;
        thrustx[i] = (float)sin(radianValue);
        thrusty[i] = (float)-cos(radianValue);
        degree += 15;
    }
}

It uses trigonometry to calculate the horizontal and vertical amounts for any of the angles 0,15,30..345 degrees. As sin and cos functions work in radians rather than degrees, the variable radianValue is calculated from the degree angle by multiplying by the value degreesToRad. If you remember your school trigonometry, one radian = 180/pi degrees. So the code divides by this value (or multiplies by its inverse in this case).

Then when you press the control key, it just adds the appropriate thrustx and thrusty value to the vx and vy variables. Simple and fast.

 

Free Programming Books

Free Programming Books

Guide to Scintifc Computing in C++The publisher Springer has made a whole raft of their books available as free downloads and this should last until the end of July. This includes a Guide to Scientific Programming in C++  and Systems Programming in Unix/Linux.

There’s also books on networking, cryptography and more.

Alternatively, if you fancy learning x86-64 Assembly Language Programming with Ubuntu then knock yourself out.  I used to write a lot of assembler (6502 and z80) a very long time ago. It’s a lot easier these days with debuggers.

 

SDL. Surfaces or textures?

SDL. Surfaces or textures?

Screenshot from DominionsWhen I first started on the asteroids game, I did it as a set of tutorials on About.com. That was around 2011/2012 and back then I used SDL 1 which was all about surfaces not textures. When I picked up SDL coding again in 2018, it had progressed to SDL2 which uses textures.

As I understand it, a surface is a structure in RAM while a texture is a structure in VRAM ( the memory in the GPU(. That makes it much faster copying pixels from VRAM to VRAM than from RAM to VRAM.

But I found it much easier to read pixels from a surface than from a texture. Chapter 38 in my e-book has a mask utility. It loads the images from disk into a surface then reads the pixels and creates the masks from that. Masks are used in collision detection. I had previously thought you couldn’t read from a texture.

However after reading this article, which writes directly to the pixels in a texture, it makes me think that reading from them should be possible. I will give it a go just because I’ve not seen it done anywhere.

Picture is from the game Dominions, created with SDL.

C++ Asteroids is progressing

C++ Asteroids is progressing

C++ AsteroidsThis is a screenshot of it as it stands and yes those asteroids are moving! It looks identical to the C version; the only difference is the code, not the appearance.

What makes it interesting is the structure. The Player and Asteroids classes both inherit from a Common base class that has all the position and move data.

It took a bit of time to get the overall architecture right. There’s a Game class which manages everything; the Player, Asteroid and Lib classes.  But Asteroids and Player classes also use the Lib class so  it took a bit of faffing around to make them all play happily together.

This is the biggest difference between C++ and C; the classes and how they all fit together. My biggest source of frustration has been arm wrestling with the C++ compiler; it sometimes seems as if never get easier! Sometimes a wrongly placed semicolon can generate hundreds of compile errors…

It took half a day to get it right and bullets should fit in much easier. Mind you I’ve had to incorporate two static variables in the Common class. One is a copy of the SDL renderer; this is needed to draw things on screen. The other is a pointer to the Game class so that I can access the DebugFlag state.  This is used to show debug information but I may be able to move the flag itself into the Common base class and change it through a call on a Player method. So long as it is static then changing it for the Player also changes it for the Asteroids and Bullets.