Menus de muerte pausa y personajes renovados

This commit is contained in:
Diego De la Viuda Llorente committed 2026-11-09 14:58:36 +01:00
1 parent 97335c9d21
commit 6a267b2cf4
54 files changed
+14033 -3170

No files matched your search

+6 -380
View File
@@ -1,385 +1,11 @@
"""Genera los cuatro atlas SVG y SpriteFrames a partir del pixel art original.
"""Compatibilidad con el comando historico: ahora genera el nuevo arte vectorial.
Uso: python tools/generate_band_art.py (requiere Pillow solo para regenerar arte).
El juego consume los SVG/.tres ya versionados; nunca ejecuta este programa.
Diego conserva exactamente sus celdas originales salvo la caida ofensiva.
Las demas apariencias reutilizan las poses comunes y el mismo punetazo.
python tools/generate_band_art.py
Los SpriteFrames de la banda mantienen las mismas 40 regiones; los atlas
pueden regenerarse tambien mediante generate_vector_character_art.py.
"""
from __future__ import annotations
from collections import defaultdict
from pathlib import Path
import math
import re
import xml.etree.ElementTree as ET
from PIL import Image, ImageDraw
ROOT = Path(__file__).resolve().parents[1]
SOURCE = ROOT / "assets/characters/ankarde/player_pixel.svg"
DESTINATION = ROOT / "assets/characters/band"
ROLES = ("guitarist", "drummer", "bassist", "singer")
OUTLINE = "#161723"
SKIN = "#ecb78b"
SKIN_LIGHT = "#ffdab0"
SKIN_DARK = "#b57964"
SHIRT = "#252b39"
SHIRT_LIGHT = "#3e475c"
HAIR = ("#30242a", "#543933", "#805345")
CELL = 64
def rgba(color: str) -> tuple[int, int, int, int]:
return tuple(bytes.fromhex(color[1:])) + (255,)
def read_source() -> dict[str, Image.Image]:
"""Reconstruye las celdas originales sin rasterizadores ni dependencias de SVG."""
result = {}
for group in ET.parse(SOURCE).getroot().findall("{*}g"):
image = Image.new("RGBA", (CELL, CELL))
draw = ImageDraw.Draw(image)
for path in group:
if not path.tag.endswith("path"):
continue
commands = path.attrib["d"]
pattern = r"M(-?\d+) (-?\d+)h(\d+)v(\d+)h-\d+z"
if re.sub(pattern, "", commands):
raise ValueError("El atlas original ya no usa rectangulos enteros: " + group.attrib["id"])
for x, y, width, height in re.findall(pattern, commands):
x, y, width, height = map(int, (x, y, width, height))
draw.rectangle((x, y, x + width - 1, y + height - 1), fill=path.attrib["fill"])
result[group.attrib["id"]] = image
return result
def appearance(source: Image.Image, role: str, pose_name: str) -> Image.Image:
"""Cambia pelo/ropa sin alterar la trayectoria de brazos del punetazo comun."""
if role == "guitarist":
return source.copy()
image = source.copy()
pixels = image.load()
hair_colors = tuple(rgba(color) for color in HAIR)
hair_points = [(x, y) for y in range(35) for x in range(CELL) if pixels[x, y] in hair_colors]
top = min(y for _, y in hair_points) - 1
left = min(x for x, _ in hair_points)
right = max(x for x, _ in hair_points)
new_hair = ("#78532b", "#d5a442", "#ffe07c") if role == "singer" else ("#10121a", "#20212c", "#3f4353")
palette = dict(zip(hair_colors, map(rgba, new_hair)))
shirt_palette = {rgba(SHIRT): rgba(SKIN_DARK), rgba(SHIRT_LIGHT): rgba(SKIN), rgba("#667185"): rgba(SKIN_LIGHT)}
for y in range(CELL):
for x in range(CELL):
color = pixels[x, y]
if y < top + 30 and color in palette:
pixels[x, y] = palette[color]
# Las camisetas acaban a mitad del brazo: el antebrazo queda descubierto.
if role in ("singer", "bassist") and color in shirt_palette:
forearm = top + 31 <= y <= top + 41 and (x < 28 or x >= 40)
extended = pose_name.startswith("punch") and x >= 45 and top + 23 <= y <= top + 33
if forearm or extended:
pixels[x, y] = shirt_palette[color]
if color == rgba("#35576d"):
pixels[x, y] = rgba("#424b36" if role == "singer" else "#363849")
elif color == rgba("#60869c"):
pixels[x, y] = rgba("#7a8664" if role == "singer" else "#686b83")
draw = ImageDraw.Draw(image)
if role == "bassist":
# Rizos a ambos lados hasta los hombros, no solo un cambio de color de Diego.
for side, x in ((-1, left - 1), (1, right + 1)):
for index, y in enumerate(range(top + 6, top + 34, 5)):
cx = x + (index % 2) * side
draw.ellipse((cx - 3, y - 2, cx + 3, y + 3), fill="#10121a")
draw.line((cx - 1, y - 1, cx + 1, y - 1, cx + 1, y + 1), fill="#414454", width=1)
for index in range(5):
x = left + 3 + index * 3
y = top + 2 + index % 2
draw.rectangle((x, y, x + 2, y + 2), fill="#20212c")
draw.point((x, y), fill="#454957")
elif role == "drummer":
# Hebras rectas, negras y largas; el brillo no se convierte en rizos.
for x in (left + 1, left + 3):
for y in range(top + 10, top + 25):
if pixels[x, y] in tuple(map(rgba, new_hair)):
pixels[x, y] = rgba("#3b3e4b")
add_wristbands(image, top)
return image
def add_wristbands(image: Image.Image, head_top: int) -> None:
"""Localiza manos de las poses originales y coloca la munequera junto al punio."""
skin_colors = {rgba(SKIN), rgba(SKIN_LIGHT), rgba(SKIN_DARK)}
pending = {(x, y) for y in range(head_top + 23, min(head_top + 43, 48))
for x in range(CELL) if image.getpixel((x, y)) in skin_colors and (x < 29 or x > 39)}
draw = ImageDraw.Draw(image)
while pending:
start = pending.pop()
component, stack = [start], [start]
while stack:
x, y = stack.pop()
for point in ((x - 1, y), (x + 1, y), (x, y - 1), (x, y + 1)):
if point in pending:
pending.remove(point)
stack.append(point)
component.append(point)
if len(component) < 5:
continue
x0, x1 = min(x for x, _ in component), max(x for x, _ in component)
y0, y1 = min(y for _, y in component), max(y for _, y in component)
if x1 - x0 > 10 or y1 - y0 > 9:
continue
if x0 > 44 and y0 < 40:
draw.rectangle((x0 - 2, y0 - 1, x0, y1 + 1), fill="#10121a")
draw.point((x0 - 1, y0 + 1), fill="#a0a5b3")
else:
draw.rectangle((x0 - 1, y0 - 2, x1 + 1, y0), fill="#10121a")
draw.point((x0, y0 - 1), fill="#a0a5b3")
def limb(draw: ImageDraw.ImageDraw, points: list[tuple[int, int]], color: str, width: int = 6) -> None:
draw.line(points, fill=OUTLINE, width=width + 2)
draw.line(points, fill=color, width=width)
def arm(draw: ImageDraw.ImageDraw, points: list[tuple[int, int]], role: str) -> None:
shoulder, elbow, hand = points
limb(draw, points, SHIRT)
if role in ("singer", "bassist"):
limb(draw, [elbow, hand], SKIN, 5)
sleeve = ((shoulder[0] + elbow[0]) // 2, (shoulder[1] + elbow[1]) // 2)
draw.line([shoulder, sleeve], fill=SHIRT_LIGHT, width=4)
x, y = hand
if role == "drummer":
band = (round(elbow[0] * .22 + x * .78), round(elbow[1] * .22 + y * .78))
draw.rectangle((band[0] - 3, band[1] - 2, band[0] + 3, band[1] + 2), fill="#10121a")
draw.point((band[0] - 2, band[1] - 1), fill="#b7bfcb")
draw.rectangle((x - 3, y - 3, x + 3, y + 2), fill=OUTLINE)
draw.rectangle((x - 2, y - 2, x + 2, y + 1), fill=SKIN)
draw.line((x - 1, y - 2, x + 2, y - 2), fill=SKIN_LIGHT)
def posed_body(idle: Image.Image, role: str, *, shift=(0, 0), hip=44,
legs=None, arms=None) -> Image.Image:
"""Poses exclusivas de ataques; el cuerpo de colision no cambia de tamano."""
dx, dy = shift
image = Image.new("RGBA", (CELL, CELL))
draw = ImageDraw.Draw(image)
if legs is None:
legs = [[(27, hip), (26, 51), (27, 57)], [(38, hip), (40, 51), (41, 57)]]
shorts = "#424b36" if role == "singer" else "#363849"
for thigh, knee, ankle in legs:
limb(draw, [thigh, knee, ankle], SKIN, 6)
midpoint = ((thigh[0] + knee[0]) // 2, (thigh[1] + knee[1]) // 2)
draw.line([thigh, midpoint], fill=shorts, width=7)
x, y = ankle
draw.rectangle((x - 4, y - 2, x + 7, y + 3), fill=OUTLINE)
draw.rectangle((x - 2, y - 2, x + 3, y), fill=SHIRT_LIGHT)
draw.line((x - 3, y + 3, x + 7, y + 3), fill="#667185")
shoulder_y = 30 + dy
draw.polygon([(25 + dx, shoulder_y - 2), (39 + dx, shoulder_y - 2),
(42 + dx, hip - 1), (23 + dx, hip - 1)], fill=OUTLINE)
draw.polygon([(26 + dx, shoulder_y), (38 + dx, shoulder_y),
(40 + dx, hip - 3), (25 + dx, hip - 3)], fill=SHIRT)
draw.line((27 + dx, shoulder_y, 26 + dx, hip - 4), fill=SHIRT_LIGHT, width=2)
draw.rectangle((25 + dx, hip - 2, 40 + dx, hip + 2), fill=OUTLINE)
draw.rectangle((26 + dx, hip - 1, 39 + dx, hip + 1), fill=shorts)
draw.point((33 + dx, hip - 1), fill="#b4b6bd")
# Pequeno emblema metalero, dibujado en pixeles y sin fuentes externas.
cy = shoulder_y + 3
draw.rectangle((31 + dx, cy, 35 + dx, cy + 4), fill="#f6ead4")
draw.point((32 + dx, cy + 1), fill=OUTLINE)
draw.point((35 + dx, cy + 1), fill=OUTLINE)
draw.rectangle((32 + dx, cy + 5, 34 + dx, cy + 6), fill="#f6ead4")
head = idle.crop((0, 0, 64, 29))
image.alpha_composite(head, (dx, dy))
if arms is None:
arms = [[(24 + dx, shoulder_y), (22 + dx, shoulder_y + 8), (23 + dx, hip - 1)],
[(40 + dx, shoulder_y), (43 + dx, shoulder_y + 8), (43 + dx, hip - 1)]]
for points in arms:
arm(draw, points, role)
return image
def instrument(image: Image.Image, body: tuple[int, int], neck: tuple[int, int], *, bass=False) -> None:
"""Guitarra roja o bajo de cuatro cuerdas; geometria entera para conservar el pixel art."""
draw = ImageDraw.Draw(image)
bx, by = body
nx, ny = neck
length = math.hypot(nx - bx, ny - by)
ux, uy = (nx - bx) / length, (ny - by) / length
px, py = -uy, ux
def point(a, b):
return (round(bx + px * a + ux * b), round(by + py * a + uy * b))
shape = [(-8, -6), (-8, 2), (-3, 9), (1, 6), (7, 8), (6, -7), (2, -4), (-2, -8)]
if bass:
shape = [(-6, -7), (-8, -1), (-6, 6), (-2, 9), (2, 6), (6, 8), (7, -1), (4, -7)]
draw.polygon([point(a, b) for a, b in shape], fill=OUTLINE)
inner = [point(a * .78, b * .80) for a, b in shape]
draw.polygon(inner, fill="#635486" if bass else "#e54f64")
draw.line([point(0, -5), neck], fill=OUTLINE, width=6 if bass else 5)
draw.line([point(0, -4), neck], fill="#b59164", width=3)
draw.line([point(-1, -3), (nx - 1, ny)], fill="#efe0b2", width=1)
draw.line([point(1, -3), (nx + 1, ny)], fill="#f7ecc8", width=1)
draw.polygon([point(-3, length - 2), point(-3, length + 4), point(2, length + 5),
point(3, length - 2)], fill=OUTLINE)
draw.line([point(0, length - 1), point(0, length + 3)], fill="#f0cd7b", width=3)
for index in range(4 if bass else 3):
draw.line([point(-3, length - 1 + index), point(-5, length - 1 + index)], fill="#b5bfca", width=1)
draw.line([point(-4, -2), point(4, -2)], fill="#efe7df", width=2)
draw.point(point(4, -4), fill="#efc45e")
def special_pose(idle: Image.Image, role: str, phase: str, index: int) -> Image.Image:
"""Sacar instrumento, tocar/gritar y recogerlo conservan las fases comunes del especial."""
progress = (index + 1) / 3 if phase == "special_start" else (1 - (index + 1) / 3 if phase == "special_end" else 1)
beat = index % 2 if phase == "special" else 0
if role == "singer":
hand_y = round(42 - 17 * progress) + beat
image = posed_body(idle, role, arms=[[(24, 30), (19, 37), (20, 32 + beat)],
[(40, 30), (47, 35), (47, hand_y)]])
draw = ImageDraw.Draw(image)
draw.line([(48, hand_y + 3), (52, 48), (49, 56), (39, 58)], fill="#697080", width=1)
draw.line((48, hand_y + 2, 46, hand_y - 5), fill=OUTLINE, width=5)
draw.line((48, hand_y + 1, 46, hand_y - 5), fill="#9ea8b9", width=2)
draw.ellipse((42, hand_y - 10, 49, hand_y - 4), fill=OUTLINE)
draw.rectangle((44, hand_y - 9, 47, hand_y - 5), fill="#c6d1df")
draw.line((44, hand_y - 7, 47, hand_y - 7), fill="#697584")
if phase == "special":
draw.rectangle((37, 21, 40, 23 + beat), fill=OUTLINE)
draw.point((38, 23), fill="#e8868c")
return image
if role == "drummer":
left = (18, round(40 - 18 * progress) + beat * 12)
right = (48, round(40 - 6 * progress) - beat * 12)
image = posed_body(idle, role, arms=[[(24, 30), (18, 29), left], [(40, 30), (47, 29), right]])
draw = ImageDraw.Draw(image)
for hand, side in ((left, -1), (right, 1)):
tip = (hand[0] + side * 6, max(2, hand[1] - 16))
draw.line([hand, tip], fill=OUTLINE, width=3)
draw.line([hand, tip], fill="#e7bd76", width=1)
draw.point(tip, fill="#fff0bd")
return image
strum = (3, 2, 0, -1, -1, 0)[index] if phase == "special" else 0
image = posed_body(idle, role, arms=[[(24, 30), (25, 40), (30, 45 + strum)],
[(40, 30), (44, 35), (46, 30)]])
instrument(image, (29, 49), (55, round(33 - 12 * progress)), bass=True)
draw = ImageDraw.Draw(image)
draw.rectangle((28, 43 + strum, 33, 45 + strum), fill=SKIN_LIGHT)
draw.rectangle((44, 31, 47, 34), fill=SKIN)
return image
def pound_pose(idle: Image.Image, role: str, index: int, *, landing=False) -> Image.Image:
if role == "guitarist":
if landing:
image = posed_body(idle, role, shift=(-1, 4), hip=47,
legs=[[(26, 46), (22, 51), (20, 57)], [(37, 46), (40, 51), (42, 57)]],
arms=[[(23, 34), (29, 39), (38, 38)], [(39, 34), (43, 38), (44, 45)]])
instrument(image, (50 - index, 53 - max(index - 1, 0) * 5), (37, 26))
ImageDraw.Draw(image).rectangle((38, 36, 42, 39), fill=SKIN_LIGHT)
else:
image = posed_body(idle, role, arms=[[(24, 30), (24, 18), (40, 22)],
[(40, 30), (47, 30), (48, 21 + index * 3)]])
instrument(image, (51, 25 + index * 4), (47 - index * 3, 5 + index))
return image
if role == "singer":
if landing:
image = posed_body(idle, role, shift=(-4, 8 - (2 if index == 2 else 0)), hip=51,
legs=[[(24, 50), (19, 54), (17, 57)], [(35, 50), (39, 52), (36, 57)]],
arms=[[(20, 38), (17, 43), (24, 42)], [(36, 38), (44, 45), (48, 57 - index)]])
else:
image = posed_body(idle, role, hip=43,
legs=[[(27, 43), (22, 47), (25, 53)], [(38, 43), (43, 46), (46, 51)]],
arms=[[(24, 30), (18, 34), (22, 30)], [(40, 30), (45, 38), (47, 46 + index)]])
return image
if landing:
return posed_body(idle, role, shift=(-1, 11 - index // 2), hip=55,
legs=[[(27, 55), (35, 54), (39, 57)], [(38, 55), (49, 51), (52, 57)]],
arms=[[(23, 41), (20, 49), (24, 54)], [(39, 41), (45, 47), (44, 52)]])
return posed_body(idle, role, hip=43,
legs=[[(27, 43), (22, 42), (23, 51)], [(38, 43), (47, 42), (50, 51)]],
arms=[[(24, 30), (20, 36), (23, 41)], [(40, 30), (46, 36), (46, 41)]])
def svg_group(name: str, image: Image.Image, index: int) -> str:
"""Agrupa tramos horizontales por color para obtener SVG de texto compacto."""
paths = defaultdict(list)
for y in range(CELL):
x = 0
while x < CELL:
color = image.getpixel((x, y))
end = x + 1
while end < CELL and image.getpixel((end, y)) == color:
end += 1
if color[3]:
hex_color = "#%02x%02x%02x" % color[:3]
paths[hex_color].append(f"M{x} {y}h{end-x}v1h-{end-x}z")
x = end
result = [f'<g id="{name}" transform="translate({index%8*64} {index//8*64})">']
for color, runs in sorted(paths.items()):
result.append(f'<path fill="{color}" d="{"".join(runs)}"/>')
result.append("</g>")
return "\n".join(result)
def write_frames(role: str, names: list[str]) -> None:
"""Los tiempos y duraciones comunes son los mismos que en el atlas original."""
text = ['[gd_resource type="SpriteFrames" load_steps=42 format=3]', '',
f'[ext_resource type="Texture2D" path="res://assets/characters/band/{role}.svg" id="atlas"]', '']
for index, name in enumerate(names):
text += [f'[sub_resource type="AtlasTexture" id="{name}"]', 'atlas = ExtResource("atlas")',
f'region = Rect2({index%8*64}, {index//8*64}, 64, 64)', 'filter_clip = true', '']
animations = {
'fall': (7, True), 'ground_pound': (12, True), 'hurt': (12, False), 'idle': (5, True),
'jump': (9, False), 'land': (16, False), 'punch': (18, False), 'special': (12, True),
'special_end': (7, False), 'special_start': (9, False), 'walk': (10, True),
'pound_land': (12, False),
}
serialized = []
for animation, (speed, loop) in animations.items():
# Fer toca una nota por pulso; Player reinicia la pose, no un bucle visual.
if role == 'bassist' and animation == 'special':
loop = False
cells = [n for n in names if n.rsplit('_', 1)[0] == animation]
durations = [1.0, .75, 1.15, .8, 1.3] if animation == 'punch' else [1.0] * len(cells)
frames = ', '.join('{"duration": %s, "texture": SubResource("%s")}' % (duration, name)
for duration, name in zip(durations, cells))
serialized.append('{\n"frames": [' + frames + '],\n"loop": ' + str(loop).lower()
+ f',\n"name": &"{animation}",\n"speed": {speed}.0\n' + '}')
text += ['[resource]', 'animations = [' + ', '.join(serialized) + ']\n']
(ROOT/'player/characters/animations').mkdir(parents=True, exist_ok=True)
(ROOT/f'player/characters/animations/{role}_frames.tres').write_text('\n'.join(text), encoding='utf-8')
def main() -> None:
originals = read_source()
# Para Diego se conserva tambien el texto SVG de cada celda no modificada.
raw_groups = {name: match.group(0) for name in originals
if (match := re.search(r'<g id="' + re.escape(name) + r'".*?</g>', SOURCE.read_text(), re.S))}
DESTINATION.mkdir(parents=True, exist_ok=True)
for role in ROLES:
frames = {name: appearance(image, role, name) for name, image in originals.items()}
idle = frames['idle_0']
for index in range(2):
if role != 'drummer':
frames[f'ground_pound_{index}'] = pound_pose(idle, role, index)
for index in range(3):
frames[f'pound_land_{index}'] = frames[f'land_{index}'].copy() if role == 'drummer' else pound_pose(idle, role, index, landing=True)
if role != 'guitarist':
for phase, count in (('special_start', 3), ('special', 6), ('special_end', 2)):
for index in range(count):
frames[f'{phase}_{index}'] = special_pose(idle, role, phase, index)
output = ['<svg xmlns="http://www.w3.org/2000/svg" width="512" height="320" viewBox="0 0 512 320" shape-rendering="crispEdges">',
f'<title>{role}: band member animations</title>',
'<!-- Celdas de 64x64. Regenerar con tools/generate_band_art.py. -->']
for index, (name, image) in enumerate(frames.items()):
if role == 'guitarist' and name in originals and not name.startswith('ground_pound'):
output.append(raw_groups[name])
else:
output.append(svg_group(name, image, index))
output.append('</svg>\n')
(DESTINATION/f'{role}.svg').write_text('\n'.join(output), encoding='utf-8')
write_frames(role, list(frames))
print('Generados cuatro atlas y cuatro recursos SpriteFrames; no se ha ejecutado Godot.')
from generate_vector_character_art import main
if __name__ == '__main__':
+430
View File
@@ -0,0 +1,430 @@
"""Genera atlas SVG vectoriales de la banda y los cinco enemigos de Mortal Maze.
python tools/generate_vector_character_art.py
Sin dependencias externas. Celdas 64x64, anatomia con rodillas, tobillos y brazos
articulados; el movimiento no altera las colisiones de Godot. Se utiliza un
acabado de ilustracion 2D con paleta reducida, contorno y luces tipo pixel-art.
Los atlas se versionan: este script NO se ejecuta durante la partida.
"""
from __future__ import annotations
from dataclasses import dataclass
from math import cos, sin, pi
from pathlib import Path
from xml.sax.saxutils import escape
ROOT = Path(__file__).resolve().parents[1]
CELL = 64
@dataclass(frozen=True)
class Look:
label: str
jacket: str
light: str
shadow: str
accent: str
accent_light: str
hair: str
hair_light: str
skin: str
skin_light: str
skin_shadow: str
pants: str
shoe: str
kind: str
LOOKS: dict[str, Look] = {
'guitarist': Look('Diego · Guitarra', '#642c35', '#b14a50', '#311f2c', '#f1bc6a', '#ffe0a1', '#191c2d', '#535167', '#d59a78', '#ffcf9f', '#a36555', '#283044', '#482b34', 'guitar'),
'drummer': Look('Iván · Batería', '#2f5969', '#65a6ae', '#1d3345', '#f2c879', '#f7e5ae', '#1c202d', '#545565', '#c98c68', '#f0be8e', '#905948', '#293044', '#26333e', 'drums'),
'bassist': Look('Fer · Bajo', '#493c6b', '#7864a2', '#2a2844', '#92c2af', '#c3ead3', '#161726', '#474057', '#ae7c60', '#e8b58c', '#825044', '#282940', '#433c58', 'bass'),
'singer': Look('Héctor · Voz', '#304b42', '#597b61', '#202d32', '#ec6251', '#ffa079', '#aa803f', '#ead183', '#d39c75', '#f4c8a0', '#a56f58', '#34333d', '#2d2f37', 'mic'),
'roadie': Look('Roadie', '#385a5d', '#618c88', '#273c4e', '#dca85e', '#ffda91', '#282c36', '#77777b', '#d1a184', '#f3c8a4', '#996a5f', '#3f4655', '#343d4b', 'roadie'),
'pogo_fan': Look('Fan del pogo', '#65436a', '#a66394', '#3b2c53', '#f3a14e', '#ffcf79', '#cb346d', '#f58ca9', '#d1a07f', '#f4caa4', '#996858', '#39415a', '#a84e55', 'punk'),
'backstage_guard': Look('Guarda', '#3b465c', '#74839a', '#252d40', '#e2a851', '#ffe3a1', '#272a34', '#666b7a', '#aa8269', '#d7ae89', '#856455', '#343947', '#303642', 'guard'),
'rival_guitarist': Look('Guitarrista rival', '#324e66', '#67859b', '#203247', '#d45176', '#f5a5bb', '#8b929b', '#dce0cf', '#c99b80', '#ffe0b0', '#916b58', '#363b52', '#37475c', 'rival'),
'feedback_tech': Look('Técnico de feedback', '#34545c', '#71a6a8', '#213943', '#bce073', '#ddf4b1', '#303d43', '#7b9998', '#b78c6f', '#e8be9b', '#966a57', '#30454d', '#335b5d', 'tech'),
}
PLAYER_NAMES = ('guitarist', 'drummer', 'bassist', 'singer')
ENEMY_NAMES = ('roadie', 'pogo_fan', 'backstage_guard', 'rival_guitarist', 'feedback_tech')
PLAYER_POSES = ([('idle', i) for i in range(4)] + [('walk', i) for i in range(6)]
+ [('jump', i) for i in range(2)] + [('fall', i) for i in range(2)]
+ [('punch', i) for i in range(5)] + [('ground_pound', i) for i in range(2)]
+ [('land', i) for i in range(3)] + [('special_start', i) for i in range(3)]
+ [('special', i) for i in range(6)] + [('special_end', i) for i in range(2)]
+ [('hurt', i) for i in range(2)] + [('pound_land', i) for i in range(3)])
ENEMY_POSES = ([('idle', i) for i in range(2)] + [('walk', i) for i in range(6)]
+ [('attack', i) for i in range(3)] + [('jump', i) for i in range(2)]
+ [('hurt', 0)] + [('death', i) for i in range(2)])
assert len(PLAYER_POSES) == 40 and len(ENEMY_POSES) == 16
class Ink:
def __init__(self) -> None:
self.lines: list[str] = []
def add(self, element: str) -> None:
self.lines.append(element)
def path(self, d: str, fill: str = 'none', stroke: str = 'none', width: float = 1,
extra: str = '') -> None:
self.add(f'<path d="{d}" fill="{fill}" stroke="{stroke}" stroke-width="{width}" '
f'stroke-linecap="round" stroke-linejoin="round" {extra}/>' )
def ellipse(self, x: float, y: float, rx: float, ry: float, fill: str,
stroke: str = 'none', width: float = 1, extra: str = '') -> None:
self.add(f'<ellipse cx="{x:.2f}" cy="{y:.2f}" rx="{rx:.2f}" ry="{ry:.2f}" '
f'fill="{fill}" stroke="{stroke}" stroke-width="{width}" {extra}/>' )
def circle(self, x: float, y: float, r: float, fill: str, extra: str = '') -> None:
self.add(f'<circle cx="{x:.2f}" cy="{y:.2f}" r="{r}" fill="{fill}" {extra}/>' )
def line(self, points: tuple[tuple[float, float], ...], fill: str, width: float,
extra: str = '') -> None:
coords = ' '.join(f'{x:.2f},{y:.2f}' for x, y in points)
self.add(f'<polyline points="{coords}" stroke="{fill}" stroke-width="{width}" '
f'fill="none" stroke-linecap="round" stroke-linejoin="round" {extra}/>' )
def output(self) -> str:
return '\n'.join(self.lines)
def limb(ink: Ink, start: tuple[float, float], middle: tuple[float, float],
end: tuple[float, float], fabric: str, lit: str, width: float) -> None:
d = f'M {start[0]:.1f} {start[1]:.1f} Q {middle[0]:.1f} {middle[1]:.1f} {end[0]:.1f} {end[1]:.1f}'
ink.path(d, 'none', '#171a29', width + 2.8)
ink.path(d, 'none', fabric, width)
ink.line(((start[0] - 1, start[1] - .2), (middle[0] - .7, middle[1] - .3)), lit, 1.3, 'opacity=".72"')
def draw_shoe(ink: Ink, ankle_x: float, ankle_y: float, look: Look, lift: float) -> None:
y = ankle_y + 1
ink.path(f'M {ankle_x-3.8:.1f} {y-1:.1f} Q {ankle_x+1:.1f} {y-4:.1f} {ankle_x+3.4:.1f} {y-1:.1f} '
f'L {ankle_x+7:.1f} {y+1:.1f} Q {ankle_x+8.3:.1f} {y+3:.1f} {ankle_x+5:.1f} {y+3:.1f} '
f'L {ankle_x-3.8:.1f} {y+2:.1f} Z', look.shoe, '#151927', 1.4)
ink.path(f'M {ankle_x-3:.1f} {y+2:.1f} L {ankle_x+6:.1f} {y+2:.1f}', 'none', '#a2abb1', 1.1)
if lift < 1:
ink.path(f'M {ankle_x:.1f} {y-2:.1f} l 3 -.2', 'none', look.accent_light, .6)
def pose_parameters(name: str, frame: int):
if name == 'walk':
phase = 2*pi*frame/6
stride = sin(phase)
bob = -.95 * abs(sin(phase))
return stride, max(0.0, cos(phase))*4, max(0.0, -cos(phase))*4, bob, 0.8*sin(phase)
if name == 'idle':
return 0, 0, 0, -.35 + .5*sin(pi*frame/2), 0
if name in ('jump', 'fall', 'ground_pound'):
return .0, 5.0 if frame == 0 else 2.0, 3.0 if frame == 0 else 5, -1.9, -1.5 if name == 'jump' else 2.2
if name in ('land', 'pound_land'):
return 0, 1.2, 1.2, 2.0 - frame*.55, 1.0
if name == 'hurt':
return .1, 0, 1, -1, -3.6
if name in ('punch', 'attack'):
return -.4 if frame == 0 else .8, 0, 1, -.7, -1.5 if frame > 0 else 2
if name.startswith('special'):
return 0, 0, 0, -.7 - .7*cos(frame*pi/3), -1
if name == 'death':
return 0, 5, 4, 4 + 2*frame, -7
return 0, 0, 0, 0, 0
def draw_hair_back(ink: Ink, look: Look, h: float) -> None:
if look.kind == 'bass':
ink.path(f'M 22 {10+h:.1f} Q 15 {14+h:.1f} 20 {30+h:.1f} L 24 {34+h:.1f} '
f'Q 27 {28+h:.1f} 29 {24+h:.1f} L 40 {25+h:.1f} Q 48 {34+h:.1f} 46 {15+h:.1f} '
f'Q 39 {6+h:.1f} 22 {10+h:.1f} Z', look.hair, '#151925', 1.5)
for x,y in ((20,21),(20.5,28),(44,25),(43,31)):
ink.path(f'M {x} {y+h:.1f} q -2 3 1 5', 'none', look.hair_light, 1.1)
elif look.kind in ('guitar','rival','roadie'):
ink.path(f'M 25 {11+h:.1f} Q 19 {10+h:.1f} 20 {21+h:.1f} L 23 {32+h:.1f} '
f'L 26 {27+h:.1f} L 40 {24+h:.1f} L 43 {32+h:.1f} '
f'Q 48 {13+h:.1f} 38 {8+h:.1f} Z', look.hair, '#121621', 1.2)
def draw_hair_front(ink: Ink, look: Look, h: float) -> None:
if look.kind == 'mic':
ink.path(f'M 26 {10+h:.1f} L 29 {2+h:.1f} L 32 {8+h:.1f} L 35 {1+h:.1f} '
f'L 38 {9+h:.1f} L 41 {5+h:.1f} L 41 {17+h:.1f} Q 32 {13+h:.1f} 26 {18+h:.1f} Z',
look.hair, '#25202a', 1.1)
ink.path(f'M 30 {7+h:.1f} L 35 {3+h:.1f} L 37 {11+h:.1f}', 'none', look.hair_light, 1.4)
elif look.kind == 'punk':
ink.path(f'M 23 {12+h:.1f} L 22 {3+h:.1f} L 27 {8+h:.1f} L 31 {0+h:.1f} L 36 {8+h:.1f} '
f'L 42 {3+h:.1f} L 40 {15+h:.1f} Q 33 {12+h:.1f} 24 {17+h:.1f} Z',
look.hair, '#2a1c2a', 1.3)
ink.path(f'M 26 {10+h:.1f} L 31 {4+h:.1f} L 32 {10+h:.1f}', 'none', look.hair_light, 1.7)
elif look.kind == 'drums':
ink.path(f'M 22 {13+h:.1f} Q 24 {4+h:.1f} 37 {7+h:.1f} L 42 {14+h:.1f} '
f'L 38 {17+h:.1f} Q 29 {12+h:.1f} 24 {19+h:.1f} Z', look.hair, '#151925', 1.3)
ink.path(f'M 21 {13+h:.1f} Q 30 {7+h:.1f} 43 {12+h:.1f} L 42 {15+h:.1f} '
f'Q 30 {11+h:.1f} 22 {16+h:.1f} Z', '#b44e46', '#171b26', 1.1)
ink.path(f'M 25 {13+h:.1f} Q 32 {10+h:.1f} 39 {13+h:.1f}', 'none', '#f1a077', 1.1)
elif look.kind == 'guard':
ink.path(f'M 23 {13+h:.1f} Q 24 {7+h:.1f} 38 {9+h:.1f} L 43 {15+h:.1f} '
f'L 22 {17+h:.1f} Z', '#242b3b', '#111724', 1.5)
ink.path(f'M 19 {15+h:.1f} Q 29 {12+h:.1f} 44 {16+h:.1f} L 45 {19+h:.1f} '
f'Q 33 {16+h:.1f} 20 {19+h:.1f} Z', look.light, '#171924', 1.1)
elif look.kind == 'tech':
ink.path(f'M 24 {10+h:.1f} Q 31 {4+h:.1f} 39 {9+h:.1f} L 41 {18+h:.1f} '
f'Q 33 {14+h:.1f} 24 {17+h:.1f} Z', look.hair, '#1c2630', 1.2)
ink.path(f'M 21 {16+h:.1f} Q 20 {3+h:.1f} 31 {6+h:.1f} Q 43 {4+h:.1f} 44 {16+h:.1f}',
'none', look.accent, 2.1)
for x in (21,43):
ink.ellipse(x, 18+h, 2.8, 5.0, '#263b47', look.accent, 1.3)
else:
ink.path(f'M 23 {13+h:.1f} Q 21 {7+h:.1f} 30 {6+h:.1f} Q 41 {6+h:.1f} 43 {14+h:.1f} '
f'L 40 {18+h:.1f} Q 36 {12+h:.1f} 30 {15+h:.1f} L 25 {19+h:.1f} Z',
look.hair, '#161925', 1.4)
ink.path(f'M 25 {12+h:.1f} Q 32 {7+h:.1f} 39 {11+h:.1f}', 'none', look.hair_light, 1.7)
if look.kind == 'bass':
ink.path(f'M 22 {15+h:.1f} Q 25 {6+h:.1f} 33 {8+h:.1f} Q 40 {6+h:.1f} 43 {14+h:.1f} '
f'L 40 {17+h:.1f} L 29 {13+h:.1f} L 25 {20+h:.1f} Z', look.hair, '#141825', 1.5)
ink.path(f'M 23 {15+h:.1f} Q 26 {10+h:.1f} 33 {10+h:.1f}', 'none', look.hair_light, 1.1)
def draw_head(ink: Ink, look: Look, bob: float, tilt: float, pose: str) -> None:
y = bob - tilt*.14
draw_hair_back(ink, look, y)
ink.path(f'M 26 {13+y:.1f} Q 32 {9+y:.1f} 39 {13+y:.1f} Q 42 {20+y:.1f} 39 {25+y:.1f} '
f'Q 36 {30+y:.1f} 31 {29+y:.1f} Q 24 {27+y:.1f} 23 {20+y:.1f} '
f'Q 22 {15+y:.1f} 26 {13+y:.1f} Z', 'url(#skin)', '#171a26', 1.3)
ink.path(f'M 26 {16+y:.1f} Q 24 {19+y:.1f} 26 {23+y:.1f}', 'none', look.skin_light, 1.2, 'opacity=".7"')
ink.ellipse(24, 20+y, 1.6, 3.0, look.skin_shadow, '#191a26', .8)
draw_hair_front(ink, look, y)
# Ojos ligeramente en perfil y cejas expresivas, sin pixeles cuadrados.
ink.path(f'M 29 {19+y:.1f} l 3 -.7 M 36 {19+y:.1f} l 2 .2', 'none', '#312531', 1.3)
ink.ellipse(30.6, 20.8+y, .72, 1.0, '#151822')
ink.ellipse(37.1, 20.9+y, .68, .95, '#151822')
ink.path(f'M 34 {21.6+y:.1f} l .6 2.1 -1.4 .7', 'none', look.skin_shadow, .8)
if look.kind in ('guitar','bass','rival','roadie'):
ink.path(f'M 29 {24+y:.1f} Q 34 {28.6+y:.1f} 38 {24+y:.1f}', 'none', look.hair, 1.1)
ink.path(f'M 32 {25+y:.1f} l 4 .2', 'none', '#f4d9bf', .7)
elif pose == 'hurt':
ink.path(f'M 32 {26+y:.1f} q 2 -1 4 .4', 'none', '#612c33', 1.1)
else:
ink.path(f'M 31 {25+y:.1f} Q 35 {26.5+y:.1f} 37 {25+y:.1f}', 'none', '#6a4142', 1.0)
if look.kind == 'mic':
ink.path(f'M 27 {22+y:.1f} q 1 7 8 6', 'none', '#704b36', .8, 'opacity=".6"')
ink.circle(39.7, 22+y, 1.0, '#ded7b9')
elif look.kind == 'guard':
ink.path(f'M 27 {20+y:.1f} L 39 {20+y:.1f}', 'none', '#2b3440', 2.1, 'opacity=".8"')
def draw_torso(ink: Ink, look: Look, bob: float, tilt: float, is_enemy: bool) -> None:
y = bob
widen = 2 if look.kind == 'guard' else 0
ink.path(f'M {24-widen} {30+y:.1f} Q 32 {27+y:.1f} {40+widen} {30+y:.1f} '
f'L {40+widen+tilt*.3:.1f} {42+y:.1f} Q 32 {46+y:.1f} {24-widen+tilt*.3:.1f} {42+y:.1f} Z',
'url(#jacket)', '#141824', 1.8)
ink.path(f'M 26 {30+y:.1f} L 30 {36+y:.1f} L 29 {42+y:.1f}', 'none', look.light, 1.6, 'opacity=".75"')
ink.path(f'M 38 {31+y:.1f} Q 35 {36+y:.1f} 38 {43+y:.1f}', 'none', look.shadow, 1.9)
ink.path(f'M 25 {43+y:.1f} Q 32 {44+y:.1f} 39 {43+y:.1f}', 'none', '#1a1d29', 2.1)
ink.circle(32.2, 43.7+y, 1.15, look.accent_light)
# Logo de escenario y costuras dibujados sin fuentes ni texto rasterizado.
if look.kind in ('guitar','rival','punk','mic'):
ink.path(f'M 29 {33+y:.1f} l 3 -1 3 1 -1 3 -1 -1 -1 3 -1 -3 Z', '#e2dfd0', '#1e2532', .45)
ink.circle(30.8, 34+y, .55, '#292c36')
ink.circle(33.3, 34+y, .55, '#292c36')
elif look.kind in ('drums','bass','tech'):
ink.path(f'M 28 {34+y:.1f} L 36 {34+y:.1f} L 34 {37+y:.1f} L 30 {37+y:.1f} Z', look.accent, '#25303b', .8)
ink.path(f'M 32 {33+y:.1f} L 32 {39+y:.1f}', 'none', look.accent_light, .9)
else:
ink.path(f'M 36 {33+y:.1f} l 3 0 -1 4 -3 0 Z', look.accent, '#222a31', .6)
if look.kind == 'guard':
ink.path(f'M 24 {29+y:.1f} l -5 3 4 7 4 -3 Z M 40 {29+y:.1f} l 5 3 -4 7 -4 -3 Z',
look.light, '#161a26', 1.4)
ink.path(f'M 28 {39+y:.1f} l 9 0', 'none', look.accent, 1.0)
if look.kind == 'tech':
ink.path(f'M 36 {32+y:.1f} l 4 1 -2 5 -4 -1 Z', look.accent_light, '#1a2329', .6)
if is_enemy:
ink.path(f'M 28 {40+y:.1f} l 9 0', 'none', look.accent, .75, 'opacity=".65"')
def draw_arms(ink: Ink, look: Look, bob: float, stride: float, pose: str,
frame: int, foreground: bool) -> None:
if foreground:
shoulder = (40.0, 31.5 + bob)
elbow = (43 + 2.0*stride, 38+bob)
wrist = (45 + 3.4*stride, 43+bob)
if pose in ('punch','attack'):
extent = [0, 5, 11, 13, 6][min(frame,4)] if pose == 'punch' else [0, 11, 5][frame]
elbow = (43+extent*.4, 33.5+bob)
wrist = (45+extent, 32+bob)
elif pose in ('special_start', 'special', 'special_end'):
wrist = (45, 21 + 2*sin(frame*pi/3)+bob)
elbow = (46, 31+bob)
elif pose in ('jump', 'fall', 'ground_pound'):
elbow = (46, 29+bob)
wrist = (50, 25+bob) if pose != 'ground_pound' else (47,17+bob)
elif pose in ('land','pound_land','death'):
wrist = (42, 43+bob)
elbow = (43, 40+bob)
elif pose == 'hurt':
elbow = (38, 30+bob)
wrist = (39, 25+bob)
else:
shoulder = (24.0, 31.5+bob)
elbow = (21 - 2*stride, 38+bob)
wrist = (20 - 3.4*stride, 43+bob)
if pose in ('punch','attack'):
elbow, wrist = (22, 37+bob), (25, 43+bob)
elif pose in ('special_start','special','special_end'):
elbow, wrist = (19, 29+bob), (20, 23+bob)
elif pose in ('jump','fall','ground_pound'):
elbow, wrist = (18, 30+bob), (15, 23+bob)
elif pose in ('land','pound_land','death'):
elbow, wrist = (21, 42+bob), (20, 46+bob)
elif pose == 'hurt':
elbow, wrist = (23, 27+bob), (24, 22+bob)
limb(ink, shoulder, elbow, wrist, look.jacket, look.light, 5.5 if look.kind!='guard' else 7)
ink.ellipse(wrist[0], wrist[1], 2.7, 3.2, look.skin, '#1b1c28', 1)
ink.path(f'M {wrist[0]-2.5:.1f} {wrist[1]-1:.1f} l 3 -1.2', 'none', look.skin_light, .8)
if look.kind in ('drums','punk','mic','rival'):
ink.line(((wrist[0]-1.8, wrist[1]-4), (wrist[0]+1.2, wrist[1]-4)), '#1b1d29', 2.6)
ink.line(((wrist[0]-1, wrist[1]-4.1), (wrist[0]+.4, wrist[1]-4.1)), look.accent, .7)
def draw_instrument(ink: Ink, look: Look, pose: str, frame: int, bob: float) -> None:
# Accesorios con lectura clara y volumen, visibles sin alterar las hitboxes.
if look.kind in ('guitar', 'bass','rival'):
if pose not in ('special','special_start','special_end','attack'):
return
body = '#d84d53' if look.kind == 'guitar' else ('#5daa88' if look.kind == 'bass' else '#9e5cba')
light = '#ff9c81' if look.kind == 'guitar' else ('#c5e5a5' if look.kind == 'bass' else '#e3a9db')
wobble = .7*sin(frame*pi/3)
ink.add(f'<g transform="translate(0 {bob+wobble:.2f}) rotate(-20 35 38)">')
ink.path('M 30 37 Q 24 36 24 42 Q 21 48 26 50 Q 31 53 35 48 '
'Q 40 52 44 45 Q 46 38 40 36 L 37 39 Z', body, '#1a1d2c', 2.3)
ink.path('M 28 43 Q 31 39 36 42 Q 41 39 41 45', 'none', light, 1.3)
ink.path('M 34 42 L 42 15 L 46 14 L 39 43 Z', '#ab885e', '#201f2b', 1.25)
for offset in (0,1.5,3):
ink.path(f'M {36+offset*.5:.1f} 43 L {43+offset*.35:.1f} 17', 'none', '#efe2c1', .38)
ink.ellipse(35, 46, 2, 1.5, '#1b1c2a')
ink.path('M 39 36 L 42 36', 'none', '#e9d4a2', .85)
ink.add('</g>')
elif look.kind == 'mic' and pose in ('special','special_start','special_end'):
ink.path(f'M 45 {20+bob:.1f} L 45 {9+bob:.1f}', 'none', '#171c28', 2.8)
ink.path(f'M 45 {20+bob:.1f} L 45 {10+bob:.1f}', 'none', '#a5bbc4', 1.4)
ink.ellipse(45, 7.5+bob, 3.5, 4.4, '#cfd6d4', '#222432', 1.2)
ink.path(f'M 42.5 {7+bob:.1f} q 2 -3 5 0', 'none', '#f8f1e0', .8)
ink.path(f'M 45 {23+bob:.1f} Q 49 {38+bob:.1f} 48 {45+bob:.1f}', 'none', '#232b33', 1)
elif look.kind == 'drums' and pose in ('special','special_start','special_end','ground_pound'):
ink.path(f'M 18 {22+bob:.1f} L 12 {6+bob:.1f} M 45 {22+bob:.1f} L 51 {6+bob:.1f}',
'none', '#d6b47c', 2.3)
ink.path(f'M 12 {7+bob:.1f} l -1 -3 M 51 {7+bob:.1f} l 1 -3', 'none', '#fff0c5', 1.0)
elif look.kind == 'roadie':
ink.path(f'M 24 {42+bob:.1f} L 41 {42+bob:.1f}', 'none', '#c39a5c', 2)
ink.path(f'M 38 {40+bob:.1f} l 4 0 0 6 -4 0 Z', look.shadow, '#1a1c29', 1)
ink.circle(40, 43+bob, 1.1, '#c9e4d8')
elif look.kind == 'guard':
ink.path(f'M 40 {38+bob:.1f} l 4 -2 2 5 -4 3 Z', '#1c232c', look.accent, 1)
elif look.kind == 'tech':
ink.path(f'M 25 {34+bob:.1f} l 4 0 1 4 -3 2 Z', '#242c37', '#131a23', .8)
ink.circle(27, 36+bob, 1.0, look.accent_light)
def draw_pose(look: Look, pose: str, frame: int, enemy: bool = False) -> str:
ink = Ink()
stride, lift_l, lift_r, bob, tilt = pose_parameters(pose, frame)
if look.kind == 'guard':
stride *= .6
if pose in ('land','pound_land'):
lift_l += 1
lift_r += 1
# Pierna lejana primero: rodillas y pies mantienen una trayectoria coherente.
if pose == 'walk':
left_x, right_x = 28+7*stride, 36-7*stride
elif pose in ('jump','fall','ground_pound'):
left_x, right_x = 25, 39
elif pose in ('punch','attack'):
left_x, right_x = 29, 41
else:
left_x, right_x = 28.8, 37.5
for hip, foot_x, lift, back in ((27.5,left_x,lift_l,True),(36.5,right_x,lift_r,False)):
hip_y = 43+bob
knee_x = (hip+foot_x)*.5 + (-2 if back else 2) + lift*.35
knee_y = 50 + bob*.4 - lift*.35
ankle_y = 55.6-lift
limb(ink, (hip, hip_y), (knee_x,knee_y), (foot_x,ankle_y),
look.pants, '#68758a' if back else look.light, 6.1)
ink.path(f'M {hip-2:.1f} {hip_y+2:.1f} l 5 0', 'none', look.shadow, 2.2)
draw_shoe(ink, foot_x, ankle_y, look, lift)
draw_arms(ink, look, bob, stride, pose, frame, False)
draw_torso(ink, look, bob, tilt, enemy)
# Cuello y collar como capas independientes.
ink.path(f'M 29 {28+bob:.1f} Q 32 {32+bob:.1f} 35 {28+bob:.1f}', 'none', look.skin_shadow, 3)
ink.path(f'M 27 {29+bob:.1f} l 5 4 5 -4', 'none', look.accent, 1.2)
draw_head(ink, look, bob, tilt, pose)
draw_arms(ink, look, bob, stride, pose, frame, True)
draw_instrument(ink, look, pose, frame, bob)
return ink.output()
def svg_atlas(name: str, poses: list[tuple[str, int]], cols: int) -> str:
look = LOOKS[name]
width = cols*CELL
height = (len(poses)+cols-1)//cols*CELL
defs = f'''<defs>
<linearGradient id="jacket" x1="0" y1="0" x2="1" y2=".7">
<stop offset="0" stop-color="{look.light}"/>
<stop offset=".38" stop-color="{look.jacket}"/>
<stop offset="1" stop-color="{look.shadow}"/>
</linearGradient>
<linearGradient id="skin" x1="0" y1="0" x2="1" y2="1">
<stop offset="0" stop-color="{look.skin_light}"/>
<stop offset=".62" stop-color="{look.skin}"/>
<stop offset="1" stop-color="{look.skin_shadow}"/>
</linearGradient>
</defs>'''
lines = [f'<svg xmlns="http://www.w3.org/2000/svg" width="{width}" height="{height}" '
f'viewBox="0 0 {width} {height}" shape-rendering="geometricPrecision">',
f'<title>{escape(look.label)} · ilustración vectorial animada</title>', defs]
for i, (pose, frame) in enumerate(poses):
x, y = i%cols * CELL, i//cols * CELL
lines.append(f'<g id="{pose}_{frame}" transform="translate({x} {y})">')
lines.append(draw_pose(look, pose, frame, name in ENEMY_NAMES))
lines.append('</g>')
return '\n'.join(lines + ['</svg>', ''])
def enemy_spriteframes(name: str) -> str:
result = ['[gd_resource type="SpriteFrames" load_steps=18 format=3]', '',
f'[ext_resource type="Texture2D" path="res://assets/enemies/{name}.svg" id="atlas"]', '']
for i, (pose, frame) in enumerate(ENEMY_POSES):
result.append(f'[sub_resource type="AtlasTexture" id="{pose}_{frame}"]')
result.append('atlas = ExtResource("atlas")')
result.append(f'region = Rect2({i%4*64}, {i//4*64}, 64, 64)')
result.append('filter_clip = true')
result.append('')
result.append('[resource]')
frames = []
for anim, speed, loop in [('idle',5.0,True),('walk',10.0,True),('attack',12.0,False),
('jump',7.0,True),('hurt',10.0,False),('death',6.0,False)]:
items = ', '.join('{"duration": 1.0, "texture": SubResource("%s_%s")}' % (n,i)
for n,i in ENEMY_POSES if n==anim)
frames.append('{\n"frames": [' + items + '],\n"loop": '+str(loop).lower()
+',\n"name": &"'+anim+'",\n"speed": '+str(speed)+'\n}')
result.append('animations = ['+', '.join(frames)+']')
return '\n'.join(result)+'\n'
def main() -> None:
for name in PLAYER_NAMES:
dest = ROOT / f'assets/characters/band/{name}.svg'
dest.write_text(svg_atlas(name, PLAYER_POSES, 8), encoding='utf-8')
print('written', dest.relative_to(ROOT))
(ROOT/'enemies/animations').mkdir(exist_ok=True)
for name in ENEMY_NAMES:
dest = ROOT / f'assets/enemies/{name}.svg'
dest.write_text(svg_atlas(name, ENEMY_POSES, 4), encoding='utf-8')
frames = ROOT / f'enemies/animations/{name}_frames.tres'
frames.write_text(enemy_spriteframes(name), encoding='utf-8')
print('written', dest.relative_to(ROOT), 'and', frames.relative_to(ROOT))
if __name__ == '__main__':
main()