import pygame.locals as pgl
-from .constants import SCREEN_SIZE, MOULD_CATEGORY, OBSTACLE_CATEGORY
+from .constants import (SCREEN_SIZE, MOULD_CATEGORY, OBSTACLE_CATEGORY,
+ TURNIP_CATEGORY)
from .loader import loader
from .sound import sound
mask=MOULD_CATEGORY | OBSTACLE_CATEGORY,
categories=MOULD_CATEGORY)
+EAT_TURNIP_FILTER = pymunk.ShapeFilter(mask=TURNIP_CATEGORY)
+
class Mould(pymunk.Body):
"""A segment of Boyd"""
space.remove(self, self._shape)
moulds.remove(self)
refresh = True
+ else:
+ # Check for turnips we can eat
+ # Note that we can only eat a tick after we spawn
+ query = space.point_query(self.position, 16, EAT_TURNIP_FILTER)
+ if query:
+ query[0].shape.body.turnip.eaten = True
return refresh
def damage(self, light_color, intensity, space, moulds):
"turnips": [],
}
self.harvested = 0
+ self.eaten = 0
@property
def station(self):
ImageButton('32', 'default_cursor.png', name='reset tool',
pos=(SCREEN_SIZE[0] - 50, SCREEN_SIZE[1] - 40)),
]
- self._update_toolbar()
+ self._update_toolbar(gamestate)
def exit(self, gamestate):
self._unset_cursor()
turnip = Turnip(age=0, pos=pos, space=self._space)
self._turnips.append(turnip)
self._seeds -= 1
- self._update_toolbar()
+ self._update_toolbar(gamestate)
except TurnipInvalidPosition as e:
# TODO: Add error sound or something
pass
if not self._paused:
self._lights.tick()
- def _update_toolbar(self):
- text = "Turnip Stocks: Seeds: %d. Planted: %d. Harvested: %d" % (
- self._seeds, len(self._turnips), self._harvested)
+ def _update_toolbar(self, gamestate):
+ text = ("Turnip Stocks: Seeds: %d. Planted: %d. "
+ "Harvested: %d. Destroyed: %d" %
+ (self._seeds, len(self._turnips),
+ self._harvested, gamestate.eaten))
self._toolbar = self._toolbar_font.render(text, True, (255, 255, 255))
def render(self, surface, gamestate):
surface.fill((0, 0, 155))
self._mould.render(surface)
- for turnip in self._turnips:
- turnip.render(surface)
+ for turnip in self._turnips[:]:
+ if turnip.eaten:
+ self._turnips.remove(turnip)
+ turnip.remove()
+ gamestate.eaten += 1
+ else:
+ turnip.render(surface)
self._lights.render_light(surface)
self._obstacles.render(surface)
self._lights.render_fittings(surface)
self._pos = kwargs.get('pos', (0, 0))
space = kwargs.get('space', None)
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.filter = TURNIP_FILTER
self._body.position = pymunk.pygame_util.from_pygame(
self._pos, pygame.display.get_surface())
+ # Add a reference so space query can get the object
+ self._body.turnip = self
if space.shape_query(self._shape):
raise TurnipInvalidPosition()
space.add(self._body, self._shape)
return {'age': self._age, 'pos': self._pos}
def remove(self):
- # FIXME: Remove body from the space
- pass
+ self._body.turnip = None
+ space = self._body.space
+ space.remove(self._body, self._shape)
def grow(self):
self._age += 1
if self._age >= 3:
# Mature, so harvest it for seeds
+ self.remove()
return random.randint(1, 3)
else:
self._update_image()