added rock texture to wall
authoradrianna <adrianna.pinska@gmail.com>
Fri, 9 Sep 2016 18:54:39 +0000 (20:54 +0200)
committeradrianna <adrianna.pinska@gmail.com>
Fri, 9 Sep 2016 18:54:48 +0000 (20:54 +0200)
tabakrolletjie/obstacles.py

index b368626431994464b7f7650ea60971ac471ecce0..81dd9cec8d937c64a649f8067391ad095f9c92ff 100644 (file)
@@ -1,10 +1,14 @@
 """ Obstacles for light and space mould. """
 
+import pygame.locals as pgl
+
 import pymunk
 import pymunk.pygame_util
 import pygame.draw
+import pygame.surface
 
-from .constants import OBSTACLE_CATEGORY
+from .constants import (SCREEN_SIZE, OBSTACLE_CATEGORY)
+from .loader import loader
 
 OBSTACLE_FILTER = pymunk.ShapeFilter(categories=OBSTACLE_CATEGORY)
 
@@ -54,10 +58,23 @@ class Wall(BaseObstacle):
     def __init__(self, vertices):
         super(Wall, self).__init__()
         self.shapes.append(pymunk.Poly(self.body, vertices))
+        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:
+                pygame_poly = [
+                    pymunk.pygame_util.to_pygame(v, self._image) for v in
+                    shape.get_vertices()]
+                pygame.draw.polygon(self._image, (255, 255, 255), pygame_poly)
+                
+            wall_texture = loader.load_image("textures", "stone.png").convert_alpha()
+            self._image.blit(wall_texture, (0, 0), None, pgl.BLEND_RGBA_MULT)
+            
+        return self._image
 
     def render(self, surface):
-        for shape in self.shapes:
-            pygame_poly = [
-                pymunk.pygame_util.to_pygame(v, surface) for v in
-                shape.get_vertices()]
-            pygame.draw.polygon(surface, (0, 0, 0), pygame_poly)
+        surface.blit(self.get_image(), (0, 0), None, 0)