From e78f6923fc05f61c0724fb9b963341562393ec1b Mon Sep 17 00:00:00 2001 From: Neil Date: Sun, 4 Sep 2016 19:06:42 +0200 Subject: [PATCH] Hack'ish rendering of walls --- tabakrolletjie/obstacles.py | 16 ++++++++++++++++ tabakrolletjie/scenes/night.py | 13 +++++++++++++ 2 files changed, 29 insertions(+) diff --git a/tabakrolletjie/obstacles.py b/tabakrolletjie/obstacles.py index e69de29..61d4376 100644 --- a/tabakrolletjie/obstacles.py +++ b/tabakrolletjie/obstacles.py @@ -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) diff --git a/tabakrolletjie/scenes/night.py b/tabakrolletjie/scenes/night.py index 630dab3..5d3721b 100644 --- a/tabakrolletjie/scenes/night.py +++ b/tabakrolletjie/scenes/night.py @@ -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: -- 2.34.1