Merge branch 'master' of ctpug.org.za:tabakrolletjie
authorSimon Cross <hodgestar@gmail.com>
Fri, 9 Sep 2016 21:40:21 +0000 (23:40 +0200)
committerSimon Cross <hodgestar@gmail.com>
Fri, 9 Sep 2016 21:40:21 +0000 (23:40 +0200)
17 files changed:
data/images/32/turnip1.png [deleted file]
data/images/32/turnip2.png [deleted file]
data/images/32/turnip3.png [deleted file]
data/images/48/lamp.png [new file with mode: 0644]
data/images/48/laser.png [new file with mode: 0644]
data/images/48/spotlight.png [new file with mode: 0644]
data/images/48/turnip1.png [new file with mode: 0644]
data/images/48/turnip2.png [new file with mode: 0644]
data/images/48/turnip3.png [new file with mode: 0644]
data/images/64/lamp.png [deleted file]
data/images/64/laser.png [deleted file]
data/images/64/spotlight.png [deleted file]
data/images/Makefile
tabakrolletjie/lights.py
tabakrolletjie/scenes/day.py
tabakrolletjie/transforms.py
tabakrolletjie/turnip.py

diff --git a/data/images/32/turnip1.png b/data/images/32/turnip1.png
deleted file mode 100644 (file)
index 6df8e84..0000000
Binary files a/data/images/32/turnip1.png and /dev/null differ
diff --git a/data/images/32/turnip2.png b/data/images/32/turnip2.png
deleted file mode 100644 (file)
index 4a88a8a..0000000
Binary files a/data/images/32/turnip2.png and /dev/null differ
diff --git a/data/images/32/turnip3.png b/data/images/32/turnip3.png
deleted file mode 100644 (file)
index 1153012..0000000
Binary files a/data/images/32/turnip3.png and /dev/null differ
diff --git a/data/images/48/lamp.png b/data/images/48/lamp.png
new file mode 100644 (file)
index 0000000..b985f44
Binary files /dev/null and b/data/images/48/lamp.png differ
diff --git a/data/images/48/laser.png b/data/images/48/laser.png
new file mode 100644 (file)
index 0000000..c23df50
Binary files /dev/null and b/data/images/48/laser.png differ
diff --git a/data/images/48/spotlight.png b/data/images/48/spotlight.png
new file mode 100644 (file)
index 0000000..b7231c8
Binary files /dev/null and b/data/images/48/spotlight.png differ
diff --git a/data/images/48/turnip1.png b/data/images/48/turnip1.png
new file mode 100644 (file)
index 0000000..6cff42f
Binary files /dev/null and b/data/images/48/turnip1.png differ
diff --git a/data/images/48/turnip2.png b/data/images/48/turnip2.png
new file mode 100644 (file)
index 0000000..0e31e29
Binary files /dev/null and b/data/images/48/turnip2.png differ
diff --git a/data/images/48/turnip3.png b/data/images/48/turnip3.png
new file mode 100644 (file)
index 0000000..de66224
Binary files /dev/null and b/data/images/48/turnip3.png differ
diff --git a/data/images/64/lamp.png b/data/images/64/lamp.png
deleted file mode 100644 (file)
index ae2443c..0000000
Binary files a/data/images/64/lamp.png and /dev/null differ
diff --git a/data/images/64/laser.png b/data/images/64/laser.png
deleted file mode 100644 (file)
index 2ba3633..0000000
Binary files a/data/images/64/laser.png and /dev/null differ
diff --git a/data/images/64/spotlight.png b/data/images/64/spotlight.png
deleted file mode 100644 (file)
index 5d54037..0000000
Binary files a/data/images/64/spotlight.png and /dev/null differ
index af81aa20a94d17d2876db507136a5c2fcbbdf202..c9077baec232f9a0d825160d897a03fc092591ff 100644 (file)
@@ -1,31 +1,37 @@
 VPATH=../../sources/vector
 
-TURNIP=seed turnip1 turnip2 turnip3
+TURNIP=turnip1 turnip2 turnip3
 MOULD_BODY=mouldA mouldB mouldC
 MOULD=eyeballA eyeballB eyeballC
 LIGHT=spotlight lamp laser
 
 IMG16=$(MOULD_BODY)
