horrible code. optimize time!
2026 - 04 - 14

I've been learning coding / using Godot Engine for about a year and a half now, and I finally figured out how you're actually supposed to organise a game.

bobby's bounce is a game I've been working on for about 4 months. The game is a level-based platformer with controls similar to Angry Birds.

bobby's bounce cover art

This is my third game. Well, maybe second because my first was just a tutorial resprite. And shit, maybe it is my first game because my second game wasn't really a game. Damn!

Anyway, to get to the point of the title. This is super embarassing ngl.
Each level had their own script attached to it, with logic manually copied and pasted onto each one.
The logic was the exact same...

...
Examples of said logic include:

Having all of that logic pasted across every level's script is a huge waste of space, and time.
It was fine at first, when I had about eight levels, but then I finally woke up and realise that this code management is diabolical.
If I want to have like 40 stages, this game is never going to come out if I keep creating levels like this.

So then, what did I do to fix this? REFACTORRRR!!!!!!
The big idea behind the refactor is to remove all the repetitive code from each level, and move it to a scene that has the logic in it's own script. The scene can then be instanced as a child node into each level providing logic to each of them.
(If none of this makes sense then the rest of this blog is not for you. read it anyway though..)

The biggest hurdle in my dumb brain was how I can access certain nodes' values and functions if the script was not on the very most parent node of the scene.
The solution to this is to use variables.
That probably sounds obvious but I'm stupid (at least I'm not dumb, though)
In the instanced script, instead of using hard coded paths for nodes, you can replace them with variables that you change in the level scene.

In Godot
I like to use @export variables. You define the variable's type/class, and they let you easily drag and drop the nodes as paths in the editor.
And then the code from the instance magically works! it's honestly magic.

After figuring this out, I even managed to decrease one of the level's scripts by 80% !!

2 lines added, 40 removed

It was extremely satisfying to apply that change and see the number. It made me feel a lot better lmao. You may judge me for terrible code, but at least I figured it out.
By the way, 10 level demo for bobby's bounce out now👉https://siloricity0.itch.io/bounce

logo