forked from Carouan/Game_Sebilias
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dialog.py
41 lines (32 loc) · 1.25 KB
/
dialog.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
import pygame
class DialogBox:
X_POSITION = 60
Y_POSITION = 470
def __init__(self):
self.box = pygame.image.load("../dialogs/dialog_box.png")
self.box = pygame.transform.scale(self.box, (700, 100))
self.texts = []
self.text_index = 0
self.letter_index = 0
self.font = pygame.font.Font("../dialogs/dialog_font.ttf", 18)
self.reading = False
def execute(self, dialog=[]):
if self.reading:
self.next_text()
else:
self.reading = True
self.text_index = 0
self.texts = dialog
def render(self, screen):
if self.reading:
self.letter_index += 1
if self.letter_index >= len(self.texts[self.text_index]):
self.letter_index = self.letter_index
screen.blit(self.box, (self.X_POSITION, self.Y_POSITION))
text = self.font.render(self.texts[self.text_index][0:self.letter_index], False, (0, 0, 0))
screen.blit(text, (self.X_POSITION + 60, self.Y_POSITION + 30))
def next_text(self):
self.text_index += 1
self.letter_index = 0
if self.text_index >= len(self.texts):
self.reading = False