1 # utility functions for the game
6 # function to draw text on surface
7 def put_text (surface
, x
, y
, size
, (r
,g
,b
), text
):
8 harisfont
= os
.path
.join ("font", "HarisComic-2.ttf")
9 textsurf
= pygame
.font
.Font (harisfont
, size
).render (text
, True, pygame
.Color (r
,g
,b
))
10 surface
.blit (textsurf
, (x
, y
))
12 # function to draw several lines of text, centered horizontally and vertically on surface
13 def put_lines (surface
, text_lines
):
16 harisfont
= os
.path
.join ("font", "HarisComic-2.ttf")
18 for size
, r
, g
, b
, text
in text_lines
:
19 s
= pygame
.font
.Font (harisfont
, size
).render (text
, True, pygame
.Color (r
,g
,b
))
21 height
= height
+ s
.get_height() + 10
24 scrwidth
= surface
.get_width ()
25 scrheight
= surface
.get_height ()
28 surface
.blit (s
, (scrwidth
/2 - s
.get_width()/2, scrheight
/2 - height
/2+ i
*s
.get_height()+10))
31 # function to ask a question and return answer
32 def ask_question (surface
, question
, answers
, bgscreen
):
37 textarray
= [ [ 22, 128, 0, 0, question
] ]
40 for answer
in answers
:
45 textarray
.append ( [20, r
, g
, b
, answer
] )
49 surface
.blit (bgscreen
, (surface
.get_width()/2 - bgscreen
.get_width()/2,
50 surface
.get_height()/2 - bgscreen
.get_height()/2))
51 put_lines (surface
, textarray
)
53 pygame
.display
.update ()
55 for event
in pygame
.event
.get ():
56 if event
.type == pygame
.QUIT
:
58 elif event
.type == pygame
.KEYDOWN
:
59 if event
.key
== pygame
.K_UP
:
63 elif event
.key
== pygame
.K_DOWN
:
65 if sel_answer
> len(answers
):
66 sel_answer
= len(answers
)
67 elif event
.key
== pygame
.K_RETURN
: