# 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
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))
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)
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 ()
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
# 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:
# 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: