From: adrianna Date: Tue, 13 Sep 2016 19:33:58 +0000 (+0200) Subject: fixed turnip/light positioning bug X-Git-Url: https://git.ctpug.org.za/?a=commitdiff_plain;h=7e9eb69b0fe8abf7d2d8314921a2550043a99d0b;p=tabakrolletjie.git fixed turnip/light positioning bug --- diff --git a/TODO.txt b/TODO.txt index 8423d38..ae4f7a4 100644 --- a/TODO.txt +++ b/TODO.txt @@ -7,7 +7,6 @@ Bugs Features -------- -* Turnip / light spacing bug: a light can be placed right below a turnip, but must be much further away if above the turnip. This happens whether the turnip or the light is placed first. I assume it has to do with how the turnip image is positioned relative to its body. * Allow denser turnip spacing * Allow going down to zero seeds by buying lights if a turnip is planted * Maybe make the mould weaker at the start @@ -48,3 +47,4 @@ Done * Five levels * Bug: have to click lights multiple times to turn them back on after the power has died * Bug: Crash when removing a rotating light +* Turnip / light spacing bug: a light can be placed right below a turnip, but must be much further away if above the turnip. This happens whether the turnip or the light is placed first. I assume it has to do with how the turnip image is positioned relative to its body. diff --git a/tabakrolletjie/lights.py b/tabakrolletjie/lights.py index 22da021..318aefc 100644 --- a/tabakrolletjie/lights.py +++ b/tabakrolletjie/lights.py @@ -280,7 +280,7 @@ class BaseLight(object): def render_fitting(self, surface): rx, ry = self.ray_manager.pygame_position(surface) - surface.blit(self.fitting_image(), (rx - 24, ry - 24), None, 0) + surface.blit(self.fitting_image(), (rx - self.FITTING_RADIUS, ry - self.FITTING_RADIUS), None, 0) def power_usage(self): if not self.on: diff --git a/tabakrolletjie/scenes/day.py b/tabakrolletjie/scenes/day.py index 4176e36..bf97f95 100644 --- a/tabakrolletjie/scenes/day.py +++ b/tabakrolletjie/scenes/day.py @@ -191,7 +191,7 @@ class DayScene(BaseScene): # 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] - 18, ev.pos[1] - 18) + pos = (ev.pos[0] - 6, ev.pos[1] - 6) try: turnip = Turnip(age=0, pos=pos, space=self._space) self._turnips.append(turnip) diff --git a/tabakrolletjie/turnip.py b/tabakrolletjie/turnip.py index b1bb5a4..1e29658 100644 --- a/tabakrolletjie/turnip.py +++ b/tabakrolletjie/turnip.py @@ -19,6 +19,7 @@ class TurnipInvalidPosition(Exception): class Turnip(object): + TURNIP_RADIUS = 24 def __init__(self, **kwargs): self._age = kwargs.get('age', 0) @@ -28,7 +29,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, 24) + self._shape = pymunk.Circle(self._body, self.TURNIP_RADIUS) self._shape.filter = TURNIP_FILTER self._body.position = pymunk.pygame_util.from_pygame( self._pos, pygame.display.get_surface()) @@ -43,7 +44,8 @@ class Turnip(object): self._image = pygame.transform.rotate(self._image, self._rotation) def render(self, surface): - surface.blit(self._image, self._pos, None) + rx, ry = self._pos + surface.blit(self._image, (rx - self.TURNIP_RADIUS, ry - self.TURNIP_RADIUS), None) def serialize(self): return {'age': self._age, 'pos': self._pos}