Radomir Dopieralski avatar Radomir Dopieralski committed 93c6faa

Dummy inventory menu

Comments (0)

Files changed (4)

jelly/__init__.py

                 self.display.update()
                 self.display.draw()
                 choice = menu.update()
-        except (util.QuitLevel, util.QuitGame):
-            raise util.QuitGame
-        if choice == 1:
-            raise util.QuitGame
+        except util.QuitLevel:
+            raise util.QuitGame()
+        if choice == 1 or choice is False:
+            raise util.QuitGame()
 
     def start(self):
         self.display.render_image('jelly/title.png')
         self.display.render_image('jelly/dead.png')
         self.game_menu()
 
+    def victory(self):
+        self.display.render_image('jelly/finish.png')
+        self.game_menu()
+
     def next_level(self):
+        self.pc.level += 1
+        if self.pc.level > 10:
+            return True
         self.level = rooms_level.Level(self.pc)
         self.display.render_level(self.level)
 
+    def quit_menu(self):
+        menu = message.Menu((200, 100), ['Continue playing', 'Exit to title'])
+        self.display.render_menu(menu)
+        choice = None
+        try:
+            while choice is None:
+                self.clock.tick(15)
+                self.display.update()
+                self.display.draw()
+                choice = menu.update()
+        except util.QuitLevel:
+            return
+        if choice == 1:
+            raise util.QuitLevel()
+
     def main(self):
         self.pc = mobs.Player()
         self.next_level()
                 elif event.type == pg.KEYDOWN and event.key == pg.K_n:
                     self.next_level()
                 elif event.type == pg.KEYDOWN and event.key == pg.K_ESCAPE:
-                    raise util.QuitLevel()
+                    self.quit_menu()
+                    self.display.refresh()
             try:
                 pc_animation = self.display.mob_sprites[id(self.pc)].animations
             except KeyError:
                 self.display.events(self.level.events)
                 self.level.events = []
             if not pc_animation:
-                if self.pc.control(self.level):
+                if self.pc.control(self.level, self.display):
                     for mob in list(self.level.mobs):
                         if mob == self.pc:
                             continue
         self.fog = None
         self.background = pygame.image.load(image_file).convert()
         self.sprites = SortedUpdates()
+        self.hud = SortedUpdates()
         self.shadows = pygame.sprite.RenderUpdates()
         self.lights = pygame.sprite.LayeredDirty()
 
     def render_menu(self, menu):
         for sprite in menu.sprites:
-            self.sprites.add(sprite)
+            self.hud.add(sprite)
 
     def render_level(self, level):
         self.first_draw = True
                 (64, 128, 255), (16, 64, 224))
         self.memory = self.fog.copy()
         self.sprites = SortedUpdates()
+        self.hud = SortedUpdates()
         self.shadows = pygame.sprite.RenderUpdates()
         self.dirty = []
         self.mob_sprites = weakref.WeakValueDictionary()
         if self.fog:
             self.lights.draw(self.fog)
             self.screen.blit(self.fog, (0, 0))
+        self.hud.draw(self.screen)
         pygame.display.update()
         self.dirty = []
 
             self.first_draw = False
         else:
             if self.fog:
+                self.hud.clear(self.screen, self.memory)
                 self.lights.clear(self.fog, self.memory)
                 visible = self.lights.draw(self.fog)
                 self.dirty.extend(visible)
                 for rect in self.dirty:
                     self.screen.blit(self.fog, rect.topleft, rect)
             else:
+                self.hud.clear(self.screen, self.background)
                 self.sprites.clear(self.screen, self.background)
                 self.shadows.draw(self.screen)
                 self.dirty.extend(self.sprites.draw(self.screen))
+            self.dirty.extend(self.hud.draw(self.screen))
             pygame.display.update(self.dirty)
             self.dirty = []
 
         self.sprites.update()
         self.shadows.update()
         self.lights.update()
+        self.hud.update()
 
     def events(self, events):
         for event in events:
                 width = text.rect.width
         self.cursor = Cursor((pos[0] + 10, pos[1] + 14))
         self.sprites.append(self.cursor)
-        self.window = Window(pos, (18 + width, 16 + 14 * len(items)))
+        self.window = Window(pos, (21 + width, 16 + 14 * len(items)))
         self.sprites.append(self.window)
 
     def move(self, di):
         self.cursor.item = max(0, min(len(self.items)-1, self.cursor.item + di))
 
+    def cleanup(self):
+        for sprite in self.sprites:
+            sprite.kill()
+        while True:
+            if pygame.event.wait().type == pg.KEYUP:
+                return
+
     def update(self):
         for event in pygame.event.get():
             if event.type == pg.KEYDOWN and event.key == pg.K_UP:
                 self.move(1)
             elif event.type == pg.KEYDOWN and event.key == pg.K_z:
                 item = self.cursor.item
-                for sprite in self.sprites:
-                    sprite.kill()
+                self.cleanup()
                 return item
+            elif event.type == pg.KEYDOWN and event.key == pg.K_x:
+                self.cleanup()
+                return False
             elif event.type == pg.QUIT:
+                self.cleanup()
                 raise util.QuitGame()
             elif event.type == pg.KEYDOWN and event.key == pg.K_ESCAPE:
+                self.cleanup()
                 raise util.QuitLevel()
         return None
 
 from pygame import locals as pg
 
 from jelly import sprites
+from jelly import message
 from jelly.util import DX, DY, dist, pos2dir, dist2
 
 
     color = 5
 
     def __init__(self):
+        self.level = 0
         self.max_hp = 100
         self.hp = self.max_hp
+        self.items = [
+            'Aaaaa',
+            'Bbbbb',
+            'Ccccc',
+            'Ddddd',
+        ]
 
 
     def place(self, (x, y)):
             level.game_over()
         return True
 
-    def control(self, level):
+    def inventory_menu(self, display):
+        menu = message.Menu((480, 20), self.items)
+        display.render_menu(menu)
+        choice = None
+        clock = pygame.time.Clock()
+        while choice is None:
+            clock.tick(15)
+            display.update()
+            display.draw()
+            choice = menu.update()
+        display.refresh()
+
+    def control(self, level, display):
         direction = None
         keys = pygame.key.get_pressed()
-        if keys[pg.K_DOWN] and keys[pg.K_LEFT]:
+        if keys[pg.K_x]:
+            self.inventory_menu(display)
+            return False
+        elif keys[pg.K_DOWN] and keys[pg.K_LEFT]:
             direction = 1
         elif keys[pg.K_UP] and keys[pg.K_LEFT]:
             direction = 3
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.