Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Moved render_bullet() and render_ship() to the Bullet and Ship classes.

  • Loading branch information...
commit bacff96189ad000e9df677011e46d2fa9a637aab 1 parent c0600c6
Al Sweigart authored August 09, 2012

Showing 1 changed file with 27 additions and 30 deletions. Show diff stats Hide diff stats

  1. 57  square-shooter/square-shooter_makeover.py
57  square-shooter/square-shooter_makeover.py
@@ -250,12 +250,35 @@ def shoot_at(self, x, y):
250 250
 
251 251
         return [b]
252 252
 
  253
+    def render(self, surface):
  254
+        bbox = pygame.draw.circle(
  255
+            surface,
  256
+            SILVER,
  257
+            scale_and_round(self.pos.x, self.pos.y),
  258
+            int(round(self.radius * MAP_SIZE)))
  259
+        pygame.draw.circle(
  260
+            surface,
  261
+            BLACK,
  262
+            scale_and_round(self.pos.x, self.pos.y),
  263
+            int(round(self.radius * 0.5 * MAP_SIZE)),
  264
+            1)
  265
+        if self.has_shield():
  266
+            pygame.draw.rect(surface, SILVER, bbox, 1)
  267
+
253 268
 
254 269
 class Bullet(ObjectOnMap):
255 270
     def __init__(self):
256 271
         super(Bullet, self).__init__(0.01) # all Bullet objects are the same size
257 272
         self.shield = False
258 273
 
  274
+    def render(self, surface):
  275
+        bbox = pygame.draw.circle(
  276
+            surface,
  277
+            RED,
  278
+            scale_and_round(self.pos.x, self.pos.y),
  279
+            int(round(self.radius * MAP_SIZE)))
  280
+        if self.shield:
  281
+            pygame.draw.rect(surface, RED, bbox, 1)
259 282
 
260 283
 class GameWorld:
261 284
     bubbles = []
@@ -490,8 +513,10 @@ def render_title_screen(self):
490 513
     def render_game_world(self):
491 514
         self.screen.set_clip((0, 0, MAP_WIDTH, MAP_HEIGHT))
492 515
 
493  
-        if self.world.ship != None: self.render_ship()
494  
-        if self.world.bullet != None: self.render_bullet()
  516
+        if self.world.ship != None:
  517
+            self.world.ship.render(self.screen)
  518
+        if self.world.bullet != None:
  519
+            self.world.bullet.render(self.screen)
495 520
 
496 521
         for bubble in self.world.bubbles:
497 522
             pos = bubble.pos
@@ -514,34 +539,6 @@ def render_game_world(self):
514 539
 
515 540
         self.screen.set_clip(None)
516 541
 
517  
-    def render_ship(self):
518  
-        ship = self.world.ship
519  
-        pos = ship.pos
520  
-        bbox = pygame.draw.circle(
521  
-            self.screen,
522  
-            SILVER,
523  
-            scale_and_round(pos.x, pos.y),
524  
-            int(round(ship.radius * MAP_SIZE)))
525  
-        pygame.draw.circle(
526  
-            self.screen,
527  
-            BLACK,
528  
-            scale_and_round(pos.x, pos.y),
529  
-            int(round(ship.radius * 0.5 * MAP_SIZE)),
530  
-            1)
531  
-        if self.world.ship.has_shield():
532  
-            pygame.draw.rect(self.screen, SILVER, bbox, 1)
533  
-
534  
-    def render_bullet(self):
535  
-        bullet = self.world.bullet
536  
-        pos = bullet.pos
537  
-        bbox = pygame.draw.circle(
538  
-            self.screen,
539  
-            RED,
540  
-            scale_and_round(pos.x, pos.y),
541  
-            int(round(bullet.radius * MAP_SIZE)))
542  
-        if self.world.ship != None and self.world.ship.has_super_bullets():
543  
-            pygame.draw.rect(self.screen, RED, bbox, 1)
544  
-
545 542
     def render_powerup(self, powerup):
546 543
         pos = powerup.pos
547 544
         radius = powerup.radius * MAP_SIZE

0 notes on commit bacff96

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