Category: Game

DungeonRush – open source C + SDL 2 game

DungeonRush – open source C + SDL 2 game

DungeonRush gameI continue my quest, looking around for open source games in C that use SDL 2. The latest one is DungeonRush by developer Rapiz1 (does no one ever use their real names these days?) who hails from Wuhan.

It is not a rogue-like, but more a Snake-like game.   You move your hero around the playing area avoiding monsters and things fired at you while picking up stuff and people to give you extra lives.  As well as the difficulty levels it includes multiplayer mode as well though I haven’t tried that.

If you are learning C or games programming, it’s worth studying to see how others do things; this includes its own text drawing and high scoring and saving high scores.  It’s quite fun to play though I am rubbish playing it, even at the normal level. I’ve added this to the C Code links page. (Accessed on the top menu),

Snake games are interesting because if you use a circular buffer, no matter how big the snake grows, you can move it by just moving the head and tail elements. An O(1) operation!

Amazing multi-platform Asteroids in C#

Amazing multi-platform Asteroids in C#

Android asteroidsAsteroids was the first full arcade game I ever wrote in C. Asteroids in C# takes things to a whole new level.  The solution contains 12 projects in all: Three Blazor projects, a WinForms version, a WPF version, a UWP (Universal Windows Platform) and a Xamarin Android Forms version (shown).

You can compile and run any of the projects though you will need to install and setup a suitable SDK and emulated (or a real device) for the Android.

Written by Howard Uman and ported by Ernie Salazar, this is a wireframe asteroids, more true to the original than my own raster version. Out of curiosity, I created an Android 9.0 emulator (I don’t have a recent Android phone) and compiled then deployed it to the emulator. The screenshot is grabbed directly from the emulator which has a less than ideal screen ratio. This would work better on a tablet.

The structure of the C# Solution is interesting. All of the game code is in the Base project. All of the other platforms just host the main game window. The game uses the SkiaSharp graphics framework for Android Forms.

This is a very nice open source project and an excellent way to see how Blazor works in both Wasm and Server mode, not to mention the Android, WinForms/WPF and UWP versions.

I have an interest in Blazor which lets you write C# code that runs in the browser very easily.  With a bit of workj, this should be runnable on a Linux webserver as well. Something for me to try…

 

 

Santa Paravia en Fiumaccio

Santa Paravia en Fiumaccio

Santa Paravia en FiumaccioI could understand you thinking “have I flipped my lid?”. What kind of a title is “Santa Paravia en Fiumaccio”? It’s actually the name of an old game written in C. A much more sophisticated Hammurabi if that makes sense.  You can read about it here on Wikipedia.

I was digging around the web looking for games in C with source code and came across a reference to it. I found it on archive.org though that version is a bit bashed up, All the < and > are displayed as their HTML equivalents – &lt; and &gt; so you need to do copy and replace on that. Plus a few of them have spaces between the & and the lt/gt!

That was about a thousand lines long. However I thought, why not do a search on the web specifically for it and found a cleaned up and slightly longer version on GitHub by DNSGeek. If you dig into his repository list you’ll see he’s also done a Python port with graphics! It also includes the instructions for playing it in a PDF.

If you try and compile the C source code, you’ll find that a curses library is missing. I’m not sure that it actually needs it so I commented out the include line and it didn’t seem to mind.  Under Visual Studio, it complains because of the strcpy functions that should be strcpy_s.

So I’ll fix the little things and see how ityplays. You just have to love a game that has functions with names like SerfsDecomposing() and SerfsProcreating()!

 

Other simple game ideas

Other simple game ideas

Dice
Image by Ana Carolina Franco from Pixabay

My recent blog about the L-Game reminded me of other simple games and I did a bit of digging on the web.  If you are ever looking for ideas for games or game mechanics, take a look at the Wikipedia page on abstract strategy games.

It reminds me of my teenage years when I used to get Games & Puzzles magazine. Here’s an interesting list of subjects from there, many with links.  I wrote my first game for my O-Level (you were allowed to do games in those days) based on  game I saw in Games & Puzzles magazine.  It was a tennis game using 2 dice. Here’s the game play details.

