(Underdepths) Pass 7

This commit is contained in:
AlexKucera committed 2026-08-16 19:10:31 +02:00
1 parent 13512b0476
commit 952ff4b734
39 files changed
+7988

No files matched your search

View File
Whitespace-only changes.
+160
View File
@@ -0,0 +1,160 @@
from __future__ import annotations
from typing import Final
MAP_WIDTH: Final = 64
MAP_HEIGHT: Final = 40
MAP_BORDER: Final = 1
TILE_SIZE: Final = 16
TILE_WALL: Final = 0
TILE_FLOOR: Final = 1
ROOM_MIN_WIDTH: Final = 4
ROOM_MAX_WIDTH: Final = 10
ROOM_MIN_HEIGHT: Final = 4
ROOM_MAX_HEIGHT: Final = 8
ROOM_MARGIN: Final = 1
BSP_MIN_ROOMS: Final = 8
BSP_MAX_ROOMS: Final = 12
MAX_MAP_ATTEMPTS: Final = 100
MAX_CORRIDOR_LENGTH: Final = 14
JUNCTION_SIZE: Final = 3
FINAL_FLOOR: Final = 9
FPS: Final = 60
GAME_TITLE: Final = "Underdepths"
PLAYER_MAX_HP: Final = 50
PLAYER_POWER: Final = 4
PLAYER_ARMOR: Final = 0
PLAYER_ACCURACY: Final = 5
PLAYER_EVASION: Final = 2
PLAYER_CRIT_CHANCE: Final = 0.10
PLAYER_SPEED: Final = 1
# --- Progression (Phase 3) ---
MAX_LEVEL: Final = 10
# cumulative XP required to REACH level index+2 (index 0 = reach level 2)
XP_THRESHOLDS: Final[tuple[int, ...]] = (30, 70, 140, 250, 400, 600, 850, 1150, 1500)
# gains granted when reaching the level used as index (index 0 unused)
LEVEL_HP_GAINS: Final[tuple[int, ...]] = (0, 10, 10, 10, 10, 15, 15, 15, 15, 20)
LEVEL_POWER_GAINS: Final[tuple[int, ...]] = (0, 1, 1, 1, 1, 2, 2, 2, 2, 3)
# --- Items (Phase 3) ---
INVENTORY_MAX_SLOTS: Final = 26
MESSAGE_LOG_LIMIT: Final = 50
HEALING_POTION_HP: Final = 30
STRENGTH_POTION_BONUS: Final = 5
STRENGTH_POTION_TURNS: Final = 20
INVISIBILITY_POTION_TURNS: Final = 15
FIREBALL_DAMAGE: Final = 20
FIREBALL_RADIUS: Final = 3
BOW_RANGE: Final = 8
BOW_HIT_PENALTY_PER_TILE: Final = 0.03
PLATE_EVASION_PENALTY: Final = -2 # -10% hit-relevant evasion: 2 points * 5% each
WAR_HAMMER_CRIT_PENALTY: Final = -0.05
# --- Content layer (Phase 3) ---
BASE_ENEMIES_PER_FLOOR: Final = 4
ENEMIES_PER_FLOOR_STEP: Final = 2
ITEMS_PER_FLOOR: Final[dict[int, tuple[int, int]]] = {
0: (2, 3),
1: (3, 3), # includes the guaranteed Shoes of Hermes
2: (3, 4), # includes the guaranteed Hunter's Bow
3: (3, 4),
4: (3, 4),
5: (4, 5),
6: (4, 5),
7: (4, 5),
8: (5, 6),
}
FINAL_FLOOR_POTIONS: Final = 2 # healing potions placed near the arena entrance
DEEP_GEAR_FLOOR: Final = 6 # guaranteed heavy weapon so floor-9 armor 8 is penetrable: 4 + 7 > 8
# --- Boss arena (floor 9) ---
ARENA_WIDTH: Final = 20
ARENA_HEIGHT: Final = 15
ARENA_ENTRANCE_OFFSET: Final = 2
ARENA_DRAGON_OFFSET: Final = 3
DRAGON_KEY: Final = "ancient_dragon"
DRAGON_BREATH_PERIOD: Final = 3 # breaths instead of a normal action every Nth turn
DRAGON_BREATH_DAMAGE: Final = 15
DRAGON_BREATH_LENGTH: Final = 8
# --- Phase 4: persistence, held-run cadence, menu, audio ---
SAVE_FILE_NAME: Final = "save.json"
RUN_INITIAL_DELAY_MS: Final = 180
RUN_REPEAT_MS: Final = 75
MENU_LABEL_NEW_GAME: Final = "New Game"
MENU_LABEL_CONTINUE: Final = "Continue"
MENU_LABEL_HOW_TO_PLAY: Final = "How to Play"
MENU_LABEL_QUIT: Final = "Quit"
HOW_TO_PLAY: Final[tuple[str, ...]] = (
"1. Move with the arrow keys or HJKL; walk into a monster to attack it.",
"2. Stand on an item and press G to pick it up.",
"3. Stand on the glowing > stairs and press F to descend.",
"4. I: inventory E: equipment Q: quaff a potion R: read a scroll.",
"5. B: fire an equipped bow at the nearest visible foe.",
"6. Shoes of Hermes: hold a direction to run; every step is a full turn.",
"7. S: save and quit M: mute ?: this screen Esc: close menus.",
)
AUDIO_SAMPLE_RATE: Final = 22050
# effect key -> (frequency Hz, seconds, volume 0..1); quiet by design
AUDIO_TONES: Final[dict[str, tuple[int, float, float]]] = {
"hit": (196, 0.09, 0.5),
"miss": (140, 0.06, 0.3),
"hurt": (98, 0.14, 0.5),
"pickup": (660, 0.08, 0.35),
"stairs": (330, 0.16, 0.4),
"levelup": (784, 0.20, 0.4),
"death": (72, 0.32, 0.5),
"victory": (988, 0.35, 0.45),
}
Color = tuple[int, int, int]
COLORS: Final[dict[str, Color]] = {
"background": (8, 8, 12),
"wall": (60, 60, 70),
"floor": (40, 35, 30),
"player": (90, 170, 230),
"stairs": (245, 210, 70),
"text": (230, 230, 235),
}
# --- Phase 4b: viewport, panels, and render tuning ---
# map viewport in tiles; the camera scrolls inside larger floors
VIEWPORT_TILES_W: Final = 46
VIEWPORT_TILES_H: Final = 26
TOPBAR_HEIGHT: Final = 44
BOTTOMBAR_HEIGHT: Final = 60
SIDEBAR_WIDTH: Final = 320
WINDOW_WIDTH: Final = VIEWPORT_TILES_W * TILE_SIZE + SIDEBAR_WIDTH
WINDOW_HEIGHT: Final = TOPBAR_HEIGHT + VIEWPORT_TILES_H * TILE_SIZE + BOTTOMBAR_HEIGHT
# pixel-art animation (ms) — idle bob, hit flash, attack lunge, text rise
ANIM_HIT_FLASH_MS: Final = 130
ANIM_ATTACK_MS: Final = 160
ANIM_TEXT_MS: Final = 900
CAMERA_EASE_PER_S: Final = 8.0
SHAKE_DECAY_PER_S: Final = 2.6
MAX_PARTICLES: Final = 350
# torch-light falloff: visible tiles darken toward the sight radius edge
LIGHT_ALPHA_AT_EDGE: Final = 205
LIGHT_ALPHA_PER_TILE: Final = 24
EXPLORED_ALPHA: Final = 205
EXPLORED_TINT: Final[Color] = (6, 8, 20)
# UI panel chrome and bars (hand-tuned to the base palette)
UI_PANEL: Final[Color] = (13, 13, 21)
UI_PANEL_LIGHT: Final[Color] = (24, 24, 36)
UI_BORDER: Final[Color] = (110, 116, 136)
UI_BORDER_DARK: Final[Color] = (52, 55, 68)
UI_TEXT_DIM: Final[Color] = (150, 150, 162)
HP_BAR: Final[Color] = (96, 200, 96)
HP_BAR_LOW: Final[Color] = (214, 84, 70)
XP_BAR: Final[Color] = (120, 170, 250)
LOG_COMBAT: Final[Color] = (235, 235, 240)
LOG_DAMAGE: Final[Color] = (235, 110, 96)
LOG_GOOD: Final[Color] = (140, 225, 130)
LOG_ITEM: Final[Color] = (240, 210, 110)
LOG_INFO: Final[Color] = (170, 200, 210)
LOG_DEFAULT: Final[Color] = (196, 196, 206)
+187
View File
@@ -0,0 +1,187 @@
from __future__ import annotations
from dataclasses import dataclass
import random
from data.constants import BASE_ENEMIES_PER_FLOOR, ENEMIES_PER_FLOOR_STEP
from entities.enemy import Enemy
@dataclass(frozen=True, slots=True)
class EnemyTemplate:
key: str
name: str
sprite_key: str
hp: int
power: int
armor: int
accuracy: int
evasion: int
crit_chance: float
speed: int
behavior: str
ranged_power: int
xp_reward: int
min_floor: int
max_floor: int
ROSTER: dict[str, EnemyTemplate] = {
template.key: template
for template in (
EnemyTemplate(
key="rat",
name="Giant Rat",
sprite_key="rat",
hp=8,
power=3,
armor=0,
accuracy=2,
evasion=2,
crit_chance=0.0,
speed=1,
behavior="wander",
ranged_power=0,
xp_reward=5,
min_floor=0,
max_floor=3,
),
EnemyTemplate(
key="goblin",
name="Goblin",
sprite_key="goblin",
hp=15,
power=5,
armor=1,
accuracy=3,
evasion=1,
crit_chance=0.05,
speed=1,
behavior="chase",
ranged_power=0,
xp_reward=12,
min_floor=0,
max_floor=5,
),
EnemyTemplate(
key="skeleton_archer",
name="Skeleton Archer",
sprite_key="skeleton_archer",
hp=12,
power=4,
armor=1,
accuracy=4,
evasion=1,
crit_chance=0.05,
speed=1,
behavior="ranged",
ranged_power=6,
xp_reward=15,
min_floor=2,
max_floor=7,
),
EnemyTemplate(
key="orc_warrior",
name="Orc Warrior",
sprite_key="orc_warrior",
hp=30,
power=8,
armor=3,
accuracy=4,
evasion=0,
crit_chance=0.05,
speed=1,
behavior="flee",
ranged_power=0,
xp_reward=25,
min_floor=3,
max_floor=8,
),
EnemyTemplate(
key="wraith",
name="Wraith",
sprite_key="wraith",
hp=20,
power=10,
armor=0,
accuracy=4,
evasion=2,
crit_chance=0.05,
speed=2,
behavior="phase",
ranged_power=0,
xp_reward=30,
min_floor=5,
max_floor=8,
),
EnemyTemplate(
key="green_slime",
name="Green Slime",
sprite_key="green_slime",
hp=18,
power=5,
armor=1,
accuracy=3,
evasion=0,
crit_chance=0.0,
speed=1,
behavior="split",
ranged_power=0,
xp_reward=18,
min_floor=4,
max_floor=8,
),
EnemyTemplate(
key="ancient_dragon",
name="Ancient Dragon",
sprite_key="ancient_dragon",
hp=120,
power=15,
armor=8,
accuracy=6,
evasion=0,
crit_chance=0.10,
speed=1,
behavior="chase",
ranged_power=0,
xp_reward=200,
min_floor=9,
max_floor=9,
),
)
}
def spawn_enemy(key: str, x: int, y: int) -> Enemy:
template = ROSTER[key]
return Enemy(
x=x,
y=y,
key=template.key,
name=template.name,
sprite_key=template.sprite_key,
hp=template.hp,
max_hp=template.hp,
power=template.power,
armor=template.armor,
accuracy=template.accuracy,
evasion=template.evasion,
crit_chance=template.crit_chance,
speed=template.speed,
behavior=template.behavior,
ranged_power=template.ranged_power,
xp_reward=template.xp_reward,
)
def enemy_count_for_floor(floor_index: int) -> int:
return BASE_ENEMIES_PER_FLOOR + ENEMIES_PER_FLOOR_STEP * floor_index
def roll_floor_enemies(floor_index: int, rng: random.Random) -> list[str]:
eligible = [
template.key
for template in ROSTER.values()
if template.min_floor <= floor_index <= template.max_floor
]
return [rng.choice(eligible) for _ in range(enemy_count_for_floor(floor_index))]
+233
View File
@@ -0,0 +1,233 @@
from __future__ import annotations
from dataclasses import dataclass
import random
from data.constants import (
BOW_RANGE,
DEEP_GEAR_FLOOR,
FINAL_FLOOR,
FINAL_FLOOR_POTIONS,
FIREBALL_DAMAGE,
FIREBALL_RADIUS,
HEALING_POTION_HP,
INVISIBILITY_POTION_TURNS,
ITEMS_PER_FLOOR,
PLATE_EVASION_PENALTY,
STRENGTH_POTION_BONUS,
STRENGTH_POTION_TURNS,
WAR_HAMMER_CRIT_PENALTY,
)
from entities.item import Item
@dataclass(frozen=True, slots=True)
class ItemTemplate:
key: str
name: str
category: str
power: int = 0
armor_bonus: int = 0
evasion_mod: int = 0
crit_mod: float = 0.0
ranged_range: int = 0
enables_running: bool = False
heal_amount: int = 0
effect: str = ""
effect_power: int = 0
effect_turns: int = 0
aoe_damage: int = 0
aoe_radius: int = 0
min_floor: int = 0
max_floor: int = 0
guaranteed_only: bool = False
CATALOG: dict[str, ItemTemplate] = {
template.key: template
for template in (
ItemTemplate(
key="rusty_dagger",
name="Rusty Dagger",
category="weapon",
power=2,
min_floor=0,
max_floor=2,
),
ItemTemplate(
key="short_sword",
name="Short Sword",
category="weapon",
power=4,
min_floor=1,
max_floor=4,
),
ItemTemplate(
key="hunters_bow",
name="Hunter's Bow",
category="weapon",
power=4,
ranged_range=BOW_RANGE,
min_floor=2,
max_floor=8,
),
ItemTemplate(
key="battle_axe",
name="Battle Axe",
category="weapon",
power=7,
min_floor=4,
max_floor=8,
),
ItemTemplate(
key="war_hammer",
name="War Hammer",
category="weapon",
power=10,
crit_mod=WAR_HAMMER_CRIT_PENALTY,
min_floor=6,
max_floor=8,
),
ItemTemplate(
key="leather_armor",
name="Leather Armor",
category="armor",
armor_bonus=2,
min_floor=0,
max_floor=3,
),
ItemTemplate(
key="chain_mail",
name="Chain Mail",
category="armor",
armor_bonus=4,
min_floor=3,
max_floor=6,
),
ItemTemplate(
key="plate_armor",
name="Plate Armor",
category="armor",
armor_bonus=7,
evasion_mod=PLATE_EVASION_PENALTY,
min_floor=5,
max_floor=8,
),
ItemTemplate(
key="healing_potion",
name="Healing Potion",
category="potion",
effect="heal",
heal_amount=HEALING_POTION_HP,
min_floor=0,
max_floor=8,
),
ItemTemplate(
key="strength_potion",
name="Strength Potion",
category="potion",
effect="strength",
effect_power=STRENGTH_POTION_BONUS,
effect_turns=STRENGTH_POTION_TURNS,
min_floor=0,
max_floor=8,
),
ItemTemplate(
key="invisibility_potion",
name="Invisibility Potion",
category="potion",
effect="invisible",
effect_turns=INVISIBILITY_POTION_TURNS,
min_floor=0,
max_floor=8,
),
ItemTemplate(
key="fireball_scroll",
name="Scroll of Fireball",
category="scroll",
effect="fireball",
aoe_damage=FIREBALL_DAMAGE,
aoe_radius=FIREBALL_RADIUS,
min_floor=0,
max_floor=8,
),
ItemTemplate(
key="teleport_scroll",
name="Scroll of Teleport",
category="scroll",
effect="teleport",
min_floor=0,
max_floor=8,
),
ItemTemplate(
key="mapping_scroll",
name="Scroll of Mapping",
category="scroll",
effect="mapping",
min_floor=0,
max_floor=8,
),
ItemTemplate(
key="shoes_of_hermes",
name="Shoes of Hermes",
category="boots",
enables_running=True,
min_floor=1,
max_floor=1,
guaranteed_only=True,
),
)
}
def spawn_item(key: str, x: int, y: int) -> Item:
template = CATALOG[key]
return Item(
x=x,
y=y,
key=template.key,
name=template.name,
sprite_key=f"item_{template.key}",
category=template.category,
power=template.power,
armor_bonus=template.armor_bonus,
evasion_mod=template.evasion_mod,
crit_mod=template.crit_mod,
ranged_range=template.ranged_range,
enables_running=template.enables_running,
heal_amount=template.heal_amount,
effect=template.effect,
effect_power=template.effect_power,
effect_turns=template.effect_turns,
aoe_damage=template.aoe_damage,
aoe_radius=template.aoe_radius,
)
def _random_pool(floor_index: int) -> list[str]:
return [
template.key
for template in CATALOG.values()
if not template.guaranteed_only
and template.min_floor <= floor_index <= template.max_floor
and not (template.key == "hunters_bow" and floor_index <= 2)
]
def roll_floor_items(floor_index: int, rng: random.Random) -> list[str]:
"""Item keys for a floor; guaranteed items replace ordinary rolls."""
if floor_index == FINAL_FLOOR:
return ["healing_potion"] * FINAL_FLOOR_POTIONS
low, high = ITEMS_PER_FLOOR[floor_index]
keys: list[str] = []
if floor_index == 1:
keys.append("shoes_of_hermes")
elif floor_index == 2:
keys.append("hunters_bow")
elif floor_index == DEEP_GEAR_FLOOR:
keys.append("battle_axe") # guaranteed answer to the dragon's armor 8
pool = _random_pool(floor_index)
while len(keys) < rng.randint(low, high):
keys.append(rng.choice(pool))
return keys
File diff suppressed because it is too large. Load diff