Added shield functionality.
Added shield functionality.

--- a/astroids.py
+++ b/astroids.py
@@ -153,8 +153,24 @@
             if contact.fixtureA.body.userData.name!='astroid': return
         else: return
 
-        contact.enabled=False
-        self.destroy=True
+        if self.shields==0: # Destroy only if the shields are dead
+            contact.enabled=False
+            self.destroy=True
+
+    def postsolve(self,contact,impulse):
+        if self.destroyed: return
+        if contact.fixtureA.body==self.ship.body:
+            if contact.fixtureB.body.userData.name!='astroid': return
+        elif contact.fixtureB.body==self.ship.body:
+            if contact.fixtureA.body.userData.name!='astroid': return
+        else: return
+
+        total_impulse=0
+        for i in range(impulse.count):
+            total_impulse+=impulse.normalImpulses[i]
+            total_impulse+=impulse.tangentImpulses[i]
+
+        self.shields=max(self.shields-total_impulse/2,0)
 
 
 
@@ -205,7 +221,6 @@
         self.fg=(255,255,255)
 
         self.height=self.font.size('A')[1]
-        print self.height
 
     def draw(self,screen):
         img=self.font.render('Distance: %d m'%self.game.score,True,self.fg)