-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhouse.py
More file actions
802 lines (702 loc) · 36.4 KB
/
Copy pathhouse.py
File metadata and controls
802 lines (702 loc) · 36.4 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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
# ============================================
# house.py - Mapa de la casa y fase de recolección
# ============================================
import pygame
import random
import math
from config import (
TILE_SIZE, MAP_COLS, MAP_ROWS, MAP_WIDTH, MAP_HEIGHT,
SCREEN_WIDTH, SCREEN_HEIGHT,
HOUSE_MAP, FURNITURE, FURNITURE_BLOCKED, ROOMS,
TILE_FLOOR, TILE_WALL, TILE_PATIO, TILE_BUNKER,
WALL_COLOR, WALL_TOP_COLOR, FLOOR_PATIO, FLOOR_LIVING,
BED_COLOR, BED_PILLOW, DESK_COLOR, LAMP_COLOR, LAMP_GLOW,
STOVE_COLOR, FRIDGE_COLOR, TABLE_COLOR, CHAIR_COLOR,
TUB_COLOR, TUB_INNER, TOILET_COLOR, SINK_COLOR,
SOFA_COLOR, TV_COLOR, TV_SCREEN, ARMCHAIR_COLOR,
BOX_COLOR, BOX_TAPE, BUNKER_ENTRANCE,
BOOK_COLORS, PICKUP_DISTANCE,
TIMER_COLOR, WHITE, BLACK, DARK_GRAY, LIGHT_GRAY,
STATE_BUNKER, STATE_ENDING, ENDING_TIMEOUT,
)
from entities import Player, Book, Camera, Inventory
# ============================================
# POSICIONES CLAVE DEL MAPA
# ============================================
# Búnker: columna 9, fila 2 (zona del patio, arriba)
BUNKER_COL = 9
BUNKER_ROW = 2
# Jugador inicia en la puerta principal (abajo centro)
PLAYER_START_COL = 9
PLAYER_START_ROW = 17
# Tiempo en segundos para el efecto de gas verde
GAS_START_TIME = 7
# Duración del congelamiento al acabarse el tiempo
FREEZE_DURATION = 3.0
# ============================================
# DECORACION INTERIOR
# ============================================
ROOM_TINTS = {
"Bano": (190, 235, 235, 18),
"Sala": (232, 218, 196, 16),
"Recamara 1": (204, 220, 242, 14),
"Cocina": (243, 233, 205, 18),
"Recamara 2": (214, 226, 242, 14),
}
def _to_screen_rect(col, row, width_tiles, height_tiles, cam_x, cam_y, inset=0):
return pygame.Rect(
int(col * TILE_SIZE - cam_x + inset),
int(row * TILE_SIZE - cam_y + inset),
int(width_tiles * TILE_SIZE - inset * 2),
int(height_tiles * TILE_SIZE - inset * 2),
)
def _draw_plant(surface, x, y, scale=1.0):
pot_w = int(18 * scale)
pot_h = int(12 * scale)
leaf_h = int(22 * scale)
pot = pygame.Rect(x - pot_w // 2, y, pot_w, pot_h)
pygame.draw.rect(surface, (124, 84, 45), pot, border_radius=3)
pygame.draw.rect(surface, (88, 58, 28), pot, 2, border_radius=3)
pygame.draw.rect(surface, (54, 132, 68), (x - 4, y - leaf_h, 8, leaf_h), border_radius=4)
pygame.draw.circle(surface, (62, 162, 78), (x - 9, y - leaf_h // 2), 6)
pygame.draw.circle(surface, (74, 178, 92), (x + 8, y - leaf_h // 2), 6)
def _draw_rug(surface, rect, base_color, accent_color):
pygame.draw.rect(surface, (0, 0, 0), rect.move(3, 4), border_radius=8)
pygame.draw.rect(surface, base_color, rect, border_radius=8)
pygame.draw.rect(surface, accent_color, rect, 2, border_radius=8)
inner = rect.inflate(-rect.width // 6, -rect.height // 6)
pygame.draw.rect(surface, accent_color, inner, 1, border_radius=6)
def _draw_picture(surface, rect, frame_color, art_color):
pygame.draw.rect(surface, (0, 0, 0), rect.move(3, 4), border_radius=3)
pygame.draw.rect(surface, frame_color, rect, border_radius=3)
pygame.draw.rect(surface, (80, 60, 40), rect, 2, border_radius=3)
inner = rect.inflate(-8, -8)
pygame.draw.rect(surface, art_color, inner, border_radius=2)
pygame.draw.line(surface, (230, 230, 230), (inner.left + 4, inner.bottom - 5), (inner.right - 4, inner.top + 5), 1)
def _draw_board(surface, rect, board_color=(56, 83, 76), line_color=(220, 240, 220)):
pygame.draw.rect(surface, (0, 0, 0), rect.move(3, 3), border_radius=4)
pygame.draw.rect(surface, board_color, rect, border_radius=4)
pygame.draw.rect(surface, (30, 40, 36), rect, 2, border_radius=4)
for i in range(3):
y = rect.top + 8 + i * 12
pygame.draw.line(surface, line_color, (rect.left + 8, y), (rect.right - 8, y), 1)
def _draw_laptop(surface, rect):
screen = pygame.Rect(rect.left + 2, rect.top + 2, rect.width - 4, rect.height - 8)
base = pygame.Rect(rect.left, rect.bottom - 8, rect.width, 8)
pygame.draw.rect(surface, (32, 32, 40), screen, border_radius=2)
pygame.draw.rect(surface, (90, 155, 220), screen.inflate(-6, -6), border_radius=1)
pygame.draw.rect(surface, (52, 52, 60), base, border_radius=2)
pygame.draw.rect(surface, (20, 20, 24), rect, 1, border_radius=2)
def _draw_books(surface, x, y, count=3):
palette = [
BOOK_COLORS["green"],
BOOK_COLORS["blue"],
BOOK_COLORS["red"],
BOOK_COLORS["purple"],
BOOK_COLORS["yellow"],
BOOK_COLORS["darkbrown"],
]
for i in range(count):
bx = x + i * 10
book = pygame.Rect(bx, y - i * 2, 8, 16)
color = palette[i % len(palette)]
pygame.draw.rect(surface, color, book, border_radius=1)
pygame.draw.rect(
surface,
(max(0, color[0] - 40), max(0, color[1] - 40), max(0, color[2] - 40)),
book,
1,
border_radius=1,
)
pygame.draw.line(surface, WHITE, (book.left + 2, book.top + 4), (book.right - 2, book.top + 4), 1)
def draw_interior_decor(surface, cam_x, cam_y):
"""Agrega decoracion fija para dar mas riqueza visual al interior."""
view_w = surface.get_width()
view_h = surface.get_height()
overlays = pygame.Surface((view_w, view_h), pygame.SRCALPHA)
for cmin, cmax, rmin, rmax, _, room_name in ROOMS:
tint = ROOM_TINTS.get(room_name)
if not tint:
continue
room_rect = _to_screen_rect(cmin, rmin, cmax - cmin + 1, rmax - rmin + 1, cam_x, cam_y)
if room_rect.right < 0 or room_rect.left > view_w or room_rect.bottom < 0 or room_rect.top > view_h:
continue
pygame.draw.rect(overlays, tint, room_rect)
border = (max(0, tint[0] - 35), max(0, tint[1] - 35), max(0, tint[2] - 35), 28)
pygame.draw.rect(overlays, border, room_rect, 1)
surface.blit(overlays, (0, 0))
# ============================================
# FUNCIONES DE DIBUJO DEL MAPA
# ============================================
def get_floor_color(col, row):
"""Obtiene el color del piso según la habitación."""
for cmin, cmax, rmin, rmax, color, _ in ROOMS:
if cmin <= col <= cmax and rmin <= row <= rmax:
return color
# Si es patio
if HOUSE_MAP[row][col] == TILE_PATIO or HOUSE_MAP[row][col] == TILE_BUNKER:
return FLOOR_PATIO
# Pasillos y puertas
return FLOOR_LIVING
def get_room_name(col, row):
"""Obtiene el nombre de la habitación en la posición dada."""
for cmin, cmax, rmin, rmax, _, name in ROOMS:
if cmin <= col <= cmax and rmin <= row <= rmax:
return name
if 1 <= row <= 3:
return "Patio"
return ""
def draw_map(surface, cam_x, cam_y):
"""Dibuja el mapa de la casa (tiles)."""
view_w = surface.get_width()
view_h = surface.get_height()
start_col = max(0, int(cam_x // TILE_SIZE))
end_col = min(MAP_COLS, int((cam_x + view_w) // TILE_SIZE) + 2)
start_row = max(0, int(cam_y // TILE_SIZE))
end_row = min(MAP_ROWS, int((cam_y + view_h) // TILE_SIZE) + 2)
for row in range(start_row, end_row):
for col in range(start_col, end_col):
tile = HOUSE_MAP[row][col]
sx = int(col * TILE_SIZE - cam_x)
sy = int(row * TILE_SIZE - cam_y)
rect = pygame.Rect(sx, sy, TILE_SIZE, TILE_SIZE)
if tile == TILE_WALL:
pygame.draw.rect(surface, WALL_COLOR, rect)
pygame.draw.rect(surface, WALL_TOP_COLOR,
(sx, sy, TILE_SIZE, 4))
pygame.draw.rect(surface, (78, 52, 26),
(sx, sy + TILE_SIZE - 4, TILE_SIZE, 4))
pygame.draw.line(surface, WALL_TOP_COLOR,
(sx, sy + TILE_SIZE // 2),
(sx + TILE_SIZE, sy + TILE_SIZE // 2), 1)
if row % 2 == 0:
pygame.draw.line(surface, WALL_TOP_COLOR,
(sx + TILE_SIZE // 2, sy),
(sx + TILE_SIZE // 2, sy + TILE_SIZE // 2), 1)
else:
pygame.draw.line(surface, WALL_TOP_COLOR,
(sx + TILE_SIZE // 4, sy + TILE_SIZE // 2),
(sx + TILE_SIZE // 4, sy + TILE_SIZE), 1)
pygame.draw.line(surface, WALL_TOP_COLOR,
(sx + 3 * TILE_SIZE // 4, sy + TILE_SIZE // 2),
(sx + 3 * TILE_SIZE // 4, sy + TILE_SIZE), 1)
elif tile == TILE_PATIO:
pygame.draw.rect(surface, FLOOR_PATIO, rect)
for i in range(3):
gx = sx + 10 + i * 14
gy = sy + 15 + (i * 7) % 20
pygame.draw.line(surface, (60, 140, 60),
(gx, gy), (gx - 2, gy - 6), 1)
pygame.draw.line(surface, (60, 140, 60),
(gx, gy), (gx + 2, gy - 5), 1)
elif tile == TILE_BUNKER:
pygame.draw.rect(surface, FLOOR_PATIO, rect)
bunker_rect = pygame.Rect(sx + 4, sy + 4, TILE_SIZE - 8, TILE_SIZE - 8)
pygame.draw.rect(surface, BUNKER_ENTRANCE, bunker_rect, border_radius=3)
pygame.draw.rect(surface, (130, 130, 145), bunker_rect, 2, border_radius=3)
pygame.draw.circle(surface, (160, 160, 170),
(sx + TILE_SIZE - 14, sy + TILE_SIZE // 2), 4)
pygame.draw.circle(surface, DARK_GRAY,
(sx + TILE_SIZE - 14, sy + TILE_SIZE // 2), 4, 1)
font_small = pygame.font.SysFont("Arial", 9, bold=True)
label = font_small.render("BUNKER", True, (200, 200, 210))
surface.blit(label, (sx + 6, sy + 6))
else:
floor_color = get_floor_color(col, row)
pygame.draw.rect(surface, floor_color, rect)
if (col * 7 + row * 11) % 5 == 0:
speck = (min(255, floor_color[0] + 6),
min(255, floor_color[1] + 6),
min(255, floor_color[2] + 6))
pygame.draw.circle(surface, speck, (sx + 18, sy + 17), 1)
if (col * 5 + row * 13) % 7 == 0:
speck = (max(0, floor_color[0] - 5),
max(0, floor_color[1] - 5),
max(0, floor_color[2] - 5))
pygame.draw.circle(surface, speck, (sx + 42, sy + 38), 1)
# --- Dibujar puerta principal (en row 18, cols 9-10) ---
# Vista: marco de puerta de madera en la pared inferior
for dc in range(2):
door_col = 9 + dc
door_sx = int(door_col * TILE_SIZE - cam_x)
door_sy = int(18 * TILE_SIZE - cam_y)
if -TILE_SIZE < door_sx < SCREEN_WIDTH and -TILE_SIZE < door_sy < SCREEN_HEIGHT:
# Piso del doorway
pygame.draw.rect(surface, FLOOR_LIVING,
(door_sx, door_sy, TILE_SIZE, TILE_SIZE))
# Marco de la puerta
pygame.draw.rect(surface, (100, 60, 25),
(door_sx, door_sy, TILE_SIZE, TILE_SIZE), 3)
def draw_furniture(surface, cam_x, cam_y):
"""Dibuja todos los muebles de la casa."""
view_w = surface.get_width()
view_h = surface.get_height()
for fc, fr, fw, fh, fcolor, fname in FURNITURE:
sx = int(fc * TILE_SIZE - cam_x)
sy = int(fr * TILE_SIZE - cam_y)
w = fw * TILE_SIZE
h = fh * TILE_SIZE
if sx + w < 0 or sx > view_w or sy + h < 0 or sy > view_h:
continue
rect = pygame.Rect(sx + 2, sy + 2, w - 4, h - 4)
shadow = rect.move(4, 5)
pygame.draw.rect(surface, (0, 0, 0), shadow, border_radius=rect.width // 8)
if fname == "cama":
pygame.draw.rect(surface, fcolor, rect, border_radius=4)
pygame.draw.rect(surface, (max(0, fcolor[0]-30), max(0, fcolor[1]-30),
max(0, fcolor[2]-30)), rect, 2, border_radius=4)
pillow = pygame.Rect(sx + 8, sy + 6, w - 16, h // 4)
pygame.draw.rect(surface, BED_PILLOW, pillow, border_radius=3)
pygame.draw.rect(surface, (210, 220, 235), pillow, 1, border_radius=3)
pygame.draw.rect(surface, (max(0, fcolor[0]-45), max(0, fcolor[1]-45),
max(0, fcolor[2]-45)),
(sx + 4, sy + 4, w - 8, h - 8), 1, border_radius=4)
for i in range(3):
ly = sy + h // 3 + i * (h // 5)
pygame.draw.line(surface, (max(0, fcolor[0]-15), max(0, fcolor[1]-15),
max(0, fcolor[2]-15)),
(sx + 6, ly), (sx + w - 6, ly), 1)
elif fname == "escritorio":
pygame.draw.rect(surface, fcolor, rect, border_radius=2)
pygame.draw.rect(surface, (max(0, fcolor[0]-30), max(0, fcolor[1]-30),
max(0, fcolor[2]-30)), rect, 2, border_radius=2)
pygame.draw.rect(surface, (min(255, fcolor[0]+20), min(255, fcolor[1]+20),
min(255, fcolor[2]+20)),
(sx + 4, sy + 2, w - 8, 4))
monitor = pygame.Rect(sx + w // 3, sy + 4, w // 3, h // 2)
pygame.draw.rect(surface, (35, 40, 50), monitor, border_radius=2)
pygame.draw.rect(surface, (90, 155, 220), monitor.inflate(-6, -6), border_radius=1)
pygame.draw.rect(surface, (75, 75, 85), (sx + w // 2 - 3, sy + h // 2, 6, 10))
pygame.draw.rect(surface, (65, 65, 72), (sx + 6, sy + h - 10, w - 12, 6), border_radius=2)
for i in range(2):
pygame.draw.line(surface, (230, 230, 230), (sx + 8, sy + h - 16 + i * 4), (sx + w - 8, sy + h - 16 + i * 4), 1)
pygame.draw.rect(surface, (225, 220, 190), (sx + 6, sy + h - 18, 10, 6), border_radius=1)
pygame.draw.rect(surface, (120, 80, 50), (sx + w - 14, sy + h - 18, 6, 6), border_radius=1)
elif fname == "lampara":
pygame.draw.rect(surface, DARK_GRAY, (sx + TILE_SIZE//3, sy + TILE_SIZE//2,
TILE_SIZE//3, TILE_SIZE//2 - 4))
pygame.draw.circle(surface, LAMP_COLOR,
(sx + TILE_SIZE//2, sy + TILE_SIZE//3), TILE_SIZE//4)
pygame.draw.circle(surface, LAMP_GLOW,
(sx + TILE_SIZE//2, sy + TILE_SIZE//3), TILE_SIZE//6)
pygame.draw.circle(surface, (255, 245, 180), (sx + TILE_SIZE//2, sy + TILE_SIZE//3), TILE_SIZE//8)
elif fname == "estufa":
pygame.draw.rect(surface, fcolor, rect, border_radius=2)
pygame.draw.rect(surface, (80, 80, 80), rect, 2, border_radius=2)
for i in range(2):
cx = sx + TILE_SIZE // 2 + i * (TILE_SIZE - 10) - 5
cy = sy + TILE_SIZE // 2
pygame.draw.circle(surface, (60, 60, 60), (cx, cy), 8)
pygame.draw.circle(surface, (80, 80, 80), (cx, cy), 8, 1)
pygame.draw.rect(surface, (35, 35, 35), (sx + 6, sy + 6, w - 12, h - 12), 1)
elif fname == "refrigerador":
pygame.draw.rect(surface, fcolor, rect, border_radius=3)
pygame.draw.rect(surface, (180, 185, 190), rect, 2, border_radius=3)
pygame.draw.rect(surface, (160, 160, 170),
(sx + w - 10, sy + h // 4, 4, h // 3), border_radius=2)
pygame.draw.line(surface, (190, 195, 200),
(sx + 4, sy + h // 3), (sx + w - 4, sy + h // 3), 2)
pygame.draw.line(surface, (245, 245, 245), (sx + 7, sy + 6), (sx + 7, sy + h - 6), 1)
elif fname == "mesa":
pygame.draw.rect(surface, fcolor, rect, border_radius=3)
pygame.draw.rect(surface, (max(0, fcolor[0]-30), max(0, fcolor[1]-30),
max(0, fcolor[2]-30)), rect, 2, border_radius=3)
pygame.draw.rect(surface, (min(255, fcolor[0]+20), min(255, fcolor[1]+20),
min(255, fcolor[2]+20)),
(sx + 5, sy + 4, w - 10, 6), border_radius=2)
pygame.draw.circle(surface, (220, 210, 180), (sx + 15, sy + 12), 4)
pygame.draw.circle(surface, (220, 210, 180), (sx + w - 16, sy + 12), 4)
pygame.draw.rect(surface, (240, 235, 220), (sx + w // 2 - 8, sy + h // 2 - 6, 16, 10), border_radius=2)
pygame.draw.line(surface, (150, 120, 80), (sx + w // 2 - 5, sy + h // 2 - 2), (sx + w // 2 + 5, sy + h // 2 - 2), 1)
elif fname == "silla":
pygame.draw.rect(surface, fcolor, rect, border_radius=2)
pygame.draw.rect(surface, (max(0, fcolor[0]-25), max(0, fcolor[1]-25),
max(0, fcolor[2]-25)), rect, 2, border_radius=2)
pygame.draw.rect(surface, (max(0, fcolor[0]-15), max(0, fcolor[1]-15),
max(0, fcolor[2]-15)),
(sx + 4, sy + 2, w - 8, 8), border_radius=2)
pygame.draw.line(surface, (70, 45, 25), (sx + 6, sy + h - 2), (sx + 6, sy + h + 6), 2)
pygame.draw.line(surface, (70, 45, 25), (sx + w - 6, sy + h - 2), (sx + w - 6, sy + h + 6), 2)
elif fname == "tina":
pygame.draw.rect(surface, fcolor, rect, border_radius=6)
inner = rect.inflate(-10, -10)
pygame.draw.rect(surface, TUB_INNER, inner, border_radius=4)
pygame.draw.rect(surface, (150, 190, 210), rect, 2, border_radius=6)
pygame.draw.arc(surface, (170, 210, 225), inner, 3.0, 6.0, 2)
elif fname == "retrete":
pygame.draw.rect(surface, fcolor, rect, border_radius=8)
pygame.draw.rect(surface, (200, 200, 200), rect, 2, border_radius=8)
pygame.draw.ellipse(surface, (230, 230, 235),
(sx + 6, sy + 6, w - 16, h - 12))
pygame.draw.ellipse(surface, (210, 210, 220), (sx + 8, sy + 8, w - 20, h - 16), 2)
elif fname == "lavabo":
pygame.draw.rect(surface, fcolor, rect, border_radius=4)
pygame.draw.rect(surface, (170, 170, 180), rect, 2, border_radius=4)
pygame.draw.circle(surface, (150, 155, 160),
(sx + TILE_SIZE // 2, sy + 10), 4)
pygame.draw.rect(surface, (130, 130, 140), (sx + w // 2 - 2, sy + 6, 4, 8))
pygame.draw.circle(surface, (110, 110, 120), (sx + w // 2, sy + 16), 2)
elif fname == "sofa":
pygame.draw.rect(surface, fcolor, rect, border_radius=5)
pygame.draw.rect(surface, (max(0, fcolor[0]-30), max(0, fcolor[1]-30),
max(0, fcolor[2]-30)), rect, 2, border_radius=5)
for i in range(1, fw):
lx = sx + i * TILE_SIZE
pygame.draw.line(surface, (max(0, fcolor[0]-20), max(0, fcolor[1]-20),
max(0, fcolor[2]-20)),
(lx, sy + 4), (lx, sy + h - 4), 1)
pygame.draw.rect(surface, (min(255, fcolor[0]+20), min(255, fcolor[1]+20), min(255, fcolor[2]+20)),
(sx + 8, sy + 6, w - 16, h // 2), border_radius=4)
pygame.draw.circle(surface, (110, 20, 20), (sx + 18, sy + 16), 4)
pygame.draw.circle(surface, (110, 20, 20), (sx + w - 18, sy + 16), 4)
pygame.draw.rect(surface, (240, 200, 170), (sx + 10, sy + 8, 14, 10), border_radius=3)
pygame.draw.rect(surface, (240, 200, 170), (sx + w - 24, sy + 8, 14, 10), border_radius=3)
elif fname == "TV":
pygame.draw.rect(surface, fcolor, rect, border_radius=2)
screen_r = rect.inflate(-8, -8)
pygame.draw.rect(surface, TV_SCREEN, screen_r, border_radius=2)
pygame.draw.line(surface, (60, 80, 100),
(screen_r.left + 3, screen_r.top + 3),
(screen_r.left + 10, screen_r.top + 3), 1)
pygame.draw.line(surface, (120, 170, 200), (screen_r.left + 2, screen_r.bottom - 3), (screen_r.right - 2, screen_r.top + 2), 1)
elif fname == "sillon":
pygame.draw.rect(surface, fcolor, rect, border_radius=4)
pygame.draw.rect(surface, (max(0, fcolor[0]-25), max(0, fcolor[1]-25),
max(0, fcolor[2]-25)), rect, 2, border_radius=4)
pygame.draw.rect(surface, (min(255, fcolor[0]+18), min(255, fcolor[1]+18), min(255, fcolor[2]+18)),
(sx + 4, sy + 4, w - 8, h // 2), border_radius=3)
elif fname == "cajas":
pygame.draw.rect(surface, fcolor, rect, border_radius=2)
pygame.draw.rect(surface, (max(0, fcolor[0]-30), max(0, fcolor[1]-30),
max(0, fcolor[2]-30)), rect, 2, border_radius=2)
pygame.draw.line(surface, BOX_TAPE,
(sx + w // 2, sy + 2), (sx + w // 2, sy + h - 2), 2)
pygame.draw.line(surface, BOX_TAPE,
(sx + 2, sy + h // 2), (sx + w - 2, sy + h // 2), 2)
pygame.draw.rect(surface, (235, 225, 180), (sx + 5, sy + 5, w - 10, 8), border_radius=1)
pygame.draw.rect(surface, (170, 140, 90), (sx + 6, sy + h - 10, w - 12, 4), border_radius=1)
else:
pygame.draw.rect(surface, fcolor, rect, border_radius=2)
pygame.draw.rect(surface, DARK_GRAY, rect, 1, border_radius=2)
def get_walkable_tiles():
"""
Retorna una lista de posiciones (col, row) donde se pueden colocar libros.
Excluye paredes, muebles, y la posición inicial del jugador.
Los libros aparecen dentro de la casa Y en el patio.
"""
walkable = []
player_start = (PLAYER_START_COL, PLAYER_START_ROW)
for row in range(MAP_ROWS):
for col in range(MAP_COLS):
tile = HOUSE_MAP[row][col]
# Piso interior y patio (no paredes, no bunker)
if tile in (TILE_FLOOR, TILE_PATIO) and (col, row) != player_start:
if (col, row) not in FURNITURE_BLOCKED:
walkable.append((col, row))
return walkable
# ============================================
# FASE DE LA CASA (PANTALLA 2)
# ============================================
class HousePhase:
"""
Fase de recolección: el jugador explora la casa,
recoge libros y debe llegar al bunker en 30 segundos.
Incluye: countdown, gas tóxico, congelamiento + fade a negro.
"""
def __init__(self, sound_manager):
self.sound_manager = sound_manager
self.reset()
def _build_static_world_surface(self):
"""Pre-renders the static house background once per reset."""
world = pygame.Surface((MAP_WIDTH, MAP_HEIGHT)).convert()
world.fill(BLACK)
draw_map(world, 0, 0)
draw_furniture(world, 0, 0)
draw_interior_decor(world, 0, 0)
return world
def reset(self):
"""Reinicia la fase de la casa."""
# Jugador: inicia en la puerta principal (abajo centro)
start_x = PLAYER_START_COL * TILE_SIZE + TILE_SIZE // 2
start_y = PLAYER_START_ROW * TILE_SIZE + TILE_SIZE // 2
self.player = Player(start_x, start_y)
self.camera = Camera()
self.inventory = Inventory()
# Temporizador de 30 segundos
self.timer = 30.0
self.timer_flash = 0
# === PANTALLA DE MODALIDAD + COUNTDOWN 3..1 ===
self.show_mode_modal = True
self.start_button_rect = pygame.Rect(
SCREEN_WIDTH // 2 - 90, SCREEN_HEIGHT // 2 + 205, 180, 45
)
self.countdown_value = 3
self.countdown_timer = 1.0
self.countdown_running = False
self.countdown_done_timer = 0.0
self.show_ya_text = False
self.game_started = False
# === CONGELAMIENTO + FADE A NEGRO ===
self.freeze_on_timeout = False
self.freeze_timer = FREEZE_DURATION
self.timeout_done = False # Ya se mostró la pantalla de timeout
# Generar 6 libros unicos en posiciones aleatorias dentro de la casa
self.books = []
walkable = get_walkable_tiles()
random.shuffle(walkable)
book_list = ["green", "red", "blue", "purple", "yellow", "darkbrown"]
for i, color in enumerate(book_list):
if i < len(walkable):
col, row = walkable[i]
bx = col * TILE_SIZE + TILE_SIZE // 2
by = row * TILE_SIZE + TILE_SIZE // 2
self.books.append(Book(bx, by, color))
# Estado
self.finished = False
self.result = None
# Sonido de pasos
self.step_timer = 0
self.step_interval = 0.25
# Bunker cercano
self.near_bunker = False
self.static_world_surface = self._build_static_world_surface()
# Fuentes
self.font_timer = pygame.font.SysFont("Arial", 28, bold=True)
self.font_small = pygame.font.SysFont("Arial", 16)
self.font_label = pygame.font.SysFont("Arial", 12)
self.font_large = pygame.font.SysFont("Arial", 36, bold=True)
self.font_medium = pygame.font.SysFont("Arial", 22)
self.font_countdown = pygame.font.SysFont("Arial", 72, bold=True)
def update(self, events, dt):
"""
Actualiza la lógica de la fase de la casa.
Retorna una tupla (next_state, data) cuando termine, o None.
"""
# === CONGELAMIENTO → FADE A NEGRO → PANTALLA TIMEOUT ===
if self.freeze_on_timeout:
self.freeze_timer -= dt
if self.freeze_timer <= 0:
# Ir directamente al EndScreen de TIMEOUT (una sola pantalla)
return (STATE_ENDING, ENDING_TIMEOUT)
return None
# === MODALIDAD PREVIA AL JUEGO ===
if self.show_mode_modal:
for event in events:
if event.type == pygame.MOUSEBUTTONDOWN:
if self.start_button_rect.collidepoint(event.pos):
self.show_mode_modal = False
self.countdown_running = True
self.countdown_value = 3
self.countdown_timer = 1.0
self.sound_manager.play("select")
self.camera.update(self.player.x, self.player.y)
return None
# === COUNTDOWN 3..1 CON PANTALLA CONGELADA ===
if self.countdown_running:
self.countdown_timer -= dt
if self.countdown_timer <= 0:
self.countdown_value -= 1
self.countdown_timer = 1.0
if self.countdown_value <= 0:
self.countdown_running = False
self.countdown_done_timer = 0.6
self.show_ya_text = True
self.camera.update(self.player.x, self.player.y)
return None
if self.countdown_done_timer > 0:
self.countdown_done_timer -= dt
if self.countdown_done_timer <= 0:
self.game_started = True
self.show_ya_text = False
self.camera.update(self.player.x, self.player.y)
return None
# === LÓGICA NORMAL DEL JUEGO ===
self.timer -= dt
self.timer_flash += dt
if self.timer <= 0:
self.timer = 0
# Congelar 3 segundos con fade a negro
self.freeze_on_timeout = True
self.freeze_timer = FREEZE_DURATION
self.sound_manager.play("error")
return None
# Movimiento del jugador
keys = pygame.key.get_pressed()
dx, dy = self.player.handle_input(keys)
self.player.try_move(dx, dy)
self.player.update(dt)
# Sonido de pasos
if self.player.moving:
self.step_timer += dt
if self.step_timer >= self.step_interval:
self.sound_manager.play("pasos")
self.step_timer = 0
else:
self.step_timer = 0
# Actualizar cámara
self.camera.update(self.player.x, self.player.y)
# Actualizar libros
for book in self.books:
book.update(dt)
# Procesar eventos
for event in events:
if event.type == pygame.KEYDOWN and event.key == pygame.K_e:
# Recoger libro
for book in self.books:
if not book.collected and book.distance_to(
self.player.x, self.player.y) < PICKUP_DISTANCE:
book.collected = True
self.inventory.add_book(book.color_name)
self.sound_manager.play("recoger")
break
# Entrar al bunker
bunker_x = BUNKER_COL * TILE_SIZE + TILE_SIZE // 2
bunker_y = BUNKER_ROW * TILE_SIZE + TILE_SIZE // 2
dist = math.sqrt((self.player.x - bunker_x) ** 2 +
(self.player.y - bunker_y) ** 2)
if dist < TILE_SIZE:
self.sound_manager.play("select")
return (STATE_BUNKER, self.inventory.get_books())
# CercanÃa al bunker
bunker_x = BUNKER_COL * TILE_SIZE + TILE_SIZE // 2
bunker_y = BUNKER_ROW * TILE_SIZE + TILE_SIZE // 2
self.near_bunker = (math.sqrt((self.player.x - bunker_x) ** 2 +
(self.player.y - bunker_y) ** 2) < TILE_SIZE)
return None
def draw(self, surface):
"""Dibuja toda la fase de la casa."""
cam_x = self.camera.x
cam_y = self.camera.y
surface.fill(BLACK)
# Fondo estatico pre-renderizado
view = pygame.Rect(int(cam_x), int(cam_y), SCREEN_WIDTH, SCREEN_HEIGHT)
surface.blit(self.static_world_surface, (0, 0), view)
# Libros
for book in self.books:
book.draw(surface, cam_x, cam_y, self.player.x, self.player.y)
# Indicador [E] bunker
if self.near_bunker and self.game_started:
bx = int(BUNKER_COL * TILE_SIZE + TILE_SIZE // 2 - cam_x)
by = int(BUNKER_ROW * TILE_SIZE - cam_y)
font = pygame.font.SysFont("Arial", 16, bold=True)
text = font.render("[E] Entrar al bunker", True, (255, 255, 100))
text_rect = text.get_rect(center=(bx, by - 10))
bg = text_rect.inflate(8, 4)
s = pygame.Surface((bg.width, bg.height), pygame.SRCALPHA)
s.fill((0, 0, 0, 160))
surface.blit(s, bg.topleft)
pygame.draw.rect(surface, (255, 255, 100), bg, 1, border_radius=3)
surface.blit(text, text_rect)
# Jugador
self.player.draw(surface, cam_x, cam_y)
# HUD (solo si el juego ha empezado)
if self.game_started:
self._draw_timer(surface)
self.inventory.draw(surface)
# === EFECTO DE GAS TÓXICO (últimos 7 segundos) ===
if self.game_started and 0 < self.timer <= GAS_START_TIME:
gas_intensity = 1.0 - (self.timer / GAS_START_TIME) # 0.0 → 1.0
gas_alpha = int(gas_intensity * 150)
gas_surface = pygame.Surface((SCREEN_WIDTH, SCREEN_HEIGHT), pygame.SRCALPHA)
gas_surface.fill((0, 180, 0, gas_alpha))
surface.blit(gas_surface, (0, 0))
# === CONGELAMIENTO + FADE A NEGRO ===
if self.freeze_on_timeout:
# Progreso del fade: 0 (justo empezó) → 1 (terminó)
fade_progress = 1.0 - (self.freeze_timer / FREEZE_DURATION)
# Gas verde al máximo + fade a negro progresivo
gas_surface = pygame.Surface((SCREEN_WIDTH, SCREEN_HEIGHT), pygame.SRCALPHA)
gas_surface.fill((0, 180, 0, 150))
surface.blit(gas_surface, (0, 0))
# Overlay negro que se intensifica
black_alpha = int(fade_progress * 255)
black_surface = pygame.Surface((SCREEN_WIDTH, SCREEN_HEIGHT), pygame.SRCALPHA)
black_surface.fill((0, 0, 0, black_alpha))
surface.blit(black_surface, (0, 0))
# === MODALIDAD / COUNTDOWN ===
if self.show_mode_modal:
self._draw_mode_modal(surface)
elif self.countdown_running or self.countdown_done_timer > 0:
self._draw_countdown(surface)
def _draw_mode_modal(self, surface):
"""Dibuja panel parcial de modalidad del juego con boton Comenzar."""
panel_w = min(940, SCREEN_WIDTH - 80)
panel_h = min(470, SCREEN_HEIGHT - 80)
panel = pygame.Rect(
(SCREEN_WIDTH - panel_w) // 2,
(SCREEN_HEIGHT - panel_h) // 2,
panel_w,
panel_h,
)
overlay = pygame.Surface((SCREEN_WIDTH, SCREEN_HEIGHT), pygame.SRCALPHA)
overlay.fill((0, 0, 0, 100))
surface.blit(overlay, (0, 0))
pygame.draw.rect(surface, (35, 35, 45), panel, border_radius=12)
pygame.draw.rect(surface, (110, 110, 135), panel, 2, border_radius=12)
title = self.font_large.render("Modalidad del Juego", True, WHITE)
surface.blit(title, title.get_rect(center=(panel.centerx, panel.top + 40)))
lines = [
"Por toda la casa estan distribuidos libros de diferentes colores.",
"Estos libros contienen formulas para resolver los problemas dentro del bunker.",
"El contenido de estos libros es el siguiente:",
"",
"- Libro Verde: Interpolacion",
"- Libro Rojo: Ec. No Lineales",
"- Libro Azul: Ec. Lineales",
"- Libro Morado: Minimos Cuadrados",
"- Libro Amarillo: Integracion y Ecuaciones Diferenciales Ordinarias (Modificado)",
"- Café Oscuro: Runge - Kutta",
"",
"Solo cuentas con 30 segundos para recoger los libros",
"Estos libros contienen formulas para poder resolver los "
"problemas solicitados por cada día.",
]
y = panel.top + 90
for line in lines:
if line == "":
y += 8
continue
text = self.font_small.render(line, True, (225, 225, 235))
surface.blit(text, (panel.left + 28, y))
y += 30
mouse = pygame.mouse.get_pos()
hover = self.start_button_rect.collidepoint(mouse)
btn_color = (70, 170, 70) if hover else (50, 140, 50)
pygame.draw.rect(surface, btn_color, self.start_button_rect, border_radius=8)
pygame.draw.rect(surface, WHITE, self.start_button_rect, 2, border_radius=8)
label = self.font_medium.render("Comenzar", True, WHITE)
surface.blit(label, label.get_rect(center=self.start_button_rect.center))
def _draw_countdown(self, surface):
"""Dibuja el countdown 3..1 al inicio con pantalla congelada."""
overlay = pygame.Surface((SCREEN_WIDTH, SCREEN_HEIGHT), pygame.SRCALPHA)
overlay.fill((0, 0, 0, 120))
surface.blit(overlay, (0, 0))
if self.countdown_running:
text = self.font_countdown.render(str(self.countdown_value), True, (255, 255, 100))
text_rect = text.get_rect(center=(SCREEN_WIDTH // 2, SCREEN_HEIGHT // 2))
shadow = self.font_countdown.render(str(self.countdown_value), True, (0, 0, 0))
surface.blit(shadow, (text_rect.x + 3, text_rect.y + 3))
surface.blit(text, text_rect)
if self.show_ya_text:
ya = self.font_countdown.render("Ya", True, (120, 255, 120))
ya_rect = ya.get_rect(center=(SCREEN_WIDTH // 2, SCREEN_HEIGHT // 2))
surface.blit(ya, ya_rect)
def _draw_timer(self, surface):
"""Dibuja el temporizador."""
timer_bg = pygame.Surface((140, 45))
timer_bg.fill((18, 18, 28))
surface.blit(timer_bg, (SCREEN_WIDTH - 150, 10))
pygame.draw.rect(surface, (120, 120, 145),
(SCREEN_WIDTH - 150, 10, 140, 45), 2, border_radius=5)
seconds = max(0, int(self.timer))
millis = int((self.timer - int(self.timer)) * 100)
if self.timer <= 10:
flash = int(self.timer_flash * 4) % 2 == 0
color = TIMER_COLOR if flash else (255, 150, 150)
else:
color = WHITE
time_str = f"{seconds:02d}.{millis:02d}"
timer_text = self.font_timer.render(time_str, True, color)
timer_rect = timer_text.get_rect(center=(SCREEN_WIDTH - 80, 32))
surface.blit(timer_text, timer_rect)
# Sin etiqueta adicional; solo el cronometro visible.