-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwriting.py
58 lines (53 loc) · 1.97 KB
/
writing.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
import pygame
def write(game,size,x,y,text):
font = pygame.font.Font('freesansbold.ttf',size)
text_surface = font.render(text, True, game.white)
text_rect = text_surface.get_rect()
text_rect.topleft = (x,y)
game.screen.blit(text_surface,text_rect)
return font.size(text)
def writeColor(game,size,x,y,text,color):
font = pygame.font.Font('freesansbold.ttf',size)
text_surface = font.render(text, True, color)
text_rect = text_surface.get_rect()
text_rect.topleft = (x,y)
game.screen.blit(text_surface,text_rect)
return font.size(text)
def writeOrientation(game,size,x,y,text,orn="R"):
font = pygame.font.Font('freesansbold.ttf',size)
text_surface = font.render(text, True, game.white)
text_rect = text_surface.get_rect()
if orn == "L":
text_rect.topleft = (x,y)
elif orn == "R":
text_rect.topright = (x,y)
game.screen.blit(text_surface,text_rect)
return font.size(text)
def wrapWrite(game,size,text,xBound,x=20,y=25):
font = pygame.font.Font('freesansbold.ttf',size)
textList = wrap(font,text,xBound)
for i in range(0,len(textList)):
text_surface = font.render(textList[i], True, game.white)
text_rect = text_surface.get_rect()
text_rect.topleft = (x,y+((size+5)*i))
game.screen.blit(text_surface,text_rect)
return font.size(text)
def wrap(font,text,windowsize):
fullText = [text]
if font.size(text)[0] > windowsize:
fullText.clear()
listText = text.split()
lineList = []
for word in listText:
lineList.append(word)
line = ' '.join(lineList)
if font.size(line)[0] > windowsize:
lastWord = lineList[-1]
lineList.pop(-1)
line = ' '.join(lineList)
fullText.append(line)
lineList.clear()
lineList.append(lastWord)
line = ' '.join(lineList)
fullText.append(line)
return fullText