Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Updated Bubble2D's update() method. How meta.

  • Loading branch information...
commit e5a7df02e6d7c25230e7fa575a20ebcea418f8bf 1 parent 9c7b390
Al Sweigart authored August 07, 2012

Showing 1 changed file with 10 additions and 8 deletions. Show diff stats Hide diff stats

  1. 18  square-shooter/square-shooter_makeover.py
18  square-shooter/square-shooter_makeover.py
@@ -87,12 +87,16 @@ def update(self, delta_t):
87 87
         self.pos.x += self.speed.x * delta_t
88 88
         self.pos.y += self.speed.y * delta_t
89 89
 
  90
+        wrapped = self.is_out()
  91
+        self.wrap_around()
  92
+        return wrapped
  93
+
90 94
     def wrap_around(self):
91 95
         """Change the position of the bubble to toroidally "wrap around" if it goes off one edge of the map."""
92  
-        if self.pos.x < 0: self.pos.x = 1
93  
-        if self.pos.y < 0: self.pos.y = 1
94  
-        if self.pos.x > 1: self.pos.x = 0
95  
-        if self.pos.y > 1: self.pos.y = 0
  96
+        if self.pos.x < 0: self.pos.x += 1
  97
+        if self.pos.y < 0: self.pos.y += 1
  98
+        if self.pos.x > 1: self.pos.x -= 1
  99
+        if self.pos.y > 1: self.pos.y -= 1
96 100
 
97 101
     def is_out(self):
98 102
         """Returns True if the center of the bubble is outside the game map, False if it is on the map."""
@@ -209,11 +213,10 @@ def update(self, delta_t):
209 213
         elif self.freeze_timer <= 0:
210 214
             for i in self.bubbles:
211 215
                 i.update(delta_t)
212  
-                i.wrap_around()
213 216
 
214 217
         if self.bullet != None:
215  
-            self.bullet.update(delta_t)
216  
-            if self.bullet.is_out():
  218
+            bullet_wrapped = self.bullet.update(delta_t)
  219
+            if bullet_wrapped:
217 220
                 self.bullet = None
218 221
 
219 222
         if self.ship == None:
@@ -232,7 +235,6 @@ def update(self, delta_t):
232 235
         self.ship.speed.x *= 0.99
233 236
         self.ship.speed.y *= 0.99
234 237
         self.ship.update(delta_t)
235  
-        self.ship.wrap_around()
236 238
 
237 239
     def handle_collisions(self, delta_t):
238 240
         for b in self.bubbles:

0 notes on commit e5a7df0

Please sign in to comment.
Something went wrong with that request. Please try again.