15. Radar, cockpit instruments and messages
Everything drawn on top of the 3-D view, specified to the pixel: where each instrument sits on the 640 × 350 screen, which line is drawn from where to where in which colour, how a value becomes a bar length, how a position in space becomes a radar blip (with the original integer arithmetic, and a demo that runs it), and every message that can appear during flight: its text, its trigger, its place and how many frames it stays.
Chapter 1 shows what the instruments mean to a player, chapter 9 how the 3-D picture under them is made. This chapter is the reference a rebuild draws from. Words used here: a frame is one pass of the main loop (18.2 per second in single player, about 70 per second in our multiplayer measurements, chapter 2); a world unit is the middle word of a 64-bit coordinate (chapter 3); Q14 numbers have 16384 = 1.0; the camera axes are a (forward), b (right) and c (c points toward the bottom of the screen; the source calls it "up", chapter 3).
Screen coordinates and drawing order
The screen is EGA mode 10h: 640 × 350 pixels, 16 colours, pixels about 1.37 times as tall as wide (chapter 9). All overlay drawing uses coordinates relative to the screen centre (320, 175): x to the right, y downward. To get the screen pixel, add 320 to x and 175 to y. In this chapter "rel" means centre-relative and "screen" means absolute pixels; every table gives both where it helps.
The drawing tools are few (src/graphics.asm):
- Line (
draw_line): a 1-pixel line, both end points included, not clipped (see the radar quirk below). Pixel rule: if |dx| > |dy| the line is x-major, otherwise (ties and single points included) y-major; the end points are swapped when needed so the major coordinate increases (swap when x1 ≥ x2, resp. y1 ≥ y2); err = major >> 1; for each of major + 1 pixels: plot, err += minor, and if err ≥ major then err −= major and step one pixel in the minor direction; then step along the major axis. - Plus (
put_plus_dot): 5 pixels, (x, y−1), (x−1..x+1, y), (x, y+1). It is drawn only if the whole plus is on screen: x−1 ≥ −320, x+1 ≤ 319, y−1 ≥ −175, y+1 ≤ 174 (rel); otherwise nothing is drawn. - Text (
draw_text): an 8 × 8 pixel font (assets/fonts/font8x8.txt) on a grid of 8-pixel columns; each glyph row is one byte, most significant bit = leftmost pixel; only the glyph's set pixels are painted, the rest keeps what is under it. - Stroke letters (
draw_vector_char): a letter made of lines on a 16 × 16 grid, scaled by a power of two; used here only for the gauge letters V and S.
For draw_text(x, y, colour, s, centre) (rel coordinates):
column = (x + 320) >> 3 // x is rounded DOWN to a multiple of 8
if centre: column = column - ((min(strlen(s), 80) + 1) >> 1) // the length scan stops after 80
left pixel = column * 8; top row = y + 175; each character 8 x 8, next character 8 pixels right
'_' moves back one column first (it underlines the letter before it; no flight text uses it)
Example: "COLLISION" (9 characters) centred at x = 0: column 40 − 5 = 35, so it covers screen x 280..351. A centred text is therefore half a character left of true centre when its length is odd. No clipping: a text that runs off the right edge continues on the next row's left side D (no flight text is long enough to do so).
What is drawn, in which order, every frame
The whole page is redrawn every frame from an empty background (chapter 2), so every
instrument is updated every frame, at the frame rate. Within a frame, later items cover earlier
ones (main, src/main.c):
| # | Step | Condition |
|---|---|---|
| 1 | Clear the page to the flash colour (normally 0 black; see "Hit flash") | always |
| 2 | Simulation; very far objects are drawn at once as white pluses (chapter 9) | always |
| 3 | Stars, then the sorted 3-D draw list | always |
| 4 | Score text | not spectating |
| 5 | Radar (grid, then blips) | shields > 0 |
| 6 | Instruments (draw_hud): sight, mouse marks, V gauge, S gauge,
velocity indicator, status lines | shields > 0 |
| 7 | The current message, then its frame counter − 1 | shields > 0 and counter > 0 |
| 5′ | Instead of 5–7: the death text | shields = 0 |
The mouse pointer (in flight a small 8 × 8 box in colour 15) is not part of this: it is drawn directly onto the page being shown, between frames (chapter 9).
Screen layout
The positions come from fixed variables (src/globals.c); nothing moves them during flight.
| Element | Anchor variable | Anchor, rel | Anchor, screen | Occupies (screen) |
|---|---|---|---|---|
| Sight | (screen centre) | (0, 0) | (320, 175) | x 272..368, y 135..215 |
| Radar centre | g_radar_cx/cy | (232, 110) | (552, 285) | grid x 472..632, y 257..317 |
| Velocity gauge "V" (zero mark) | g_vgauge_x/y | (−288, 118) | (32, 293) | x 6..48, y 221..349 |
| Shield gauge "S" (top of scale) | g_sgauge_x/y | (−240, 46) | (80, 221) | x 54..96, y 221..349 |
| Velocity indicator (centre) | g_attitude_x/y | (−232, −100) | (88, 75) | x 16..160, y 11..139 |
| Score and status lines | g_score_x/y | (160, −160) | (480, 15) | x 480..608, y 15..~76 |
| Message line | (fixed) | (0, −80), centred | row 95 | y 95..102 |
| Death text | (fixed) | (0, 0) and (0, 32), centred | rows 175, 207 | y 175..182, 207..214 |
Colours
All instruments use colour roles, entries of a 12-word table
(g_colors), so that the /M switch can make everything grey. The game
never changes the EGA palette, so the colours are the standard ones.
| Role | Used for here | Colour | RGB | /M |
|---|---|---|---|---|
| [0] frame | radar grid, gauge scales, velocity indicator axes, V and S | 4 red | #AA0000 | 8 |
| [1] HUD | plain sight, mouse marks, score, status texts, death text | 12 light red | #FF5555 | 7 |
| [2] HUD highlight | locked sight, gauge bars, indicator lines, status bars, messages | 10 light green | #55FF55 | 15 |
| [3] alien | alien blips | 10 light green | #55FF55 | 7 |
| [4] enemy missile | enemy missile blips | 14 yellow | #FFFF55 | 15 |
| [5] satellite | satellite blips (own and other players') | 15 white | #FFFFFF | 15 |
| [6] pod | pod blips | 13 light magenta | #FF55FF | 7 |
| [7] collision flash | background after a collision | 10 light green | #55FF55 | 7 |
| [8] hit flash | background after a hit | 12 light red | #FF5555 | 7 |
| [9] powered-hit flash | background after a powered hit (multiplayer) | 14 yellow | #FFFF55 | 15 |
| player blips | other players' ships: slots 1–2 / 3–4 | 10 / 9 light blue | #55FF55 / #5555FF | 7 |
The player colours are set when a multiplayer session starts (net_start_session,
src/net.c): a ship's colour depends on its slot only, not
on who is watching. Roles [10] and [11] are the title logo's.
The radar
The radar (draw_radar and radar_blip,
src/radar.c) is a small picture of the plane of your
ship's wings, seen from behind and above. Objects ahead of you appear above the centre, objects
behind you below it; left is left. Each object is a vertical stalk standing on that plane
and a 5-pixel plus at the object's end of the stalk: the stalk's length and direction tell how far the object is
above or below your wing plane.
Grid geometry
Ten lines in colour 4, always the same; the centre is C = (232, 110) rel = (552, 285) screen. The outline is a trapezoid: a wide near edge 32 pixels below the centre and a narrow far edge 28 pixels above it, which makes the grid look like a floor in perspective.
| # | Line | From (C-relative) | To (C-relative) | Screen |
|---|---|---|---|---|
| 1 | near (front) edge | (−80, +32) | (+80, +32) | (472,317)–(632,317) |
| 2 | far (back) edge | (−50, −28) | (+50, −28) | (502,257)–(602,257) |
| 3 | left side | (−80, +32) | (−50, −28) | (472,317)–(502,257) |
| 4 | right side | (+80, +32) | (+50, −28) | (632,317)–(602,257) |
| 5 | centre line (straight ahead) | (0, +32) | (0, −28) | (552,317)–(552,257) |
| 6 | cross line through you | (−64, 0) | (+64, 0) | (488,285)–(616,285) |
| 7 | left half line | (−40, +32) | (−25, −28) | (512,317)–(527,257) |
| 8 | right half line | (+40, +32) | (+25, −28) | (592,317)–(577,257) |
| 9 | near cross line | (−72, +16) | (+72, +16) | (480,301)–(624,301) |
| 10 | far cross line | (−57, −15) | (+57, −15) | (495,270)–(609,270) |
From a position in space to a blip
The radar does no 3-D work of its own. Every frame, when an object is moved and measured for
drawing (render_object, src/render.c,
chapter 9), three things are stored in it, and the radar reuses them later in the same frame:
- Distance exponent
dist_expand directiondir: the vector from your ship to the object, in world axes, block-normalised (chapter 3): start with the exponent equal to the model's scale (1 for ships, aliens, the mutant and pods; 0 for missiles and satellites); halve the whole vector (exponent − 1) while any component is outside −16385..16384; double it (exponent + 1) while all components are inside −8192..8191, testing after each doubling whether the exponent now equals 8 and stopping if so.dir= the three middle words. - Camera coordinates
cam_x, cam_y, cam_z=dirdotted with the camera axes b (right), c (toward the bottom of the screen) and a (forward), with the Q14 dot product.
In short: n tells how many times the offset was doubled to fill 16 bits; the radar undoes
that and then divides by 28 − zoom. Precisely: let n = dist_exp − scale. It is the number of doublings the vector got (negative:
halvings), so cam = the true camera-space offset × 2n. The radar then
needs only shifts:
// radar_blip(cam, n, colour) -- all values 16-bit signed integers
if n < zoom: return // too far for this zoom: not drawn at all
s = n + 8 - zoom // 8..22
bx = cam_x >> s // arithmetic shift = floor division by 2^s
by = cam_y >> s // height off the wing plane, same downward screen axis (+ = down)
bz = cam_z >> (s + 1) // distance ahead, at HALF scale
x = 232 + bx // rel coordinates; screen = +320, +175
plane = 110 - bz // the row where the object's foot is on the plane
blip_row = 110 - bz + by // the row of the object itself
draw_line(x, plane, x, blip_row, colour) // the stalk (a single pixel when by = 0)
put_plus_dot(x, blip_row, colour) // the 5-pixel plus, only if fully on screen
Because cam is the true offset × 2n, shifting by n + 8 − zoom leaves offset ÷ 28 − zoom: one radar pixel = 28 − zoom world units sideways and vertically, and twice that ahead/behind. Every object gets the same scale, whatever its model.
- Normalisation works on the 64-bit coordinates. "Middle dword" = bits 16..47 of a
component. Halve (arithmetic shift right of the whole 64-bit value) while any middle dword is
≥ 0x4001 or < −0x4001; then, while every middle dword is < 0x2000 and ≥ −0x2000, shift all
three left by one and add 1 to the exponent, stopping as soon as the exponent equals 8.
dir= bits 16..31 of each component. - Dot product (
vec3_dot): s = a0·b0 + a1·b1 + a2·b2 as a 32-bit sum (wrapping); result = bits 14..29 of s as a signed 16-bit number, i.e. floor(s ÷ 16384) for every value that occurs here. - Shifts are arithmetic (round toward −∞): −1 >> 3 = −1, −8 >> 3 = −1, −9 >> 3 = −2. A 16-bit value shifted by 16 or more gives 0 or −1, so a very near object at a far-out zoom sits on the centre lines (counts never exceed 23, so the 286's "count mod 32" rule never applies).
- Which objects use which scale: aliens, pods and other players' ships subtract their model scale (1); enemy missiles and satellites use dist_exp directly, which is the same thing because their scale is 0.
- When: the values are those computed earlier in the same frame, with this frame's camera (the ship is updated first, chapter 17). Objects whose update did not run this frame keep their previous values.
Worked example
An alien (scale 1) is at offset (300, −500, 2000) world units from you; your ship has the start orientation (forward = +z, right = +x, c = +y). Zoom 2.
- Normalise: exponent starts at 1. No component is too big. All are inside −8192..8191, so double: (600, −1000, 4000), exp 2; again (1200, −2000, 8000), exp 3; again (2400, −4000, 16000), exp 4; now 16000 ≥ 8192, stop. dir = (2400, −4000, 16000), dist_exp = 4, n = 3.
- Camera coordinates with the start axes: cam = (2400, −4000, 16000).
- n = 3 ≥ zoom 2: drawn. s = 3 + 8 − 2 = 9. bx = 2400 >> 9 = 4; by = −4000 >> 9 = −8 (−7.8 rounded down); bz = 16000 >> 10 = 15.
- x = 236, plane row = 110 − 15 = 95, blip row = 95 − 8 = 87 (rel). On screen: a green stalk from (556, 270) up to (556, 262) and a plus centred on (556, 262), as in the layout figure.
The same alien at zoom −1 (the start zoom): s = 3 + 8 + 1 = 12, bx = 0, by = −1, bz = 1: a two-pixel stalk (552, 284)–(552, 283) and the plus centred on (552, 283), on the centre line.
Zoom levels and the cut-off
The zoom (g_radar_zoom) is an integer from −6 to +2, 9 levels. It starts at
−1 when the program starts and is never reset, not by a new game or a new level.
Keypad + adds 1 (up to 2, magnifies), keypad − subtracts 1 (down to −6),
one step per key make code, i.e. one per press and repeating while the key is held (keyboard
auto-repeat; the keyboard handler latches every make code) D, read in the ship update (player_update,
src/control.c) only during flight and even while
dead.
An object is drawn only if n ≥ zoom. Working the normalisation rule backwards, that is the case exactly when every world-axis component r of the offset (in world units, with its fraction) lies in the range of the last column:
| Zoom | World units per radar pixel (sideways, height) | … ahead/behind | Object shown when each component r satisfies |
|---|---|---|---|
| +2 | 64 | 128 | −4096 ≤ r < 4096 |
| +1 | 128 | 256 | −8192 ≤ r < 8192 |
| 0 | 256 | 512 | −16385 ≤ r < 16385 |
| −1 (start) | 512 | 1024 | −32770 ≤ r < 32770 |
| −2 | 1024 | 2048 | −65540 ≤ r < 65540 |
| −3 | 2048 | 4096 | −131080 ≤ r < 131080 |
| −4 | 4096 | 8192 | −262160 ≤ r < 262160 |
| −5 | 8192 | 16384 | −524320 ≤ r < 524320 |
| −6 | 16384 | 32768 | −1048640 ≤ r < 1048640 |
General form D: for zoom k ≥ 1 the range is −214−k ≤ r < 214−k; for k ≤ 0 it is −16385·2−k ≤ r < 16385·2−k (the normalisation's asymmetric limits). In radar pixels this is always about 64, so the visible region is a cube of about ±64 radar pixels: an object on one of your own axes reaches at most 64 pixels to the side, 64 pixels up or down (stalk) and 32 pixels ahead or behind on the plane. The numbers were checked by running the arithmetic (the demo's code) at the boundaries D.
- The cut-off cube is aligned with the world, not with your ship D. The test looks at the offset's world x, y, z before it is turned into your view. When you turn, an object at a fixed distance can appear or disappear: the cube's corners reach √3 ≈ 1.73 times as far as its faces. A blip can therefore lie up to about 110 pixels sideways or vertically and 55 rows ahead or behind from the centre.
- The grid is in perspective, the blips are not D. Blips are placed with a plain scale (x unchanged by distance, ahead at half scale), so at the far edge a blip can be up to 64 pixels to the side while the grid there is only 50 wide; an object straight ahead can sit up to 4 rows above the far edge (diagonal ones farther). The grid is decoration, not a scale.
- The stalk is not clipped D. Its x can reach 232 + 110 = 342 rel, which is past the right edge of the screen (319). The line routine computes the byte address as row × 80 + x ÷ 8, so such a stalk appears at the left edge one row lower (screen x 0..22). Rows below 349 are in the page's unused memory (the page is 32 KB, 409 rows) and are not seen. The lowest reachable row is bounded by about row 409 (blip row ≤ 110 + 124 rel); in that extreme corner case a pixel could land a few bytes past the 32 KB page, in the first row of the other page D (bound only; not shown to be reachable). The plus itself is clipped (not drawn).
- Exploding objects are not shown: their blip vanishes the frame they are destroyed. A
cloaked player is still shown (their ship is measured but not drawn,
remote_players_update). - A stale blip for one frame D: a peer's packets land in
its record whenever they arrive. If its status becomes 2 (name screen) before
remote_players_updateruns, that update skips the ship (no new camera values), butdraw_radarstill draws it with the previous frame's values, because the record is only freed (type 0) by the network step at the end of the frame.
What appears on the radar
| Order | Object | Mode | Condition | n used | Colour |
|---|---|---|---|---|---|
| 1 | grid | both | always | – | 4 |
| 2a | other player's ship, peer i = 0..2 (3 for a spectator) | multi | record in use (type ≠ 0) and not exploding (state ≠ −1); cloaked included | dist_exp − 1 | slot 1–2: 10, slot 3–4: 9 |
| 2b | that player's satellite (right after its ship) | multi | type > 0 (not exploding) | dist_exp | 15 |
| 3 | aliens 0..7 (incl. the mutant) | single | type > 0 and state ≥ 0 | dist_exp − 1 | 10 |
| 4 | enemy missiles 0..3 | single | type > 0 and state ≥ 0 | dist_exp | 14 |
| 5 | pods 0..5 | single | type > 0 and state ≥ 0 (also while being towed) | dist_exp − 1 | 13 |
| 6 | your own satellite | both | type > 0 | dist_exp | 15 |
Not on the radar: your own ship (it is the centre), laser shots (yours, the aliens', other players'), your homing missiles, explosions, stars. Order matters only where blips overlap: later ones are drawn over earlier ones. The radar is drawn only while your shields are above 0, so it disappears on the death screen.
draw the 10 grid lines (table above) in colour[0]
if multiplayer:
for i in 0 .. num_peers-1: // 3 peers, or 4 when spectating
if peer_ship[i].type != 0 and peer_ship[i].state != -1:
radar_blip(peer_ship[i].cam, peer_ship[i].dist_exp - scale(peer_ship[i].model), player_colour[i])
if peer_item[i].type > 0:
radar_blip(peer_item[i].cam, peer_item[i].dist_exp, colour[5])
else:
for each alien (8): if type > 0 and state >= 0: radar_blip(cam, dist_exp - scale, colour[3])
for each enemy missile (4): if type > 0 and state >= 0: radar_blip(cam, dist_exp, colour[4])
for each pod (6): if type > 0 and state >= 0: radar_blip(cam, dist_exp - scale, colour[6])
if my_item.type > 0: radar_blip(my_item.cam, my_item.dist_exp, colour[5])
Try the radar
Place one object relative to your ship (in world axes) and turn the ship. The script performs the original integer steps: 64-bit block normalisation, the Q14 dot products, the shifts and the pixel-exact line and plus routines, and paints the screen area around the radar (x 420..639, rows 160..349) enlarged, stretched to the real pixel shape. With heading 0, x is right, y is "c" (positive = drawn below you on the radar), z is ahead.
The sliders are cubic (fine near 0, up to ±1.5 million units); type exact values into the boxes. The heading is applied as one rotation of the start orientation with the game's own rotation routine (including its length correction) and cross-product routine (including the lost borrow, chapter 3) and the sine table formula (16384 · sin, truncated toward zero). In play the axes come from many small rotations, so their low bits differ; this does not change the rules.
Cockpit instruments
All drawn by draw_hud (src/hud.c) in this
order, every frame while the shields are above 0. All coordinates below are rel unless marked
"screen". Every bar is drawn as lines, never filled.
1. Sight
Without a target, a cross of four arms with an open middle, colour [1] (12):
| Arm | Line (rel) | Screen |
|---|---|---|
| up | (0, −40)–(0, −12) | (320,135)–(320,163) |
| down | (0, 40)–(0, 12) | (320,215)–(320,187) |
| right | (48, 0)–(16, 0) | (368,175)–(336,175) |
| left | (−48, 0)–(−16, 0) | (272,175)–(304,175) |
With a target (g_have_target ≠ 0) a bracket of four triangles instead, colour [2]
(10). For each sign pair (sx, sy) in the order (−,−), (+,−), (−,+), (+,+) three lines: P–Q, P–R,
Q–R with P = (40·sx, 15·sy), Q = (20·sx, 30·sy), R = (10·sx, 7·sy). Top-left triangle on screen:
(280,160), (300,145), (310,168).
Target lock (missile lock): g_have_target is cleared at the start of
aliens_update (src/aliens.c) and set when
any alien that was not already dying when the loop reached it (an alien set exploding by your
ramming earlier in the same pass is still tested) has cam_z > 0 and |cam_x| < L and |cam_y| < L, with
L = 0xC0 << dist_exp (or 0xC0 >> −dist_exp when negative), all in 16-bit arithmetic,
so at dist_exp 8 L is negative and the test fails. Details: chapter 6. Only single player
computes it.
2. Mouse marks
Only with mouse steering (g_mouse_enabled, set by both mouse options of the Controls
menu, "reversed" included). With the pointer's screen position
(mx, my) (its 8 × 8 box has its top-left pixel there), let X = mx − 320 + 4, Y = my − 175 + 4. Four
diagonal strokes, colour [1]: (X−36, Y−12)–(X−28, Y−20), (X+36, Y−12)–(X+28, Y−20),
(X+36, Y+12)–(X+28, Y+20), (X−36, Y+12)–(X−28, Y+20). The mouse driver keeps the pointer inside
screen x 44..587, y 28..313 during flight.
3. Velocity gauge "V" (throttle)
Shows the throttle (the forward speed you asked for), not the actual speed. Anchor (x, y) = (−288, 118), screen (32, 293). The throttle changes by 8 per frame while Shift / Ctrl is held and lies in −0x70..+0x90 (−112..144).
t = throttle >> 1 // −56..72 (arithmetic shift of the low word)
line (x−16, y−72)–(x−16, y+56) colour[0] // scale, screen (16,221)–(16,349)
line (x−16, y)–(x+16, y) colour[0] // zero mark, screen (16,293)–(48,293)
if t > 0: outline in colour[2]: (x+8, y−1)–(x+8, y−t), (x−8, y−1)–(x−8, y−t),
(x−8, y−1)–(x+8, y−1), (x−8, y−t)–(x+8, y−t)
if t < 0: the same with y+1 instead of y−1 (y−t is below the zero mark)
stroke letter 'V' at (x−26, y−72), colour[0], half size
So the bar is a 17-pixel-wide rectangle (screen x 24..40) from just above (forward) or just below (reverse) the zero mark; full forward throttle reaches the scale's top (row 221), full reverse its bottom (row 349). Throttle 0: no bar.
4. Shield gauge "S"
Not drawn for a spectator. Anchor (x, y) = (−240, 46), screen (80, 221). Shields are 0..32.
t = shields << 2 // 0..128
line (x−16, y)–(x−16, y+128) colour[0] // scale, screen (64,221)–(64,349)
line (x−16, y+128)–(x+16, y+128) colour[0] // base, screen (64,349)–(96,349)
if t > 0: outline in colour[2]: (x+8, y+127)–(x+8, y+128−t), (x−8, y+127)–(x−8, y+128−t),
(x−8, y+127)–(x+8, y+127), (x−8, y+128−t)–(x+8, y+128−t)
stroke letter 'S' at (x−26, y), colour[0], half size
Full shields: a rectangle from screen row 221 to 348, x 72..88. One shield = 4 rows.
A stroke letter is one polyline through points on a 16 × 16 grid; the routine
draw_vector_char(x, y, colour, shift, ch) shifts every coordinate right by
shift (left for a negative one) and adds the anchor (x, y) (top-left). The HUD always
passes shift 1, "half size". V: (0,0) (8,16) (16,0) →
screen (6,221)–(10,229)–(14,221). S: (16,4) (12,0) (4,0) (0,4) (4,8) (12,8) (16,12) (12,16) (4,16)
(0,12) → at (54, 221) the points (62,223) (60,221) (56,221) (54,223) (56,225) (60,225) (62,227)
(60,229) (56,229) (54,227). Full font: src/tables.c,
routine src/effects.c.
5. Velocity indicator (three axes)
Only in Polygons mode (not in Lines mode). The variable names say "attitude", but it shows
the ship's velocity in its own axes (g_vel_body, world units per frame,
computed in the ship update: velocity's middle words dotted with b, c, a). Centre (x, y) =
(−232, −100), screen (88, 75).
vx = vel_body[0] >> 2 // sideways (right +)
vy = vel_body[1] >> 2 // along c (+ = down on screen)
t = vel_body[2] >> 3 // forward
line (x−72, y)–(x+72, y) colour[0] // screen (16,75)–(160,75)
line (x, y−64)–(x, y+64) colour[0] // screen (88,11)–(88,139)
line (x−64, y+32)–(x+64, y−32) colour[0] // oblique "depth" axis, screen (24,107)–(152,43)
line (x, y)–(x+vx, y) colour[2]
line (x, y)–(x, y+vy) colour[2]
line (x, y)–(x+2t, y−t) colour[2] // forward speed along the oblique axis
One pixel = 4 world units per frame sideways or vertically; forward, t = speed ÷ 8, drawn 2t across and t up. Full throttle (forward speed 0x90 = 144) gives t = 18, a line to (124, 57); with extra thrust (speed 288) t = 36 reaches (160, 39), past the end of the drawn axis. A line of zero length is still one pixel, so the centre pixel is always green.
6. Score and status lines
Anchor (sx, sy) = (160, −160), screen (480, 15). All texts are left-aligned at column 60 (screen x 480), colour [1] (12); bars colour [2] (10). A "bar of t" is a line from x = 480 to 480 + t, so it has t + 1 pixels.
| Text / bar | Shown when | Text top row (screen) | Bar row(s) and length |
|---|---|---|---|
| "SCORE: %6ld" (e.g. "SCORE: 1250", 13 characters) | not spectating; also on the death screen (drawn before the shields test) | 15 | – |
| "CLOAK ACTIVE" (cloak switched on) or "CLOAK READY" | cloak time > 0 (multiplayer only) | 31 | row 41: t = cloak_time >> 2 (0x200 after pick-up = 128) |
| "MISSILES: %d" | missiles > 0 (single player only) | 31 (same row as the cloak; never both) | – |
| "EXTRA FIRE POWER" | fire power > 0 (0..0x100 powered shots) | 47 | from row 57: stacked, see below, 0x40 per row |
| "EXTRA THRUST" | extra thrust > 0 (0..0x1000 units) | 63 | from row 73: stacked, 0x400 per row |
// stacked bar, used for fire power (U = 0x40, R(v) = (v mod 0x40) * 2)
// and thrust (U = 0x400, R(v) = (v mod 0x400) / 8, floor)
r = R(value); if value mod U == 0: r = 128 // an exact multiple shows a full last row
row = first row
for k in 1, 2, 3: // thresholds U, 2U, 3U
if value > k*U: line (480, row)–(608, row); row = row + 1
line (480, row)–(480 + r, row)
Examples: fire power 0x100 → four full rows (57..60); 0x41 → one full row and a 3-pixel line (r = 2); 0x40 → one full row. Thrust 0x400 → one full row; 0x401 → one full row and a 1-pixel line (r = 0). The numbers are not shown, only the bars. Why cloak and missiles never show at once D: cloak time is only given by the multiplayer cloak satellite, and the missile count is set to 0 before every multiplayer round and raised in flight only by the single-player missile satellite.
Calls in this order, each in colour [1], not centred, x = sx = 160 (rel) O (src/hud.c):
if cloakTime > 0: draw_text(160, −144, "CLOAK ACTIVE" or "CLOAK READY"); bar on rel row −134
if missiles > 0: draw_text(160, −144, "MISSILES: %d") // two separate tests: if both
// held, both are drawn, missiles on top
if firePower > 0: draw_text(160, −128, "EXTRA FIRE POWER"); bars from rel row −118
if extraThrust > 0: draw_text(160, −112, "EXTRA THRUST"); bars from rel row −102
Rel row + 175 = the screen rows of the table above. Only the S gauge (4) is skipped for a spectator; the other instruments of this section follow their own conditions alone.
- A locked sight can stick into multiplayer D. Only the
single-player alien update writes
g_have_target. If the last single-player frame had an alien in the lock window (for example, killed while aiming), a later multiplayer game shows the triangle bracket all the time. It is cosmetic: Enter toggles the cloak there. - The V gauge shows the throttle (requested speed) only; while you tumble after a collision or fly with extra thrust, the true speed differs. The velocity indicator shows the true one.
- The shield gauge has no "empty" state on screen: at 0 shields the whole HUD is replaced by the death text.
Messages
The game has one message slot: a text pointer and a frame counter
(g_message_ptr, g_message_timer). Whoever sets it replaces the current
message and restarts the counter; there are no priorities and no queue. The text is drawn at
(0, −80) centred, colour [2] (light green), top row 95, steady (no blinking), every frame while the
counter is above 0; after drawing, the counter goes down by 1.
| Text (table entry) | Shown when | Mode | Frames | Set by |
|---|---|---|---|---|
| "WARNING: MISSILE LAUNCH DETECTED" (0x5C) | an alien launches a missile (a free enemy missile slot existed); sound 3 | single | 16 | enemy_missile_launch |
| "No Target" (0x62) | Enter / Caps Lock without a lock (every make code: holding the key repeats it) | single | 16 | player_fire_missile |
| "Missile Launched" (0x5A) | Enter / Caps Lock with a lock, a missile in stock and a free slot (of 4) | single | 16 | player_fire_missile |
| "WARNING: POD IN DANGER" (0x6A) | a Pirate reaches a pod and starts towing it; sound 3 | single | 16 | ai_abductor |
| "POD DESTROYED" (0x6C) | a Pirate escapes with its pod (both vanish), or a Commander reaches a pod (pod explodes, alien becomes the mutant; sound 0) | single | 16 | ai_abductor, ai_pod_killer |
| "COLLISION" (0x12) | you ram an alien or another ship and survive it | both | 48 | player_bump |
| "EXTRA SHIELDS" (0x20), "MISSILES" (0x4E), "EXTRA THRUST" (0x88), "EXTRA FIRE POWER" (0x22) | satellite collected (kind 1, 2, 3, 4); sound 2 | single | 32 | apply_pickup |
| "SHIELDS RESTORED" (0x7C) | any satellite collected (every kind restores shields; cloak, thrust or fire power come silently) | multi | 32 | apply_pickup |
| "%s has been killed" (0x72), with the player's name | another player's ship starts exploding; sound 0 | multi | 64 | remote_players_update |
| "Cloak Destroyed!" (0x0C) | you are hit while you have cloak time; the cloak time is lost | multi | 48 | net_sync_frame |
At 18.2 frames per second 16 frames are 0.88 s, 32 are 1.76 s, 48 are 2.64 s, 64 are 3.5 s; at the multiplayer frame rate the same counts last about a quarter as long.
- Same frame, several writers: the last one wins. The writers run in this order within a frame: ship update ("No Target", "Missile Launched") → multiplayer: other ships ("COLLISION", "… has been killed") → single player: aliens (missile warning, pod messages, "COLLISION") → satellites (pick-ups) → after drawing: multiplayer network step ("Cloak Destroyed!").
- Frames shown: a message set before the drawing step is drawn the same frame; with a start value N it is drawn on exactly N frames. "Cloak Destroyed!" is set after the drawing step and so appears from the next frame (still 48 frames).
- While dead (shields 0) the message is neither drawn nor counted down; after a multiplayer respawn the remainder is shown D.
- Pick-ups always set the counter to 32, even in multiplayer, where only "SHIELDS RESTORED" sets the text: the pointer is set first in that case, so the pair stays consistent.
- Reset: the counter is set to 0 at the start of every level (single player) and every round (multiplayer: after Esc and the name screen). A multiplayer death respawns inside the frame loop without this reset, so a message can survive it.
- The text pointer of "… has been killed" points into one buffer (
g_kill_msg); a second kill rewrites it.
Hit flash
Events store a colour in g_flash_color; the next frame clears its page
with that colour instead of black and resets it to 0. The whole background (under stars, models
and instruments) is then that colour for exactly one frame. Because the page drawn in frame N+1
is shown from the flip of frame N+2, the flash appears one frame after the message of the same
event. Hits found in the multiplayer network step (after drawing) set both at once, so their
flash and "Cloak Destroyed!" appear together.
| Event | Colour |
|---|---|
| Collision: ramming an alien (single player, also when it kills you), or a ship you survive (multiplayer; a fatal ship-to-ship ram sets no flash) | [7] 10 light green |
| Hit by an alien shot or an enemy missile (single player), by a normal laser shot (multiplayer) | [8] 12 light red |
| Hit by a powered laser shot (multiplayer, 2 shields) | [9] 14 yellow |
Death screen texts
While the shields are 0, player_dead_screen
(src/screens.c) replaces radar, instruments and
message; the world keeps running behind it and the score stays.
| Text | Mode | Position | Colour | When |
|---|---|---|---|---|
| "Game Over" (0x28) | single | (0, 0) centred: screen x 280..351, rows 175..182 | [1] 12 | every dead frame |
| "You were killed by %s" (0x46), the killer's name | multi | (0, 0) centred | [1] 12 | every dead frame |
| "Press ENTER to restart" (0x6E) | both | (0, 32) centred: screen x 232..407, rows 207..214 | [1] 12 | after the 64-frame countdown, unless a single player's score enters the high-score table (then the game goes straight to the initials entry) |
During the 64-frame countdown Enter and the mouse button are swallowed. Details of what follows: chapters 4, 8 and 17.
Compute in the original pixel space, then scale. Keep a virtual 640 × 350 screen with the centre at (320, 175) and use every number in this chapter unchanged. To draw at W × H, map x → x · W/640 and y → y · H/350 separately (the pixels were 1.37 times taller than wide; for a 4:3 area H = 0.75 W). This keeps every shape: the radar trapezoid, the gauges, the bracket. Draw lines with a width of about W/640 and the 8 × 8 font as a bitmap scaled by W/640 × H/350 (nearest-neighbour keeps it crisp); align text to the 8-pixel column grid before scaling.
Keep the radar arithmetic in integers (normalisation, Q14 dot, shifts), as in the demo's code: the cut-off cube and the rounding of blip positions follow from it. A smooth modern radar may compute bx = offset ÷ 28−zoom in floating point and place it at sub-pixel positions in the scaled space; keep the half scale ahead, the n ≥ zoom test (or decide to replace the world-aligned cube by a ship-aligned one, and say so), the colours and the order.
Decide the quirks: clip the radar stalk (the original wraps it to the left edge), reset the target lock in multiplayer, and decide whether the grid should match the blip mapping (the original's does not). Messages: one slot, last writer wins, counts in frames; if your frame rate differs from 18.2 per second, convert the counts (chapter 20) so that they last as long in seconds.