self._resistances = {}
self._age = 0
self._img = None
+ self._health = 500
def pygame_pos(self, surface):
"""Convert to pygame coordinates and offset position so
"""Grow and / or Die"""
self._age += 1
+ # we regain a health every tick, so we heal in the dark
+ if self._health < 100:
+ self._health += 1
+
refresh = False
if (self._age % 15) == 0 and len(moulds) < 1000:
spawn = False
if spawn:
child = Mould(gamestate, space, pos)
+ child._health = self._health
moulds.append(child)
refresh = True
refresh = True
return refresh
- def damage(self, light_color, intensity):
+ def damage(self, light_color, intensity, space, moulds):
"""Take damage for light, adjusted for resistances."""
+ self._health -= 3
+ if self._health <= 0 and self._age <= 120:
+ # We die of damage
+ space.remove(self, self._shape)
+ moulds.remove(self)
+ return True
+ return False
class Boyd(object):
def __init__(self, gamestate, space):
- seed = Mould(gamestate, space, (350, 350))
+ seed = Mould(gamestate, space, (350, 370))
self._moulds = [seed]
self._image = pygame.surface.Surface(SCREEN_SIZE)
self._image.convert_alpha(pygame.display.get_surface())
self._image.blit(seed.get_image(),
seed.pygame_pos(self._image), None, pgl.BLEND_RGBA_ADD)
- def tick(self, gamestate, space):
+ def tick(self, gamestate, space, lights):
redraw = False
+ # Handle spawn events
for mould in self._moulds[:]:
+ # Handle updates
if mould.tick(gamestate, space, self._moulds):
redraw = True
+ # Check for damage
+ if lights.lit_by(mould.position):
+ if mould.damage(None, None, space, self._moulds):
+ redraw = True
if redraw:
self._image.fill((0, 0, 0, 0))
for mould in self._moulds: