Added a different font
authorHarishankar <v.harishankar@gmail.com>
Sat, 1 Oct 2011 05:52:06 +0000 (11:22 +0530)
committerHarishankar <v.harishankar@gmail.com>
Sat, 1 Oct 2011 05:52:06 +0000 (11:22 +0530)
Added a more suitable font for the game

font/HarisComic-2.ttf [deleted file]
font/harisgamefont.ttf [new file with mode: 0644]
maingame.py
objects/key.png
objects/key2.png [new file with mode: 0644]
utility.py

diff --git a/font/HarisComic-2.ttf b/font/HarisComic-2.ttf
deleted file mode 100644 (file)
index 8c69af2..0000000
Binary files a/font/HarisComic-2.ttf and /dev/null differ
diff --git a/font/harisgamefont.ttf b/font/harisgamefont.ttf
new file mode 100644 (file)
index 0000000..36cefd8
Binary files /dev/null and b/font/harisgamefont.ttf differ
index b894164..7b54c2d 100644 (file)
@@ -13,7 +13,7 @@ class MainGame:
        # initialize the game
        def __init__ (self):
                pygame.init ()
-               self.screen  = pygame.display.set_mode ((720, 512))
+               self.screen  = pygame.display.set_mode ((720, 512), pygame.FULLSCREEN)
                pygame.display.set_caption ("The Adventures of Butaba")
 
                # initalize background graphics
@@ -37,6 +37,8 @@ class MainGame:
                self.img_lightning.set_colorkey (pygame.Color (0, 255, 0))
                self.img_key = pygame.image.load (os.path.join ("objects", "key.png")).convert ()
                self.img_key.set_colorkey (pygame.Color (0, 255, 0))
+               self.img_key2 = pygame.image.load (os.path.join ("objects", "key2.png")).convert ()
+               self.img_key2.set_colorkey (pygame.Color (0, 255, 0))
                self.img_chest = pygame.image.load (os.path.join ("objects", "chest.png")).convert ()
                self.img_chest.set_colorkey (pygame.Color (0, 255, 0))
 
@@ -65,7 +67,7 @@ class MainGame:
 
                self.level1 = level.Level (level.LEVEL_1)
                self.level1e = level.Level (level.LEVEL_1E,
-                                                                       objects = [ gameobjects.Key (4, 3, "a chest key", self.img_key, level.KEY_CHEST1),
+                                                                       objects = [ gameobjects.Key (4, 3, "a chest key", self.img_key2, level.KEY_CHEST1),
                                                                                                gameobjects.Key (4, 3, "a room key", self.img_key, level.KEY_ROOM1),
                                                                                                gameobjects.HealthPotion (4, 2, self.img_redpotion),
                                                                                                gameobjects.Chest (2, 5, "chest", self.img_chest, level.KEY_CHEST1, True)
@@ -96,6 +98,7 @@ class MainGame:
                        for event in pygame.event.get ():
                                if event.type == pygame.QUIT:
                                        sys.exit (0)
+                               # if keyboard event
                                if event.type == pygame.KEYDOWN:
                                        if event.key == pygame.K_UP:
                                                self.move_butaba_up ()
@@ -105,6 +108,24 @@ class MainGame:
                                                self.move_butaba_left ()
                                        elif event.key == pygame.K_RIGHT:
                                                self.move_butaba_right ()
+                                       # drinking health potion in inventory
+                                       elif event.key == ord ("h") or event.key == ord ("H"):
+                                               self.inventory_drink_health_potion ()
+                                       # quit the game
+                                       elif event.key == ord ("q") or event.key == ord ("Q"):
+                                               sys.exit (0)
+
+       # drink a health potion if it is in the player's inventory
+       def inventory_drink_health_potion (self):
+               # if health is maxed out then ignore
+               if self.butaba.health == butaba.Butaba.MAXHEALTH:
+                       self.status_message = "You already have maximum health."
+               else:
+                       # look for a health potion
+                       for item in self.butaba.inventory:
+                               if isinstance (item, gameobjects.HealthPotion) is True:
+                                       self.use_object (item)
+                                       break
 
        def move_butaba_up (self):
                # clear any status messages
@@ -223,7 +244,10 @@ class MainGame:
                # if the object is a health potion
                if isinstance (obj, gameobjects.HealthPotion) is True:
                        obj.use (self.butaba)
-                       self.currentlevel.objects.remove (obj)
+                       if obj in self.currentlevel.objects:
+                               self.currentlevel.objects.remove (obj)
+                       elif obj in self.butaba.inventory:
+                               self.butaba.inventory.remove (obj)
                        self.status_message = "You gained health"
                # if the object is a chest
                elif isinstance (obj, gameobjects.Chest) is True:
@@ -327,29 +351,29 @@ class MainGame:
        # Draw the status infodisplay
        def draw_status (self):
                self.screen.blit (self.img_redpotion, (485, 10))
-               utility.put_text (self.screen, 550, 25, 24, (255, 0, 0), "%d" % self.butaba.health)
+               utility.put_text (self.screen, 550, 25, 20, (255, 0, 0), "%d" % self.butaba.health)
 
                self.screen.blit (self.img_lightning, (620, 10))
-               utility.put_text (self.screen, 660, 20, 24, (255,255,255), "%d" % self.butaba.strength)
+               utility.put_text (self.screen, 660, 25, 20, (255,255,255), "%d" % self.butaba.strength)
 
                self.screen.blit (self.img_wand, (485, 65))
-               utility.put_text (self.screen, 550, 75, 24, (0, 0, 255), "%d" % self.butaba.magic)
+               utility.put_text (self.screen, 550, 75, 20, (0, 0, 255), "%d" % self.butaba.magic)
 
                self.screen.blit (self.img_bulb, (620, 65))
-               utility.put_text (self.screen, 660, 75, 24, (0, 255, 0), "%d" % self.butaba.experience)
+               utility.put_text (self.screen, 660, 75, 20, (0, 255, 0), "%d" % self.butaba.experience)
 
                self.screen.blit (self.img_goldcoins, (485, 110))
-               utility.put_text (self.screen, 550, 130, 24, (255, 255, 0), "%d" % self.butaba.gold)
+               utility.put_text (self.screen, 550, 130, 20, (255, 255, 0), "%d" % self.butaba.gold)
 
                if self.status_message is not None:
-                       utility.put_text (self.screen, 10, 485, 18, (255,255, 0), "%s" % self.status_message)
+                       utility.put_text (self.screen, 10, 485, 16, (255,255, 0), "%s" % self.status_message)
 
        # display the inventory of the player
        def draw_inventory (self):
                # draw the inventory slots
                r = 1
                c = 1
-               utility.put_text (self.screen, 490, 170, 22, (255,255 , 0), "Inventory")
+               utility.put_text (self.screen, 490, 170, 16, (255,255 , 0), "Inventory")
                for i in range (butaba.Butaba.MAXITEMS):
                        self.screen.blit (self.img_inventory, (440+c*54, 150+r*54))
                        if c % 4 == 0:
index 69f35fd..9377d87 100644 (file)
Binary files a/objects/key.png and b/objects/key.png differ
diff --git a/objects/key2.png b/objects/key2.png
new file mode 100644 (file)
index 0000000..0f125c1
Binary files /dev/null and b/objects/key2.png differ
index 9c68c05..5ef5428 100644 (file)
@@ -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