-IMG32=$(TURNIP) $(MOULD_BODY) $(MOULD) $(LIGHT)
-IMG64=$(MOULD_BODY) $(LIGHT)
+IMG32=$(MOULD_BODY) $(MOULD) $(LIGHT) seed
+IMG48=$(LIGHT) $(TURNIP)
+IMG64=$(MOULD_BODY)
 
 CURSORS=seed $(LIGHT)
 
 PNG16=$(patsubst %, 16/%.png, $(IMG16))
 PNG32=$(patsubst %, 32/%.png, $(IMG32))
+PNG48=$(patsubst %, 48/%.png, $(IMG48))
 PNG64=$(patsubst %, 64/%.png, $(IMG64))
 PNG_CURSORS=$(patsubst %, cursors/%.png, $(CURSORS))
 
-all: $(PNG16) $(PNG32) $(PNG64) $(PNG_CURSORS)
+all: $(PNG16) $(PNG32) $(PNG48) $(PNG64) $(PNG_CURSORS)
 
 16/%.png: %.svg
        @mkdir -p `dirname $@`
        @inkscape -z -e $@ -w 16 -h 16 $<
-       
+
 32/%.png: %.svg
        @mkdir -p `dirname $@`
        @inkscape -z -e $@ -w 32 -h 32 $<
-       
+
+48/%.png: %.svg
+       @mkdir -p `dirname $@`
+       @inkscape -z -e $@ -w 48 -h 48 $<
+
 64/%.png: %.svg
        @mkdir -p `dirname $@`
        @inkscape -z -e $@ -w 64 -h 64 $<
index d20ab3570663ba1132345d1f093aea8b9b7985ce..2952da5c86680eada28d63130e425bf017179e87 100644 (file)
@@ -38,6 +38,11 @@ class LightManager(object):
         for light in self._lights:
             light.add(self._space)
 
+    def add_light(self, cfg):
+        light = BaseLight.load(cfg)
+        self._lights.append(light)
+        light.add(self._space)
+
     def toggle_nearest(self, *args, **kw):
         light = self.nearest(*args, **kw)
         if light:
@@ -99,7 +104,7 @@ class BaseLight(object):
     # defaults
     RAY_MANAGER = RayPolyManager
     FITTING_IMG = None
-    FITTING_RADIUS = 10.0
+    FITTING_RADIUS = 24.0
 
     # cached surfaces
     _surface_cache = {}
@@ -200,13 +205,13 @@ class BaseLight(object):
         if self._image is None:
             fitting_colour = self.COLOURS[self.colour]
             self._image = loader.load_image(
-                "64", self.FITTING_IMG,
+                "48", self.FITTING_IMG,
                 transform=Multiply(colour=fitting_colour))
         return self._image
 
     def render_fitting(self, surface):
         rx, ry = self.ray_manager.pygame_position(surface)
-        surface.blit(self.get_image(), (rx - 32, ry - 32), None, 0)
+        surface.blit(self.get_image(), (rx - 24, ry - 24), None, 0)
 
     def tick(self):
         pass
index fc79ffce07f41a69d13b472aa2d70b3676365388..7860c87b44e4db2d09c7c11549215648a0ab0acb 100644 (file)
@@ -1,5 +1,6 @@
 """ Be prepared. """
 
+import pygame.display
 import pygame.locals as pgl
 
 import pymunk
@@ -11,7 +12,7 @@ from ..obstacles import ObstacleManager
 from ..events import SceneChangeEvent
 from ..utils import debug_timer
 from ..loader import loader
-from ..transforms import Overlay, Multiply
+from ..transforms import Overlay, Multiply, Alpha
 
 from ..constants import SCREEN_SIZE, FONTS
 from ..widgets import ImageButton
@@ -80,6 +81,41 @@ class DayScene(BaseScene):
             tool.render(surface)
         self._draw_cursor(surface)
 
