312 lines
9.5 KiB
Python
312 lines
9.5 KiB
Python
"""Procedural pixel-art grids: 2D arrays of single-char palette keys.
|
|
|
|
``render/sprites.get_sprite`` rasterizes a grid to a cached Surface, mapping each
|
|
char to a color from ``data.constants.PALETTE``. ``.``/space = transparent. The
|
|
marker char ``a`` is an item accent replaced at raster time by a per-kind tint
|
|
(``TINTS``), so one category shape recolors into distinct items. Rows may be
|
|
ragged; the rasterizer pads short rows with transparency.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
# Palette keys (see data.constants.PALETTE):
|
|
# . space = transparent K = darkest outline k = outline shade
|
|
# h = light/white s = stairs yellow y = yellow b = blue
|
|
# r = red g = green p = purple c = bone white o = brown n = dark red
|
|
# H = blood/damage a = item accent (tinted per kind)
|
|
|
|
GRIDS: dict[str, list[str]] = {
|
|
|
|
# ---- stairs: glowing yellow descending staircase (3 steps down-right) ----
|
|
"stairs": [
|
|
"..............",
|
|
".KKKKKK.......",
|
|
".KyyyyyK......",
|
|
".KsssssK......",
|
|
".KKKKKKK......",
|
|
"....KKKKKK....",
|
|
"....KyyyyyK...",
|
|
"....KsssssK...",
|
|
"....KKKKKKK...",
|
|
".......KKKKKK.",
|
|
".......KyyyyyK",
|
|
".......KsssssK",
|
|
".......KKKKKKK",
|
|
"..............",
|
|
"..............",
|
|
],
|
|
|
|
# ---- player: hooded adventurer, blue cloak, steel highlight ----
|
|
"player": [
|
|
"....KKKK....",
|
|
"...KhKKhk...",
|
|
"..KhhhhhhK..",
|
|
"..KhccccKh..",
|
|
"..KhhhhhhK..",
|
|
".KbbbbbbbbK.",
|
|
".KbhbbbbhbK.",
|
|
".KbbbbbbbbK.",
|
|
".KbbbbbbbbK.",
|
|
".KbbKKKKbbK.",
|
|
".KbK....KbK.",
|
|
".KK......KK.",
|
|
"............",
|
|
"............",
|
|
],
|
|
|
|
# ---- rat: small brown body, ears, pink tail ----
|
|
"rat": [
|
|
"..............",
|
|
"...KK....KK...",
|
|
"...KoK..KoK...",
|
|
"..KooooooK....",
|
|
".KooooooooK.KK",
|
|
".KoohhooooKKK.",
|
|
".KooooooooK...",
|
|
".KooooooooK...",
|
|
"..KooooooK....",
|
|
"...KooooK.....",
|
|
"....KhhK......",
|
|
"....K..K...oo.",
|
|
"...........oo.",
|
|
"..............",
|
|
],
|
|
|
|
# ---- goblin: green humanoid, pointed ears, crude blade ----
|
|
"goblin": [
|
|
"..............",
|
|
"..K.K....K.K..",
|
|
"..KgK....KgK..",
|
|
".KggggggggggK.",
|
|
".KgghhhhhggK..",
|
|
".KggKrrKggK...", # eyes/mouth
|
|
".KggggggggK...",
|
|
".KgggggggggK..",
|
|
".KgggKKKgggK..",
|
|
".KggK...KggK..",
|
|
".KgK.....KgK..",
|
|
".KK.......KK..",
|
|
".....yy.......", # crude blade
|
|
".....yy.......",
|
|
],
|
|
|
|
# ---- skeleton archer: thin bones, ribcage, drawn bow + quiver, glowing eyes ----
|
|
"skeleton_archer": [
|
|
"..............",
|
|
".....KKKK.....",
|
|
"....KccccK....",
|
|
"....KqccqK....", # glowing eye sockets
|
|
"....KccccK....",
|
|
"....KchhcK....", # cheek bones
|
|
".....KKKK.....", # teeth
|
|
"y...KccccK..o.", # quiver fletch | shoulders | bow tip
|
|
"yo..KcKKcK.o..", # ribs + bow limb
|
|
"yo..KcKKcKo...", # bow belly (closest to body)
|
|
"yo..KcKKcKo...",
|
|
"yo..KcKKcK.o..",
|
|
"yo..KcKKcK..o.", # bow tip
|
|
"y...KcKKcK...o",
|
|
"....KK..KK....", # pelvis
|
|
"....Kc..cK....", # thin bony legs
|
|
],
|
|
|
|
# ---- orc warrior: broad hulking brute, plate pauldrons, tusks, big blade ----
|
|
"orc_warrior": [
|
|
"..............",
|
|
".....KKKK.....",
|
|
"....KnnnnK....",
|
|
"....KHnnHK....", # red eyes / heavy brow
|
|
"....KnnnnK....",
|
|
"...hKnnnnKh...", # jutting tusks
|
|
"..KnnnnnnnnK..", # thick neck
|
|
"KKnnnnnnnnnnKK", # massive plate shoulders
|
|
"KnhhnnnnnnhhnK", # pauldron highlights
|
|
"KnnnnnnnnnnnnK", # broad chest
|
|
".KKnnnyynnnKK.", # fists + yellow crossguard
|
|
"..KnGGGGGGnK..", # big steel blade
|
|
"..KnhGGGGhnK..", # blade bright edge
|
|
"...KKGGGKK....", # heavy blade tip
|
|
"...KKK..KKK...", # legs
|
|
"...KK....KK...", # feet
|
|
],
|
|
|
|
# ---- wraith: translucent purple wisps, tattered cloak, no legs ----
|
|
"wraith": [
|
|
"..............",
|
|
".....KKKK.....",
|
|
"....KppppK....",
|
|
"...KppppppK...",
|
|
"...KpHHppK....", # glowing eyes
|
|
"...KpppppK....",
|
|
"..KpppppppK...",
|
|
".KpppppppppK..",
|
|
".KpKpKpKpKpK..", # tattered hem
|
|
"KpK.pK.pK.pK..",
|
|
"p.p..p...p..p.",
|
|
"..............",
|
|
"..............",
|
|
"..............",
|
|
],
|
|
|
|
# ---- green slime: big glossy domed blob, highlight, googly eyes, drip ----
|
|
"green_slime": [
|
|
"..............",
|
|
"...KKKKKKKK...",
|
|
"..KggggggggK..",
|
|
".KgghhhhgggK..", # glossy top-left highlight
|
|
".KghhKKhhggK..", # sheen
|
|
"KgggggggggggK.",
|
|
"KgghKggKhgggK.", # two googly eyes
|
|
"KgggggggggggK.",
|
|
"KgggggggggggK.",
|
|
".KgggggggggK..",
|
|
".KgggggggggK..",
|
|
"..KKKKKKKKKK..", # flat bottom (squished on ground)
|
|
".....g........", # drip
|
|
"....gg........",
|
|
".....g........",
|
|
"..............",
|
|
],
|
|
|
|
# ---- small slime: smaller cuter variant ----
|
|
"small_slime": [
|
|
"..............",
|
|
"..............",
|
|
"..............",
|
|
"....KKKKKK....",
|
|
"...KggggggK...",
|
|
"..KggHHggggK..",
|
|
"..KgghhggggK..",
|
|
"..KggggggggK..",
|
|
"..KggggggggK..",
|
|
"...KKKKKKKK...",
|
|
".....g........",
|
|
"..............",
|
|
"..............",
|
|
"..............",
|
|
],
|
|
|
|
# ---- ancient dragon: large red boss, horns, wings, fangs ----
|
|
"ancient_dragon": [
|
|
"K............K",
|
|
"KK..........KK",
|
|
".KrK......KrK.", # wing tips
|
|
"KrrrK....KrrrK",
|
|
"KrrrrKKKKrrrrK",
|
|
".KrrrrrrrrrrK.", # horns sweep
|
|
"..KHHrrrrHHK..", # eyes
|
|
"..KrrrrrrrrK...",
|
|
"..KrKnnnrKrK...", # fanged maw
|
|
".KrrrrrrrrrrK..",
|
|
"KrrKrrrrrrKrrK.",
|
|
"KrK..KrrK..KrK.",
|
|
"K.....KK.....K.",
|
|
"..............",
|
|
],
|
|
}
|
|
|
|
# ---- item category base shapes; the 'a' marker is tinted per kind (TINTS) ----
|
|
GRIDS["_weapon"] = [
|
|
"......Kh......", # pointed tip
|
|
".....KhaK.....", # blade (a = per-kind tint) w/ bright edge (h)
|
|
".....Khaa.....",
|
|
"....Khaaa.....",
|
|
"....KhaaK.....",
|
|
"...Khaaaa.....",
|
|
"...KhaaaK.....",
|
|
"..Khaaaaa.....",
|
|
"..KhaaaaK.....",
|
|
".Khaaaaaa.....",
|
|
".KhaaaaaK.....",
|
|
"KKyyyyyyyyyKK.", # wide yellow crossguard
|
|
"...KaaaaK.....", # grip
|
|
"...KaaaaK.....",
|
|
"...KaaaaK.....",
|
|
"....KyyK......", # pommel
|
|
]
|
|
GRIDS["_armor"] = [
|
|
"...KKKKKKKK...", # shield top
|
|
"..KaaaaaaaaK..",
|
|
".KaahhaaaaaaK.", # top-left highlight
|
|
".KaahbhaaaaaK.", # blue boss
|
|
"KaaabbbaaaaaK.", # blue cross (steel rim accents)
|
|
"KaaabbbaaaaaK.",
|
|
"KaaaabbbaaaK..",
|
|
"KaaaaaaaaaK...",
|
|
".KaaaaaaK.....",
|
|
"..KaaaaK......",
|
|
"...KaaK.......",
|
|
"....KK........", # point
|
|
"..............",
|
|
"..............",
|
|
"..............",
|
|
"..............",
|
|
]
|
|
GRIDS["_potion"] = [
|
|
".....KKKK.....", # neck
|
|
"....KooooK....", # cork
|
|
"....KKKKKK....", # shoulder
|
|
"..KKaaaaaaKK..",
|
|
".KaaaaaaaaaaK.",
|
|
".KaahaaaaaaaK.", # glass highlight
|
|
"KaaaaaaaaaaaK.", # round bulb (a = per-kind liquid)
|
|
"KaaaaaaaaaaaK.",
|
|
"KaaaaaaaaaaaK.",
|
|
"KaaaaaaaaaaaK.",
|
|
".KaaaaaaaaaK..",
|
|
".KaaaaaaaaaK..",
|
|
"..KKaaaaaKK...", # base
|
|
"..............",
|
|
"..............",
|
|
"..............",
|
|
]
|
|
GRIDS["_scroll"] = [
|
|
"..............",
|
|
".KhC......ChK.", # rolled end caps (top)
|
|
"KhCk......kChK", # cylindrical rolls: bright rim (h) + dark core (k)
|
|
"KhCkCCCCCCkChK", # flat paper between the rolls
|
|
"KhCkChCCCCkChK", # ruled line
|
|
"KhCkaaaaaakChK", # ribbon tie (a = per-kind tint)
|
|
"KhCkaaaaaakChK",
|
|
"KhCkCCChCCkChK", # ruled line
|
|
"KhCkCCCCCCkChK",
|
|
"KhCkCCCCCCkChK",
|
|
"KhCk......kChK", # rolls
|
|
".KhC......ChK.", # rolled end caps (bottom)
|
|
"..............",
|
|
"..............",
|
|
"..............",
|
|
"..............",
|
|
]
|
|
|
|
# Point every item kind at its category base shape (shared list, read-only).
|
|
_WEAPON_KINDS = ("rusty_dagger", "short_sword", "battle_axe", "war_hammer")
|
|
_ARMOR_KINDS = ("leather_armor", "chain_mail", "plate_armor")
|
|
_POTION_KINDS = ("healing_potion", "strength_potion", "invisibility_potion")
|
|
_SCROLL_KINDS = ("fireball_scroll", "teleport_scroll", "mapping_scroll")
|
|
for _k in _WEAPON_KINDS:
|
|
GRIDS[_k] = GRIDS["_weapon"]
|
|
for _k in _ARMOR_KINDS:
|
|
GRIDS[_k] = GRIDS["_armor"]
|
|
for _k in _POTION_KINDS:
|
|
GRIDS[_k] = GRIDS["_potion"]
|
|
for _k in _SCROLL_KINDS:
|
|
GRIDS[_k] = GRIDS["_scroll"]
|
|
|
|
# Per-kind accent tint applied to the 'a' marker (category hue + per-kind flavor).
|
|
TINTS: dict[str, tuple[int, int, int]] = {
|
|
"rusty_dagger": (170, 130, 80),
|
|
"short_sword": (210, 215, 225),
|
|
"battle_axe": (150, 155, 165),
|
|
"war_hammer": (120, 115, 130),
|
|
"leather_armor": (150, 110, 60),
|
|
"chain_armor": (120, 130, 145),
|
|
"chain_mail": (120, 130, 145),
|
|
"plate_armor": (170, 175, 190),
|
|
"healing_potion": (220, 80, 80),
|
|
"strength_potion": (230, 150, 60),
|
|
"invisibility_potion": (200, 160, 220),
|
|
"fireball_scroll": (240, 150, 60),
|
|
"teleport_scroll": (150, 120, 220),
|
|
"mapping_scroll": (90, 220, 220),
|
|
}
|