Category: Ebook

Chapter list for my recent eBook

Chapter list for my recent eBook

Book cover for learn C games programming

The files on GitHub have been revised and now include all image and sound files and tasks.json updated for clang-14. Note because GitHub doesn’t allow hidden files/folders like .vscode to be uploaded, I’ve included the .vscode folders as vscode and you need to rename them.

Chapter 1. Introduction to C programming
Chapter 2. Setting up a development environment
Chapter 3. Writing your first C program
Chapter 4. Working with Variables and Data Types
Chapter 5. So what is a pointer?
Chapter 6. A little Bit of C code
Chapter 7. A Quick Overview of Visual Studio
Chapter 8. Array variables
Chapter 9. Loop the loops
Chapter 10. More loops

Chapter 11. About operators
Chapter 12. Structs
Chapter 13. Functions
Chapter 14. More about functions
Chapter 15. Pointers
Chapter 16. Text Strings
Chapter 17. The Asteroids Game
Chapter 18. Architecture of C Programs
Chapter 19. Graphics
Chapter 20. An SDL Demo program

Chapter 21. The Game Loop
Chapter 22. Drawing Text
Chapter 23. More Game Elements
Chapter 24. Adding in asteroids
Chapter 25. Adding in bullets
Chapter 26. Editing with Visual Studio Code
Chapter 27. Restructuring
Chapter 28. Show the Score
Chapter 29. Explosions
Chapter 30. Sounds

Chapter 31. Detecting Collisions Part 1
Chapter 32. Detecting Collisions Part 2
Chapter 33. Detecting Collisions Part 3
Chapter 34. Passing Parameters into functions
Chapter 35. Detecting Collisions Part 4
Chapter 36. Ever Wondered about if (!value)
Chapter 37. Adding Level Structure
Chapter 38. Alien Ships!
Chapter 39. The High Score
Chapter 40. Finishing off

Raspberry Pi Sound issues- trying to fix it

Raspberry Pi Sound issues- trying to fix it

Loudpeaker
Image by OpenClipart-Vectors from Pixabay

In working through my Linux/Raspberry Pi eBook(Yes – the second eBook!), I’m up to the chapter where sounds are introduced using the SDL_mixer library. And I’ve hit two sets of problems.

It sometimes refuses to initialize the sound code.  This code below hits the LogError line:

	int success=Mix_OpenAudio(22050, AUDIO_S16LSB, 2, 8192);
	if (success==-1 ) {
		LogError("InitSetup failed to init audio");
	}

The other day it was working but not today. Now I have updated the Pi’s code (sudo apt update etc) but I wouldn’t have expected that to break it. I’ve been looking on the internet and find the whole thing a bit complicated.

I’ve got my Pi running 64-bit Raspberry Pi OS. I’ve changed the output device to headphones which plug into the headphone socket. If I run the VLC media player and tell it to play into the headphones, it will happily play the .wav files I’ve got for the asteroids game.

But if I run speaker-test, a terminal application with this command line

speaker-test -c2 -twav -l7 plughw:1,0

I get

speaker-test 1.2.4

Playback device is default
Stream parameters are 48000Hz, S16_LE, 2 channels
WAV file(s)
Setting of hwparams failed: Invalid argument

By running this command:

aplay -L

I got 71 lines of output but of these these below are the most important

output
hw:CARD=Headphones,DEV=0
    bcm2835 Headphones, bcm2835 Headphones

and the speaker-test command using the device parameter –Dhw:Headphones now worked. I’ve highlighted the bits in the aplay output needed to identify the device.

The new command  is

speaker-test -c2 -twav -l7 -Dhw:Headphones

I can now hear a female voice saying front left then front right a few times in my headphones.

So my Pi’s sound device is working; I just have to figure why SDL_mixer isn’t always. I’ll keep looking.

And the second problem which only occurs when the mixer is working, is when you play a lot of sounds. The PlayASound() function checks the result. On Windows it never had a problem but on Raspberry Pi, when you blow up a lot of asteroids say at one time, it plays a number of explosions then returns an error for each explosion after that. I think there’s only so many channels; that’s an easy fix; just ignore the error and return as if it succeeded.

Update to the Windows eBook

Update to the Windows eBook

Visual Studio configurationA reader asked me how to setup SDL2 for Windows given recent changes in SDL2. Specifically the files and libsdl projects have been moved from the libsdl.org website to GitHub. You can easily find SDL2 Image, Mixer, TTF etc.

However it can still be quite daunting setting up Visual Studio for SDL2. You have to download the specific files, then configure the project properties to specify the include paths for header files and then the lib files, both the path to them and identify the ones you want to use.

As I’m on my new PC, I bit the bullet and went through the process of setting it up. It took just over an hour to configure it.  I’ve put it into a PDF that’s a couple of pages long.

So the game works but only after I disabled the sound code; it was failing in the call to Mix_OpenAudio(). I think recent work on the SDL Mixer needs some work on my part. I need to sit down and look at the SDL Mixer page and figure out what’s failing. Once that’s done, I’ll update the files.

 

Designing a Rogue-like game for book two

Designing a Rogue-like game for book two

My 2nd eBook is going to be a bit like the first one- first it teaches C but it is oriented towards Raspberry Pis.  Then it shows how to program Asteroids (like the first book) followed by a Match three game and finally a Rogue type dungeon explorer game.

Rogue like game

Dungeon assets from itch.io
Dungeon assets

Now some rogue-likes stay true to the originals which were text based. Like this above from an article on Wikipedia. Now that’s ok, but I fancy something a bit more colourful so I’m going to use 16 x 16 pixel graphics.

I did a bit of searching and found these dungeon graphics on itch.io. I’ll use those to start with but may change. The view is not quite top down but top down with a bit of isometric in it. It looks better than pure top down.

So I figure the game has to have these elements.

(1) Generate a dungeon with multiple rooms and levels and stairs between,

(2) Fill the dungeon with monsters and treasures.

(3) Move the player’s character through the dungeon fighting monsters, picking up things including keys and maintaining a small inventory.

(4) Add some side quests like needing to find keys to open a chest with a magical item.

(5) I’ll also need to devise a simple combat system with magic.

Do monsters move- you’d hope so. How are rooms connected, in fact how are dungeons generated? I created a dungeon generator for the postal game Quest 30 years ago and can remember how I did it so there’ll will be that to implement in C.

I’m also going to leave out things like needing food and water.

So there it is now. Now to start writing the software. I’ll update this with progress reports.

Beej’s Guide to C programming

Beej’s Guide to C programming

BookBrian Hall (aka Beej) has written or collected guides to several programming languages including one on C. Out of curiosity I pasted the one document HTML version into both Word and a text editor to get a feel for how big it is and it filled 416 pages on Word, almost 13,700 lines in a text editor.

It is quite comprehensive covering most aspects of C. He has a disclaimer that its a work in practice and there may be bits that need correcting but still, if you are looking for an excellent guide to C, I’d definitely recommend it and if you like it, send him a tip on Paypal.

 

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.

 

 

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…