Commits

Radomir Dopieralski  committed c302519 Draft

Add player character death

  • Participants
  • Parent commits ef2b2a6

Comments (0)

Files changed (1)

File deevo/__main__.py

         dummy = Dummy()
         dummy.rect = pygame.Rect((0, 0, 64, 64))
         dummy.rect.midbottom = self.rect.midbottom
+        if (pygame.sprite.collide_rect(self.shadow, gunner.shadow) and
+            pygame.sprite.collide_mask(self.shadow, gunner.shadow)):
+            gunner.dead = True
         if gunner.ray.alive() and pygame.sprite.collide_rect(gunner.ray, dummy):
             self.glow.brightness = 192
             if not self.glow.alive():
             self.depth += self.dy
         if self.rect.right < 0 or self.rect.top > 600 or self.rect.bottom < 0:
             self.kill()
+        if self.rect.right < 0:
+            gunner.dead = True
 
 
 class Glow(Sprite):
 
     def update(self):
         if self.brightness > 0:
-            self.brightness -= 16
+            self.brightness -= 48
             self.image.set_alpha(self.brightness)
         else:
             self.kill()
 
     def __init__(self):
         super(Gunner, self).__init__()
+        self.image = self.image.subsurface(self.image.get_rect())
         self.rect.topleft = (128, 312)
         self.dzs = itertools.cycle([0, -2, -1, 0, 1, 2])
         self.dx = 0
         self.ddy = 0
         self.depth = self.rect.top
         self.ray = Ray(self)
-        shadows.add(Shadow(self, (-8, 12)))
+        self.shadow = Shadow(self, (-8, 12))
+        shadows.add(self.shadow)
+        self.dead = False
+        self.opacity = 256
 
     def update(self):
+        if self.dead:
+            self.opacity -= 16
+            if self.opacity <= 0:
+                self.kill()
+            self.image.set_alpha(self.opacity)
+            return
         keys = pygame.key.get_pressed()
         if keys[pygame.K_SPACE]:
             self.ray.brightness = 192
     def __init__(self):
         pygame.display.set_mode((800, 600))
         self.load()
-        self.level()
 
     def load(self):
         global SHEET
         SHEET[18].set_alpha(64)
         SHEET[19].set_alpha(64)
 
-    def level(self):
+    def new_level(self):
         global shadows
         global sprites
         global gunner
                 raise SystemExit()
             elif event.type == pygame.KEYDOWN:
                 if event.key == pygame.K_SPACE:
-                    return
+                    break
+        while True:
+            event = pygame.event.wait()
+            if event.type == pygame.QUIT:
+                raise SystemExit()
+            elif event.type == pygame.KEYUP:
+                if event.key == pygame.K_SPACE:
+                    break
 
     def main(self):
         screen = pygame.display.get_surface()
 game = Game()
 while True:
     game.image('intro.png')
+    game.new_level()
     game.main()