import level
import butaba
+import utility
+import object
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))
# 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
# 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 ()
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
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))