X-Git-Url: https://harishankar.org/repos/?p=butaba-adventures.git;a=blobdiff_plain;f=maingame.py;fp=maingame.py;h=7b54c2de2ba1893f0be38c744636b1412e044374;hp=b894164ffe187d26516d2180c591d133664022b1;hb=0c8a13e68a280cfbcb3248e0c33937f6553c841d;hpb=93cc3bd06a6052df2a827cf35b6609fc1476a63e diff --git a/maingame.py b/maingame.py index b894164..7b54c2d 100644 --- a/maingame.py +++ b/maingame.py @@ -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: