changeset 19:3a831478eda4

adjusted tower pivot and angle definitions to better match scribbled assets
author ark
date 2026-10-20 00:36 +0200
parents 5dc69898a091
children 4348b83d3e6b
files config/game.toml tools/build.py tools/preview.py
diffstat 3 files changed, 73 insertions(+), 38 deletions(-) [+]
line wrap: on
line diff
--- a/config/game.toml	Tue Oct 20 00:14:24 2026 +0200
+++ b/config/game.toml	Tue Oct 20 00:36:53 2026 +0200
@@ -214,21 +214,21 @@
 # sprite drawing direction (art.md): angle the drawing points to as drawn,
 # 0 right, -90 up. sprites not listed do not turn.
 [art.angle]
-t1 = 0
-t1_2 = 0
-t1_3 = 0
+t1 = -2
+t1_2 = -3
+t1_3 = -6
 t1_4 = 0
 t1_5 = 0
-t2 = -90
+t2 = -95
 t2_2 = -90
-t2_3 = -90
+t2_3 = -89
 t2_4 = -90
-t2_5 = -90
-t3 = -45
-t3_2 = -45
-t3_3 = -45
-t3_4 = -45
-t3_5 = -90
+t2_5 = -95
+t3 = -43
+t3_2 = -48
+t3_3 = -15
+t3_4 = -15
+t3_5 = -88
 p0 = -90
 p3 = -45
 
@@ -241,17 +241,17 @@
 [art.pivot]
 t1 = [0.37, 0.5]
 t1_2 = [0.30, 0.5]
-t1_3 = [0.33, 0.5]
-t1_4 = [0.35, 0.5]
+t1_3 = [0.33, 0.48]
+t1_4 = [0.35, 0.52]
 t1_5 = [0.27, 0.5]
 t2 = [0.49, 0.57]
 t2_2 = [0.50, 0.61]
-t2_3 = [0.49, 0.64]
-t2_4 = [0.50, 0.71]
+t2_3 = [0.50, 0.64]
+t2_4 = [0.48, 0.71]
 t2_5 = [0.50, 0.72]
 t3 = [0.40, 0.62]
 t3_2 = [0.41, 0.59]
-t3_3 = [0.41, 0.48]
+t3_3 = [0.41, 0.43]
 t3_4 = [0.45, 0.46]
 t3_5 = [0.49, 0.54]
 
--- a/tools/build.py	Tue Oct 20 00:14:24 2026 +0200
+++ b/tools/build.py	Tue Oct 20 00:36:53 2026 +0200
@@ -509,7 +509,7 @@
 
 def step_previews(cfg, maps, force, changed):
     outputs = [PREVIEW / f"map{m}.png" for m in range(MAPS)] + [PREVIEW / "towers.png"]
-    # the tower sheet shows the pivots, footprint and sprite scale from game.toml
+    # the tower sheet shows the angles, pivots, footprint and sprite scale from game.toml
     if not changed and not stale([CONFIG / "game.toml"], outputs, force):
         print("previews: up to date")
         return
@@ -518,7 +518,8 @@
         preview.map_preview(ART / f"map{m}.png", mp).save(PREVIEW / f"map{m}.png")
         if len(mp["routes"]) > 1:
             preview.route_sheet(ART / f"map{m}.png", mp).save(PREVIEW / f"map{m}_routes.png")
