Esempio n. 1
0
def generate_sphere_sprite(radius, color, scale, layer=None):
    scaled_radius = int(round(radius * scale))
    if scaled_radius <= 0:
        scaled_radius = 1

    sprite = Sprite()
    if layer is not None:
        sprite.layer = layer

    width = height = scaled_radius * 2
    surface = Surface((width, height))
    surface.set_colorkey((0, 0, 0))
    draw.circle(surface, color, (scaled_radius, scaled_radius), scaled_radius, 0)
    sprite.image = surface

    return sprite
Esempio n. 2
0
def build_ship_sprite(size=None, scale=None, orientation=None, heading=None, main_engine=False, retro_engine=False):
    ship_height = int(round(size * scale))
    if ship_height <= 0:
        ship_height = 9

    width = ship_height / 3

    flame_height = ship_height / 5
    image_width = width
    image_height = ship_height + (flame_height * 2)

    sprite = Sprite()
    sprite.layer = 10
    surface = Surface((image_width, image_height))
    surface.set_colorkey((0, 0, 0))

    ship_top = flame_height
    ship_bottom = image_height - flame_height
    ship_left = 0
    ship_right = image_width
    ship_middle = image_width / 2

    ship_triangle = [(ship_middle, ship_top), (ship_left, ship_bottom), (ship_right, ship_bottom)]
    draw.polygon(surface, (255, 255, 255), ship_triangle)

    if main_engine:
        bottom_flame = [(ship_middle, ship_bottom), (0, image_height), (image_width, image_height)]
        draw.polygon(surface, (255, 255, 0), bottom_flame)

    if retro_engine:
        top_flame = [(ship_middle, ship_top), (0, 0), (image_width, 0)]
        draw.polygon(surface, (255, 255, 0), top_flame)

    rotated_surface = transform.rotate(surface, -orientation)

    sprite.image = rotated_surface

    return sprite