Added the Conversation Interaction
[butaba-adventures.git] / maingame.py
index b70d48c..687db49 100644 (file)
@@ -2,59 +2,115 @@ import pygame
 import sys
 import random
 import os.path
+import cPickle
 
 import level
 import butaba
+import utility
+import gameobjects
+import constants
+import npcs
 
 class MainGame:
 
        # initialize the game
        def __init__ (self):
                pygame.init ()
-               self.screen  = pygame.display.set_mode ((640, 480))
+               self.screen  = pygame.display.set_mode ((720, 512))
                pygame.display.set_caption ("The Adventures of Butaba")
 
                # initalize background graphics
-               self.tileset = pygame.image.load (os.path.join ("background", "tileset.png")).convert ()
+               self.img_tileset = pygame.image.load (os.path.join ("background", "tileset.png")).convert ()
+
+               self.img_menu = pygame.image.load (os.path.join ("background", "menu_screen.png")).convert ()
+
+               self.img_inventory = pygame.image.load (os.path.join ("background", "inventory.png")).convert ()
+
+               self.img_chestbg = pygame.image.load (os.path.join ("background", "chestcontent.png")).convert ()
+
+               self.img_dialogue = pygame.image.load (os.path.join ("background", "dialog_screen.png")).convert ()
+               self.img_dialogue.set_colorkey (pygame.Color (0, 255, 0))
+
 
                # initialize object graphics
-               self.redpotion = pygame.image.load (os.path.join ("objects", "red-potion.png")).convert ()
-               self.redpotion.set_colorkey (pygame.Color (0, 255, 0))
-               self.goldcoins = pygame.image.load (os.path.join ("objects", "gold-coins.png")).convert ()
-               self.goldcoins.set_colorkey (pygame.Color (0, 255, 0))
-               self.wand = pygame.image.load (os.path.join ("objects", "wand.png")).convert ()
-               self.wand.set_colorkey (pygame.Color (0, 255, 0))
-               self.bulb = pygame.image.load (os.path.join ("objects", "bulb.png")).convert ()
-               self.bulb.set_colorkey (pygame.Color (0, 255, 0))
-               self.lightning = pygame.image.load (os.path.join ("objects", "lightning.png")).convert ()
-               self.lightning.set_colorkey (pygame.Color (0, 255, 0))
+               self.img_redpotion = pygame.image.load (os.path.join ("objects", "red-potion.png")).convert ()
+               self.img_redpotion.set_colorkey (pygame.Color (0, 255, 0))
+               self.img_goldcoins = pygame.image.load (os.path.join ("objects", "gold-coins.png")).convert ()
+               self.img_goldcoins.set_colorkey (pygame.Color (0, 255, 0))
+               self.img_wand = pygame.image.load (os.path.join ("objects", "wand.png")).convert ()
+               self.img_wand.set_colorkey (pygame.Color (0, 255, 0))
+               self.img_bulb = pygame.image.load (os.path.join ("objects", "bulb.png")).convert ()
+               self.img_bulb.set_colorkey (pygame.Color (0, 255, 0))
+               self.img_lightning = pygame.image.load (os.path.join ("objects", "lightning.png")).convert ()
+               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))
 
                # initialize player graphics
