Exemple #1
0
 def on_destroy(self):
     # Create explosion
     for s in self.body.shapes:
         bodydef = Body()
         bodydef.ccd = True
         debris = self.melee.world.append_body(bodydef)
         debris.linear_velocity = Vec2(randrange(-100.0, 100.0), 
                                     randrange(-100.0, 100.0))
         junk = Debris(self.melee, debris)
         if isinstance(s, BoundPolygon):
             # Polygon
             debris.position = self.body.position + s.centroid
             polydef = Polygon()
             polydef.density = 10
             polydef.vertices = s.vertices
             shape = debris.append_shape(polydef)
             # Register shapes for collision callbacks
             self.melee.contact_register[hash(shape)] = junk
         else:
             # Circle
             debris.position = self.body.position + s.local_position
             circdef = Circle()
             circdef.density = 10
             circle.radis = s.radius
             shape = debris.append_shape(circdef)
             self.melee.contact_register[hash(shape)] = junk
             
         debris.set_mass_from_shapes()
Exemple #2
0
    def __init__(self, melee):
        Ship.__init__(self, melee)
        
        ##
        ## Manually Create turret
        ## TODO: Eventually this will be autogenerated via SVG
        
        from utils.squirtle import SVG
        svg_turret = SVG('data/ships/nemesis-turret.svg')
        svg_turret.init((105.908, 106.821), self.scale)
        
        # Create body
        bodydef = Body()
        bodydef.ccd = True
        bodydef.position = self.body.position 
        self.turret = melee.world.append_body(bodydef)
        self.turret.angular_velocity = self.body.angular_velocity
        self.turret.linear_velocity = self.body.linear_velocity
        
        # Create shapes
        self.radius = 0.85
        density = 2.0
        # Base
        base = Circle()
        base.collision_group = self.group
        base.radius = self.radius 
        base.density = density
        # Barrel
        verts = [Vec2(0.15, -2), Vec2(0.15, 0), Vec2(-0.15, 0), Vec2( -0.15, -2)]
        barrel = Polygon()
        barrel.vertices = verts
        barrel.collision_group = self.group
        barrel.density = density
        
        s1 = self.turret.append_shape(base)
        s2 = self.turret.append_shape(barrel)
        self.turret.set_mass_from_shapes()
       
		# Create secondary
        SecondaryWeapon(self, melee, self.turret, svg_turret)
Exemple #3
0
 def fire(self):
     
     # This is a specalized function..
     
     if not self.primary_time() or self.battery <= self.pEnergy:
         return  
     
     # Drain battery
     self.battery_cost(self.pEnergy)
     
     # Create body and shape
     bodydef = Body()
     bodydef.ccd = True
     bodydef.angle = self.body.angle + (pi * 0.5) + self.turret_angle
     bodydef.position = self.turret.get_world_point(Vec2(0, -3))
     shell = self.melee.world.append_body(bodydef)
     angle = vforangle(bodydef.angle)
     velocity = rotate(angle, (0.0, -150.0))
     vb = self.body.linear_velocity
     shell.linear_velocity = Vec2(velocity[0]+vb.x, velocity[1]+vb.y)
     
     polydef = Polygon()
     verts = [Vec2(0.5, 0.8), Vec2(-0.5, 0.8), Vec2(-0.5, -0.8), Vec2(0.5, -0.8)]
     polydef.vertices = verts
     polydef.density = 5
     polydef.collision_group = self.group
     
     shell.append_shape(polydef)
     shell.set_mass_from_shapes()
     
     # Create projectile
     projectile = PrimaryWeapon(self, self.melee, shell)
     projectile.group = self.group
     projectile.lifetime = 2.5
     projectile.damage = 10
     projectile.health = 5
     projectile.shapes = verts 
Exemple #4
0
 def __init__(self, melee):
     Actor.__init__(self, melee)
     
     # Set max linear and angular velocity
     self.max_linear_velocity = 50
     self.max_angular_velocity = pi
     
     # Physics (based on SVG shapes)
     self.translate = calc_center(self.lines[self.parts.index(self.center_part)])
     self.svg.init(self.translate, self.scale)
     
     bodydef = Body()
     bodydef.ccd = True
     bodydef.position = self.initial_position
     self.body = melee.world.append_body(bodydef)
     self.body.linear_velocity = self.initial_velocity
     self.body.angular_velocity = self.initial_ang_vel
     
     for p in self.lines:
         polygondef = Polygon()
         polygondef.density = self.density
         # Ensure points are oriented ccw
         ccw = convex_hull(p)
         # Translate and scale points
         verts = []
         for v in ccw:
             x = (v[0] - self.translate[0]) * self.scale
             y = (v[1] - self.translate[1]) * self.scale
             verts.append(Vec2(x, y))   
         polygondef.vertices = verts
         polygondef.collision_group = self.group
         shape = self.body.append_shape(polygondef)
         # Register shapes for collision callbacks
         melee.contact_register[hash(shape)] = self
         
     self.body.set_mass_from_shapes()