-    preview.tower_sheet(ASSETS, cfg["art"]["pivot"], cfg["placement"]["footprint_radius"],
+    preview.tower_sheet(ASSETS, cfg["art"]["angle"], cfg["art"]["pivot"],
+                        cfg["placement"]["footprint_radius"],
                         cfg["scale"]["sprite"]).save(PREVIEW / "towers.png")
     print(f"previews: wrote {PREVIEW.relative_to(ROOT)}/")
 
--- a/tools/preview.py	Tue Oct 20 00:14:24 2026 +0200
+++ b/tools/preview.py	Tue Oct 20 00:36:53 2026 +0200
@@ -3,6 +3,8 @@
 without starting the game.
 """
 
+import math
+
 from PIL import Image, ImageDraw
 
 ROUTE_COLOURS = [(220, 0, 160), (0, 90, 255), (255, 120, 0), (0, 160, 60),
@@ -81,45 +83,77 @@
     return sheet
 
 
-def tower_sheet(assets, pivots, footprint, scale):
+# screen angle the turning towers face on the tower sheet, the same as a new
+# tower in the game: up
+FACE = -90
+
+
+def _turned(im, pivot, drawn):
+    """
+    im on a transparent square with the pivot (shares of width and height) at
+    its centre. a sprite drawn pointing to angle drawn is turned around the
+    pivot to face FACE; drawn None leaves it as it is.
+    """
+    px, py = round(im.width * pivot[0]), round(im.height * pivot[1])
+    r = math.ceil(max(math.hypot(px - x, py - y) for x in (0, im.width) for y in (0, im.height)))
+    sq = Image.new("RGBA", (2 * r, 2 * r), (0, 0, 0, 0))
+    sq.alpha_composite(im, (r - px, r - py))
+    if drawn is None:
+        return sq
+    # pillow turns anticlockwise, screen angles grow clockwise
+    return sq.rotate(drawn - FACE, resample=Image.BICUBIC)
+
+
+def tower_sheet(assets, angles, pivots, footprint, scale):
     """
     tower levels 1-5 per row: at full size on grey, so the white fill shows,
-    and at game scale next to each other. a cross marks the rotation point,
-    which is the tower position, and a circle the footprint around it.
-    footprint is the footprint radius in map pixels, scale the sprite scale.
+    and at game scale next to each other. turning towers are turned by their
+    drawing direction in angles to face up, as in the game; a line from the
+    pivot shows that direction, and each tower is labelled with its angle. a
+    cross marks the rotation point, which is the tower position, and a circle
+    the footprint around it. footprint is the footprint radius in map pixels,
+    scale the sprite scale.
     """
     rows = []
     for t in range(4):
         names = [f"t{t}"] + [f"t{t}_{lv}" for lv in range(2, 6)]
-        rows.append([Image.open(assets / f"{n}.png") for n in names])
+        rows.append([(n, _turned(Image.open(assets / f"{n}.png"), pivots.get(n, (0.5, 0.5)),
+                                 angles.get(n))) for n in names])
     pad = 16
-    cell_w = max(im.width for r in rows for im in r) + pad
-    cell_h = max(im.height for r in rows for im in r) + pad
-    small_w = round(cell_w * scale) + 4
+    cell = max(im.width for r in rows for _, im in r) + pad
+    cell_h = cell + 12
+    small_w = round(cell * scale) + 4
     full_r = footprint / scale
-    sheet = Image.new("RGBA", (5 * cell_w + 5 * small_w + pad, 4 * cell_h + 20),
+    sheet = Image.new("RGBA", (5 * cell + 5 * small_w + pad, 4 * cell_h + 20),
                       (170, 170, 170, 255))
     draw = ImageDraw.Draw(sheet)
     for lv in range(5):
-        draw.text((lv * cell_w + pad, 4), f"level {lv + 1}", fill=(0, 0, 0))
-    draw.text((5 * cell_w + pad, 4), f"game scale {scale}", fill=(0, 0, 0))
+        draw.text((lv * cell + pad, 4), f"level {lv + 1}", fill=(0, 0, 0))
+    draw.text((5 * cell + pad, 4), f"game scale {scale}, turning towers face {FACE}",
+              fill=(0, 0, 0))
+    dx, dy = math.cos(math.radians(FACE)), math.sin(math.radians(FACE))
     for t, r in enumerate(rows):
         y = 20 + t * cell_h
-        for lv, im in enumerate(r):
-            x = lv * cell_w + pad // 2
-            sheet.alpha_composite(im, (x, y))
-            name = f"t{t}" if lv == 0 else f"t{t}_{lv + 1}"
-            px, py = pivots.get(name, (0.5, 0.5))
-            cx, cy = x + round(im.width * px), y + round(im.height * py)
+        cy = y + 12 + cell // 2
+        for lv, (name, im) in enumerate(r):
+            # label above, sprite centred on the pivot in the cell below it
+            drawn = angles.get(name)
+            draw.text((lv * cell + pad // 2, y), f"{name}: " + ("does not turn" if drawn is None
+                                                               else f"angle {drawn}"),
+                      fill=(0, 0, 0))
+            cx = lv * cell + cell // 2
+            sheet.alpha_composite(im, (cx - im.width // 2, cy - im.height // 2))
+            if drawn is not None:
+                arm = cell // 2 - pad // 2
+                draw.line((cx, cy, cx + dx * arm, cy + dy * arm), fill=(255, 0, 0))
             draw.line((cx - 5, cy, cx + 5, cy), fill=(255, 0, 0))
             draw.line((cx, cy - 5, cx, cy + 5), fill=(255, 0, 0))
             draw.ellipse((cx - full_r, cy - full_r, cx + full_r, cy + full_r),
                          outline=(0, 0, 255), width=2)
             small = im.resize((max(1, round(im.width * scale)), max(1, round(im.height * scale))),
                               Image.LANCZOS)
-            sx, sy = 5 * cell_w + pad + lv * small_w, y + cell_h // 3
-            sheet.alpha_composite(small, (sx, sy))
-            scx, scy = sx + small.width * px, sy + small.height * py
+            scx, scy = 5 * cell + pad + lv * small_w + small_w // 2, cy
+            sheet.alpha_composite(small, (scx - small.width // 2, scy - small.height // 2))
             draw.ellipse((scx - footprint, scy - footprint, scx + footprint, scy + footprint),
                          outline=(0, 0, 255))
     return sheet