1. illume
  2. outofdesert

Commits

illume  committed 7c9ab28

Added an Indicator of how much you have done on the level.

Using pygame Sprite system.

  • Participants
  • Parent commits 0e62260
  • Branches default

Comments (0)

Files changed (1)

File outofdesert/main.py

View file
  • Ignore whitespace
 import pygame
 from pygame.locals import *
 
+WIDTH, HEIGHT = 640,480
 
 
 class Sprite(pygame.sprite.DirtySprite):
     def start(self):
-        # when it gets to 1.0 the game is complete, 0.0 fail.
-        self.indicator = 0.5
-        self.elapsed_time = 0.0
         self.image = None
         self.rect = None
 
         # when it gets to 1.0 the game is complete, 0.0 fail.
         self.indicator = 0.5
 
+        self.indicator = Indicator().start()
+        self.indicator.add(self)
+        return self
+
 
 class Hero(Sprite):
     def start(self):
 
 class Indicator(Sprite):
     def start(self):
-        pass
+        # when it gets to 1.0 the game is complete, 0.0 fail.
+        self.indicator = 0.5
+        self.rect = Rect(WIDTH -100, 0, 100, 20)
+        self.image = pygame.Surface((100, 20))
+        return self
+
+    def update(self, *args):
+        self.indicator += 0.001
+        howmuch = int(100 * self.indicator)
+        #print ("howmuch %s %s" % (howmuch, self.indicator))
+        self.image.fill(Color("white"))
+        self.image.fill(Color("red"), (0, 0, howmuch, 20))
+        self.dirty = 1
+
+
 
 class Floor(Sprite):
     def start(self):
     #dirty = [pygame.display.get_surface().get_size()]
     dirty = []
     going = True
-    g = Game()
+    g = Game().start()
+    clock = pygame.time.Clock()
+
     while going:
         events = pygame.event.get()
         for e in events:
             if e.type == QUIT or e.type == KEYDOWN and e.key == K_ESCAPE:
                 going = False
+        g.update()
         dirty = g.draw(screen)
         pygame.display.update(dirty)
+        clock.tick(20)
 
 
+