i have a python pygame program that simulates a racecar, driving and dodging blocks, this program worked 100% until i tried it today, now it gives me a error, the error is:
JavaScript
x
17
17
1
Warning (from warnings module):
2
File "/home/vandeventer/Documents/Pieter/pygame.resies.py", line 50
3
largeText = pygame.font.Font(None,75)
4
RuntimeWarning: use font: libSDL_ttf-2.0.so.0: cannot open shared object file: No such file or directory
5
(ImportError: libSDL_ttf-2.0.so.0: cannot open shared object file: No such file or directory)
6
Traceback (most recent call last):
7
File "/home/vandeventer/Documents/Pieter/pygame.resies.py", line 151, in <module>
8
begin()
9
File "/home/vandeventer/Documents/Pieter/pygame.resies.py", line 29, in begin
10
message_display(over)
11
File "/home/vandeventer/Documents/Pieter/pygame.resies.py", line 50, in message_display
12
largeText = pygame.font.Font(None,75)
13
File "/usr/local/lib/python3.4/dist-packages/pygame/__init__.py", line 74, in __getattr__
14
raise NotImplementedError(MissingPygameModule)
15
NotImplementedError: font module not available
16
(ImportError: libSDL_ttf-2.0.so.0: cannot open shared object file: No such file or directory)
17
this makes me think somethings wrong with the font i use, it is realy very frustrating, and i realy cant see anything wrong, here is my code:
JavaScript
1
155
155
1
import pygame
2
import time
3
import random
4
5
6
pygame.init()
7
8
display_width = 1500
9
display_height = 1000
10
11
black = (255,255,255)
12
white = (255,255,255)
13
red = (255,0,0)
14
back_ground = (25,25,25)
15
over = "Start your engins!"
16
17
18
19
car_width = 50
20
21
gameDisplay = pygame.display.set_mode((display_width,display_height))
22
pygame.display.set_caption("A bit Racey")
23
clock = pygame.time.Clock()
24
25
carImg = pygame.image.load("resieskar.png")
26
resized = pygame.transform.scale(carImg, (50, 100))
27
28
def begin():
29
message_display(over)
30
31
def you_win():
32
message_display("You Win!")
33
34
def things_dodged(count):
35
font = pygame.font.SysFont(None,25)
36
text = font.render("Dodged: "+str(count),True,white)
37
gameDisplay.blit(text, (0,0))
38
39
def things(thingx, thingy, thingw, thingh, color):
40
pygame.draw.rect(gameDisplay, block_color, [thingx, thingy, thingw, thingh])
41
42
def car(x,y):
43
gameDisplay.blit(resized,(x,y))
44
45
def text_objects(text, font):
46
textSurface = font.render(text, True, black)
47
return textSurface, textSurface.get_rect()
48
49
def message_display(text):
50
largeText = pygame.font.Font(None,75)
51
TextSurf, TextRect = text_objects(text, largeText)
52
TextRect.center = ((display_width/2),(display_height/2))
53
gameDisplay.blit(TextSurf, TextRect)
54
pygame.display.update()
55
56
time.sleep(2)
57
game_loop()
58
59
def crash():
60
message_display('You Crashed!')
61
62
63
64
def game_loop():
65
global block_R
66
global block_G
67
global block_B
68
global block_color
69
70
black = (0,0,0)
71
white = (255,255,255)
72
red = (255,0,0)
73
block_R = random.randrange(100,200)
74
block_G = random.randrange(100,200)
75
block_B = random.randrange(30,200)
76
77
block_color = (block_R,block_G,block_B)
78
79
x = (display_width*0.45)
80
y = (display_height*0.8)
81
x_change = 0
82
83
thing_width = 100
84
thing_startx = random.randrange(0, display_width-thing_width)
85
thing_starty = -600
86
thing_speed = 5
87
thing_height = 100
88
dodged = 0
89
dificuilty = 2
90
bigger = 15
91
92
gameExit = False
93
94
while not gameExit:
95
96
for event in pygame.event.get():
97
if event.type == pygame.QUIT:
98
pygame.quit()
99
quit()
100
101
102
if event.type == pygame.KEYDOWN:
103
104
if event.key == pygame.K_RIGHT:
105
x_change = 50
106
107
elif event.key == pygame.K_LEFT:
108
x_change = -50
109
110
if event.type == pygame. KEYUP:
111
if event.key == pygame.K_LEFT or event.key == pygame.K_RIGHT:
112
x_change = 0
113
114
115
x += x_change
116
117
118
119
gameDisplay.fill(back_ground)
120
121
# things(thingx, thingy, thingw, thingh, color)
122
things(thing_startx, thing_starty, thing_width, thing_height, block_color)
123
thing_starty += thing_speed
124
car(x,y)
125
things_dodged(dodged)
126
if dodged > 34:
127
you_win()
128
129
if x > display_width - car_width or x < 0:
130
crash()
131
132
if thing_starty > display_height:
133
thing_starty = 0 - thing_height
134
thing_startx = random.randint(0,(795-int(thing_width)))
135
dodged += 1
136
bigger = bigger * 0.9
137
dificuilty = dificuilty * 0.6
138
thing_speed += dificuilty
139
thing_width += bigger
140
141
142
143
if y < thing_starty+thing_height:
144
if x > thing_startx and x < thing_startx+thing_width or x+car_width > thing_startx and x+car_width<thing_startx+thing_width:
145
crash()
146
147
148
pygame.display.update()
149
clock.tick(60)
150
151
begin()
152
game_loop()
153
pygame.quit()
154
quit()
155
the only parts where i use the font is in message_display() and things_dodged() id realy like any help, thanks
Advertisement
Answer
it was actuely very weird, today i decided to try and figure it out, and it worked perfectly fine, anyway, its fixed now