shrub achieved
authoradrianna <adrianna.pinska@gmail.com>
Sat, 10 Sep 2016 11:41:02 +0000 (13:41 +0200)
committeradrianna <adrianna.pinska@gmail.com>
Sat, 10 Sep 2016 11:41:10 +0000 (13:41 +0200)
data/stations/station-alpha.json
tabakrolletjie/obstacles.py

index 07f23e98b7cf1b134c6c6148341be9efb5a2fa97..4678e6c56e80cb67124589739f0e979312f5cb4e 100644 (file)
       "vertices": [
         [200, 350], [250, 350], [250, 400], [200, 400]
       ]
+    },
+    {
+      "type": "shrub",
+      "shrublets": [
+        [600, 100, 50], [700, 200, 100]
+      ]
     }
   ],
   "lights": [
index bae1c1dac23c0d7da1f6710d81c856a0c1b30c30..9adb80308180f40a76accc528492d7fe9026c35c 100644 (file)
@@ -79,3 +79,29 @@ class Wall(BaseObstacle):
 
     def render(self, surface):
         surface.blit(self.get_image(), (0, 0), None, 0)
+
+
+class Shrub(BaseObstacle):
+
+    def __init__(self, shrublets):
+        super(Shrub, self).__init__()
+        for [x, y, r] in shrublets:
+            self.shapes.append(pymunk.Circle(self.body, r, offset=(x, y)))
+        self._image = None
+
+    def get_image(self):
+        if self._image is None:
+            self._image = pygame.surface.Surface(SCREEN_SIZE).convert_alpha()
+            self._image.fill((0,0,0,0))
+                
+            for shape in self.shapes:
+                centre = pymunk.pygame_util.to_pygame(shape.offset, self._image)
+                pygame.draw.circle(self._image, (255, 255, 255), centre, int(shape.radius))
+                
+            shrub_texture = loader.load_image("textures", "shrub.png").convert_alpha()
+            self._image.blit(shrub_texture, (0, 0), None, pgl.BLEND_RGBA_MULT)
+            
+        return self._image
+
+    def render(self, surface):
+        surface.blit(self.get_image(), (0, 0), None, 0)