From 45ffa874250543c24b642b5ab53b57692239711b Mon Sep 17 00:00:00 2001 From: Dejvino Date: Tue, 10 Nov 2026 22:11:33 +0100 Subject: [PATCH] Trails: match erase width to draw width, bright flashing missile head - Enemy missile trails now drawn 3px thick via drawThickLine() with a bright head dot (white) that flashes against the trail color every couple of frames, like the Atari 2600 - eraseBombTrail() uses a thicker erase band than the draw (5px, 7px for wigging smart bombs) plus a 2px tip circle, so no trail residue is left behind when a missile dies or impacts --- examples/MissileCommand/MissileCommand.ino | 46 ++++++++++++++++++---- 1 file changed, 38 insertions(+), 8 deletions(-) diff --git a/examples/MissileCommand/MissileCommand.ino b/examples/MissileCommand/MissileCommand.ino index 0cb4838..d2ca83f 100644 --- a/examples/MissileCommand/MissileCommand.ino +++ b/examples/MissileCommand/MissileCommand.ino @@ -557,6 +557,28 @@ static void fireAuto() // --------------------------------------------------------------------------- // Trail cleanup // --------------------------------------------------------------------------- +// Thick line: `w` parallel lines offset perpendicular to the dominant axis. +// Missile trails are drawn 3px wide, so erase passes must be at least as +// wide or they leave residue. +static void drawThickLine(int x0, int y0, int x1, int y1, int w, uint16_t c) +{ + int dx = (x1 > x0) ? x1 - x0 : x0 - x1; + int dy = (y1 > y0) ? y1 - y0 : y0 - y1; + if (dx >= dy) { + for (int i = 0; i < w; i++) { + int off = i - w / 2; + tft.drawLine(x0, y0 + off, x1, y1 + off, c); + } + } else { + for (int i = 0; i < w; i++) { + int off = i - w / 2; + tft.drawLine(x0 + off, y0, x1 + off, y1, c); + } + } +} + +#define TRAIL_W 3 // enemy trail thickness (px) + // Does the segment (x0,y0)-(x1,y1) pass within `rad` of (px,py)? static bool linePassesNear(int x0, int y0, int x1, int y1, int px, int py, int rad) { @@ -575,12 +597,16 @@ static bool linePassesNear(int x0, int y0, int x1, int y1, int px, int py, int r return ddx * ddx + ddy * ddy <= (long)rad * rad; } -// Enemy trails persist while the bomb falls (classic look), but vanish the -// moment the bomb is destroyed or reaches the ground, like the Atari 2600. +// Enemy trails persist while the bomb falls (classic look, drawn TRAIL_W px +// thick with a 2px head dot), but vanish the moment the bomb is destroyed or +// reaches the ground, like the Atari 2600. The erase band is wider than the +// draw: smart bombs wiggle sideways off the straight path, so their erase +// must sweep a wider corridor. static void eraseBombTrail(const Bomb &b) { - tft.drawLine((int)b.sx, (int)b.sy, (int)b.x, (int)b.y, TFT_BLACK); - tft.fillCircle((int)b.x, (int)b.y, 1, TFT_BLACK); + drawThickLine((int)b.sx, (int)b.sy, (int)b.x, (int)b.y, + b.smart ? 7 : 5, TFT_BLACK); + tft.fillCircle((int)b.x, (int)b.y, 2, TFT_BLACK); // repair anything the erase swept over if (cross.drawn && linePassesNear((int)b.sx, (int)b.sy, (int)b.x, (int)b.y, cross.dx, cross.dy, 8)) { @@ -657,10 +683,14 @@ static void updateBombs() float nxf = b.x + edx * b.speed; float nyf = b.y + edy * b.speed; uint16_t col = b.smart ? TFT_MAGENTA : TFT_RED; - tft.drawLine((int)b.x, (int)b.y, (int)nxf, (int)nyf, col); - if ((int)nxf != (int)b.x || (int)nyf != (int)b.y) { - tft.fillCircle((int)nxf, (int)nyf, 1, col); - } + + // Restore the previous head dot to trail color (so the path stays a + // continuous 3px line), extend the trail, then draw the new head: a + // bright dot that flashes, like the 2600 version. + tft.fillCircle((int)b.x, (int)b.y, 2, col); + drawThickLine((int)b.x, (int)b.y, (int)nxf, (int)nyf, TRAIL_W, col); + uint16_t headCol = (frameCount % 4) < 2 ? TFT_WHITE : col; + tft.fillCircle((int)nxf, (int)nyf, 2, headCol); b.x = nxf; b.y = nyf;