Commits

Radomir Dopieralski committed 72d0aef

Simplistic item equipping

  • Participants
  • Parent commits 7feac4a

Comments (0)

Files changed (4)

File jelly/game.py

             return
 
     def game_menu(self):
-        menu = message.Menu((80, 380), ['Start new game', 'Exit'])
+        menu = message.Menu((80, 380), ['Start new game', 'Exit'], [0])
         self.display.render_menu(menu)
         choice = None
         try:
 
     def quit_menu(self):
         menu = message.Menu(
-                (290, 200),
-                ['Continue playing', 'Quit to title', 'Exit game'])
+            (290, 200),
+            ['Continue playing', 'Quit to title', 'Exit game'],
+            [0],
+        )
         self.display.render_menu(menu)
         choice = None
         try:

File jelly/items.py

 def use_item(item, mob, level):
     if item == 'Bandaid':
         mob.hp = min(mob.max_hp, mob.hp + 10)
+        return True
     elif item == 'First aid kit':
         mob.hp = mob.max_hp
+        return True
     elif item == 'Heavy wrench':
+        mob.weapon = item
         mob.damage = 2
     elif item == 'Wooden mallet':
+        mob.weapon = item
         mob.damage = 3
     elif item == 'Fire axe':
+        mob.weapon = item
         mob.damage = 8
-
+    return False

File jelly/message.py

         tile = self.tiles[80]
         self.image = pygame.surface.Surface((width, height))
         self.image.set_colorkey((0, 0, 0))
-        self.image.fill((25, 100, 252), (4, 4, width - 8, height - 8))
+        self.image.fill((0x16, 0x52, 0xcd), (4, 4, width - 8, height - 8))
         for y in xrange(8, height - 8, 4):
             self.image.blit(tile, (0, y), (0, 8, 8, 4))
             self.image.blit(tile, (width - 8, y), (24, 8, 8, 4))
 
 
 class Menu(object):
-    def __init__(self, pos, items):
+    def __init__(self, pos, items, highlights=[]):
         self.pos = pos
         self.sprites = []
         self.items = items
         width = 0
         for i, item in enumerate(items):
-            text = Text(item)
+            if i in highlights:
+                color = (255, 255, 0)
+            else:
+                color = (250, 250, 250)
+            text = Text(item, color)
             self.sprites.append(text)
             text.rect.topleft = (pos[0] + 12, pos[1] + 14 * i + 6)
             if width < text.rect.width:

File jelly/mobs.py

         self.hp = self.max_hp
         self.items = collections.Counter()
         self.damage = 1
+        self.weapon = None
 
 
     def place(self, (x, y)):
 
     def inventory_menu(self, display):
         item_list = [k for (k, v) in self.items.iteritems() if v]
-        labels = ['%s x%d' % (k, v) for (k, v) in self.items.iteritems() if v]
-        menu = message.Menu((480, 20), labels or ['Empty'])
+        labels = []
+        equipped = []
+        for item, count in self.items.iteritems():
+            if self.weapon == item:
+                equipped.append(len(labels))
+                labels.append('%s (equipped)' % item)
+            elif count:
+                labels.append('%s x%d' % (item, count))
+        menu = message.Menu((480, 20), labels or ['Empty'], equipped)
         display.render_menu(menu)
         choice = None
         clock = pygame.time.Clock()
         if keys[pg.K_x]:
             item = self.inventory_menu(display)
             if item:
-                items.use_item(item, self, level)
-                self.items[item] -= 1
+                if items.use_item(item, self, level):
+                    self.items[item] -= 1
                 return True
             return False
         elif keys[pg.K_DOWN] and keys[pg.K_LEFT]: