itch.io is community of indie game creators and players

Devlogs

Update # 4 - refactoring and other code changes

Scramble RND Revisited
A downloadable game for Windows and Linux

Time for another update! Some time has passed, as real life goes on and you need to take care of things. But let's continue.

I am using the Godot Engine to make this game. It's fun, flexible, exports to all major operating systems and it's free and ready to run from Steam of all places.  Of course it is not without its quirks (like the need to force shader compiling to avoid hiccups during game-play) but that is a small price to pay for such a good general purpose game engine.

As a game grows, so does its code base. I've been wrestling with a few things:

  • Communication between game objects got more and more complex, and don't feel "right". You know that feeling?
  • Silly little bugs that annoy me but are hard to track down.

Let's look at the first point. One design pattern that I used in my other games was that of an event bus. I knew this would make signalling easier and more simple to track.  I was not sure how to implement this in Godot until I found this great GDQuest tutorial. Their implementation of this pattern as an auto-load script (singleton)  is simple and effective.

Mine looks like this now:

# events.gd
# autoload script
extends Node
# gui signals
signal fuel_changed(amount)
signal lives_changed(value)
signal level_changed(value)
signal score_changed(value)
signal hiscore_changed(value)
signal stats_visible(bool_value)
# screen signals
signal screen_wipe_requested(name)
signal screen_wipe_finished(name)
# game event signals
signal player_died(position)

And every object in the game can send a global signal using:

Events.emit_signal("fuel_changed", fuel_amount)

Every object in the game can also listen to any global event by connecting to it by:

Events.connect("fuel_changed", self, "_on_fuel_update")

Using this has also allowed me to fully decouple the GUI, scene fader and switcher from the rest of the game code, making re-use much simpler. The scene tree has changed a bit because of this but it looks a lot cleaner now. I am sure I will now also be able to free the landscape bits from the Play scene as well.

Which leads to the next issue. Small irritating bugs.  As I started refactoring code I thought it was a good time to start implementing more strict code rules. Blitz Max in particular was excellent at this when using the strict keyword. This required you to define each and every variable and object. This is not possible in GDScript, but the next best thing is called Static Typing.  While adding this I solved several small bugs that eluded me from the start.

Growing pains. We all go through them. But I am happy now and am almost ready to start producing some audio and sound effects. For that, I am going to use ChipTone, right here on itch. What a great community!

Download Scramble RND Revisited
Read comments (2)