-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmessage_display.py
More file actions
32 lines (27 loc) · 1010 Bytes
/
message_display.py
File metadata and controls
32 lines (27 loc) · 1010 Bytes
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
import pygame
from settings import MESSAGE_DISPLAY_DURATION, MESSAGE_FADE_SPEED
class MessageDisplay:
def __init__(self):
self.messages = []
def add_message(self, text, position, color, font_size):
self.messages.append({
'text': text,
'position': position,
'color': color,
'font_size': font_size,
'timer': MESSAGE_DISPLAY_DURATION,
'alpha': 255
})
def update(self):
for msg in self.messages:
msg['timer'] -= 1
if msg['timer'] <= 0:
msg['alpha'] -= MESSAGE_FADE_SPEED
if msg['alpha'] <= 0:
self.messages.remove(msg)
def draw(self, screen):
for msg in self.messages:
font = pygame.font.Font(None, msg['font_size'])
text_surface = font.render(msg['text'], True, msg['color'])
text_surface.set_alpha(msg['alpha'])
screen.blit(text_surface, msg['position'])