2. The Fractal Code Cycle
The Fractal Code Cycle is a simple yet powerful way of thinking about code in games.
It's based on the traditional Input -> Process -> Output model.
Think of it like this: Your entire game is one big code cycle.
First, input is read from the user and game state.
Second, the input and game state is processed in some way and the game state is updated.
Finally, the output is drawn on the screen and played through the speakers.
The process repeats until the game is closed.
Within this big cycle, there are smaller cycles at each level.
For example, in the platformer we will build:
- The main game loop as described above is one cycle
- The player character has it's own cycle
- Input: Game state, user input
- Process: Update position, apply physics, resolve collisions...
- Output: New player position, status, animation...
- The jump mechanic of the player has it's own cycle
- Input: Jump button state, game state
- Process: Apply jump force
- Output: New position, play jump sound
By breaking down problems in this simple way, we reduce the friction of implementing complex mechanics.
As we build these games together, you'll see how we can use this to tackle everything from simple movement code to complex AI logic.