-
Notifications
You must be signed in to change notification settings - Fork 2
/
Text.py
66 lines (53 loc) · 2.16 KB
/
Text.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
65
66
import pygame
import random
import numpy as np
class Text:
text_list = []
class __DrawText:
def __init__(self, screen, sprite, text, x, y, tweak_x, tweak_y, size):
self.screen = screen
self.sprite = sprite
self.text = text
self.x = x
self.y = y
self.tweak_x = tweak_x
self.tweak_y = tweak_y
self.size = size
self.time = 120
def draw(self):
if self.sprite is not None:
self.x = self.sprite.rect.right + self.tweak_x
self.y = self.sprite.rect.top + self.tweak_y
if self.x < -20:
return True
# 文字のアウトライン
for tweak in range(2):
font = pygame.font.SysFont("msgothicmsuigothicmspgothic", self.size)
text_data = font.render(self.text, True, (0, 0, 0))
for i in range(4):
rad = i / 2 * np.pi
x = np.cos(rad) + self.x
y = np.sin(rad) + self.y
self.screen.blit(text_data, [x + tweak, y])
# 文字本体
for tweak in range(2):
font = pygame.font.SysFont("msgothicmsuigothicmspgothic", self.size)
text_data = font.render(self.text, True, (255, 255, 255))
self.screen.blit(text_data, [self.x + tweak, self.y])
return False
@classmethod
def set(cls, screen, text, x=0, y=0, size=20, sprite=None, tweak_x=0, tweak_y=0):
if type(text) is str:
cls.text_list.append(cls.__DrawText(screen, sprite, text, x, y, tweak_x, tweak_y, size))
elif type(text) is list:
index = random.randint(0, len(text) - 1)
cls.text_list.append(cls.__DrawText(screen, sprite, text[index], x, y, tweak_x, tweak_y, size))
@classmethod
def update(cls):
isRemove = False
for count, text in enumerate(cls.text_list):
if count < 3:
isRemove = text.draw()
text.time -= 1
if text.time == 0 or isRemove:
cls.text_list.remove(text)