Month: November 2020

So I’ve decided- graphics it is for the roguelike

So I’ve decided- graphics it is for the roguelike

Dawnlike on OpenGameart
Dawnlike on OpenGameArt.org

I did a quick search for free rogue graphics yesterday and found an astonishing quantity of rogue type graphics in sizes varying from 8 x 8 (pixels), 10 x 10, 16 x 16, 32 x 32 and 64 x 64. I haven’t quantified these sizes exactly but the 16 x 16 ones seems to be the most frequent and so that’s what I’ll pick.  This post on Reddit provided links to many free (and some paid), most on the OpenGameArt website.

As a programmer sorting out graphics, it can be a very time consuming thing to do, so expect to spend a lot of time on it. You’ve got to satisfy yourself that you have enough graphics.  Not just for terrain (e.g. dungeons and cities) but also for monsters. There are artists who will draw you more on sites like fiverr.com but that’s all cost.  If you can draw or recolour then that’s a major plus.

Recolouring is another problem. With game graphics, you ideally want them all from the same source or else you’ll have the problem of mismatched sets. Nothing jars visually more than mixing graphics with different palettes. I’m no artist but even I can tell when something works and when it doesn’t.

Also there’s the question of perspective. The Dawnlike graphics are a sort of mix of from above but with a slant so you see front walls. Whereas something like the Kenney rogue game pack is front on. So you have to decide which you are going to go with.

My ideal game would be one of my favourites- Ultima 3. This is probably because its the only Ultima that I have played right through to the end and finished it! It was also the first. It took me about three months of one hour’s play a night. And I took copious notes. But as you can see its a bit more than a rouge like game! Those screenshots are from a CBM-64 which had a 320 x 200 screen (the image below is a composite of nine screens) borrowed from https://imgur.com/gallery/UvrzmBt. You can of course get the PC version sof Ultima III (and I and II) from gog.com.  (Note these are straight links not affiate. I receive nothing from them). I did buy Ultima I-VI from gog.com.

Ultima 3 screens

Tutorial seven on pointers and C strings published

Tutorial seven on pointers and C strings published

A different kind of sea string
Image by Steve Norris from Pixabay

The tutorials from About.com continue with the 7th one (of about 30) published. This is about C strings which are really just pointers to an array of characters.  Once you understand pointers strings are easy enough to understand.

C is not a great programming language for string handling. To do a lot of manipulation is tedious and error prone. You’ll find safe versions of many of the standard functions for things like string copying and appending. The difference between the safe functions and the non-safe functions is that the safe functions include a maximum length.

For example strcpy() is used to copy a string. It’s definition is this:

char *strcpy(char *dest, const char *src)

That is, it copies a string pointed to by src to a string pointed by dest and confusing also returns a pointer to dest.  What a waste of a function. It could have returned an int saying how many characters were copied instead. Because it relies on src pointing to a string (char *) that terminates with a null (or 0). If the null is missing it can copy a lot more characters and that’s how buffer overflow bugs happen. So you have strncpy which is defined as this:

char *strncpy(char *dest, const char *src, size_t n)

The extra parameter is how many characters are to be copied. That way if it goes wrong, it is limited to n.

The picture? That’s a different kind of sea string…<groan>

Rogue like – do you use graphics or text?

Rogue like – do you use graphics or text?

Rogue games search The original rogue used graphics. This was back in the era of terminals and home computers and graphics could be quite limited. So there’s a tradition of using text. However if you do a google image search for rogue game like I did here, you can see that while many of them are text there are a couple that are graphics.

So the question is do you use graphics or text?

Text has the advantage that its just there. All you have to do is choose the appropriate character.

Plus if you use Unicode (always a bit of a pain in C but doable) then you have access to hundreds of thousands of different characters. Like this one:

👾. Which is actually these

👾

👾

More information about this one from here.

Graphics on the other hand can be a lot more colourful but you have to get them drawn, or acquire them from somewhere like kenney.nl. So not an easy one to decide. If I had the resources I’d use graphics, but I’ll keep to the tradition of using Text.

A tip. When you have a question like “What characters are used in rogue” just try it. There is so much information on the web that there’s a good chance that someone will have done it. I’m finding this more and more and sure enough, I found this on Reddit. How would you have ever found that out before the web existed?

Can you compile this?

Can you compile this?

No return
Image by PublicDomainPictures from Pixabay

It’s just a little bit of C. I compiled it with these three compilers. MS VC (16.7.7 on Windows) gcc, and clang on Ubuntu 20.04 LTS. MS VC picked up the _Noreturn and complained, gcc 9.33 compiled it with not a whisper while clang 10.0.0 warned about void in the main function but compiled it anyway.

Both the clang and gcc compiled files ran and as you’d expect sat in an infinite loop until I control-c’d it.

However soon MS VC will compile it. According to this blog entry, MSVC from 16.8 preview 3 supports C11 and the _Noreturn feature (which tells the compiler that the function never returns) will be ok. Both gcc and clang support C11 so no problems.

#include <stdio.h>

_Noreturn void nrloop() {
	while (1) {
		;
	}
}

void main() {
	nrloop();
}

 

When would I use such a function, you might ask. IO can’t see me using it much unless I wnt to write a background thread function that just runs forever. I have indeed written such a function recently but it was in Delphi not C. Another use is a function that exits perhaps vi a jmp. It also lets the compiler know so it can optimize return code away.

As I said, I don’t think I’ll be using it much if at all.

An interesting game system – Fiasco

An interesting game system – Fiasco

Fiascao game coverAs well as games programming, I like game design and one of the best ways to practise this arcane art is to look at other people’s ideas and borrow/pinch/steal/be inspired by them.

The image is here is from a game Fiasco by a designer called Jason Morningstar of bullypulpitgames.com. It’s such a different game (they call it a weird game)  and you can see what it’s about on their Fiasco page as well as look at the various downloads.

Why I like it is because it gives you a flavour of tv shows with complex plot lines like Fargo. There are several ‘players’ involved and you’re never quite sure how things are going to turn out; there’s not what you would call a hero. You don’t get that in many computer games so anything that can advance the art is very welcome.

OF course turning it into a computer game would present some challenges. But I’d play it!

 

So what do you think this code does?

So what do you think this code does?

Math(s) symbols
Image by Chuk Yong from Pixabay

Here’s a little C function. It’s not exactly intuitive what it does and I’ve renamed it to prevent giving it away.

  float mystery( float number )
  {
    long i;
    float x2, y;
    const float threehalfs = 1.5F;

    x2 = number * 0.5F;
    y  = number;
    i  = * ( long * ) &y;                       
    i  = 0x5f3759df - ( i >> 1 );               
    y  = * ( float * ) &i;
    y  = y * ( threehalfs - ( x2 * y * y ) );   
    return y;
  }

If it helps, this line is really the heart of it.

    i  = 0x5f3759df - ( i >> 1 );  

Mystified? Well it’s a fast inverse square root. No one really knows who wrote it though John Carnack of Quake and Doom fame popularised it. There’s an interesting discussion about the author but no one really knows.

There’s less need for this type of thing nowadays because of all the fast silicon but back 20-25 years ago when graphics processors were in their very infancy, it was a highly useful optimization. Mind you , you’d need to know assembly language inside out to come up with stuff like this.

So much fun from 16 x 16-tixy.land

So much fun from 16 x 16-tixy.land

tixy.landIf you are looking for inspiration for games creation, take a look at tixy.land. It’s a 16 x 16 square of dots whose colour is determined by a user entered JavaScript function. If you click the page, you’ll see new patterns. This was created by a developer Martin Kleppe and you can see other examples in this twitter thread..

