Programming of the core mechanic of Re-Slash
I am @lwyx, programmer of our entry Re-Slash, and i am going to briefly explain how I made the core mechanic of the game, an infinite loop of the player inputs.
First of all, after choosing the idea to develop, the most important thing is to get the core mechanics working as soon as possible, so the designer can start making and testing levels. So in our case, the looping of the player inputs was the first priority.
In a 72h jam, the ideal scenario is to get the core mechanic working on the first half day, or maybe the first day if it is a bit complex. I completed it fast since it was pretty simple.
The way it works is, as I said, straightforward, since it just needed some array management. I made a custom struct which contained an array of inputs for each type of input that the player could do:
- A boolean array for the buttons pressed each frame.
- A Vector2 array for the position of the joystick (or keyboard arrows and mouse) each frame.
- A float array for the value of the axes (gamepad triggers) each frame.
This way I could store in the same frame any combination of buttons, joystick movement and axes values. When I talk about frames, I am referring to physics frames that do not fluctuate like the graphic frames.
Then, I worked on a script that registers the inputs that the player executes every frame during a certain amount of time (this varies each level), and stores them in the previous arrays depending on the input type. When the “recording” time ends, the script just reads an element of the array each frame and simulates them as player inputs. Of course, the lenght of the array had to be calculated depending on the time record. In our case, we had 50 physics updates per second, so we multiplied that with the number of seconds we wanted to record to get the length of the array.
Here you can see it working.
https://www.youtube.com/watch?v=U_QlAFJ9T04
This way the script is very modular and can be used in almost any situation that you need to save the inputs of the player, with any controller it is using. Unluckily, we didn’t manage to get the gamepad functional on WebGL, but I promise it works! :stuckouttongue:
And this is how I made the core mechanic of our game, Re-Slash. I advise you to try it out and see by yourself how wonderful it works. :slight_smile:
Play here
