1 # Boyd, the friendly, misunderstood turnip loving, light hating space mould
6 import pymunk.pygame_util
11 import pygame.locals as pgl
13 from .constants import SCREEN_SIZE, MOULD_CATEGORY, OBSTACLE_CATEGORY
14 from .loader import loader
16 MOULD_FILTER = pymunk.ShapeFilter(
17 mask=MOULD_CATEGORY | OBSTACLE_CATEGORY,
18 categories=MOULD_CATEGORY)
21 class Mould(pymunk.Body):
22 """A segment of Boyd"""
24 def __init__(self, gamestate, space, pos):
25 super(Mould, self).__init__(0, 0, pymunk.Body.STATIC)
27 self._shape = pymunk.Circle(self, 16)
28 space.add(self, self._shape)
29 self._shape.filter = MOULD_FILTER
30 self._resistances = {}
37 ('mouldA.png', 'mouldB.png', 'mouldC.png'))
38 self._img = loader.load_image("32", name)
41 def tick(self, gamestate, space, moulds):
42 """Grow and / or Die"""
47 if (self._age % 15) == 0 and len(moulds) < 1000:
48 # Spawn a new child, if we can
50 choice = random.randint(0, 4)
52 pos = self.position + (0, 24)
54 pos = self.position + (24, 0)
56 pos = self.position + (-24, 0)
58 pos = self.position + (0, -24)
60 if pos[0] < 0 or pos[0] >= SCREEN_SIZE[0]:
62 if pos[1] < 0 or pos[1] >= SCREEN_SIZE[1]:
64 # Check for free space
65 # We allow some overlap, hence not checking full radius
66 query = space.point_query(pos, 8, MOULD_FILTER)
69 # if not isinstance(x.shape.body, Mould):
70 # print x.shape, x.shape.body
73 child = Mould(gamestate, space, pos)
79 space.remove(self, self._shape)
84 def damage(self, light_color, intensity):
85 """Take damage for light, adjusted for resistances."""
90 def __init__(self, gamestate, space):
91 seed = Mould(gamestate, space, (400, 400))
93 self._image = pygame.surface.Surface(SCREEN_SIZE)
94 self._image.convert_alpha(pygame.display.get_surface())
95 self._image.fill((0, 0, 0, 0))
97 def tick(self, gamestate, space):
99 for mould in self._moulds[:]:
100 if mould.tick(gamestate, space, self._moulds):
103 self._image.fill((0, 0, 0, 0))
104 for mould in self._moulds:
105 pos = pymunk.pygame_util.to_pygame(mould.position, self._image)
106 self._image.blit(mould.get_image(), pos, None,
109 def render(self, surface):
111 surface.blit(self._image, (0, 0), None, pgl.BLEND_RGBA_ADD)