The function is limited to 32 characters but even so that gives you a lot of possibilities. Most patterns are dynamic, changing as you watch. It’s quite fascinating.  The pattern shown in the screen shot is from Math.tan(t*(100-y*x)/9). and the actual url (including the code is)

https://tixy.land/?code=Math.tan%28t*%28100-y*x%29%2F9%29

The %28 etc are the HTML encoding of (, while %29 is ) and %2f is /.

You can edit any function on the page so try substituting sin, cos instead of tan. Also abs works as well.

So I’m playing Rogue… in my browser

So I’m playing Rogue… in my browser

RogueThe internet archive (yes them again!) not only has archives of most things I’ve done, but they also have an archive of 7000 games from the Dos era that you can play in your browser. You don’t have to install anything, just click on it and it installs the DosBox emulator for the browser and runs it.

Thankfully they have provided a filter so you can search . Looking through the first page I spotted Rogue and Warlords II, two of my old favourites. The screenshot is me after just having bumped of an Emu. That white square in a corridor between the bottom two rooms.

The collection has loads of all classics; it’s a very nice bit of work. Games from this era (very roughly the 90s) tended to be 2D. It wasn’t until the mid 90s that 3D games like Quake and Doom appeared.

I did a search for Empire in the text box and it found Empire Deluxe (a game I have and occasionally play 27 years after I bought it) plus a load of other games like Master of Orion.

Back in the day I worked as a game designer for MicroProse (yes the Civilization people) from 1992-1993 and though I never met Sid Meier, i did cross swords (metaphorically) with the other cofounder Wild Bill Stealey at a company BBQ (in the UK) by er failing to catch a baseball.

Games back then still came on floppy disk. Installing a game from 18 disks was not a fun task….

A collection of app ideas

A collection of app ideas

Collections
Image by pencil parker from Pixabay

Now this isn’t a bad thing. On GitHub, someone has built a collection of ideas if you are looking to develop something to further your skills. There always seems top be something about November as a month to do things, whether it’s growing a moustache (“Movember), Writing a 50,000 word novel (NaNoWriMo) or this.

These are in three tiers with 35 Tier 1 “Developers in the early stages of their learning journey. Those who are typically focused on creating user-facing applications.”,  the same number at Tier 2 “Developers at an intermediate stage of learning and experience. They are comfortable in UI/UX, using development tools, and building apps that use API services.” and 20 at Tier 3. “Developers who have all of the above, and are learning more advanced techniques like implementing backend applications and database services.”

If you finish all those, you’ll have done 90 projects. The last 20 of course being the most complex and including such things as a Discord Bot that plays Battleships, an Elevator simulator, a fats food restaurant simulator and the like. There’s no platform or programming language specified.

I’ve seen elevator simulators done before. Single elevator or multiple ones and for varying numbers of storeys.  Optimising the algorithm to minimise the waiting time is interesting and not always obvious. Do you have elevators wait wat floors when not in use or do they sit on the ground floor.

The author of this Florin pop has also completed 100 projects in 100 days if you fancy a challenge.

Star Ruler 2 – Open Source 4X game

Star Ruler 2 – Open Source 4X game

Star Ruler 2This is a 4x game (Explore, Expand, Exploit, Exterminate) .  “Select from one of seven races – or craft your own – to explore dozens, hundreds, or even thousands of systems in a galaxy of your choosing. Expand across unique and varied planets and ultimately exterminate – or subjugate – any who stand in your way either in offline single player or up to 28 player multiplayer.” as gog.com put it.

But as well as being available on Gog.com or Steam, it’s also open source but that doesn’t include the music from the game.  So you can pay for the game on Gog.com/Steam or download the open source version and build it yourself.

The GitHub website contains the full source code needed to build Star Ruler 2, and all secondary scripts, data files and assets required to run it. It’s 45% C and 22.5% C++ according to GitHub with a sprinkling of Flash (arr ar- saviour of the Universe- er sorry).