From: Simon Cross Date: Fri, 9 Sep 2016 21:40:21 +0000 (+0200) Subject: Merge branch 'master' of ctpug.org.za:tabakrolletjie X-Git-Tag: tabakrolletjie-v1.0.0~143 X-Git-Url: https://git.ctpug.org.za/?a=commitdiff_plain;h=3298860ded0d6898b881c58f27f300ad4ee20fe6;hp=b1cbbc6a48f68e43b72293ef0d6d24450ce40c7e;p=tabakrolletjie.git Merge branch 'master' of ctpug.org.za:tabakrolletjie --- diff --git a/data/images/32/turnip1.png b/data/images/32/turnip1.png deleted file mode 100644 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 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 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 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 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 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 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 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 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 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 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 index 5d54037..0000000 Binary files a/data/images/64/spotlight.png and /dev/null differ diff --git a/data/images/Makefile b/data/images/Makefile index af81aa2..c9077ba 100644 --- a/data/images/Makefile +++ b/data/images/Makefile @@ -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 $< diff --git a/tabakrolletjie/lights.py b/tabakrolletjie/lights.py index d20ab35..2952da5 100644 --- a/tabakrolletjie/lights.py +++ b/tabakrolletjie/lights.py @@ -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 diff --git a/tabakrolletjie/scenes/day.py b/tabakrolletjie/scenes/day.py index fc79ffc..7860c87 100644 --- a/tabakrolletjie/scenes/day.py +++ b/tabakrolletjie/scenes/day.py @@ -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) diff --git a/tabakrolletjie/transforms.py b/tabakrolletjie/transforms.py index b748b6e..88f5161 100644 --- a/tabakrolletjie/transforms.py +++ b/tabakrolletjie/transforms.py @@ -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 diff --git a/tabakrolletjie/turnip.py b/tabakrolletjie/turnip.py index f40478a..b67196a 100644 --- a/tabakrolletjie/turnip.py +++ b/tabakrolletjie/turnip.py @@ -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):