N°1 - Demo Code Reiview
So performing a "code review" of my own work was not easy. So I asked myself: "What do I want to add to the game".
The answer was, as all of you who have tried to make a game before will know, very long, complex and involved lots of functionalities and making the next best Mario with a Penguin ready to storm the indie game scene. In reality this will be impossible to accomplish. So I reigned my creativity in and picked two aspects of the game I want to improve. These were:
1) The characters - I wanted a new mechanic for the Penguin, and for the Snowman to present new challenges.
2) More bonus items - collectables are always fun, and I liked how the hat challenge played out. As the asset pack has lots of stock images in I decided they would all make cool collectables for future challenges.
And so I had my starting point, and on that I started combing through the Penguin, Snowman and bonus item code, looking for ways to improve them in order to implement my two new ideas.
Penguin & Snowman
For the Penguin & Snowman logic, I had implemented a basic attempt at a state machine using the match statement... This led to one script, with lots of mixed up functions, behaving sort of like a state machine. As I wanted some new behaviours, it was not easy to add this into the current code. I needed to simplify things to make it easier to grow. Also, for those of you who have played the demo (if you haven't, give it a try), there are some "jittery" moments and I was sure this was due to the code. My dad suggested the solution to my problem is a State Machine. So I did some research on state machines and watched a few tutorials and had a go myself. My first attempt was done in a blank project to ensure I understood the basics, and once I'd got the hang of it, I implemented what I now consider to be a proper state machine to the Penguin and Snowman. So this...
became this...
For those of you who watch Godot videos on YouTube, yes the inspiration for this is from the GDQuest tutorial (if you don't know who they are then check them out!)! I have adapted it to my own needs but I'm very happy with the results and can say that the "jittery" behaviour has improved! Also I have found it easier to implement new states to the characters as you can just "insert" a new state logic and just add the transitions in without lots of ifs/elifs/else.
Improvement aspect number one was done! I have a new mechanic for the penguin, and the snowman will present a new challenge for the player!
Note to self for future projects: Implement the state pattern from the offset for all characters as it is easy to grow as the project gets more complex!
Bonus Items
Now onto aspect number 2 - more bonus items! When I first added the different bonus items, I created separate scenes per bonus items, and then gave them their separate scripts. Unbeknown to me at the time, all of the scripts were the same. I went through the different scripts to see how I would go about adding in the new ones! It was only then that it hit me that all scripts were pretty much the same...
What I should have done is create one script that I can attach to all of my bonus items. There is no point having 5 scrips with a "connect signal to GUI function" which is exactly the same in each script. This is not good programming.
Speaking of the connect signal to GUI function... on collecting each bonus item, a signal is sent to the GUI. Each bonus item's signal has its own function to update the GUI. As you can see from the snapshot below, all of the functions pretty much did the same thing and were rather short.
To make this more elegant, I have decided on the following:
- create a single script that will be given to all the different bonus items, with one single exported variable "item" which I can use to name the bonus item. (Note: there are a couple of specifics but I will just integrate these with "if item == ..." to ensure everything is in one place)
- when a bonus item is collected, it will send out the "collected signal, along with the item name.
- the GUI will have one function for updating itself when a bonus item is collected, making use of "match" with the item that it is sent.
- Create a standardised bonus item scene that all bonus items can be created from by instancing it when creating a new item.
After implementing the above, I now have a single script as opposed to one per bonus item, and one function rather than one per bonus item. My initial though was debugging this will be very simple, and when I ran a little test no debugging was required at all! Jackpot!
All I had to do was create lots of scenes with different textures and, voila, improvement aspect number two was dealt with.
Note to self for future platformer projects: treat all collectable items the same in Godot!
*************
Now if you have got this far, this might not seem a lot to you guys. But to me this is an achievement. I became a first time father in February, and as all of you know, babies take up a lot of time! I will do my best to keep you all posted on any progress I make, my personal goal is to have the game finished for Christmas!I have a clear idea of where I want to take this game, and when I get some time I will take it there, I will just go one baby step at a time...
Stay safe,
JWR26
Get Penguiner
Penguiner
A mini platformer where you play a penguin... so a "Penguiner" if you like!
Status | In development |
Author | JWR26 Games |
Genre | Platformer |
Tags | 2D, Christmas, festive, penguin, Singleplayer, winter |
Languages | English |
More posts
- Diving back in...Mar 16, 2021
- Asset sourcesJan 04, 2021
Leave a comment
Log in with itch.io to leave a comment.