Amade Game Developer's Handbook¶
This book teaches you how to program games by building them: first a game of Mines, then Solitaire, and step by step action games, a tower defence and finally a small real-time strategy game. While the games grow, so does the engine underneath them, amade-game-engine. You will not only use an engine, you will see why each part of it exists, because you write the game that first needs it.
All games are real programs. They run on the amadeOS desktop, follow its look and its colour themes, and they run on Windows and other Linux systems as well. Every piece of code in this book is taken from those games. It compiles, it is tested, and you can check it out and change it.
Who this book is for¶
You know Java: classes and interfaces, List and Map, lambdas, record and enum. You can write a small program and run it.
You have never written a game. You do not need to know Swing, Java2D, game loops, sprites, collision or pathfinding. The book introduces each of them at the point where a game needs it.
If you are still learning Java itself, work through a Java beginners' book first and come back. The games will be waiting.
How the book works¶
Each game chapter follows the same plan:
- What you build: a screenshot and the rules of the game.
- What you will learn: the new ideas of the chapter.
- The rules as a model: plain Java, no window yet, with tests.
- Building it step by step: drawing, input, the window.
- What moves into the engine, and why only now.
- Exercises to make the game your own.
The chapters build on each other. Read them in order the first time; later the chapter titles and the search help you find things again.
Code excerpts look like this, with the file they come from above them:
private int[] neighbours(int i) {
int c = i % columns;
int r = i / columns;
int[] result = new int[8];
int size = 0;
for (int dr = -1; dr <= 1; dr++) {
for (int dc = -1; dc <= 1; dc++) {
if ((dr != 0 || dc != 0) && contains(c + dc, r + dr)) result[size++] = (r + dr) * columns + c + dc;
}
}
return Arrays.copyOf(result, size);
}
Boxes point out things worth remembering:
Tip
A shortcut or a good habit.
Pitfall
A mistake that is easy to make, and how to avoid it.
Behind the scenes
Background you can skip on first reading.
The games¶
| Part | Games | You learn |
|---|---|---|
| I. Games that wait for you | Mines, Solitaire | Model and rules, drawing with Java2D, mouse input, Model-View-Presenter, high scores, drag and drop, animation, undo |
| II. Action | Paddle, Bricks, Snake, Rocks, Swarm, Maze, Blast, Jump, Hover Cab | Game loop, keyboard, sprites, collision, sound, tile maps, AI, cameras, physics, speech synthesis |
| III. Strategy | Towers, Sands, Colony, Town | Mouse in world coordinates, pathfinding for many units, selection, fog of war, saving games, roads and goods, seasons, the isometric view, networks and services |
Part IV, the engine manual, comes after the games. It describes the engine by subsystem rather than by game: what each part is for, when to choose it, how it works, and which chapter introduced it. Use it to look things up once you have read the games, or when you start a game of your own.
Two appendices close the book: Java2D and X11 pitfalls, the rules for fast and correct drawing, and a glossary of the words of game programming, each with the chapter that explains it.
What is written so far and what comes next is listed in The Road Ahead.
Conventions¶
- The book is about Java 25, built with Gradle. Commands are for a Linux shell; on Windows use
gradlew.batinstead of./gradlew. - Names follow the amadeOS projects: repositories
amade-<name>-game, Java packageseu.amadeos.games.<name>, the engine ineu.amadeos.gameengine. - All code is licensed under the EUPL-1.2, as is this book. Use it, change it, share it.
Ready? Start with setting up your machine.