So far in my snake game the score is printed in python shell. How can i have it printed in the games window instead? So that the game and the score are in the same window?
Thanks Eric
while running:
screen.fill((0, 0, 0))
worm.move()
worm.draw()
food.draw()
if worm.crashed:
exit();
elif worm.x <= 0 or worm.x >= w -1:
running = False
elif worm.y <= 0 or worm.y >= h-1:
running = False
elif worm.position() == food.position():
score += 1
worm.eat()
print " score: %d" % score
food = Food(screen)
elif food.check(worm.x, worm.y):
score += 1
worm.eat()
print "score: %d" % score
food = Food(screen)
elif running == False:
exit();
for event in pygame.event.get():
if event.type == pygame.quit:
running = False
elif event.type == pygame.KEYDOWN:
worm.event(event)
pygame.display.flip()
clock.tick(100)
Edit-
while running:
screen.fill((0, 0, 0))
worm.move()
worm.draw()
food.draw()
pygame.font.init()
pygame.font.get_fonts()
if worm.crashed:
exit();
elif worm.x <= 0 or worm.x >= w -1:
running = False
elif worm.y <= 0 or worm.y >= h-1:
running = False
elif food.check(worm.x, worm.y):
score += 1
worm.eat()
food = Food(screen)
message = 'score: %d' % score
font = pygame.font.Font(None, 40)
text = font.render(message, 1, white)
screen.blit(text, (50, 50))
elif running == False:
exit();
for event in pygame.event.get():
if event.type == pygame.quit:
running = False
elif event.type == pygame.KEYDOWN:
worm.event(event)
Why isnt the Score Apearing, im not getting any errors?
Use the font module to render fonts on screen.
From the userguide: