-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathui.py
More file actions
155 lines (125 loc) · 5.74 KB
/
Copy pathui.py
File metadata and controls
155 lines (125 loc) · 5.74 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
"""
Interface do usuário: HUD, menus e efeitos visuais.
"""
import pygame
from settings import (
FONT_SMALL, FONT_MEDIUM, FONT_LARGE,
WHITE, YELLOW, RED, BLUE, BLACK,
SCREEN_W, SCREEN_H, TILE_SIZE, STATE_MENU,
STATE_PLAYING, STATE_PAUSED, STATE_GAMEOVER, STATE_WIN
)
class UI:
def __init__(self):
self.flash_timer = 0
self.high_score = 0
def draw_hud(self, surface, score, lives, level):
# Fundo da HUD
hud_rect = pygame.Rect(0, 0, SCREEN_W, 50)
pygame.draw.rect(surface, BLACK, hud_rect)
pygame.draw.line(surface, BLUE, (0, 50), (SCREEN_W, 50), 2)
# Score
score_text = FONT_MEDIUM.render(f"SCORE: {score}", True, WHITE)
surface.blit(score_text, (10, 10))
# High Score
hs_text = FONT_MEDIUM.render(f"HIGH: {self.high_score}", True, YELLOW)
surface.blit(hs_text, (SCREEN_W // 2 - hs_text.get_width() // 2, 10))
# Level
lvl_text = FONT_MEDIUM.render(f"LEVEL: {level}", True, WHITE)
surface.blit(lvl_text, (SCREEN_W - lvl_text.get_width() - 10, 10))
# Vidas (desenha mini Pacmans)
lives_text = FONT_SMALL.render("LIVES:", True, WHITE)
surface.blit(lives_text, (10, 28))
for i in range(lives):
cx = 70 + i * 20
cy = 37
pygame.draw.circle(surface, YELLOW, (cx, cy), 6)
def draw_menu(self, surface):
overlay = pygame.Surface((SCREEN_W, SCREEN_H))
overlay.set_alpha(200)
overlay.fill(BLACK)
surface.blit(overlay, (0, 0))
title = FONT_LARGE.render("PACMAN", True, YELLOW)
surface.blit(title, (SCREEN_W // 2 - title.get_width() // 2, 100))
self.flash_timer += 1
if self.flash_timer % 60 < 30:
start = FONT_MEDIUM.render("PRESS ENTER TO START", True, WHITE)
surface.blit(start, (SCREEN_W // 2 - start.get_width() // 2, 250))
controls = FONT_SMALL.render("ARROWS / WASD to move | P to pause", True, WHITE)
surface.blit(controls, (SCREEN_W // 2 - controls.get_width() // 2, 320))
ghosts_info = [
("BLINKY", RED, "chases you directly"),
("PINKY", (255, 184, 255), "ambushes from ahead"),
("INKY", CYAN, "unpredictable patterns"),
("CLYDE", ORANGE, "switches between chase and scatter"),
]
y = 380
for name, color, desc in ghosts_info:
pygame.draw.circle(surface, color, (SCREEN_W // 2 - 140, y), 8)
txt = FONT_SMALL.render(f"{name}: {desc}", True, WHITE)
surface.blit(txt, (SCREEN_W // 2 - 120, y - 7))
y += 22
def draw_pause(self, surface):
overlay = pygame.Surface((SCREEN_W, SCREEN_H))
overlay.set_alpha(180)
overlay.fill(BLACK)
surface.blit(overlay, (0, 0))
pause = FONT_LARGE.render("PAUSED", True, YELLOW)
surface.blit(pause, (SCREEN_W // 2 - pause.get_width() // 2, SCREEN_H // 2 - 40))
self.flash_timer += 1
if self.flash_timer % 60 < 30:
cont = FONT_MEDIUM.render("PRESS P TO RESUME", True, WHITE)
surface.blit(cont, (SCREEN_W // 2 - cont.get_width() // 2, SCREEN_H // 2 + 20))
def draw_gameover(self, surface, score, new_high):
overlay = pygame.Surface((SCREEN_W, SCREEN_H))
overlay.set_alpha(200)
overlay.fill(BLACK)
surface.blit(overlay, (0, 0))
go = FONT_LARGE.render("GAME OVER", True, RED)
surface.blit(go, (SCREEN_W // 2 - go.get_width() // 2, 150))
sc = FONT_MEDIUM.render(f"FINAL SCORE: {score}", True, WHITE)
surface.blit(sc, (SCREEN_W // 2 - sc.get_width() // 2, 230))
if new_high:
nh = FONT_MEDIUM.render("NEW HIGH SCORE!", True, YELLOW)
surface.blit(nh, (SCREEN_W // 2 - nh.get_width() // 2, 270))
self.flash_timer += 1
if self.flash_timer % 60 < 30:
restart = FONT_MEDIUM.render("PRESS ENTER TO RESTART", True, WHITE)
surface.blit(restart, (SCREEN_W // 2 - restart.get_width() // 2, 330))
def draw_win(self, surface, score, level):
overlay = pygame.Surface((SCREEN_W, SCREEN_H))
overlay.set_alpha(200)
overlay.fill(BLACK)
surface.blit(overlay, (0, 0))
win = FONT_LARGE.render("YOU WIN!", True, GREEN)
surface.blit(win, (SCREEN_W // 2 - win.get_width() // 2, 150))
sc = FONT_MEDIUM.render(f"SCORE: {score}", True, WHITE)
surface.blit(sc, (SCREEN_W // 2 - sc.get_width() // 2, 230))
nxt = FONT_MEDIUM.render(f"NEXT LEVEL: {level + 1}", True, YELLOW)
surface.blit(nxt, (SCREEN_W // 2 - nxt.get_width() // 2, 270))
self.flash_timer += 1
if self.flash_timer % 60 < 30:
cont = FONT_MEDIUM.render("PRESS ENTER TO CONTINUE", True, WHITE)
surface.blit(cont, (SCREEN_W // 2 - cont.get_width() // 2, 330))
def draw_ready(self, surface):
self.flash_timer += 1
if self.flash_timer % 60 < 30:
ready = FONT_LARGE.render("READY!", True, YELLOW)
surface.blit(ready, (SCREEN_W // 2 - ready.get_width() // 2, SCREEN_H // 2 - 50))
def draw_fruit(self, surface, fruit_pos, fruit_type):
if fruit_pos is None:
return
cx = fruit_pos[0] * TILE_SIZE + TILE_SIZE // 2
cy = fruit_pos[1] * TILE_SIZE + TILE_SIZE // 2
colors = {
'cherry': RED,
'strawberry': (255, 0, 100),
'orange': ORANGE,
'apple': (255, 0, 0),
'melon': GREEN,
}
color = colors.get(fruit_type, RED)
pygame.draw.circle(surface, color, (cx, cy), 8)
pygame.draw.circle(surface, WHITE, (cx - 3, cy - 3), 2)
pygame.draw.circle(surface, WHITE, (cx + 3, cy - 3), 2)
# Constante GREEN local
GREEN = (0, 255, 0)