X-Git-Url: https://harishankar.org/repos/?p=butaba-adventures.git;a=blobdiff_plain;f=utility.py;fp=utility.py;h=5d8c45d0e3e24bbbe6c95ffcc066c4212d7489dc;hp=0000000000000000000000000000000000000000;hb=7dbb8e9b6766b7c0c17433bea3c88a321036b837;hpb=42a1f54d2fc5153bff97a8fc77086c4b7606c25e diff --git a/utility.py b/utility.py new file mode 100644 index 0000000..5d8c45d --- /dev/null +++ b/utility.py @@ -0,0 +1,29 @@ +# utility functions for the game +import pygame +import os.path + +# function to draw text on surface +def put_text (surface, x, y, size, (r,g,b), text): + harisfont = os.path.join ("font", "HarisComic-2.ttf") + textsurf = pygame.font.Font (harisfont, size).render (text, True, pygame.Color (r,g,b)) + surface.blit (textsurf, (x, y)) + + + +# function to ask a question and return answer +def ask_question (surface, question, answers): + pygame.draw.rect (surface, pygame.Color (255, 255, 128), pygame.Rect (40, 40, 480-40, 480-40)) + + put_text (surface, 60, 60, 22, (0, 0, 192), question) + + i = 1 + for answer in answers: + put_text (surface, 60, i*20+60, 22, (0, 0, 128), "%d" % i) + put_text (surface, 80, i*20+60, 22, (0, 0, 0), answer) + + while 1: + for event in pygame.event.get (): + if event.type == pygame.QUIT: + sys.exit (0) + elif event.type == pygame.KEYDOWN: + print event.key