-               self.butabafront = pygame.image.load (os.path.join ("sprite", "butaba-front.png")).convert ()
-               self.butabafront.set_colorkey (pygame.Color (0, 255, 0))
-               self.butababack = pygame.image.load (os.path.join ("sprite", "butaba-back.png")).convert ()
-               self.butababack.set_colorkey (pygame.Color (0, 255, 0))
-               self.butabaleft = pygame.image.load (os.path.join ("sprite", "butaba-left.png")).convert ()
-               self.butabaleft.set_colorkey (pygame.Color (0, 255, 0))
-               self.butabaright = pygame.image.load (os.path.join ("sprite", "butaba-right.png")).convert ()
-               self.butabaright.set_colorkey (pygame.Color (0, 255, 0))
+               self.img_butabafront = pygame.image.load (os.path.join ("sprite", "butaba-front.png")).convert ()
+               self.img_butabafront.set_colorkey (pygame.Color (0, 255, 0))
+               self.img_butababack = pygame.image.load (os.path.join ("sprite", "butaba-back.png")).convert ()
+               self.img_butababack.set_colorkey (pygame.Color (0, 255, 0))
+               self.img_butabaleft = pygame.image.load (os.path.join ("sprite", "butaba-left.png")).convert ()
+               self.img_butabaleft.set_colorkey (pygame.Color (0, 255, 0))
+               self.img_butabaright = pygame.image.load (os.path.join ("sprite", "butaba-right.png")).convert ()
+               self.img_butabaright.set_colorkey (pygame.Color (0, 255, 0))
+
+               # initialize NPC graphics
+               self.img_bulisa = pygame.image.load (os.path.join ("sprite", "bulisa.png")).convert ()
+               self.img_bulisa.set_colorkey (pygame.Color (0, 255, 0))
+
+               # initialize portraits
+               self.img_butaba_portrait = pygame.image.load (os.path.join ("portraits", "butaba.png")).convert ()
+               self.img_bulisa_portrait = pygame.image.load (os.path.join ("portraits", "bulisa.png")).convert ()
 
                # set level data
                self.setup_levels ()
                # set current level and position of our character
                self.currentlevel = self.level1
 
+               # set the status message
+               self.status_message = "Game started"
+
                self.butaba = butaba.Butaba (5,0, butaba.Butaba.RIGHT)
 
        # set up the levels and their interactions
        def setup_levels (self):
-               self.level1 = level.Level (level.LEVEL_1)
+               # set up the objects first
+               chest1 = gameobjects.Chest (2, 6, "chest", self.img_chest, constants.KEY_CHEST1, True)
+               chest2 = gameobjects.Chest (6, 6, "chest", self.img_chest, constants.KEY_CHEST2, True)
+               key1 = gameobjects.Key (5, 3, "a chest key", self.img_key2, constants.KEY_CHEST1)
+               key2 =  gameobjects.Key (5, 3, "a chest key", self.img_key, constants.KEY_CHEST2)
+               potion = gameobjects.HealthPotion (5, 2, self.img_redpotion)
+               gold50 = gameobjects.GoldCoins (6, 2, self.img_goldcoins, 50)
+               gold25 = gameobjects.GoldCoins (6, 2, self.img_goldcoins, 25)
+               gold10 = gameobjects.GoldCoins (6, 2, self.img_goldcoins, 10)
+               potion2 = gameobjects.HealthPotion (5, 2, self.img_redpotion)
+               potion3 = gameobjects.HealthPotion (5, 2, self.img_redpotion)
+
+               npc_bulisa = npcs.Bulisa (4, 3, self.img_bulisa, self.img_bulisa_portrait,
+                                                                               [ os.path.join ("dialogues", "bulisa1.dlg") ])
+
+               chest1.objects = [ gold50, gold25, potion2, potion3, key2, gold10 ]
+
+               # create the levels
+               self.level1 = level.Level (cPickle.load (file ("levels/level1.dat")),
+                               objects = [ chest1 ] )
 
-       # function to draw text
-       def put_text (self, x, y, size, (r,g,b), text):
-               harisfont = os.path.join ("font", "HarisComic-2.ttf")
-               surf = pygame.font.Font (harisfont, size).render (text, True, pygame.Color (r,g,b))
-               self.screen.blit (surf, (x, y))
+               self.level1w = level.Level (cPickle.load (file ("levels/level1w.dat")))
+
+               self.level1e = level.Level (cPickle.load (file ("levels/level1e.dat")),
+                               objects = [ key1, potion, chest2 ], npcs = [ npc_bulisa ])
+
+               # set up the interaction between levels
+               self.level1.levelright = self.level1e
+               self.level1.levelleft = self.level1w
+               self.level1e.levelleft = self.level1
+               self.level1w.levelright = self.level1
 
        def main_loop (self):
                # main game loop
