X-Git-Url: https://harishankar.org/repos/?p=butaba-adventures.git;a=blobdiff_plain;f=utility.py;h=bc760f337879759c394b5973c485dd6d53c58023;hp=9c68c050b275782679a3e249fd639a219a8af073;hb=6552a4a3522d0b48177a9c2ebedda92b824874f7;hpb=4b6e952b476861c8979dc395781964099285a4c6 diff --git a/utility.py b/utility.py index 9c68c05..bc760f3 100644 --- a/utility.py +++ b/utility.py @@ -5,7 +5,7 @@ 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") + harisfont = os.path.join ("font", "harisgamefont.ttf") textsurf = pygame.font.Font (harisfont, size).render (text, True, pygame.Color (r,g,b)) surface.blit (textsurf, (x, y)) @@ -13,19 +13,19 @@ def put_text (surface, x, y, size, (r,g,b), text): def put_lines (surface, text_lines): textsurfs = [] height = 0 - harisfont = os.path.join ("font", "HarisComic-2.ttf") + harisfont = os.path.join ("font", "harisgamefont.ttf") for size, r, g, b, text in text_lines: s = pygame.font.Font (harisfont, size).render (text, True, pygame.Color (r,g,b)) - # add 10 for spacing - height = height + s.get_height() + 10 + # add spacing + height = height + s.get_height()*1.5 textsurfs.append (s) scrwidth = surface.get_width () scrheight = surface.get_height () i = 0 for s in textsurfs: - surface.blit (s, (scrwidth/2 - s.get_width()/2, scrheight/2 - height/2+ i*s.get_height()+10)) + surface.blit (s, (scrwidth/2 - s.get_width()/2, scrheight/2 - height/2+ i* (s.get_height()*1.5))) i += 1 # function to ask a question and return answer @@ -34,7 +34,7 @@ def ask_question (surface, question, answers, bgscreen): sel_answer = 1 while 1: - textarray = [ [ 22, 128, 0, 0, question ] ] + textarray = [ [ 10, 128, 0, 0, question ] ] i = 1 for answer in answers: @@ -42,7 +42,7 @@ def ask_question (surface, question, answers, bgscreen): r, g, b = 0, 0, 216 else: r, g, b = 0, 0, 0 - textarray.append ( [20, r, g, b, answer] ) + textarray.append ( [10, r, g, b, answer] ) i += 1 @@ -67,3 +67,43 @@ def ask_question (surface, question, answers, bgscreen): elif event.key == pygame.K_RETURN: return sel_answer +# function displaying the contents of a container. Object must contain +# items list +# edgewidth - container edges to avoid drawing items in +def display_container_contents (surface, obj, bgimage, edgewidth=0): + + # get the number of items + numitems = len (obj.objects) + # number of rows + num_rows = (bgimage.get_height () - edgewidth*2) / 48 + # number of cols + num_cols = (bgimage.get_width () - edgewidth*2) / 48 + + objposx = surface.get_width()/2 - bgimage.get_width()/2 + objposy = surface.get_height()/2 - bgimage.get_height()/2 + + while 1: + # display the background for the container + surface.blit (bgimage, (objposx, objposy)) + + # display each item in the container + i = 0 + j = 0 + + for item in obj.objects: + surface.blit (item.image, (objposx + edgewidth+ j*48, objposy + edgewidth + i*48)) + j += 1 + if j >= num_cols: + j = 0 + i += 1 + # only display as many items as will fit in the container + if i >= num_rows: + break + + pygame.display.update () + for event in pygame.event.get (): + if event.type == pygame.QUIT: + sys.exit (0) + elif event.type == pygame.KEYDOWN: + if event.key == pygame.K_ESCAPE: + return