Support for z ordering of objects. Debug overlay is Z=100 and the game debuginfo
Support for z ordering of objects. Debug overlay is Z=100 and the game
HUD is Z=10. Rest is Z=0.

--- a/astroids.py
+++ b/astroids.py
@@ -225,6 +225,8 @@
 
         self.height=self.font.size('A')[1]
 
+        self.z=10
+
     def draw(self,screen):
         img=self.font.render('Distance: %d m'%self.game.score,True,self.fg)
         screen.blit(img,(10,screen.get_size()[1]-self.height-10))

file:a/game.py -> file:b/game.py
--- a/game.py
+++ b/game.py
@@ -106,9 +106,21 @@
             gobj.update()
 
     def draw(self):
+        objects={} # Stores objects as function of z
         for gobj in self.objects:
-            if gobj.visible:
-                gobj.draw(self.screen)
+            if not gobj.visible: continue # Ignore invisible objects
+            if gobj.z not in objects:
+                objects[gobj.z]=[]
+            objects[gobj.z].append(gobj)
+
+        # Sort with smallest z first
+        zs=objects.keys()
+        zs.sort()
+
+        # Draw in order
+        for z in zs:
+            for obj in objects[z]:
+                obj.draw(self.screen)
 
 
 class GameObject(object):
@@ -120,6 +132,7 @@
         self.game.add_object(self)
 
         self.visible=True
+        self.z=0
 
     def remove(self):
         self.game.remove_object(self)
@@ -173,6 +186,7 @@
         self.views=[]
 
         self.visible=False
+        self.z=100
 
     def add_view(self,view):
         # Repack the rectangles using very basic algorith (stop at step 3 of