def __init__(self): self.__images = [ pg.transform.flip( pg.transform.scale( pg.image.load(join(_ball, "snowball_0" + str(i) + ".png")), _ball_scale), True, False) for i in range(1, 7) ] self.__images.append( pg.transform.flip( pg.transform.scale( pg.image.load(join(_ball, "snowball_07.png")), (30, 30)), True, False)) self.__is_thrown = False self.__index = 0 self.rotate_image = self.__images[self.__index] image = self.__images[self.__index] Base.__init__(self, image) Circle.__init__(self, self.rect, collision_type=4, radius=15)
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)
def __init__(self, melee): Actor.__init__(self, melee) # Randomize velocity ub = melee.aabb.upper_bound lb = melee.aabb.lower_bound x = randrange(lb.x, ub.x) y = randrange(lb.y, ub.y) av = 0.1 vx = randrange(-50.0, 50.0) vy = randrange(-50.0, 50.0) # Create body bodydef = Body() bodydef.ccd = True bodydef.position = Vec2(x, y) self.body = melee.world.append_body(bodydef) self.body.angular_velocity = av self.body.linear_velocity = Vec2(vx, vy) # Create shape self.radius = 1.0 density = 10.0 c1 = Circle() c1.radius = self.radius self.c1_local = -1.0, 1.0 c1.local_position = Vec2(*self.c1_local) c1.density = density s1 = self.body.append_shape(c1) c2 = Circle() c2.radius = self.radius self.c2_local = 1.0, 1.0 c2.local_position = Vec2(*self.c2_local) c2.density = density s2 = self.body.append_shape(c2) self.body.set_mass_from_shapes() # Register shapes for collision callbacks melee.contact_register[hash(s1)] = self melee.contact_register[hash(s2)] = self