Programming and Engines

Programming Concepts Behind Games, in Plain Terms

A plain-language map of the main code ideas inside a video game: loops, state, collisions, randomness, saving, and the tools teams use to build them.

On this page
  1. A game is a program that never stops asking questions
  2. The loop that drives everything
  3. Data and state
  4. Rules for what touches what
  5. Behavior and decisions
  6. Controlled randomness
  7. Putting it on screen
  8. The tools around the code
  9. Where beginners get stuck
  10. A suggested path

A game is a program that never stops asking questions

Most software waits for you to do something and then responds. A game keeps going whether or not you press anything. Dozens of times every second it asks the same questions: what did the player do, what should change in the world because of that, and what should the screen look like now? Nearly every programming idea in a game exists to answer one of those questions quickly and consistently.

You do not need to write code to understand these ideas. This guide walks through the main ones in the order a player would meet them, and points out where each one tends to go wrong.

The loop that drives everything

The central structure is the main loop. Each pass reads the controller or keyboard, updates every object in the world, and draws the result. One pass produces one frame. When people say a game runs at 60 frames per second, they mean this cycle completes 60 times each second, which leaves roughly 16.7 milliseconds per pass.

That time budget shapes many other decisions. Anything the game does must fit inside a frame, or the player sees stutter. This is why teams spend so much effort on performance profiling, which means measuring where the time actually goes instead of guessing.

Data and state

Every game is, underneath, a large collection of values: a position, a health number, a flag saying a door is open. Programmers call the full set of those values the game state. Almost everything else is a matter of changing that state in a controlled way.

Objects in a game are usually described by what they hold. A character might hold a position, a speed, a health value and a current animation. A bullet holds a position and a direction. Keeping these descriptions tidy is what lets a small team add a new enemy without rewriting the old ones.

State is also what makes saving possible. To store progress, the game writes out enough of its state to rebuild the world later. Deciding what counts as “enough” is harder than it sounds, and it is a common source of bugs.

Rules for what touches what

Games need to know when things meet: a sword hits a shield, a player lands on a platform, a car scrapes a wall. The usual approach is to wrap each object in a simple invisible shape and test whether shapes overlap. Real objects are far too detailed to compare exactly every frame, so games use approximations. Collision detection is one of the most important places where “close enough” is a deliberate design choice.

Behavior and decisions

Enemies and companions seem to think, but most of them follow a short list of rules. A guard might patrol, notice the player, chase, then give up and return. Programmers organize this as a set of named conditions with rules for moving between them, often called state machines. A handful of states with clear transitions can look surprisingly believable.

Getting from one place to another is a separate problem. Characters need a simplified picture of the level, such as a grid or a set of connected walkable areas, so that a search method can find a route. That is the job of character pathfinding.

Controlled randomness

Many games rely on chance: where loot drops, how a map is generated, whether an attack lands. Computers do not produce true randomness by default. They produce sequences that look random but are calculated from a starting number. That starting number is the reason two players can share the same generated world, and it is also why a bug can sometimes be reproduced exactly. The details are covered in random seeds.

Randomness also touches fairness and design. How often something rare appears is a design decision. Games that sell chance-based items for real money carry real financial risk for players, and anyone spending on them should treat the outcome as uncertain.

Putting it on screen

Drawing involves its own set of ideas. A 2D game often cuts characters into frames stored in sprite sheets and flips between them. A 3D game describes shapes with points and surfaces, then hands the heavy math to the graphics processing hardware. The code decides what to draw and where; the hardware does most of the pixel work.

The tools around the code

Few teams write everything from scratch. A game engine supplies ready-made versions of common pieces such as drawing, sound, input and physics, so the team can concentrate on what is unique about their game. How those pieces are organized internally is a topic of its own, often called game engine architecture. Choosing among engines is a project decision rather than a technical contest, and engine choice depends heavily on what you are making and who is making it.

Alongside the engine sits the team’s workflow. Programmers, artists and designers all change files, and version control keeps those changes from colliding. Large art and audio files need extra care, because they behave differently from text.

Where beginners get stuck

A few themes come up again and again.

  • Too much at once. Starting with a large project hides the basic ideas under hundreds of features. A tiny game that uses a loop, some state and a simple collision test teaches more.
  • Fixing symptoms. A character falling through the floor looks like a physics problem, but the cause might be a frame that took too long. Look for the underlying cause before changing numbers.
  • Old bugs returning. Changing one system can quietly break another. Teams rely on regression testing to catch this, and so can a solo developer with a short checklist.

A suggested path

If you want to understand games better, or you are curious about learning to code, pick one idea and build the smallest possible version of it. Move a square with the keyboard. Make it stop at a wall. Give it a simple enemy that switches between two states. Each of those exercises maps directly to a section above, and none needs a large framework.

Whether or not you ever write a line, knowing these ideas changes how you play. A stutter, an enemy that gets stuck on a corner, or a save file that refuses to load all become understandable as ordinary engineering problems with ordinary causes.

Keep exploring

Guides from other topics

All topics →