Objects added to game rendering
[butaba-adventures.git] / utility.py
diff --git a/utility.py b/utility.py
new file mode 100644 (file)
index 0000000..5d8c45d
--- /dev/null
@@ -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