Foreword
This is a book about making 2D games in Mar: games that run in any browser and, from the same source file, as native iOS apps. It is the practical companion to The Book of Mar. That book explains why the language is the way it is. This one is about shipping something with a title screen.
The claim we will spend the whole book cashing in is simple to state. A game is a pure function of time and input. Mar takes that claim literally: your entire game is one immutable value (the Model), one pure function that advances it (update), and one pure function that draws it (view). There is no game engine object, no scene graph to mutate, no entity system to configure. The “engine” is the same Model-View-Update loop that powers a to-do list, ticking sixty times a second.
This sounds like a stunt. It is not. The examples folder of the Mar repository contains, among others, a pseudo-3D racing game, a raycasting dungeon crawler, a vertical shoot-em-up with ten stages of world-driven music, a rhythm runner, an arcade soccer game, a Zelda-style RPG, an asynchronous multiplayer card game, and a real-time strategy game that pathfinds hundreds of units. All of them are pure Mar. All of them hold sixty frames per second. Several of them are the worked examples of this book.
Who this book is for
You want to make a small, sharp 2D game: an arcade action game, a puzzle, a runner, a shooter, a little RPG. You know how to program, and you have at least skimmed Part I of The Book of Mar (immutability, pure functions, union types, and Mar’s exact-numbers stance). We will recap each idea in one breath as it becomes load-bearing, but we will not re-teach the language.
No game development experience is assumed. Where a term like “fixed timestep”, “AABB”, or “telegraph” appears, it is explained on the spot.
How to read it
- Chapter 2, Zero to Playable, builds a complete game in one sitting. Read it first; every later chapter refers back to it.
- Part I, The Machine, is how a Mar game runs: the loop, the tick, the draw list, integer math, and deterministic randomness. This is the part that makes everything else make sense.
- Part II, The Craft, is the toolbox: input on every kind of device, art made from rectangles, collision, sound effects, music, and game feel.
- Part III, The Ship, is the distance between a demo and a game: structure, performance, platforms, multiplayer, and deployment.
- The appendices are the pages you will keep open while coding: a cheat sheet of the whole game-facing API, and the complete list of traps we know about, each with its escape route.
One promise, carried over from the first book: everything here is real. Every API in these pages exists in the shipped language, every listing follows the same shapes the example games use, and every trap in Appendix B was hit by a real game first.