The tennis court is split into 12 segments numbered 1-12 with the net between segments 6 and 7. Bit Like this:

   Opponent
-----------
12        1
11        2
10        3
9         4
8         5
7         6
--- Net ----
6         7
5         8
4         9
3        10
2        11
1        12
-----------
   You

The ball starts with you. To serve, you roll two dice and move the ball by the total. So if you get less than 7 then the serve failed as the ball doesn’t cross the net, otherwise it moves the ball by that amount so it ends in segments 7-12.

If for example you rolled 9 then the ball would be in segment 9 which from your opponents point of view is 4. The opponent can now roll either one or two dice and move the ball by the amount. In this case I’d choose one dice as a roll of 1 or 2 would fall short but 3-6 would get it over the net. If you rolled two dice then 9 or above would take the ball out of the court.  There’s no real skill except figuring out whether 1 or 2 dice maximises the odds of the ball staying in play.

It’s a fun little game and easy to code in C or any language.

An intriguing Matchbox based learning machine

An intriguing Matchbox based learning machine

Matchbox
Image by Horst Winkler from Pixabay

I mentioned Menace the other day. This was a “Learning Machine” implemented entirely with Matchboxes. This was back in the 1960s. The idea is that a simple game like noughts and crosses (aka Tic-tac-toe) can be played by a crude form of learning computer.

You need enough matchboxes for every possible position in the game. That’s 304 matchboxes and you start but putting four coloured beads into each box for every possible turn. These represent the possible moves. To make a move, you pick the box corresponding to the position shake it and draw a bead out and play that move.

And so on until the game is finished. Then if Menace (as it was called- Machine Educable Noughts And Crosses Engine) won, you add three beads to each winning Matchbox, put one back in if its a draw and remove all of that colour if it lost.  Gradually it becomes better at winning.

There’s a far detailed write up here. It’s an intriguing technique though possibly not the easiest to apply as it requires you to have a matchbox for every position in a game. Fine with noughts and crosses but impossible with chess. Instead of Matchboxes, it could be done way faster in software.

It needs games with determinate moves and not too many, though I suppose with RAM in modern PCs, a few million moves would be manageable. One possibility would be the L game. I’ve never heard of anyone doing that, and it would make for an interesting project. I’ll add it to my list of future projects. Now I wonder how many possible moves there are in a L- Game? It’s made more complex because you can optionally move one of the single pieces as well as the L-Shape which can be rotated and flipped and it’s a 4 x 4 board not 3 x 3 as in noughts and crosses. .

Thinking about Slay tutorial 7- Game AI

Thinking about Slay tutorial 7- Game AI

Slay gamesHaving just published Slay Tutorial three, making the Onslaught game play well as a computer opponent(well up to 8 of them)  has been weighing on my mind. I have played the original Slay perhaps a couple of thousand times, so I’m reasonably familiar with strategy.

There’s almost 500 games on the Slay game chooser screen shown with four different sizes of islands; the four boxes. Usually by the time I’ve played through all games here (probably taking 18 months to two years) , I can start again and have forgotten what it was like. Plus I think it randomises the starting positions so you get a lot of replay value.

In the first Slay Tutorial I published a map of the tutorials and so far am sticking to it. Tutorial seven is the one for the game AI and its on my mind. I play all the Slay games at the same top intelligence level and even it sometimes makes stupid mistakes like leaving an area vulnerable to splitting and losing all units due to starvation.

The main aim of any player is to expand their territory at the expense of other players. Joining territories can be one tactic as its lets you support the bigger units. The 2 point unit is a Peasant then there’s Spearmen (6 points) , Knights (18 point) and Baron (54 points).  Getting a Knight early on gives you a big advantage as it can defeat castles and too often I’ve seen a territory with one or two spearmen get trapped by castles and destroyed in a few turns.

Likewise putting a castle down early on can secure a territory for a while. Or if you have a larger area, a couple of castles can shield your flanks so you can focus yoyr troops against one enemy and not worry about other players moving in.

Self Playing

