Kumatori Panic! Devlog #2 - Menu system, gameloop, difficulty
So with all the basics in place, let’s actually crate a game! For that we need a Menu from which you can start, and a proper gameloop of winning and losing! For this we need to create a state machine first to handle our scenes! Basically we do a simple codebase to be able to branch the code, depending on which “state” we are. Are we in the menu? Call the update and draw for the menu. Are we in the game? Call that for the game. Did we lose? Set state to menu for basically a “return to menu option”.
Here is the code on how I do all of this, feel free to take it for your own usage.
But for a menu we will need an art, so I quickly tried to do my own rendition of the cartridge art, and just draw it into the menu scene upscaled, just like how I did it in Druid Dash.
With the menu completed we need rules to end the game. One of the easiest to handle is to see if we have chick that cannot be matched anymore (1 or 2 of the same color, as we need 3 to match). If so, just do a state=3 and the update will automatically go into the update_gameover() code.
But that is not all, I wanted to have a limitation for the player. Limiting all steps would be to harsh, so at the moment we have the following! An energy meter that depletes only when we push a chicken, and refills when we match chickens. Refilled amount depends on the number of chickens matched. If you ran out of energy, the game ends.
One last thing after this is how we handle level loading and unloading as random heavily plays part in the map generation. Luckily PICO-8 has a handy function called SRAND(seed) which will let you to manipulate random calls. If you call SRAND(2) for ex before your generation, every random call will be individually the same no matter how many times you redo. So if you save the seed before each map, you can just call the loading function, set the SRAND() to the map’s seed and the generation will be the exact same! Magic!
With all this only one thing is left. Handling the difficulty of the game. At the moment I have a very rudementary method. There is a difficulty variable calculated with difficulty = flr(level*4.5) and for the stage we generate this many chickens. Furthermore to avoid overloading the player, we introduce the many type of chicks later in the game with a pretty trick of manipulating a random table to choose colors from. If we are later in the game, we add all colors into the table, and all color could appear on the map! Limit the number and slowly let it grow and you got an interesting difficulty curve of increasing amount of chicks and colors!
So what issues do we have left? Currently, there is no checks if the player can complete the stage. For example you could get 3 chicks that are surrounded on 3 sides by trees, you cannot push any, but the game doesn’t end as it sees the “option to match”. This I want to solve with the option of picking up a chick for energy and carry it around for energy to place it down in a new place. Not only this solves the issue of impossible placements, but it ties the original cart image into the game, where the bear is actually holding a chick! You can also run out of energy due to me not knowing how much to give you, so if that happens, feel free to try a few times, then restart.
That is all for today’s devlog, see you in the next one!