XMLGameEngine

An engine for describing games built around Xerces, exprtk, and SFML.

View the Project on GitHub beefviper/XMLGameEngine

34. Lunar Lander

Status: built (games/lunarlander.xml, tests/test_lunarlander.cpp, tests/test_lines_and_pixels.cpp); new verbs and tags: <line>, <type>pixel</type>, <acceleration>, <accelerate>, <stop />, <slower>, <faster>

Why this game

Lunar Lander (Atari, 1979) is drawn entirely from lines, and it asks three things the language could not yet say: a constant pull on an object (gravity), a thrust that is held and runs out, and a landing that is good or bad depending on how fast you touch. It also needs the ground to be touched only where it is really drawn, because a jagged moon inside a bounding box is mostly empty. That last need is the same one a fighting game has, so it was made general.

The game as described

An 800 by 600 window. The moon’s surface (two runs of peaks, slopes and a ledge) is one object drawn from fifteen <line>s, with a gap left for the pad, which is a short thick green line. The lander is thirteen lines. It falls under its own <acceleration>; the keys fire three thrusters (up, left, right), each of which adds to the velocity while held and burns one unit of fuel a frame, and does nothing once the fuel is gone. Touching the ground, the bottom edge, or the pad faster than safespeed wrecks it; touching the pad slower sets it down. Both end the game, through lander.crashed and lander.landed.

What it tests

Question How the file answers it
Can a picture be described as data? Yes: <line> tags inside a <sprite> are drawn once, when the game loads, into a bitmap that is transparent where nothing is drawn.
Does what is tested match what is drawn? Yes: <type>pixel</type> on a collision looks at the same bitmap the backend shows.
Can gravity be data rather than a rule? Yes: an object’s <acceleration> is added to its velocity every frame.
Can a key be held for thrust and cost something? Yes: <accelerate direction= burn=> adds while held and uses up a variable.
Can the same pair of objects have a good and a bad result? Yes: <slower> and <faster> filter a rule by the speed of the object, so the pad has a rule for each.

Decisions

Options considered

Approximations

No rotation, no zoom, no score by landing place or fuel left, no sound, one pad, one shape of terrain. Only the lines of the terrain are solid, not the space under them, so a lander that somehow got below a line would fall freely (the bottom edge still ends the game). The window backends (SFML, raylib, SDL2) were written against their headers and compile-checked; the game was played frame by frame in the tests, not watched in a window.