@@ -62,11 +118,17 @@ class MainGame:
                        # clear screen
                        self.screen.fill (pygame.Color (0,0,0))
                        # draw the level
-                       self.draw_level (self.currentlevel)
+                       self.draw_level_background (self.currentlevel)
+                       # draw level objects
+                       self.draw_level_objects (self.currentlevel)
+                       # draw the NPCs in the level
+                       self.draw_level_npcs (self.currentlevel)
                        # draw our character
                        self.draw_butaba ()
+                       # display the character's inventory
+                       self.draw_inventory ()
                        # draw the status info
-                       self.draw_information ()
+                       self.draw_status ()
                        # update the display
                        pygame.display.update ()
 
@@ -74,6 +136,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 ()
@@ -83,8 +146,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):
+               # look for a health potion
+               for item in self.butaba.objects:
+                       if isinstance (item, gameobjects.HealthPotion) is True:
+                               self.use_object (self.butaba, item)
+                               break
 
        def move_butaba_up (self):
+               # clear any status messages
+               self.status_message = None
                # first if butaba is not facing up, make him face up
                if self.butaba.position <> butaba.Butaba.BACK:
                        self.butaba.position = butaba.Butaba.BACK
@@ -94,16 +173,28 @@ class MainGame:
                if self.butaba.row <= 0:
                        # if there is a level above set current level to that one
                        if self.currentlevel.leveltop is not None:
-                               # make sure there is no obstacle
                                lastrow = len (self.currentlevel.leveltop.background) - 1
+                               # interact with objects
+                               if self.level_interact (self.currentlevel.leveltop, lastrow, self.butaba.col) is False:
+                                       return
+
+                               # make sure there is no obstacle
                                if self.check_background_obstacle (self.currentlevel.leveltop, lastrow, self.butaba.col) is False:
                                        self.currentlevel = self.currentlevel.leveltop
                                        self.butaba.row = lastrow
                # normal upward movement
-               elif self.check_background_obstacle (self.currentlevel, self.butaba.row-1, self.butaba.col) is False:
-                       self.butaba.row -= 1
+               else:
+                       # if there is any object in that place interact with it
+                       # if any object is a blocking object then avoid movement
+                       if self.level_interact (self.currentlevel, self.butaba.row-1, self.butaba.col) is False:
+                               return
+
+                       if self.check_background_obstacle (self.currentlevel, self.butaba.row-1, self.butaba.col) is False:
+                               self.butaba.row -= 1
 
        def move_butaba_down (self):
+               # clear any status messages
+               self.status_message = None
                # first if butaba is not facing forward, make him face forward/down
                if self.butaba.position <> butaba.Butaba.FRONT:
                        self.butaba.position = butaba.Butaba.FRONT
@@ -113,12 +204,21 @@ class MainGame:
                if self.butaba.row >= len (self.currentlevel.background)-1:
                        # if there is a level below set current level to that one
                        if self.currentlevel.levelbottom is not None:
+                               # interact with objects if any
+                               # if any object is a blocking object then avoid movement
+                               if self.level_interact (self.currentlevel.levelbottom, 0, self.butaba.col) is False:
+                                       return
                                # make sure there is no obstacle at that position
                                if self.check_background_obstacle (self.currentlevel.levelbottom, 0, self.butaba.col) is False:
                                        self.currentlevel = self.currentlevel.levelbottom
                                        self.butaba.row = 0
                # normal downward movement
-               elif self.check_background_obstacle (self.currentlevel, self.butaba.row+1, self.butaba.col) is False:
+               else:
+                       # interact with objects if any
+                       # if any object is a blocking object then avoid movement
+                       if self.level_interact (self.currentlevel, self.butaba.row+1, self.butaba.col) is False:
+                               return
+                       if self.check_background_obstacle (self.currentlevel, self.butaba.row+1, self.butaba.col) is False:
                                self.butaba.row += 1
 
        # check if a background tile is an obstacle
@@ -128,7 +228,141 @@ class MainGame:
                else:
                        return False
 
+       # get and interact with objects and characters if present in a particular row/col
+       def level_interact (self, level, row, col):
+               objs = []
+               # get list of objects at current location
+               for obj in level.objects:
+                       if obj.row == row and obj.col == col:
+                               objs.append (obj)
+
+               notblock = self.interact_objects (level, objs)
+
+               # get npc at current location
+               current_npc = None
+               for npc in level.npcs:
+                       if npc.row == row and npc.col == col:
+                               current_npc = npc
+                               break
+
+               # npcs always block the tile. So return false if there is an NPC
+               # at the location
+               if current_npc is not None:
+                       self.interact_npc (current_npc)
+                       return False
+
+               return notblock
+
+       # interaction with npcs
+       def interact_npc (self, npc):
+               # interact with NPC and get the response ID
+               resp_id = utility.dialogue_play (self.screen, self.img_dialogue, npc, self.img_butaba_portrait, 0, 90)
+
+               # if none
+               if resp_id is None:
+                       self.status_message = "You cannot initiate a conversation with %s" % npc.charname
+
+       # interaction with objects
+       def interact_objects (self, container, objs):
+               # overall flag for blocking/non-blocking objects
+               notblock = True
+
+               # now perform interaction
+               for obj in objs:
+                       # run the object interact function
+                       if obj.interact () is False:
+                               notblock = False
+                       # if object can be picked up ask
+                       if obj.can_pickup is True:
+                               ans = utility.ask_question (self.screen, "Found %s." % obj.text, ["Pick up", obj.use_str, "Ignore"], self.img_menu)
+                               # if the answer is "pick up"
+                               if ans == 1:
+                                       self.pickup_object (container, obj)
+                               elif ans == 2:
+                                       # use the object according to its type
+                                       self.use_object (container, obj)
+                       # if it cannot be picked up, try to use it anyway
+                       else:
+                               ans = utility.ask_question (self.screen, "Found %s." % obj.text, [obj.use_str, "Ignore"], self.img_menu)
+                               if ans == 1:
+                                       self.use_object (container, obj)
+
+               return notblock
+
+       # transfer an object from one container to another
+       # container must have an objects list
+       def transfer_object (self, source, obj, dest):
+               # remove object from source
+               source.objects.remove (obj)
+               # add object to destination
+               dest.objects.append (obj)
+
+       # picking up an object
+       def pickup_object (self, container, obj):
+               # only if object can be picked up, pick it up or use it
+               if obj.can_pickup is True:
+                       # check if the inventory is full
+                       if len (self.butaba.objects) >= butaba.Butaba.MAXITEMS:
+                               self.status_message = "Cannot pick up item. Inventory full"
+                       else:
+                               # add item to inventory
+                               self.transfer_object (container, obj, self.butaba)
+
+                               self.status_message = "You picked up %s" % obj.text
+
+       # this method uses the object first by calling the object use () method
+       # and then performing specific actions as necessary
+       def use_object (self, container, obj):
+               # if the object is a health potion
+               if isinstance (obj, gameobjects.HealthPotion) is True:
+                       if self.butaba.health < butaba.Butaba.MAXHEALTH:
+                               obj.use (self.butaba)
+                               container.objects.remove (obj)
+                               self.status_message = "You gained health"
+                       else:
+                               self.status_message = "You already have maximum health!"
+               # if the object is a chest
+               elif isinstance (obj, gameobjects.Chest) is True:
+                       # if chest is locked, try to open it
+                       if obj.locked is True:
+                               # try opening the chest with every item 9the use () function
+                               # of the chest determines if item is a key anyway
+                               fittedkey = None
+                               for invobj in self.butaba.objects:
+                                       fittedkey = obj.use (invobj)
+                                       # if a key fits
+                                       if fittedkey is not None:
+                                               break
+                               # if no key found
+                               if fittedkey is None:
+                                       self.status_message = "No key found to open %s" % obj.text
+                               # chest successfully unlocked
+                               else:
+                                       self.status_message = "You unlocked the %s" % obj.text
+                                       # remove the key from Butaba
+                                       self.butaba.objects.remove (fittedkey)
+                                       # add an experience point for unlocking chest subject
+                                       # to a limit of KNOWLEDGEMAX_CHEST_UNLOCK
+                                       if self.butaba.experience < constants.KNOWLEDGEMAX_CHEST_UNLOCK:
+                                               self.butaba.experience += 1
+                                               self.status_message += " and gained experience!"
+                       # display the contents of the chest
+                       else:
+                               item = utility.get_container_object (self.screen, obj, self.img_chestbg, 30)
+                               if item is not None:
+                                       self.interact_objects (obj, [ item, ])
+
+               # if the object is gold coins
+               elif isinstance (obj, gameobjects.GoldCoins) is True:
+                       obj.use (self.butaba)
+                       self.status_message = "You picked up %d gold." % obj.value
+                       # remove the gold coins after adding it to Butaba's gold
+                       container.objects.remove (obj)
+
        def move_butaba_left (self):
+               # clear any status messages
+               self.status_message = None
+
                # first if Butaba is not facing left, make him face left
                if self.butaba.position <> butaba.Butaba.LEFT:
                        self.butaba.position = butaba.Butaba.LEFT
@@ -138,17 +372,29 @@ class MainGame:
                if self.butaba.col <= 0:
                        # if there is a level to the right set current level to that one
                        if self.currentlevel.levelleft is not None:
-                               # make sure there is no obstacle at that position of movement
                                # get the last column of the previous level
                                lastcol = len (self.currentlevel.levelleft.background[0]) - 1
+                               # interact with objects if any
+                               # if any object is a blocking object then avoid movement
+                               if self.level_interact (self.currentlevel.levelleft, self.butaba.row, lastcol) is False:
+                                       return
+                               # make sure there is no obstacle at that position of movement
                                if self.check_background_obstacle (self.currentlevel.levelleft, self.butaba.row, lastcol) is False:
                                        self.currentlevel = self.currentlevel.levelleft
                                        self.butaba.col = lastcol
                # normal left movement
-               elif self.check_background_obstacle (self.currentlevel, self.butaba.row, self.butaba.col-1) is False:
-                       self.butaba.col -= 1
+               else:
+                       # interact with objects if any
+                       # if any object is a blocking object then avoid movement
+                       if self.level_interact (self.currentlevel, self.butaba.row, self.butaba.col-1) is False:
+                               return
+                       if self.check_background_obstacle (self.currentlevel, self.butaba.row, self.butaba.col-1) is False:
+                               self.butaba.col -= 1
 
        def move_butaba_right (self):
+               # clear any status messages
+               self.status_message = None
+
                # First if Butaba is not facing right make him face right
                if self.butaba.position <> butaba.Butaba.RIGHT:
                        self.butaba.position = butaba.Butaba.RIGHT
@@ -158,48 +404,102 @@ class MainGame:
                if self.butaba.col >= len (self.currentlevel.background[0])-1:
                        # if there is a level to the right swap current level with that one
                        if self.currentlevel.levelright is not None:
-                       # make sure there is no obstacle at that position of movement
+                               # interact with objects if any
+                               # if any object is a blocking object then avoid movement
+                               if self.level_interact (self.currentlevel.levelright, self.butaba.row, 0) is False:
+                                       return
+
+                               # make sure there is no obstacle at that position of movement
                                # get the last column of the previous level
                                if self.check_background_obstacle (self.currentlevel.levelright, self.butaba.row, 0) is False:
                                        self.currentlevel = self.currentlevel.levelright
                                        self.butaba.col = 0
                # normal right movement
-               elif self.check_background_obstacle (self.currentlevel, self.butaba.row, self.butaba.col + 1) is False:
-                       self.butaba.col += 1
+               else:
+                       # interact with objects if any
+                       # if any object is a blocking object then avoid moving
+                       if self.level_interact (self.currentlevel, self.butaba.row, self.butaba.col + 1) is False:
+                               return
+                       if self.check_background_obstacle (self.currentlevel, self.butaba.row, self.butaba.col + 1) is False:
+                               self.butaba.col += 1
 
        def draw_butaba (self):
                if self.butaba.position == butaba.Butaba.FRONT:
-                       self.screen.blit (self.butabafront, (self.butaba.col*48, self.butaba.row*48))
+                       self.screen.blit (self.img_butabafront, (self.butaba.col*48, self.butaba.row*48))
                elif self.butaba.position == butaba.Butaba.BACK:
-                       self.screen.blit (self.butababack, (self.butaba.col*48, self.butaba.row*48))
+                       self.screen.blit (self.img_butababack, (self.butaba.col*48, self.butaba.row*48))
                elif self.butaba.position == butaba.Butaba.LEFT:
-                       self.screen.blit (self.butabaleft, (self.butaba.col*48, self.butaba.row*48))
+                       self.screen.blit (self.img_butabaleft, (self.butaba.col*48, self.butaba.row*48))
                elif self.butaba.position == butaba.Butaba.RIGHT:
-                       self.screen.blit (self.butabaright, (self.butaba.col*48, self.butaba.row*48))
-
-       # Draw the sidebar infodisplay
-       def draw_information (self):
-               self.screen.blit (self.redpotion, (485, 10))
-               self.put_text (550, 25, 28, (255, 0, 0), "%d" % self.butaba.health)
-               self.screen.blit (self.goldcoins, (485, 50))
-               self.put_text (550, 75, 28, (255, 255, 0), "%d" % self.butaba.gold)
-               self.screen.blit (self.wand, (485, 120))
-               self.put_text (550, 130, 28, (0, 0, 255), "%d" % self.butaba.magic)
-               self.screen.blit (self.bulb, (485, 180))
-               self.put_text (550, 190, 28, (0, 255, 0), "%d" % self.butaba.experience)
-               self.screen.blit (self.lightning, (485, 240))
-               self.put_text (550, 250, 28, (255,255,255), "%d" % self.butaba.strength)
-
-       # Draw the level background tiles
-       def draw_level (self, level):
+                       self.screen.blit (self.img_butabaright, (self.butaba.col*48, self.butaba.row*48))
+
+
+       # Draw the status infodisplay
+       def draw_status (self):
+               self.screen.blit (self.img_redpotion, (485, 10))
+               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, 25, 20, (255,255,255), "%d" % self.butaba.strength)
+
+               self.screen.blit (self.img_wand, (485, 65))
+               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, 20, (0, 255, 0), "%d" % self.butaba.experience)
+
+               self.screen.blit (self.img_goldcoins, (485, 110))
+               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, 10, (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, 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:
+                               r += 1
+                               c = 1
+                       else:
+                               c += 1
+
+               r = 1
+               c = 1
+               for obj in self.butaba.objects:
+                       self.screen.blit (obj.image, (440+c*54+2, 150+r*54+2))
+                       if c % 4 == 0:
+                               r += 1
+                               c = 1
+                       else:
+                               c += 1
+
+       # Draw the level background tiles on surface
+       def draw_level_background (self, level):
                i = 0
                for row in level.background:
                        j = 0
                        for tilerow, tilecol, is_solid in row:
                                tilex = tilecol * 48
                                tiley = tilerow * 48
-                               self.screen.blit (self.tileset, (j*48, i*48), pygame.Rect (tilex, tiley, 48, 48))
+                               self.screen.blit (self.img_tileset, (j*48, i*48), pygame.Rect (tilex, tiley, 48, 48))
 
                                j += 1
                        i += 1
 
+       # Draw the level objects
+       def draw_level_objects (self, level):
+               for obj in level.objects:
+                       if obj.image is not None:
+                               self.screen.blit (obj.image, (obj.col*48, obj.row*48))
+
+
+       # Draw the NPCs in the level
+       def draw_level_npcs (self, level):
+               for npc in level.npcs:
+                       if npc.image is not None:
+                               self.screen.blit (npc.image, (npc.col*48, npc.row*48))