projects
/
tabakrolletjie.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
0ca1478
)
Add circular fitting to lights.
author
Simon Cross
<hodgestar@gmail.com>
Tue, 6 Sep 2016 19:44:18 +0000
(21:44 +0200)
committer
Simon Cross
<hodgestar@gmail.com>
Tue, 6 Sep 2016 19:44:18 +0000
(21:44 +0200)
tabakrolletjie/lights.py
patch
|
blob
|
history
diff --git
a/tabakrolletjie/lights.py
b/tabakrolletjie/lights.py
index 7620c480915c1e8b5bc2226ba1ec64028a7631f9..c5c72af0df43cb289f4528ea94fabb65c41b52ee 100644
(file)
--- a/
tabakrolletjie/lights.py
+++ b/
tabakrolletjie/lights.py
@@
-5,13
+5,20
@@
import pymunk
import pymunk.pygame_util
import pygame.draw
import pymunk.pygame_util
import pygame.draw
-from .constants import SCREEN_SIZE, LIGHT_CATEGORY
+from .constants import (
+ SCREEN_SIZE, LIGHT_CATEGORY, FITTINGS_CATEGORY)
from .utils import debug_timer
LIGHT_FILTER = pymunk.ShapeFilter(
from .utils import debug_timer
LIGHT_FILTER = pymunk.ShapeFilter(
- mask=pymunk.ShapeFilter.ALL_MASKS ^ LIGHT_CATEGORY,
+ mask=pymunk.ShapeFilter.ALL_MASKS ^ (
+ LIGHT_CATEGORY | FITTINGS_CATEGORY),
categories=LIGHT_CATEGORY)
categories=LIGHT_CATEGORY)
+FITTINGS_FILTER = pymunk.ShapeFilter(
+ mask=pymunk.ShapeFilter.ALL_MASKS ^ (
+ LIGHT_CATEGORY | FITTINGS_CATEGORY),
+ categories=FITTINGS_CATEGORY)
+
def screen_rays(pos):
""" An iterable that returns ordered rays from pos to the edge of the
def screen_rays(pos):
""" An iterable that returns ordered rays from pos to the edge of the
@@
-70,8
+77,9
@@
class BaseLight(object):
def __init__(self, colour, position):
self.on = True
self.body = pymunk.Body(0, 0, pymunk.body.Body.STATIC)
def __init__(self, colour, position):
self.on = True
self.body = pymunk.Body(0, 0, pymunk.body.Body.STATIC)
+ self.fitting = pymunk.Circle(self.body, 5.0)
self.colour = colour
self.colour = colour
- self.position = p
osition
+ self.position = p
ymunk.Vec2d(position)
@classmethod
def load(cls, config):
@classmethod
def load(cls, config):
@@
-89,7
+97,8
@@
class BaseLight(object):
calculate_ray_polys(space, self.body, self.position))
for shape in shapes:
shape.filter = LIGHT_FILTER
calculate_ray_polys(space, self.body, self.position))
for shape in shapes:
shape.filter = LIGHT_FILTER
- space.add(self.body, *shapes)
+ self.fitting.filter = FITTINGS_FILTER
+ space.add(self.body, self.fitting, *shapes)
def shapes_for_ray_polys(self, ray_polys):
return ray_polys
def shapes_for_ray_polys(self, ray_polys):
return ray_polys
@@
-103,6
+112,8
@@
class BaseLight(object):
subsurface = surface.copy()
light_colour = self.COLOURS[self.colour]
for shape in self.body.shapes:
subsurface = surface.copy()
light_colour = self.COLOURS[self.colour]
for shape in self.body.shapes:
+ if shape is self.fitting:
+ continue
pygame_poly = [
pymunk.pygame_util.to_pygame(v, surface) for v in
shape.get_vertices()]
pygame_poly = [
pymunk.pygame_util.to_pygame(v, surface) for v in
shape.get_vertices()]
@@
-114,9
+125,11
@@
class BaseLight(object):
surface.blit(subsurface, (0, 0), None)
def render_fittings(self, surface):
surface.blit(subsurface, (0, 0), None)
def render_fittings(self, surface):
+ centre = self.position + self.fitting.offset
pygame.draw.circle(
surface, (255, 255, 0),
pygame.draw.circle(
surface, (255, 255, 0),
- pymunk.pygame_util.to_pygame(self.position, surface), 5)
+ pymunk.pygame_util.to_pygame(centre, surface),
+ int(self.fitting.radius))
class SpotLight(BaseLight):
class SpotLight(BaseLight):