Commits

Radomir Dopieralski  committed 8aacaae

Display hitpoints

  • Participants
  • Parent commits 2e88714

Comments (0)

Files changed (9)

File jelly/finish.png

Old
Old image
New
New image

File jelly/game.py

 from jelly import util
 
 
+LEVELS = [
+    (1, 4, 8, [mobs.PurpleJelly]),
+    (1, 5, 8, [mobs.PurpleJelly, mobs.PinkJelly]),
+    (2, 6, 12, [mobs.PurpleJelly, mobs.PinkJelly]),
+    (2, 7, 8, [mobs.PurpleJelly, mobs.RedJelly]),
+    (3, 8, 12, [mobs.PurpleJelly, mobs.RedJelly]),
+    (3, 8, 12, [mobs.PurpleJelly, mobs.PinkJelly, mobs.RedJelly]),
+    (2, 6, 8, [mobs.RedJelly]),
+    (4, 8, 12, [mobs.PurpleJelly, mobs.RedJelly, mobs.BlueJelly]),
+    (2, 12, 16, [mobs.BlueJelly]),
+    (5, 8, 20, [mobs.PurpleJelly, mobs.RedJelly, mobs.BlueJelly, mobs.PinkJelly]),
+]
+
+
 class Game(object):
     def __init__(self):
         self.display = display.Display()
         self.game_menu()
 
     def next_level(self):
+        params = LEVELS[self.pc.level]
         self.pc.level += 1
-        if self.pc.level > 10:
+        if self.pc.level >= len(LEVELS):
             return True
         self.level = rooms_level.Level(self.pc)
+        self.level.populate(*params)
         self.display.render_level(self.level)
+        self.display.hud.add(message.Health(self.pc))
 
     def quit_menu(self):
         menu = message.Menu(

File jelly/items.py

+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+
+ITEMS = [
+    'Empty',
+    'Heavy wrench',
+    'Wooden mallet',
+    'First aid kit',
+    'Bandaid',
+    'Bomb',
+    'Fire axe',
+]
+

File jelly/jelly.png

Old
Old image
New
New image

File jelly/message.py

                 raise util.QuitLevel()
         return None
 
+class Health(pygame.sprite.Sprite):
+    tiles = None
+
+    def __init__(self, owner):
+        super(Health, self).__init__()
+        if self.tiles is None:
+            self.tiles = resource.load_tiles('jelly.png', 32, 32)
+        self.owner = owner
+        self.image = self.tiles[92].copy()
+        self.rect = self.image.get_rect()
+        self.rect.center = 32, 32
+
+
+    def update(self):
+        gauge = int(max(0, min(26, 26 * self.owner.hp / self.owner.max_hp)))
+        self.image = self.tiles[92].copy()
+        self.image.blit(self.tiles[93], (3, 0), (3, 0, gauge, 32))

File jelly/mobs.py

 
 from jelly import sprites
 from jelly import message
+from jelly import items
 from jelly.util import DX, DY, dist, pos2dir, dist2
 
 
     if not possible:
         return False
     direction = random.choice(possible)
-    MobClass = random.choice([BlueJelly, PurpleJelly, PinkJelly, RedJelly])
+    MobClass = random.choice(mob.spawns)
     pos = (x + DX[direction], y + DY[direction])
     spawnee = MobClass(pos)
     level.spawn(spawnee, mob)
     max_hp = 2
     hunted = False
     behaviors = [attack_behavior, wander_behavior]
+    spawns = []
 
     def __init__(self, (x, y)):
         self.pos = x, y
 
     def __init__(self, *args, **kwargs):
         super(Crate, self).__init__(*args, **kwargs)
-        self.item = 'Empty'
+        self.item = random.choice(items.ITEMS)
 
     def control(self, level):
         pass

File jelly/rooms_level.py

         for room in rooms:
             (x, y), (w, h) = room
             self._fill((x, y), (w + 1, h + 1), 1)
-            for i in xrange(r(1, 4)):
-                MobClass = random.choice([
-                    mobs.PinkJelly,
-                    mobs.PurpleJelly,
-                    mobs.RedJelly,
-                    mobs.BlueJelly,
-                    mobs.BlackJelly,
-                    mobs.Crate,
-                ])
-                self.spawn(MobClass((r(x, x + w), r(y, y + h))))
 
         (x, y), (w, h) = random.choice(rooms)
         pc_pos = (r(x, x+w), r(y, y+h))
 
         self.rooms = rooms
 
+    def populate(self, bosses, items, monsters, kinds):
+        r = random.randint
+        for i in xrange(bosses):
+            (x, y), (w, h) = random.choice(self.rooms)
+            pos = (r(x, x + w), r(y, y + h))
+            mob = mobs.BlackJelly(pos)
+            mob.spawns = kinds
+            self.spawn(mob)
+        for i in xrange(items):
+            (x, y), (w, h) = random.choice(self.rooms)
+            pos = (r(x, x + w), r(y, y + h))
+            mob = mobs.Crate(pos)
+            self.spawn(mob)
+        for i in xrange(monsters):
+            (x, y), (w, h) = random.choice(self.rooms)
+            pos = (r(x, x + w), r(y, y + h))
+            mob = random.choice(kinds)(pos)
+            self.spawn(mob)
+
 
     def _fill(self, (sx, sy), (width, height), fill):
         for y in xrange(sy, sy + height):

File jelly/tutorial.png

Removed
Old image

File tutorial.png

Added
New image