Commits

Radomir Dopieralski committed b811804 Draft

Level definition

Comments (0)

Files changed (1)

 
     def update(self):
         if self.rect.right < 0:
-            self.rect.left = 800
+            self.kill()
 
 
 class Fridge(Thing):
     Shadow = LargeShadow
     shadow_offset = (0, 0)
 
-    def __init__(self, (x, y), index = 4):
-        super(Fridge, self).__init__((x, y), index)
+    def __init__(self, (x, y), monster=12, dieto=13, hp=10):
+        super(Fridge, self).__init__((x, y), 4)
         self.glow = Glow(self, (-12, -12))
         self.hp = 10
+        self.monster = monster
+        self.dieto = dieto
+        self.monster_hp = hp
 
     def update(self):
-        if self.rect.right < 0:
-            self.rect.left = 800
-
         if self.hp>0 and gunner.ray.alive() and pygame.sprite.collide_rect(gunner.ray, self):
             self.glow.brightness = 192
             if not self.glow.alive():
             self.hp -= 1
             if self.hp <= 0:
                 self.image = SHEET[5]
-                sprites.add(Monster(self.rect.topleft))
+                sprites.add(Monster(self.rect.topleft, self.monster, self.dieto,
+                                    self.monster_hp))
                 sprites.add(FridgeDoor(self))
                 self.depth -= 1
 
+        if self.rect.right < 0:
+            self.kill()
 
 class FridgeDoor(Thing):
     Shadow = LargeShadow
         else:
             self.rect.move_ip(self.dx, self.dy + self.dzs.next())
             self.depth += self.dy
-        if self.rect.right < 0:
-            self.rect.left = 800
         if self.rect.right < 0 or self.rect.top > 600 or self.rect.bottom < 0:
             self.kill()
 
         shadows = pygame.sprite.RenderUpdates()
         gunner = Gunner()
         sprites.add(gunner)
-        sprites.add(Fridge((600, 10), 4))
-        sprites.add(Fridge((200, 410), 4))
-        sprites.add(Thing((400, 210), 3))
-        sprites.add(Thing((100, 350), 15))
-        sprites.add(Monster((700, 100)))
-        sprites.add(Monster((500, 300), 8, 7))
-        sprites.add(Monster((200, 200), 10, 14))
+        self.level = iter(sorted([
+            (200, 100, Thing, 3),
+            (220, 150, Thing, 13),
+            (250, 250, Thing, 15),
+            (600, 280, Fridge),
+            (1200, 210, Thing, 15),
+            (1500, 200, Monster),
+            (1500, 400, Monster),
+            (2100, 300, Monster, 10, 14),
+        ]))
+
 
     def main(self):
         screen = pygame.display.get_surface()
         for i in range(8):
             wall.blit(SHEET[11], (i*128, 0))
         offset = 0
+        progress = 0
         background.blit(wall, (-offset, -32))
         screen.blit(background, (0, 0))
         pygame.display.flip()
         clock = pygame.time.Clock()
-        while True:
+        nextelem = self.level.next()
+        mx, my, Something = nextelem[:3]
+        finish = False
+        while not finish or len(sprites) > 1:
+            while not finish and mx < progress + 800:
+                sprites.add(Something((mx - progress, my), *nextelem[3:]))
+                try:
+                    nextelem = self.level.next()
+                    mx, my, Something = nextelem[:3]
+                except StopIteration:
+                    finish = True
             clock.tick(15)
             for event in pygame.event.get():
                 if event.type == pygame.QUIT:
                 offset = (offset + dx) % 128
                 dirty.append(background.blit(wall, (-offset, -32)))
                 screen.blit(background, (0, 0, 800, 96))
+                progress += dx
             dirty += shadows.draw(screen)
             dirty += sprites.draw(screen)
             pygame.display.update(dirty)