Skip to content

How this engine was coded

EndersteveGamer edited this page Apr 12, 2023 · 5 revisions

How the engine works

This engine was coded when I was still learning programming, so I don't recommand coding like I did in this engine,
but I will still explain here how it was coded

The main menu

The main menu is mainly done by using multiple variables to store which option of each menu is selected, and having a function to display each sub-menu
It also has a variable that stores which sub-menu is active
When pressing a key, it will check which sub-menu is active, and react accordingly (change the selected option of the current menu for a up or down key, change the current sub-menu for the enter key...)

The options

A dictionary stores a value for each String corresponding to the name of an option. In the options menu, when interacting with an option, its value will be changed in this dictionary. When exiting the game, the dictionary of the options written in a json file, and loaded back at startup

The game

Charts

The chart is storing all the arrows that will appear in the level
The charts are stored in two different formats, depending on the mod or engine it's coming from: it can use the mustHitSection element or not.
Each chart is divided in multiple sections, and each note has a position (the time in milliseconds when the player will have to hit it) and a column.
For charts using mustHitSection, each section defines if the player has to hit the arrows. If yes, then the arrow will be on the player's side. If not, then it's on the bot side. So the column of the arrows is between 0 and 3 (4 different columns).
For charts that are not using it, the columns are between 0 and 7, so there are 4 for the bot and 4 for the player

Displaying the arrows

First you have to get the current position of the arrow, and that is the position in the modchart - the current time in the level. So an arrow that is at position 1000(ms) at 1000ms in the song will be at position 0.
Then displaying the arrows is actually easy: you can just set the vertical position of the arrow to its position multiplied with the speed of the arrows, and add the distance from the edge of where you have to hit the arrow. This is if your y axis is pointing down, and that's the case with Pygame

Hitting arrows and accuracy

To hit an arrow, the game checks all the notes that are in the right timing window. Then for all the arrows that are in the timing window, it will hit the one that came the earliest (from the arrows that are at 45, -15 and 26 it will hit the one at -15). Note that the timing window is on both sides, both before and after the hit position. Once the player hits an arrow, it will calculate its accuracy based on the timing, and give it a percentage (100% for sicks, 0% for shits...)
The accuracy is the average of all percentages

Missing arrows

If an arrow is so much in the negatives that it is outside of the hit window, it will be counted as a miss

Displaying the characters

Each character has a list of frames that are taken from the instructions of an XML file, that tells where the frame is located in the corresponding PNG file. Each character has multiple animations for each direction, and each direction has multiple frames

Clone this wiki locally