In Slay once you are eliminated the games plays through until one player beats everyone else. But self-playing can also be a useful way to have computer players learn. One possibility is to try and implement a “matchbox” AI. This was done with Tic-Tac-Toe (noughts and crosses for us Brits) with Menace, Now it may be that Onslaught is too complex to implement that but there’s a lot of RAM available, so if I can limit the number of setups that it recognises then maybe?

Anyway there’s a fair bit of time and Tutorials 4-6 to do before I get to Tutorial seven.

PS

If you move the mouse over the About Me, you’ll see a link to a page that has short cut links to all blog posts along with the title of each.  It’s a quicker way of navigating.

 

Thinking about my Inselkampf reimagination

Thinking about my Inselkampf reimagination

Database schema
Image by mcmurryjulie from Pixabay

In an earlier post on web games, I mentioned an old multi-player web game that I used to play and which was discontinued in 2014.  I have a rough design for this and am busy learning Blazor as I believe that would be the best technology to use. It lets you run C# programs in the browser, no JavaScript needed. This simplifies input with verification and also updating the web page without having to do lots of messy Ajax stuff.

But being a web game there is a web server involved and the big question is what sort of data architecture to use? The most obvious one is probably using a relational database behind the scenes. That way each game (with up to 1,000 players) is held in a single database in about 12 tables. I’ll probably use MariaDB.

I did consider doing everything in RAM but its a terrible abuse of a web server and rather restricts it to running one or two games. Pulling stuff out of a database is much less strain on the system than having a few hundred MB of RAM tied up per game. A web server can support multiple games which helps keep the costs down.

Also with a web game, it raises the possibility of caching certain static files on disk to improve throughput.  This blog uses WordPress but has a cache so when you view a page, it’s almost certainly been pre-generated rather than built on the fly.

An example of a web game that I admire is Torn.com.

A newish game platform

A newish game platform

Blazor DungoonWeb games have been largely Flash in the past though that took a nosedive in the ‘tens (2010 onwards) and Flash is officially no more as of 2021. The spirit lives on in JavaScript games and there are innumerable games in JavaScript. That said, I’ve never been that keen on JavaScript. I talked about Web games in a post back in December and particularly that I saw Blazor as a possible game platform.

Today though I discovered Awesome Blazor on GitHub and it includes 18 Blazor web games including a multiplayer dungeon which is shown (I think it looks like a bit Pacmanish personally) . Most of these are ASP .NET Core 3.1 (which became .NET 5 late last year).

Some games will use wasm (Web Assembly) while other use C# in a terminal. As a simple proof of concept but nicely done, have a look at the virtual train set online.  You can lay track and then run one or more trains along it. Impressive as a demonstration of what you can do with C# and Blazor in a browser.

So someone wanted to know how to go about creating a dating sim

So someone wanted to know how to go about creating a dating sim

Wikipedia Ren'Py imageThis was a question in the reddit gamedev subreddit.

Here’s my answer. “Think about how you might make it work as a roleplaying game. You’d have a set of characteristics- age, cuteness, physical attraction, charisma, boldness etc. Have your characters roll 3 6 sided dice to get these. Then you can work out an easy scoring system by comparing similar characteristics.

So once you have a basic matching algorithm, your game has to let the player find potential dates. In the gym, supermarket, dating site, college etc. Perhaps you get an initial idea about someone you meet and then you get multiple dialogs where you try and figure out how to ask them out. Choose the wrong phrase (e.g. “Do you spit or swallow?” ) and you won’t see them for dust. Maybe if the person you are asking out has a large personality they’ll laugh at your humour and say yes.

Then you have to decide what wins the game. Getting to first base, 2nd, breakfast? Or you get a low score when they tell you they’ve decided to become a nun because of you…

How you implement it is entirely up to you? Things like renpy, or maybe you’ll do the whole thing. For the possible target market I think you might have to make it graphical. Perhaps a comic-book type approach? That way you don’t need too many drawn backgrounds.”

This is the kind of thing you might use Renpy for. What is Ren’py? Ren’Py is a visual novel engine used by thousands of creators around the world that helps you use words, images, and sounds to tell interactive stories on computers and mobile devices. These can be both visual novels and life simulation games.

I got the screenshot from Wikipedia. Talk about breaking the fourth wall! And yes Ren’py has an irritating apostrophe in the middle!