def __init__(self, start, end, arrow_size=10, stroke_color=(0,0,0), stroke_width=1, stroke_opacity=1): SvgCollection.__init__(self) self.type = "arrow" self.add(Line(start, end, stroke_color, stroke_width, stroke_opacity)) arrow_direction = util.direction(start, end) d1 = util.scale_vector(util.rotate_2D_vector(arrow_direction, math.pi * 5/6), arrow_size) d2 = util.scale_vector(util.rotate_2D_vector(arrow_direction, math.pi * -5/6), arrow_size) e1 = util.add_vector(end, d1) e2 = util.add_vector(end, d2) self.add(Line(end, e1, stroke_color, stroke_width, stroke_opacity)) self.add(Line(end, e2, stroke_color, stroke_width, stroke_opacity))
def spawn_engine_particles(self, destination_list): if self.engine_particles_to_spawn <= 0: return location_offset = util.scale_vector(self.direction_vector, -3) location = util.add_vector(self.get_rect().center, location_offset) vel_offset = util.scale_vector(self.direction_vector, self.particle_direction) particle_velocity = util.add_vector(self.get_velocity(), vel_offset) particle.spawn_particles(destination_list, count=self.engine_particles_to_spawn, location=location, velocity=particle_velocity, color=dark_red, fade_to_color=light_yellow) self.engine_particles_to_spawn = 0
def __init__(self, origin, text, font_size=None, fill_color=None, stroke_color=None, stroke_width=0): SvgObject.__init__(self) self.type = "text" self.xml_value = text self.set_attribute("x", origin[0]) self.set_attribute("y", origin[1]) self.set_attribute_color("fill", fill_color) self.set_attribute("font-size", font_size) self.set_attribute_color("stroke", stroke_color) self.set_attribute("stroke-width", stroke_width) if (font_size == None): font_size = default_font_size self.min_corner = util.add_vector(origin, (0, -font_size)) self.max_corner = util.add_vector(origin, (0, 0)) # I don't know how to asses the pixel length of the text
def fire_laser(self, delta_time): if self.last_fire >= self.fire_rate: # print("laser fired! " + str(delta_time)) self.last_fire = 0 location = self.get_rect().center offset = util.scale_vector(self.direction_vector, 5) final_location = util.add_vector(offset, location) laser = lasermod.Laser(final_location, self.direction_vector, self.get_velocity()) self.lasers.append(laser)
def init_image(hp): # todo make the drawing cooler. direction_of_draw = pygame.math.Vector2((0, -1)) total_points = hp + 2 degrees_per_point = 360 / total_points diameter = diameter_from_hp(hp) radius = int(diameter / 2) surface = pygame.Surface((diameter, diameter), pygame.SRCALPHA) center_point = surface.get_rect().center points = [] previous_scalar = radius for _ in range(total_points): point_scalar = max(min(util.gauss(previous_scalar + 1, 3), radius), 1) previous_scalar = point_scalar point = util.scale_vector(direction_of_draw, point_scalar) point = util.add_vector(point, center_point) points.append(point) direction_of_draw = direction_of_draw.rotate(degrees_per_point) pygame.draw.polygon(surface, asteroid_color, points) return surface
def pan(self, offset): self.min_corner = util.add_vector(self.min_corner, offset) self.max_corner = util.add_vector(self.max_corner, offset) pass