-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug_sprites.py
More file actions
184 lines (143 loc) · 7.68 KB
/
Copy pathdebug_sprites.py
File metadata and controls
184 lines (143 loc) · 7.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
import pygame
import constants
import os
import fx
def run_viewer():
pygame.init()
WIN_W, WIN_H = 1024, 768
screen = pygame.display.set_mode((WIN_W, WIN_H))
pygame.display.set_caption("Z80-Dungeon - Animation & Paper Flip")
clock = pygame.time.Clock()
# Police principale pour les titres
font = pygame.font.Font("assets/fonts/PressStart2P.ttf", 14)
# Nouvelle police plus petite pour les noms de sprites
font_small = pygame.font.Font("assets/fonts/PressStart2P.ttf", 8)
# 1. Chargement
path_dungeon = "assets/0x72_DungeonTilesetII_v1.7/0x72_DungeonTilesetII_v1.7.png"
path_textures = "assets/Textures16x16ByAndrox/ALL_content.png"
path_ui = "assets/Buttons16x16.png"
sheet_dungeon = pygame.image.load(path_dungeon).convert_alpha()
sheet_textures = pygame.image.load(path_textures).convert_alpha() if os.path.exists(path_textures) else sheet_dungeon
sheet_ui = pygame.image.load(path_ui).convert_alpha()
scroll_y = 0
# --- VARIABLES D'ANIMATION ---
anim_timer = 0
flip_val = 1.0 # 1.0 = Droite, -1.0 = Gauche
flip_dir = -1
flip_state = "IDLE" # États : "IDLE" ou "FLIPPING"
wait_timer = 0 # Compteur pour les 10 secondes
# --- VARIABLES DE DEBUG ---
show_guides = True # True = on affiche, False = on cache
running = True
while running:
dt = clock.tick(60) # Delta time en ms
anim_timer += dt
# --- LOGIQUE PAPER FLIP (Attente 10s + Flip rapide) ---
if flip_state == "IDLE":
wait_timer += dt
if wait_timer >= 5000: # 10 000 ms = 10 secondes
flip_state = "FLIPPING"
wait_timer = 0
elif flip_state == "FLIPPING":
# On effectue le flip assez vite (400ms pour le mouvement)
speed = (dt / 400)
if flip_val > -1.0 and flip_dir == -1: # On va vers la gauche
flip_val -= speed
if flip_val <= -1.0:
flip_val = -1.0
flip_dir = 1 # Prochain mouvement sera vers la droite
flip_state = "IDLE"
elif flip_val < 1.0 and flip_dir == 1: # On va vers la droite
flip_val += speed
if flip_val >= 1.0:
flip_val = 1.0
flip_dir = -1 # Prochain mouvement sera vers la gauche
flip_state = "IDLE"
# Inputs (Gestion du scroll inchangée)
keys = pygame.key.get_pressed()
if keys[pygame.K_UP]: scroll_y += 20
if keys[pygame.K_DOWN]: scroll_y -= 20
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
# --- DETECTION DES TOUCHES (CLAVIER) ---
if event.type == pygame.KEYDOWN:
# Bascule de l'affichage des guides
if event.key == pygame.K_h:
show_guides = not show_guides
# Quitter le programme
if event.key == pygame.K_q:
running = False
# Gestion souris (scroll)
if event.type == pygame.MOUSEBUTTONDOWN:
if event.button == 4: scroll_y += 40
if event.button == 5: scroll_y -= 40
hauteur_totale_estimee = len(constants.SPRITE_THEMES) * 450
max_scroll = -(hauteur_totale_estimee - WIN_H)
if scroll_y > 0: scroll_y = 0
if scroll_y < max_scroll: scroll_y = max_scroll
screen.fill((30, 30, 35))
current_y = 80 + scroll_y
for theme_name, sprites in constants.SPRITE_THEMES.items():
if not sprites: continue
fx.draw_text_aligned(screen, f"--- {theme_name} ---", font, constants.COLOR_YELLOW, (WIN_W // 2, current_y - 60), anchor="center")
current_x = 40
floor_y = current_y + 80
for name, data in sprites.items():
r = data["rect"]
frames_count = data["frames"]
# --- CALCUL DE LA FRAME ACTUELLE ---
# On change de frame toutes les 150ms
current_f = (anim_timer // 150) % frames_count
# On calcule le retour à la ligne
if current_x + (r[2] * 4) > 980:
current_x = 40
current_y += 180
floor_y = current_y + 80
# Dessin de la ligne rouge uniquement si activé
if show_guides and -50 < floor_y < WIN_H + 50:
pygame.draw.line(screen, (255, 50, 50), (20, floor_y), (1000, floor_y), 2)
active_sheet = sheet_textures if theme_name == "DECORS" else sheet_dungeon
# --- EXTRACTION ET TRANSFORMATION ---
src_rect = pygame.Rect(r[0] + (current_f * r[2]), r[1], r[2], r[3])
try:
sprite_surf = active_sheet.subsurface(src_rect)
# --- NOUVEAU : On vérifie si c'est un personnage ---
is_character = (theme_name != "DECORS")
# On n'applique flip_val que si c'est un perso
current_flip = flip_val if is_character else 1.0
w_orig, h_orig = r[2], r[3]
target_w = max(1, int(w_orig * abs(current_flip)))
# Scale Paper Flip
scaled = pygame.transform.scale(sprite_surf, (target_w, h_orig))
# Miroir uniquement pour les persos qui regardent à gauche
if is_character and current_flip < 0:
scaled = pygame.transform.flip(scaled, True, False)
final_surf = pygame.transform.scale(scaled, (target_w * 4, h_orig * 4))
# Rendu : Centré pour les persos, fixe pour les textures
if is_character:
pos_x = current_x + (w_orig * 2) - (final_surf.get_width() // 2)
else:
pos_x = current_x
pos_y = floor_y - (h_orig * 4)
if -h_orig*4 < pos_y < WIN_H:
screen.blit(final_surf, (pos_x, pos_y))
# Hitbox uniquement pour persos si activé
if is_character and show_guides:
hb_w, hb_h = 10*4, 4*4
pygame.draw.rect(screen, (0, 255, 0), (current_x + (w_orig*4-hb_w)//2, floor_y - hb_h, hb_w, hb_h), 1)
except: pass
fx.draw_text_retro(screen, name, font_small, (200, 200, 200), (current_x, floor_y + 10))
current_x += (r[2] * 4) + 80 # Espace réduit car on anime sur place
current_y += 220
# --- DESSIN DE L'INTERFACE (UI) ---
# On vérifie si la touche est actuellement pressée pour l'effet "actif"
keys = pygame.key.get_pressed()
# Affichage des boutons
fx.draw_button_tip(screen, sheet_ui, constants.UI_BUTTONS["KEY_H"], keys[pygame.K_h],
font, "Afficher Guides", (WIN_W - 300, 10))
fx.draw_button_tip(screen, sheet_ui, constants.UI_BUTTONS["KEY_Q"], keys[pygame.K_q],
font, "Quitter", (WIN_W - 300, 45))
pygame.display.flip()
pygame.quit()
if __name__ == "__main__": run_viewer()