-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlog_manager.py
64 lines (53 loc) · 2.12 KB
/
log_manager.py
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
import pygame
from sceneManager import SceneManager
from sceneManager import SceneManager
from sounds_manager import SoundManager
# Display text function
# Define colors
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
# Clear screen function
def clear_screen(window):
window.fill(BLACK)
pygame.display.flip()
# Typewriter effect using time tracking (non-blocking)
class Typewriter:
def __init__(self, text, font, pos, speed=50, wait_before_start=0, silent=False, on_finish=lambda: None):
self.text = text
self.pos = pos
self.font = font
self.speed = speed # Speed in milliseconds per character
self.wait = wait_before_start # Wait in milliseconds before it starts
self.current_index = 0
self.last_update_time = pygame.time.get_ticks()
self.done = False
self.silent = silent
self.on_finish = on_finish
def update(self):
now = pygame.time.get_ticks()
delay = now - self.last_update_time
if self.drawable() and delay > self.speed:
self.last_update_time = now
if self.current_index < len(self.text):
if self.current_index == 0:
SoundManager.play_sound('GUI Sound Effects_038', 0.1)
self.current_index += min(2, len(self.text) - self.current_index)
if not self.silent and not pygame.mixer.get_busy() and not self.text[self.current_index - 1] != ' ':
SoundManager.play_sound('TF_GUI-Sound-7', 1.0)
if not self.done and self.current_index >= len(self.text): # If we want it to disappear
print('ok fini')
print(self.text)
self.on_finish()
self.done = True
def drawable(self):
now = pygame.time.get_ticks()
delay = now - self.last_update_time
if delay < self.wait:
return False
else:
self.wait = 0
return True
def draw(self, surface):
#if self.drawable():
text_surface = self.font.render(self.text[:self.current_index], True, WHITE)
surface.blit(text_surface, self.pos)