From: Simon Cross Date: Sat, 10 Sep 2016 10:54:59 +0000 (+0200) Subject: Merge branch 'master' of ctpug.org.za:tabakrolletjie X-Git-Tag: tabakrolletjie-v1.0.0~127 X-Git-Url: https://git.ctpug.org.za/?p=tabakrolletjie.git;a=commitdiff_plain;h=cd254036f630c40baab130f5fab14e9d11bc286e;hp=a2c09130986d18095773c96b9dc797f3b3eb542d Merge branch 'master' of ctpug.org.za:tabakrolletjie --- diff --git a/data/images/32/light_mask_2_1.png b/data/images/32/light_mask_2_1.png new file mode 100644 index 0000000..e95ffee Binary files /dev/null and b/data/images/32/light_mask_2_1.png differ diff --git a/data/images/32/light_mask_2_2.png b/data/images/32/light_mask_2_2.png new file mode 100644 index 0000000..82fc4ab Binary files /dev/null and b/data/images/32/light_mask_2_2.png differ diff --git a/data/images/32/light_mask_3_1.png b/data/images/32/light_mask_3_1.png new file mode 100644 index 0000000..c4316c6 Binary files /dev/null and b/data/images/32/light_mask_3_1.png differ diff --git a/data/images/32/light_mask_3_2.png b/data/images/32/light_mask_3_2.png new file mode 100644 index 0000000..9b69af2 Binary files /dev/null and b/data/images/32/light_mask_3_2.png differ diff --git a/data/images/32/light_mask_3_3.png b/data/images/32/light_mask_3_3.png new file mode 100644 index 0000000..da894e7 Binary files /dev/null and b/data/images/32/light_mask_3_3.png differ diff --git a/data/images/48/light_mask_2_1.png b/data/images/48/light_mask_2_1.png new file mode 100644 index 0000000..245f371 Binary files /dev/null and b/data/images/48/light_mask_2_1.png differ diff --git a/data/images/48/light_mask_2_2.png b/data/images/48/light_mask_2_2.png new file mode 100644 index 0000000..8d7ab24 Binary files /dev/null and b/data/images/48/light_mask_2_2.png differ diff --git a/data/images/48/light_mask_3_1.png b/data/images/48/light_mask_3_1.png new file mode 100644 index 0000000..7c8e0ca Binary files /dev/null and b/data/images/48/light_mask_3_1.png differ diff --git a/data/images/48/light_mask_3_2.png b/data/images/48/light_mask_3_2.png new file mode 100644 index 0000000..beff279 Binary files /dev/null and b/data/images/48/light_mask_3_2.png differ diff --git a/data/images/48/light_mask_3_3.png b/data/images/48/light_mask_3_3.png new file mode 100644 index 0000000..c3e4fda Binary files /dev/null and b/data/images/48/light_mask_3_3.png differ diff --git a/data/images/Makefile b/data/images/Makefile index c9077ba..641c3e5 100644 --- a/data/images/Makefile +++ b/data/images/Makefile @@ -1,16 +1,18 @@ VPATH=../../sources/vector +SEED=seed TURNIP=turnip1 turnip2 turnip3 MOULD_BODY=mouldA mouldB mouldC MOULD=eyeballA eyeballB eyeballC LIGHT=spotlight lamp laser +LIGHT_MASK=light_mask_2_1 light_mask_2_2 light_mask_3_1 light_mask_3_2 light_mask_3_3 IMG16=$(MOULD_BODY) -IMG32=$(MOULD_BODY) $(MOULD) $(LIGHT) seed -IMG48=$(LIGHT) $(TURNIP) +IMG32=$(MOULD_BODY) $(MOULD) $(LIGHT) $(SEED) $(LIGHT_MASK) +IMG48=$(LIGHT) $(TURNIP) $(LIGHT_MASK) IMG64=$(MOULD_BODY) -CURSORS=seed $(LIGHT) +CURSORS=$(SEED) $(LIGHT) PNG16=$(patsubst %, 16/%.png, $(IMG16)) PNG32=$(patsubst %, 32/%.png, $(IMG32)) diff --git a/data/stations/station-alpha.json b/data/stations/station-alpha.json index 5df98c3..f0e27e5 100644 --- a/data/stations/station-alpha.json +++ b/data/stations/station-alpha.json @@ -42,7 +42,7 @@ "intensity": 0.5 }, { - "type": "multicolourlamp", + "type": "lamp", "colours": ["red", "yellow", "green"], "position": [300, 300], "intensity": 0.5 diff --git a/sources/vector/light_mask_2_1.svg b/sources/vector/light_mask_2_1.svg new file mode 100644 index 0000000..728794b --- /dev/null +++ b/sources/vector/light_mask_2_1.svg @@ -0,0 +1,77 @@ + + + + + + + + + + + + image/svg+xml + + + + + + + + + diff --git a/sources/vector/light_mask_2_2.svg b/sources/vector/light_mask_2_2.svg new file mode 100644 index 0000000..a795c14 --- /dev/null +++ b/sources/vector/light_mask_2_2.svg @@ -0,0 +1,77 @@ + + + + + + + + + + + + image/svg+xml + + + + + + + + + diff --git a/sources/vector/light_mask_3_1.svg b/sources/vector/light_mask_3_1.svg new file mode 100644 index 0000000..19e6ab7 --- /dev/null +++ b/sources/vector/light_mask_3_1.svg @@ -0,0 +1,77 @@ + + + + + + + + + + + + image/svg+xml + + + + + + + + + diff --git a/sources/vector/light_mask_3_2.svg b/sources/vector/light_mask_3_2.svg new file mode 100644 index 0000000..98ecf9f --- /dev/null +++ b/sources/vector/light_mask_3_2.svg @@ -0,0 +1,77 @@ + + + + + + + + + + + + image/svg+xml + + + + + + + + + diff --git a/sources/vector/light_mask_3_3.svg b/sources/vector/light_mask_3_3.svg new file mode 100644 index 0000000..a3071b4 --- /dev/null +++ b/sources/vector/light_mask_3_3.svg @@ -0,0 +1,77 @@ + + + + + + + + + + + + image/svg+xml + + + + + + + + + diff --git a/tabakrolletjie/lights.py b/tabakrolletjie/lights.py index 8b688f7..1eaba7c 100644 --- a/tabakrolletjie/lights.py +++ b/tabakrolletjie/lights.py @@ -14,7 +14,7 @@ from .constants import LIGHT_CATEGORY, FITTINGS_CATEGORY, COLOURS from .rays import RayPolyManager from .utils import DetailedTimer from .loader import loader -from .transforms import Multiply +from .transforms import Multiply, MultiplyImage LIGHT_FILTER = pymunk.ShapeFilter( mask=pymunk.ShapeFilter.ALL_MASKS ^ ( @@ -129,6 +129,7 @@ class BaseLight(object): self.body, self.FITTING_RADIUS, self.ray_manager.position) self.fitting.filter = FITTINGS_FILTER self._fitting_image = None + self._colour_mult_image = None @property def position(self): @@ -205,10 +206,30 @@ class BaseLight(object): def fitting_image(self): if self._fitting_image is None: - fitting_colour = COLOURS[self.colour] - self._fitting_image = loader.load_image( + fitting_colours = [COLOURS[c] for c in self.colour_cycle] + ncolour = len(fitting_colours) + if ncolour > 3: + print "Multicoloured light should not have more than 3 colours" + ncolour = 3 + + if ncolour == 1: + self._fitting_image = loader.load_image( "48", self.FITTING_IMG, - transform=Multiply(colour=fitting_colour)) + transform=Multiply(colour=fitting_colours[0])) + else: + if self._colour_mult_image is None: + self._colour_mult_image = pygame.surface.Surface((48, 48)) + + for i in range(ncolour): + sector = loader.load_image( + "48", "light_mask_%d_%d.png" % (ncolour, i + 1), + transform=Multiply(colour=fitting_colours[i])) + self._colour_mult_image.blit(sector, (0,0), None, 0) + + self._fitting_image = loader.load_image( + "48", self.FITTING_IMG, + transform=MultiplyImage(image=self._colour_mult_image)) + return self._fitting_image def invalidate_fitting_image(self): @@ -248,14 +269,6 @@ class Lamp(BaseLight): FITTING_IMG = "lamp.png" -class MultiColourLamp(BaseLight): - - FITTING_IMG = "lamp.png" - - def __init__(self, **kw): - super(MultiColourLamp, self).__init__(**kw) - - class PulsatingLamp(BaseLight): FITTING_IMG = "lamp.png" diff --git a/tabakrolletjie/scenes/day.py b/tabakrolletjie/scenes/day.py index 589f8b2..933f16b 100644 --- a/tabakrolletjie/scenes/day.py +++ b/tabakrolletjie/scenes/day.py @@ -1,5 +1,7 @@ """ Be prepared. """ +import math + import pygame.display import pygame.locals as pgl @@ -34,6 +36,7 @@ class DayScene(BaseScene): self._paused = False self._tool = None self._light_color = None + self._dragging = None for turnip_data in gamestate.turnips: turnip = Turnip(space=self._space, **turnip_data) # Turnips grow at dawn @@ -113,6 +116,15 @@ class DayScene(BaseScene): # TODO: Add error sound or something pass + def _update_light_angle(self, pos): + # Update the angle of the given light + pos = pymunk.pygame_util.to_pygame(pos, pygame.display.get_surface()) + distance = pos - self._dragging.position + angle = math.atan2(distance[1], distance[0]) + # Set light angle to this position + self._dragging.ray_manager.direction = math.degrees(angle) + # TODO: Update gamestate with new angle + def _place_spotlight(self, gamestate, colour, ev): if self._seeds > 5: pos = pymunk.pygame_util.from_pygame(ev.pos, @@ -126,7 +138,8 @@ class DayScene(BaseScene): "type": "spotlight", "colour": colour, "position": pos, - "angle_limits": [0, 90], + "direction": 45, + "spread": 90, "intensity": 0.5, "radius_limits": [0, 100], } @@ -138,7 +151,7 @@ class DayScene(BaseScene): pos = pymunk.pygame_util.from_pygame(ev.pos, pygame.display.get_surface()) # Bail if we're too close to an existing light - if self._lights.nearest(pos, max_distance=25): + if self._lights.nearest(ev.pos, surfpos=True, max_distance=25): return self._seeds -= 3 self._update_toolbar(gamestate) @@ -203,9 +216,22 @@ class DayScene(BaseScene): # Not tool, so check lights self._lights.toggle_nearest(ev.pos, surfpos=True) print self._lights.lit_by(ev.pos, surfpos=True) - elif ev.button == 3 and self._tool: - self._tool = None - self._unset_cursor() + elif ev.button == 3: + light = self._lights.nearest(ev.pos, surfpos=True, + max_distance=5.0) + if light: + # Start drag to rotate light + self._dragging = light + elif self._tool: + # Unset tool + self._tool = None + self._unset_cursor() + elif ev.type == pgl.MOUSEMOTION: + if self._dragging: + # Calculate angle between current position and mouse pos + self._update_light_angle(ev.pos) + elif ev.type == pgl.MOUSEBUTTONUP: + self._dragging = None @debug_timer("day.tick") def tick(self, gamestate): diff --git a/tabakrolletjie/transforms.py b/tabakrolletjie/transforms.py index 88f5161..50cb1d1 100644 --- a/tabakrolletjie/transforms.py +++ b/tabakrolletjie/transforms.py @@ -66,6 +66,16 @@ class Multiply(Transform): return surface +class MultiplyImage(Transform): + """ Apply a colour by multiplying. """ + + ARGS = ["image"] + + def apply(self, surface): + surface.blit(self.image, (0, 0), None, pgl.BLEND_RGBA_MULT) + return surface + + class Alpha(Transform): """ Make translucent. """