Continuing work on context-sensitive dialogs
[butaba-adventures.git] / maingame.py
index 66f28b8..9ba5ea2 100644 (file)
@@ -50,6 +50,8 @@ class MainGame:
                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))
                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))
+               self.img_bucket = pygame.image.load (os.path.join ("objects", "bucket.png")).convert ()
+               self.img_bucket.set_colorkey (pygame.Color (0, 255, 0))
 
                # initialize player graphics
                self.img_butabafront = pygame.image.load (os.path.join ("sprite", "butaba-front.png")).convert ()
 
                # initialize player graphics
                self.img_butabafront = pygame.image.load (os.path.join ("sprite", "butaba-front.png")).convert ()
@@ -90,30 +92,45 @@ class MainGame:
                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)
                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)
+               bucket = gameobjects.Bucket (6, 3, self.img_bucket)
+
+               well1 = gameobjects.Well (4, 7)
+               well2 = gameobjects.Well (5, 7)
+               well3 = gameobjects.Well (4, 8)
+               well4 = gameobjects.Well (5, 8)
 
                npc_bulisa = npcs.Bulisa (4, 3, self.img_bulisa, self.img_bulisa_portrait,
                                                                                [ os.path.join ("dialogues", "bulisa1.dlg"),
                                                                                  os.path.join ("dialogues", "bulisa2.dlg"),
 
                npc_bulisa = npcs.Bulisa (4, 3, self.img_bulisa, self.img_bulisa_portrait,
                                                                                [ os.path.join ("dialogues", "bulisa1.dlg"),
                                                                                  os.path.join ("dialogues", "bulisa2.dlg"),
-                                                                                 os.path.join ("dialogues", "bulisa3.dlg") ] )
+                                                                                 os.path.join ("dialogues", "bulisa3.dlg"),
+                                                                                 os.path.join ("dialogues", "bulisa4.dlg") ] )
 
 
-               chest1.objects = [ gold50, gold25, potion2, potion3, key2, gold10 ]
+               chest1.objects = [ gold50, gold25, key2, gold10 ]
 
                # create the levels
 
                # create the levels
-               self.level1 = level.Level (cPickle.load (file ("levels/level1.dat")),
+               self.level1 = level.Level (cPickle.load (file (os.path.join ("levels", "level1.dat"))),
                                objects = [ chest1 ] )
 
                                objects = [ chest1 ] )
 
-               self.level1w = level.Level (cPickle.load (file ("levels/level1w.dat")))
+               self.level1w = level.Level (cPickle.load (file (os.path.join ("levels", "level1w.dat"))))
 
 
-               self.level1e = level.Level (cPickle.load (file ("levels/level1e.dat")),
+               self.level1e = level.Level (cPickle.load (file (os.path.join ("levels", "level1e.dat"))),
                                objects = [ key1, potion, chest2 ], npcs = [ npc_bulisa ])
 
                                objects = [ key1, potion, chest2 ], npcs = [ npc_bulisa ])
 
+               self.level1ee = level.Level (cPickle.load (file (os.path.join ("levels", "level1ee.dat"))),
+                               objects = [ well1, well2, well3, well4 ])
+
+               self.level1n = level.Level (cPickle.load (file (os.path.join ("levels", "level1n.dat"))),
+                               objects = [ bucket ])
+
                # set up the interaction between levels
                self.level1.levelright = self.level1e
                self.level1.levelleft = self.level1w
                self.level1e.levelleft = self.level1
                # set up the interaction between levels
                self.level1.levelright = self.level1e
                self.level1.levelleft = self.level1w
                self.level1e.levelleft = self.level1
+               self.level1e.levelright = self.level1ee
+               self.level1ee.levelleft = self.level1e
                self.level1w.levelright = self.level1
                self.level1w.levelright = self.level1
+               self.level1.leveltop = self.level1n
+               self.level1n.levelbottom = self.level1
 
        def main_loop (self):
                # main game loop
 
        def main_loop (self):
                # main game loop
@@ -267,7 +284,6 @@ class MainGame:
        def interact_npc_bulisa (self, npc):
                # set initial response ID to none
                resp_id = None
        def interact_npc_bulisa (self, npc):
                # set initial response ID to none
                resp_id = None
