X-Git-Url: https://harishankar.org/repos/?p=butaba-adventures.git;a=blobdiff_plain;f=maingame.py;fp=maingame.py;h=af06593f01b52876ccadf3cc84f2014d7f6d8a54;hp=b70d48cb9a6a3ca84ef0797f66fa01534db525bf;hb=7dbb8e9b6766b7c0c17433bea3c88a321036b837;hpb=42a1f54d2fc5153bff97a8fc77086c4b7606c25e diff --git a/maingame.py b/maingame.py index b70d48c..af06593 100644 --- a/maingame.py +++ b/maingame.py @@ -5,6 +5,8 @@ import os.path import level import butaba +import utility +import object class MainGame: @@ -29,6 +31,9 @@ class MainGame: self.lightning = pygame.image.load (os.path.join ("objects", "lightning.png")).convert () self.lightning.set_colorkey (pygame.Color (0, 255, 0)) + self.key = pygame.image.load (os.path.join ("objects", "key.png")).convert () + self.key.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)) @@ -48,13 +53,12 @@ class MainGame: # set up the levels and their interactions def setup_levels (self): - self.level1 = level.Level (level.LEVEL_1) - # 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.level1 = level.Level (level.LEVEL_1) + self.level1e = level.Level (level.LEVEL_1E, + objects = [ object.Key (4, 3, self.key, level.KEY_CHEST1) ]) + self.level1.levelright = self.level1e + self.level1e.levelleft = self.level1 def main_loop (self): # main game loop @@ -62,11 +66,13 @@ 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 our character self.draw_butaba () # draw the status info - self.draw_information () + self.draw_status () # update the display pygame.display.update () @@ -177,21 +183,23 @@ class MainGame: 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): + + # Draw the status infodisplay + def draw_status (self): self.screen.blit (self.redpotion, (485, 10)) - self.put_text (550, 25, 28, (255, 0, 0), "%d" % self.butaba.health) + utility.put_text (self.screen, 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) + utility.put_text (self.screen, 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) + utility.put_text (self.screen, 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) + utility.put_text (self.screen, 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) + utility.put_text (self.screen, 550, 250, 28, (255,255,255), "%d" % self.butaba.strength) + - # Draw the level background tiles - def draw_level (self, level): + # Draw the level background tiles on surface + def draw_level_background (self, level): i = 0 for row in level.background: j = 0 @@ -203,3 +211,8 @@ class MainGame: 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))