Objects added to game rendering
[butaba-adventures.git] / utility.py
1 # utility functions for the game
2 import pygame
3 import os.path
4
5 # function to draw text on surface
6 def put_text (surface, x, y, size, (r,g,b), text):
7 harisfont = os.path.join ("font", "HarisComic-2.ttf")
8 textsurf = pygame.font.Font (harisfont, size).render (text, True, pygame.Color (r,g,b))
9 surface.blit (textsurf, (x, y))
10
11
12
13 # function to ask a question and return answer
14 def ask_question (surface, question, answers):
15 pygame.draw.rect (surface, pygame.Color (255, 255, 128), pygame.Rect (40, 40, 480-40, 480-40))
16
17 put_text (surface, 60, 60, 22, (0, 0, 192), question)
18
19 i = 1
20 for answer in answers:
21 put_text (surface, 60, i*20+60, 22, (0, 0, 128), "%d" % i)
22 put_text (surface, 80, i*20+60, 22, (0, 0, 0), answer)
23
24 while 1:
25 for event in pygame.event.get ():
26 if event.type == pygame.QUIT:
27 sys.exit (0)
28 elif event.type == pygame.KEYDOWN:
29 print event.key