def take_damage(self, amount): self.damage += amount if self.damage >= self.health and not self.has_exploded: # create an explosion self.has_exploded = True Explosion(self._body.position, BLOCK_SIZE, velocity=self._body.velocity) # remove joints for block in self._adjacent_blocks: toremove = self._joints & block._joints for joint in toremove: block._joints.remove(joint) SPACE.remove(*self._joints) self._joints = WeakSet() # remove ties to the construction for block in self._adjacent_blocks: block._adjacent_blocks.remove(self) self._adjacent_blocks = WeakSet() elif self.damage >= self.health * 2: Explosion(self._body.position, BLOCK_SIZE, velocity=self._body.velocity) for i in range(random.randint(1,5)): Resource(self) SPACE.remove(self._body, self._shape) SPACE.blocks.remove(self) if self in SPACE.controllable_blocks: SPACE.controllable_blocks.remove(self) if self in SPACE.controller_blocks: SPACE.controller_blocks.remove(self)
def upkeep(self): if self.decay_chance > random.random(): SPACE.remove(self._shape, self._body) SPACE.resources.remove(self) if hasattr(self._shape, "target") and self._shape.target(): b = self._shape direction = b.target().position - b.body.position if direction.length < BLOCK_SIZE / 2: block = b.target()._get_block() if block: block.resource_count += 1 SPACE.resources.remove(self) # TODO: 160 is the radius of the field... # let's get that dynamically direction.length = max(0.1, (160 - direction.length) / 160) b.body.apply_impulse(direction)
def deactivate(self): SPACE.remove(self._tractor_link, self._tractor_body, self._tractor_shape) self._tractor_body = self._tractor_link = self._tractor_shape = None
def deactivate(self): SPACE.remove(self._shield_link, self._shield_body, self._shield_shape) self._shield_body = self._shield_link = self._shield_shape = None
def upkeep(self): self.ttl -= 1 if self.ttl < 1: SPACE.remove(self._shape, self._body) SPACE.projectiles.remove(self)
def upkeep(self): self.ticks -= 1 if self.ticks <= 0: SPACE.remove(self._body, self._shape) SPACE.explosions.remove(self)