-               print (gamestate.mission_bulisa_water_from_well, gamestate.mission_bulisa_water_from_well_complete)
                # not yet started mission drawing water from well and not refused it
                if (gamestate.mission_bulisa_water_from_well is False
                        and gamestate.mission_bulisa_water_from_well_refused is False):
                # not yet started mission drawing water from well and not refused it
                if (gamestate.mission_bulisa_water_from_well is False
                        and gamestate.mission_bulisa_water_from_well_refused is False):
@@ -280,14 +296,25 @@ class MainGame:
                        # set the current dialog
                        npc.currentdialog = 2
                        resp_id = utility.dialogue_play (self.screen, self.img_dialogue, npc, self.img_butaba_portrait, 0, 90)
                        # set the current dialog
                        npc.currentdialog = 2
                        resp_id = utility.dialogue_play (self.screen, self.img_dialogue, npc, self.img_butaba_portrait, 0, 90)
-               # mission accepted but not completed
+               # mission accepted but not completed - check if completed and set value
+               # accordingly
                elif (gamestate.mission_bulisa_water_from_well is True
                        and gamestate.mission_bulisa_water_from_well_complete is False):
                elif (gamestate.mission_bulisa_water_from_well is True
                        and gamestate.mission_bulisa_water_from_well_complete is False):
-                       npc.currentdialog = 1
+                       for invobj in self.butaba.objects:
+                               if isinstance (invobj, gameobjects.Bucket) is True:
+                                       if invobj.liquid == "water":
+                                               gamestate.mission_bulisa_water_from_well_complete = True
+                                               self.butaba.objects.remove (invobj)
+                                               break
+                       # water mission is not completed yet
+                       if gamestate.mission_bulisa_water_from_well_complete is False:
+                               npc.currentdialog = 1
+                       else:
+                               npc.currentdialog = 3
+
                        # get the response ID
                        resp_id = utility.dialogue_play (self.screen, self.img_dialogue, npc, self.img_butaba_portrait, 0, 90)
 
                        # get the response ID
                        resp_id = utility.dialogue_play (self.screen, self.img_dialogue, npc, self.img_butaba_portrait, 0, 90)
 
-               print resp_id
                # if response ID is 12, then drawing water from well mission is refused
                if resp_id == "12" or resp_id == "18":
                        gamestate.mission_bulisa_water_from_well_refused = True
                # if response ID is 12, then drawing water from well mission is refused
                if resp_id == "12" or resp_id == "18":
                        gamestate.mission_bulisa_water_from_well_refused = True
@@ -394,6 +421,32 @@ class MainGame:
                        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)
                        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)
+               # using a bucket means emptying it
+               elif isinstance (obj, gameobjects.Bucket) is True:
+                       if obj.liquid is not None:
+                               self.status_message = "You emptied the bucket of %s" % obj.liquid
+                               obj.use (self.butaba)
+                       else:
+                               self.status_message = "Bucket is already empty."
+               # using a well
+               elif isinstance (obj, gameobjects.Well) is True:
+                       # if the well is not dry, i.e. it has some liquid
+                       if obj.liquid is not None:
+                               # search butaba inventory for an empty bucket
+                               for invobj in self.butaba.objects:
+                                       # bucket found, now check if it is empty
+                                       if isinstance (invobj, gameobjects.Bucket) is True:
+                                               # if empty fill it
+                                               if invobj.liquid is None:
+                                                       obj.use (invobj)
+                                                       self.status_message = "You successfully filled the %s with %s" % (invobj.text, obj.liquid)
+                                                       if self.butaba.strength < constants.STRENGTHMAX_DRAW_WELL_WATER:
+                                                               self.butaba.strength += 2
+                                                               self.status_message += " and gained strength!"
+                                                       return
+                               self.status_message = "You have no empty bucket to draw %s with!" % obj.liquid
+                       else:
+                               self.status_message = "%s appears to be dry!" % obj.text
 
        def move_butaba_left (self):
                # clear any status messages
 
        def move_butaba_left (self):
                # clear any status messages