+    def _place_seed(self, gamestate, ev):
+        if self._seeds > 0:
+            # plant seed
+            # We don't want top-left to equal the mouse position,
+            # since that looks weird, but we don't want to center
+            # the turnip under the mouse either, since that
+            # causes issues as well, so we compromise
+            pos = (ev.pos[0] - 8, ev.pos[1] - 8)
+            try:
+                turnip = Turnip(age=0, pos=pos, space=self._space)
+                self._turnips.append(turnip)
+                self._seeds -= 1
+                self._update_toolbar(gamestate)
+            except TurnipInvalidPosition as e:
+                # TODO: Add error sound or something
+                pass
+
+    def _place_spotlight(self, gamestate, colour, ev):
+        if self._seeds > 5:
+            self._seeds -= 5
+            self._update_toolbar(gamestate)
+            pos = pymunk.pygame_util.from_pygame(ev.pos,
+                                                 pygame.display.get_surface())
+            cfg = {
+                "type": "spotlight",
+                "colour": colour,
+                "position": pos,
+                "direction": 45,
+                "angle_limits": [0, 90],
+                "intensity": 0.5,
+                "radius_limits": [0, 100],
+            }
+            gamestate.station["lights"].append(cfg)
+            self._lights.add_light(cfg)
+
     def event(self, ev, gamestate):
         if ev.type == pgl.KEYDOWN:
             if ev.key in (pgl.K_q, pgl.K_ESCAPE):
@@ -101,7 +137,7 @@ class DayScene(BaseScene):
                         else:
                             self._tool = tool.name
                             if self._tool == 'seed':
-                                self._set_cursor(tool.name)
+                                self._set_cursor('seed', transform=Alpha(alpha=172))
                             elif self._tool == 'red_spotlight':
                                 self._set_cursor(
                                     'spotlight',
@@ -114,21 +150,11 @@ class DayScene(BaseScene):
                                         colour=(0, 0, 255, 172)))
                         return
                 if self._tool == "seed":
-                    if self._seeds > 0:
-                        # plant seed
-                        # We don't want top-left to equal the mouse position,
-                        # since that looks weird, but we don't want to center
-                        # the turnip under the mouse either, since that
-                        # causes issues as well, so we compromise
-                        pos = (ev.pos[0] - 8, ev.pos[1] - 8)
-                        try:
-                            turnip = Turnip(age=0, pos=pos, space=self._space)
-                            self._turnips.append(turnip)
-                            self._seeds -= 1
-                            self._update_toolbar(gamestate)
-                        except TurnipInvalidPosition as e:
-                            # TODO: Add error sound or something
-                            pass
+                    self._place_seed(gamestate, ev)
+                elif self._tool == 'red_spotlight':
+                    self._place_spotlight(gamestate, 'red', ev)
+                elif self._tool == 'blue_spotlight':
+                    self._place_spotlight(gamestate, 'blue', ev)
                 else:
                     # Not tool, so check lights
                     self._lights.toggle_nearest(ev.pos, surfpos=True)
index b748b6e2f545e9a8745f0b869f2c09fde3ddbf4f..88f516169e02dfe46ff22523eb28a353ad421a75 100644 (file)
@@ -64,3 +64,13 @@ class Multiply(Transform):
         mult.fill(self.colour)
         surface.blit(mult, (0, 0), None, pgl.BLEND_RGBA_MULT)
         return surface
+
+
+class Alpha(Transform):
+    """ Make translucent. """
+
+    ARGS = ["alpha"]
+
+    def apply(self, surface):
+        surface.fill((255, 255, 255, self.alpha), None, pgl.BLEND_RGBA_MULT)
+        return surface
index f40478a1e79834ec64ff5433590c6820fa42664f..b67196a525da4d00d19c024aee3880399194a49c 100644 (file)
@@ -28,7 +28,7 @@ class Turnip(object):
         self._update_image()
         self.eaten = False  # Flag for boyd
         self._body = pymunk.Body(0, 0, pymunk.Body.STATIC)
-        self._shape = pymunk.Circle(self._body, 16)
+        self._shape = pymunk.Circle(self._body, 24)
         self._shape.filter = TURNIP_FILTER
         self._body.position = pymunk.pygame_util.from_pygame(
             self._pos, pygame.display.get_surface())
@@ -39,7 +39,7 @@ class Turnip(object):
         space.add(self._body, self._shape)
 
     def _update_image(self):
-        self._image = loader.load_image('32', 'turnip%d.png' % (self._age + 1))
+        self._image = loader.load_image('48', 'turnip%d.png' % (self._age + 1))
         self._image = pygame.transform.rotate(self._image, self._rotation)
 
     def render(self, surface):