Hack'ish rendering of walls
authorNeil <neil@dip.sun.ac.za>
Sun, 4 Sep 2016 17:06:42 +0000 (19:06 +0200)
committerNeil <neil@dip.sun.ac.za>
Sun, 4 Sep 2016 17:06:51 +0000 (19:06 +0200)
tabakrolletjie/obstacles.py
tabakrolletjie/scenes/night.py

index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..61d4376e29da7080a71dbfcf16a38eb0ab29883a 100644 (file)
@@ -0,0 +1,16 @@
+import pymunk
+import pymunk.pygame_util
+import pygame.draw
+
+
+class Wall(object):
+
+    def __init__(self, vertices, space):
+        body = pymunk.Body(0, 0, pymunk.body.Body.STATIC)
+        self._shape = pymunk.Poly(body, vertices)
+        space.add(self._shape)
+
+    def render(self, surface):
+        pygame_poly = [pymunk.pygame_util.to_pygame(v, surface) for v in
+                       self._shape.get_vertices()]
+        pygame.draw.polygon(surface, (0, 0, 0), pygame_poly)
index 630dab3ef7fa46d7ace48ce3b6ea74efd25b3cc5..5d3721bd99e9c9a7cc195acb9f444e2e5736f01e 100644 (file)
@@ -2,7 +2,10 @@
 
 import pygame.locals as pgl
 
+import pymunk
+
 from .base import BaseScene
+from ..obstacles import Wall
 from ..events import SceneChangeEvent
 
 
@@ -11,8 +14,18 @@ class NightScene(BaseScene):
         import pprint
         pprint.pprint(gamestate.station)
 
+        self._space = pymunk.Space()
+
+        self._obstacles = []
+        self._lights = []
+        for obs in gamestate.station['obstacles']:
+            wall = Wall(obs['vertices'], self._space)
+            self._obstacles.append(wall)
+
     def render(self, surface, gamestate):
         surface.fill((0, 0, 255))
+        for obs in self._obstacles:
+            obs.render(surface)
 
     def event(self, ev, gamestate):
         if ev.type == pgl.KEYDOWN: