Getting started
Learning paths through this topic
Make the game run at the same speed on every screen
On a fast monitor the hero runs faster, on a slow computer the jumps change and enemies slip through walls. The AI often ties the game to the screen refresh. This entry gives a loop that steps the game at a steady pace and survives a long stall.
Make sliding, slowing down and camera easing feel the same at any frame rate
A hero that glides to a stop in a fraction of a second on one computer slides for ages on another, and a braking hero can even shoot backwards. The cause is a small piece of arithmetic the AI writes the quick way. This entry gives the versions that behave the same everywhere.
Stop enemies from jumping ahead when you return to the game tab
Switch to another tab for a minute and the game may race through everything it missed, or move every enemy across the screen in one frame. This entry gives a clock that measures the time between frames, limits one frame's time and can be paused cleanly.
Keep a high score list that handles ties, a full list and odd names
A list of best scores looks simple until two players reach the same score, the list is full, or someone types a long or empty name. This entry says who is placed first at a tie, when a score does not make it onto the list, and how to clean names.
Fix a homing missile that spins the long way round or circles its target
A homing missile sometimes turns almost a full circle to face something just behind it, or flips wildly when the target crosses straight behind. The angle wraps around at one point and the AI forgets that. This entry turns by the short way with a limited speed.
Turn "jump this high in this long" into numbers that really give that jump
You tell the AI a jump should be a certain height and take a certain time, and the jump comes out a little lower than you asked, every time. The textbook formula does not match how a game moves in steps. This entry gives the numbers that match, and shows how to prove it.
Find keys that do two things at once or fight with the browser
When the AI adds a dash, a menu and a reload, the same key often ends up doing two jobs, or a key the browser needs for itself stops working. This entry gives a check for both, and it knows that different spellings of one key are the same key.
Fix a hero that keeps running after you click away and come back
Hold a key, switch to another window, let go, return, and the hero runs on by itself. The game never heard the key come up. This entry gives an input keeper that releases everything when the window loses attention and tells a fresh press from a held key.
Give hits a push that works even when attacker and victim overlap
A push away from the attacker needs a direction, and when two bodies stand in the same spot there is none, so the victim does not move at all. Repeated hits can also add up to a launch. This entry chooses a direction every time and keeps the push the same size.
Catch broken levels the AI draws before the game starts on them
When an AI draws levels as rows of letters, one missing character gives you a crooked room, a hero who falls out of the world or a level with no way out. This entry gives a check that names each problem and where it sits, so you can send it straight back.
Make the crosshair hit where the mouse points when the game is scaled
Shots land beside the cursor as soon as the game window is stretched, centred in a larger page or shown with black bars. The mouse reports positions on the page, not inside the game. This entry converts them correctly and tells you when the cursor is on the bars.
Make a piercing shot or sword swing hurt each enemy once, not every frame
A shot that passes through an enemy touches it for many frames in a row, so the enemy melts in an instant, and a sword swing does the same. This entry keeps a short memory of who an attack has already hurt, and lets you choose whether it may hurt again after a while.