Ejemplo n.º 1
0
 def check_death(self):
     remove_list = []
     for unit in self.units:
         if unit.health <= 0:
             for unit2 in self.units:
                 if unit2.parent_unit == unit:
                     self.release_unit(unit2)
             unit.deactivate()
             physics.update_bodies_now = True
             env.unbind_keys_for_unit(unit)
             unit.die()
             remove_list.append(unit)
             sound.play(resources.expl_medium)
             particle.new_explosion(
                 unit.x, unit.y, 
                 int(30*unit.explosion_size),
                 int(150*unit.explosion_size),
                 int(15*unit.explosion_size)
             )
     
     if self.units[0] in remove_list:
         for unit in self.units:
             unit.health = 0
             if unit.x != 0 or unit.y != 0:
                 particle.new_explosion(unit.x, unit.y)
      
     if len(remove_list) > 0: 
         for unit in remove_list:
             self.units.remove(unit)
         self.update_center_of_mass()
         
     if len(self.units) == 0:
         physics.body_update_list.remove(self)
         physics.space.remove(self.body)
         if self == level.player:
             level.restart_countdown = 3.0
             level.player = None
             sound.play(resources.expl_large)
Ejemplo n.º 2
0
 def _release_unit_now(self, unit):
     #Find the new body's global coordinates and rotation
     physics.unit_update_list.remove(unit)
     new_body_position = self.body.local_to_world(unit.circle.center)
     new_body_rotation = math.degrees(self.body.angle) - unit.local_angle
     
     angle_to_unit = self.body.angle
     angle_to_unit += math.atan2(unit.offset[1], unit.offset[0])
     extra_angle = angle_to_unit + math.pi/2
     extra = self.body.angular_velocity * math.sqrt(unit.offset_dist_sq)
     new_body_velocity = (
         self.body.velocity.x + extra * math.cos(extra_angle),
         self.body.velocity.y + extra * math.sin(extra_angle)
     )
     
     unit.remove_shapes()
     
     #Create a new body, pass it the unit
     new_body = SingleBody(new_body_position, new_body_rotation, unit)
     new_body.body.velocity = new_body_velocity
     new_body.body.angular_velocity = self.body.angular_velocity
     unit.parent = None
     if unit.active:
         unit.active_timer = 1.0
         unit.deactivate()
     unit.release()
     #Fix self
     self.update_center_of_mass()
     
     if hasattr(unit, 'obj_id'):
         if unit.obj_id in event.release_funcs.keys():
             for func in event.release_funcs[unit.obj_id]:
                 try:
                     func(unit.obj_id)
                 except TypeError:
                     func()
     
     event.update_player_units(self.units)
Ejemplo n.º 3
0
 def clean_up_game(self):
     for unit in physics.unit_update_list:
         unit.deactivate()