Exemplo n.º 1
0
    def generate_person(self):
        # Picks a random movement direction
        direction = Vector2()
        angle = random.random() * math.pi * 2
        direction.x = math.cos(angle)
        direction.y = math.sin(angle)

        # Places the asteroid outside of the screen
        position = Vector2()
        position.x = SCREEN_WIDTH / 2 + direction.x * (SCREEN_WIDTH / 1.5)
        position.y = SCREEN_HEIGHT / 2 + direction.y * (SCREEN_HEIGHT / 1.5)

        speed = -Vector2(direction.x, direction.y) * 200 * random.random()
        torque = 0.5 * random.random()

        assets = [
            'resources/images/people/pilot.png',
            'resources/images/people/gunner.png',
            'resources/images/people/technician.png'
        ]

        asteroid = Asteroid(self,
                            position.x,
                            position.y,
                            speed=speed,
                            torque=torque,
                            asset=assets[random.randint(0,
                                                        len(assets) - 1)])
        self.asteroids.append(asteroid)
Exemplo n.º 2
0
    def draw_layers_range(self, screen, start, how_many):
        for index in range(start, start + how_many):
            layer = self._tmx_data.layers[index]
            if layer.visible == 0:
                continue

            offset_x = layer.offsetx + self._layer_offsets[index].x
            offset_y = layer.offsety + self._layer_offsets[index].y

            if isinstance(layer, pytmx.TiledTileLayer):
                # for x, y, image in layer.tiles():
                pass
            elif isinstance(layer, pytmx.TiledObjectGroup):
                for obj in layer:
                    if hasattr(obj, 'points'):
                        # draw_lines(poly_color, obj.closed, obj.points, 3)
                        pass
                    elif obj.image:
                        self._drawable.texture = obj.image
                        self._drawable.scale = Vector2(obj.width, obj.height)
                        self._drawable.pos = Vector2(obj.x - offset_x,
                                                     obj.y - offset_y)
                        self._drawable.draw(screen)

                        # obj.image.blit(obj.x - offset_x, (Gfx.screen_height - obj.y) - offset_y, 0, w, h)
                    else:
                        # draw_rect(rect_color, (obj.x, obj.y, obj.width, obj.height), 3)
                        pass
            elif isinstance(layer, pytmx.TiledImageLayer):
                if layer.image:
                    pass
Exemplo n.º 3
0
    def __init__(self, ship, world):
        super().__init__(ship._world, 0, 0)
        self._ship = ship

        self._quad = QuadDrawable(0, 0, 0, 0)
        self._quad.texture = Texture.load_from_file(
            'resources/images/shield_arc.png')
        self._quad.shader = ShaderProgram.from_files(
            vert_file='resources/shaders/base.vert',
            frag_file='resources/shaders/rgba.frag')
        self._quad.size = Vector2(self._quad.texture.width,
                                  self._quad.texture.height) * 0.67
        self._quad.anchor = Vector2(0, self._quad.size.y / 2)

        self._physicsShield = PhysicsShield(
            self,
            ship._physicsShip,
            world.physicsWorld,
            center=self._ship._physicsShip.body.position,
            radius=(self._quad.size.x / PHYSICS_SCALE) * 1.1,
        )
        self._collision_timer = 0

        self._rad1 = ship._dim.y / 2.9
        self._rad2 = ship._dim.y / 2.9
        self._angle = 0
        self._angle_speed = 1
        self._enable = False
        self._charge = 0
        self.shield_state = ShieldState(self)
        self.update(0, (0.0, 0.0, 0.0))
Exemplo n.º 4
0
    def __init__(self,
                 pos_x=0.0,
                 pos_y=0.0,
                 size_x=100,
                 size_y=100,
                 scale_x=1,
                 scale_y=1,
                 angle=0):
        self._pos = Vector2(pos_x, pos_y)
        # Size in pixels of the quad
        self._size = Vector2(size_x, size_y)
        # Anchor point
        self._anchor = Vector2(0, 0)
        # Angle to rotate around the anchor (radians)
        self._angle = angle
        # Scale to apply to the drawable (1.0 == 100%)
        self._scale = Vector2(scale_x, scale_y)
        # Defines if the texture is flipped horizontally
        self._flip_x = False
        # Defines if the texture is flipped vertically
        self._flip_y = False
        self._texture = None
        self._shader = None

        self._m_translation = None
        self._m_size = None
        self._m_rotation = None
        self._m_scale = None
        self._m_anchor = None
        self._m_transform = None
        self._is_transform_invalid = True
        self._rebuild_matrices()

        self._vao = glGenVertexArrays(1)
        glBindVertexArray(self._vao)

        # Vertices
        self._vbo = glGenBuffers(1)
        glBindBuffer(GL_ARRAY_BUFFER, self._vbo)
        self._vertices = np.array([0, 0, 0, 1, 1, 1, 1, 0], dtype=np.int16)
        glBufferData(GL_ARRAY_BUFFER, self._vertices.nbytes, self._vertices,
                     GL_STATIC_DRAW)
        glEnableVertexAttribArray(0)
        glVertexAttribPointer(0, 2, GL_UNSIGNED_SHORT, GL_FALSE, 0, None)

        # Texture coordinates
        self._vbo_uvs = glGenBuffers(1)
        glBindBuffer(GL_ARRAY_BUFFER, self._vbo_uvs)
        self._texture_coordinates = np.array([0, 0, 0, 1, 1, 1, 1, 0],
                                             dtype=np.int16)
        glBufferData(GL_ARRAY_BUFFER, self._texture_coordinates.nbytes,
                     self._texture_coordinates, GL_STATIC_DRAW)
        glEnableVertexAttribArray(1)
        glVertexAttribPointer(1, 2, GL_UNSIGNED_SHORT, GL_FALSE, 0, None)

        glBindVertexArray(0)
        if self._default_shader is None:
            self._setup_default_shader()
        self.shader = self._default_shader
Exemplo n.º 5
0
 def update(self, game_speed):
     self._quad.size = Vector2(
         self._ship._dim.x * self._ship.ship_state.energy /
         ShipState.MAX_ENERGY,
         self._quad.size.y,
     )
     self._quad.pos = self._position + Vector2(-self._ship._dim.x / 2,
                                               -self._ship._dim.y / 3)
Exemplo n.º 6
0
def update_frame(delta_ms):
    global animation_angle
    animation_angle += delta_ms / 1000
    animation_scale = math.fabs(math.sin(animation_angle * 2))
    quads[9].scale = Vector2(animation_scale, animation_scale)
    quads[10].angle = animation_angle
    quads[11].scale = Vector2(animation_scale, animation_scale)
    quads[11].angle = animation_angle
Exemplo n.º 7
0
    def __init__(self, width, height, flip_y=True):
        super().__init__()

        self._fbo = FrameBuffer(width, height)
        self._drawable = QuadDrawable()
        self._drawable.size = Vector2(width, height)
        self._drawable.flip_y = flip_y
        self._drawable.pos = Vector2(0, height)
        self._drawable.invalidate_matrices()
        self._drawable.texture = self._fbo.texture
Exemplo n.º 8
0
    def update(self, game_speed):
        time_delta = game_speed * config.GAME_FRAME_MS
        alive = 0
        for p in self.players:
            if p.is_live():
                alive += 1

        if alive <= 1 and self.game_over_timer <= 0:
            self.game_over_timer = 5000

        if self.game_over_timer > 0 and self.game_over_timer < time_delta:
            self.restart_game()
            return

        self.game_over_timer -= time_delta

        if self.game_over_timer <= 0:
            self.game_over_timer = 0

        self.stage.update(game_speed)
        for e in self.asteroids:
            e.update(game_speed)
        for e in self.entities:
            e.update(game_speed)

        if random.randint(0, 10000) < 100:
            self.generate_asteroid()

        self.check_asteroids()

        # Check position of physical objects
        for e in self.entities:
            if not isinstance(e, Ship):
                continue

            pos = e._physicsShip.body.position
            force_dir = Vector2()
            if pos.x < 0:
                force_dir = Vector2(1, 0)
            elif pos.x > self.bounds.w / PHYSICS_SCALE:
                force_dir = Vector2(-1, 0)
            elif pos.y < 0:
                force_dir = Vector2(0, 1)
            elif pos.y > self.bounds.h / PHYSICS_SCALE:
                force_dir = Vector2(0, -1)

            intensity = 100
            force_dir *= intensity
            force_apply_pos = e._physicsShip.body.GetWorldPoint(
                localPoint=(0.0, 0.0))
            e._physicsShip.body.ApplyLinearImpulse((force_dir.x, force_dir.y),
                                                   force_apply_pos, True)
Exemplo n.º 9
0
    def __init__(self, x=0.0, y=0.0, scale_x=1, scale_y=1, angle=0):
        self._pos = Vector2(x, y)
        self._angle = angle
        self._scale = Vector2(scale_x, scale_y)
        self._texture = None
        self._shader = None
        self._flip_x = False
        self._flip_y = False

        self._m_translation = self._m_rotation = self._m_scale = None
        self._m_transform = None
        self._is_transform_invalid = True
        self._rebuild_matrices()
Exemplo n.º 10
0
 def __mul__(self, other):
     if isinstance(other, Vector2):
         result = self._m @ other.v
         return Vector2(result[0], result[1])
     elif isinstance(other, Matrix4):
         return Matrix4(other._m @ self._m)
     return None
Exemplo n.º 11
0
    def __init__(
            self,
            world,
            x,
            y,
            speed,
            torque,
            asset='resources/images/asteroides/asteroid_01.png',
            scale=1,
    ):
        super().__init__(world, x, y, 0)
        # Slightly smaller than the image
        texture = Texture.load_from_file(asset)
        image_size = min(texture.width, texture.height)

        radius = ((image_size / PHYSICS_SCALE) / 2) * 0.8

        self._quad = QuadDrawable(x, y, texture.width * scale, texture.height * scale)
        self._quad.anchor_to_center()
        self._quad.texture = texture
        self._quad.shader = ShaderProgram.from_files(vert_file='resources/shaders/base.vert', frag_file='resources/shaders/rgba.frag')

        self._physicAsteroid = PhysicsAsteroid(
            self,
            world.physicsWorld,
            center=Vector2(x / PHYSICS_SCALE, y / PHYSICS_SCALE),
            radius=radius,
            speed=speed,
            torque=torque,
        )
Exemplo n.º 12
0
    def __init__(self, ship, offset_x, offset_y, offset_angle):
        self._ship = ship
        self.offset_x = offset_x
        self.offset_y = offset_y
        self.offset_angle = offset_angle

        self.side_trail_dimensions = Vector2(56 * self._ship.size,
                                             11 * self._ship.size)
        self.side_trail = QuadDrawable(0, 0, self.side_trail_dimensions.x,
                                       self.side_trail_dimensions.y)
        self.side_trail.texture = Texture.load_from_file(
            'resources/images/ship/side_trail.png')
        self.side_trail.anchor = Vector2(56 * self._ship.size,
                                         5 * self._ship.size)
        self.side_trail.angle = offset_angle

        self.update(0, 0)
Exemplo n.º 13
0
 def draw_string(self, screen, font_size, string, x, y, scale=1):
     font = self._font_faces[font_size]
     for char in string:
         c = font.get_char(char)
         self._quad.texture = self._page_textures[font_size][c.page_index]
         self._quad.size = Vector2(c.width, c.height) * scale
         self._quad.pos = Vector2(x + c.offset_x * scale,
                                  y + c.offset_y * scale)
         self._character_program.bind()
         self._character_program.set_uniform_2f('area_pos',
                                                c.x / font.page_width,
                                                c.y / font.page_height)
         self._character_program.set_uniform_2f('area_size',
                                                c.width / font.page_width,
                                                c.height / font.page_height)
         self._quad.draw(screen)
         x += c.advance_x * scale
Exemplo n.º 14
0
    def __init__(self, data, frame_name):
        self.name = frame_name
        self.image_file = data['image_file']
        self.image = data['image']

        anchor = data.get('anchor')
        if anchor:
            self.anchor = Vector2(anchor['x'], anchor['y'])
        else:
            self.anchor = Vector2(0, 0)

        rect = data.get('rect')
        if rect:
            self.rect = Rect(rect['x'], rect['y'], rect['width'],
                             rect['height'])
        else:
            self.rect = Rect(0, 0, self.image.width, self.image.height)

        attack_box = data.get('attack_box')
        if attack_box:
            if attack_box['width'] < 0:
                attack_box['x'] += attack_box['width']
                attack_box['width'] = -attack_box['width']
            if attack_box['height'] < 0:
                attack_box['y'] += attack_box['height']
                attack_box['height'] = -attack_box['height']

            self.attack_box = Rect(attack_box['x'], attack_box['y'],
                                   attack_box['width'], attack_box['height'])
        else:
            self.attack_box = None

        hit_box = data.get('hit_box')
        if hit_box:
            if hit_box['width'] < 0:
                hit_box['x'] += hit_box['width']
                hit_box['width'] = -hit_box['width']
            if hit_box['height'] < 0:
                hit_box['y'] += hit_box['height']
                hit_box['height'] = -hit_box['height']

            self.hit_box = Rect(hit_box['x'], hit_box['y'], hit_box['width'],
                                hit_box['height'])
        else:
            self.hit_box = Rect(0, 0, 0, 0)
Exemplo n.º 15
0
 def __init__(self, filename):
     self._tmx_data = pytmx.TiledMap(filename,
                                     invert_y=True,
                                     image_loader=self._image_loader)
     self._size = self._tmx_data.width * self._tmx_data.tilewidth, self._tmx_data.height * self._tmx_data.tileheight
     self._layer_offsets = [
         Vector2(0, 0) for _ in range(0, len(self._tmx_data.layers))
     ]
     self._drawable = QuadDrawable()
Exemplo n.º 16
0
 def update(self, game_speed, axis):
     if axis > 0:
         self.side_trail.size = self.side_trail_dimensions
         self.side_trail.pos = PHYSICS_SCALE * (
             self._ship._physicsShip.body.transform *
             (self.offset_x / PHYSICS_SCALE, self.offset_y / PHYSICS_SCALE))
         self.side_trail.angle = self.offset_angle + self._ship._quad.angle
     else:
         self.side_trail.size = Vector2(0, 0)
Exemplo n.º 17
0
    def draw_char(self, screen, font_size, char, x, y, scale=1):
        font = self._font_faces[font_size]
        c = font.get_char(char)
        s = self._character_program

        self._quad.texture = self._page_textures[font_size][c.page_index]
        self._quad.size = Vector2(c.width, c.height) * scale
        self._quad.pos = Vector2(x, y + c.offset_y * scale)
        self._quad.shader = s
        s.bind()
        s.set_uniform_matrix4('projection', screen.projection_matrix.m)
        s.set_uniform_2f('area_pos', c.x / font.page_width,
                         c.y / font.page_height)
        s.set_uniform_2f('area_size', c.width / font.page_width,
                         c.height / font.page_height)
        self._quad.draw(screen)

        return c.advance_x
Exemplo n.º 18
0
    def generate_asteroid(self):
        # Picks a random movement direction
        direction = Vector2()
        angle = random.random() * math.pi * 2
        direction.x = math.cos(angle)
        direction.y = math.sin(angle)

        # Places the asteroid outside of the screen
        position = Vector2()
        position.x = SCREEN_WIDTH / 2 + direction.x * (SCREEN_WIDTH / 1.5)
        position.y = SCREEN_HEIGHT / 2 + direction.y * (SCREEN_HEIGHT / 1.5)

        speed = -Vector2(direction.x, direction.y) * 1000 * random.random()
        torque = 1 * random.random()
        asteroid = Asteroid(self,
                            position.x,
                            position.y,
                            speed=speed,
                            torque=torque)
        self.asteroids.append(asteroid)
Exemplo n.º 19
0
    def __init__(self, ship, offset_x, offset_y):
        self._isBoosting = False
        self._ship = ship
        self.offset_x = offset_x
        self.offset_y = offset_y

        self.engine_trail_dimensions = Vector2(130 * self._ship.size,
                                               344 * self._ship.size)
        self.engine_trail = QuadDrawable(0, 0, self.engine_trail_dimensions.x,
                                         self.engine_trail_dimensions.y)
        self.engine_trail.texture = Texture.load_from_file(
            'resources/images/ship/trail.png')
        # Don't ask why 173...
        self.engine_trail.anchor = Vector2(65 * self._ship.size,
                                           173 * self._ship.size)
        self.engine_trail.shader = ShaderProgram.from_files(
            vert_file='resources/shaders/base.vert',
            frag_file='resources/shaders/rgba.frag')

        self.update(0, 0, False)
Exemplo n.º 20
0
    def __init__(self, width, height, cloud_list):
        start_x = random.randint(0, width)
        start_y = random.randint(0, height)
        cloud_number = random.randint(0, len(cloud_list))

        self.pos = Vector2(start_x, start_y)
        self.speed_x = (random.random() - 0.5) / 10
        self.speed_y = (random.random() - 0.5) / 10

        self.quad = None
        size = calculate_size(width, height)
        create_cloud_quad(self, size, cloud_list, cloud_number)
Exemplo n.º 21
0
    def draw(self, screen):
        if self._frame is None:
            return

        self._drawable.pos = Vector2(
            self._x, self._y)  # - camera.offset.x, self._y - camera.offset.y)
        self._drawable.draw(screen)

        # DEBUG boxes
        if Sprite.DEBUG:
            # TODO: !!!
            pass
Exemplo n.º 22
0
    def __init__(
            self,
            world,
            bullet_mgr,
            controllers,
            x,
            y,
            z=0,
            angle=0,
            color='standard',
    ):
        super().__init__(world, x, y, z)
        self.world = world

        self._dim = Vector2(130 * SCALE, 344 * SCALE)
        self._angle = angle
        self._physicsShip = PhysicsShip(
            self,
            world.physicsWorld,
            x / config.PHYSICS_SCALE,
            y / config.PHYSICS_SCALE,
            angle=angle,
        )

        # Used by ship components to scale themselves
        self.size = SCALE

        self._quad = QuadDrawable(0, 0, self._dim.x, self._dim.y)
        self._quad.pos = self._position
        self._quad.anchor = self._dim.__div__(2.0)

        texture_file = SHIP_TEXTURES.get(color, SHIP_TEXTURES['standard'])
        self._quad.texture = Texture.load_from_file(texture_file)
        self._quad.shader = ShaderProgram.from_files(vert_file='resources/shaders/base.vert', frag_file='resources/shaders/rgba.frag')

        self.controllers = controllers
        self.pilotController = controllers[0] if len(controllers) else None
        self.shieldController = controllers[1] if len(controllers) > 1 else None
        self.turretController = controllers[2] if len(controllers) > 2 else None

        self.shields = [
            Shield(self, world),
            Shield(self, world),
        ]

        self.turret_right = Turret(self, bullet_mgr, offset_x=-59 * SCALE, offset_y=2 * SCALE)
        self.turret_left = Turret(self, bullet_mgr, offset_x=59 * SCALE, offset_y=2 * SCALE)

        self.ship_state = ShipState(self)

        self.trail = Trail(self, 0, 0)
        self.side_trail_left = SideTrail(self, 28 * SCALE, 40 * SCALE, -45)
        self.side_trail_right = SideTrail(self, -25 * SCALE, 40 * SCALE, 225)
Exemplo n.º 23
0
 def update(self, game_speed, trigger_intensity, boost):
     self._isBoosting = boost
     """`trigger_intensity` is a number from 0 to 1 representing how much a player is
     pressing the controller's right trigger.
     """
     self.engine_trail.size = self.engine_trail_dimensions * (
         1 if boost else trigger_intensity)
     self.engine_trail.pos = Vector2(
         self._ship._quad.pos.x + self.offset_x,
         self._ship._quad.pos.y + self.offset_y,
     )
     self.engine_trail.angle = self._ship._quad._angle
Exemplo n.º 24
0
 def update(self, screen):
     pos = self._physics.body.position
     if pos.x < 0 or pos.x > self._world.bounds.w / PHYSICS_SCALE or \
                     pos.y < 0 or pos.y > self._world.bounds.h / PHYSICS_SCALE:
         # Bullet is outside the screen
         self.remove_bullet()
     else:
         # Update the position of the bullet
         pos *= PHYSICS_SCALE
         self._quad.pos = Vector2(pos[0], pos[1])
         self._quad.angle = self._physics.body.angle
         pos /= PHYSICS_SCALE
Exemplo n.º 25
0
    def __init__(self, begin_x, begin_y, width, height, planet_list):
        start_x = begin_x + width / 8 + random.randint(-width / 4, width / 4)
        start_y = begin_y + height / 8 + random.randint(
            -height / 4, height / 4)
        planet_number = random.randint(0, len(planet_list))
        self.pos = Vector2(start_x, start_y)
        self.speed_x = (random.random() - 0.5) / 100
        self.speed_y = (random.random() - 0.5) / 100
        self.rotation_speed = (random.random() - 0.5) / 800

        self.quad = None
        size = calculate_size(width, height)
        create_planet_quad(self, size, planet_list, planet_number)
Exemplo n.º 26
0
    def generate_asteroid(self):
        # Picks a random movement direction
        direction = Vector2()
        angle = random.random() * math.pi * 2
        direction.x = math.cos(angle)
        direction.y = math.sin(angle)

        # Places the asteroid outside of the screen
        position = Vector2()
        position.x = SCREEN_WIDTH / 2 + direction.x * (SCREEN_WIDTH / 1.5)
        position.y = SCREEN_HEIGHT / 2 + direction.y * (SCREEN_HEIGHT / 1.5)

        assets = [
            'resources/images/asteroides/asteroid_01.png',
            'resources/images/asteroides/asteroid_02.png',
            'resources/images/asteroides/asteroid_03.png',
            'resources/images/asteroides/asteroid_04.png',
            'resources/images/asteroides/asteroid_05.png',
            'resources/images/asteroides/asteroid_06.png',
            'resources/images/asteroides/asteroid_07.png',
            'resources/images/asteroides/asteroid_08.png',
            'resources/images/asteroides/asteroid_09.png',
            'resources/images/asteroides/asteroid_10.png',
            'resources/images/asteroides/asteroid_11.png',
            'resources/images/asteroides/asteroid_12.png',
            'resources/images/asteroides/asteroid_13.png',
            'resources/images/asteroides/asteroid_14.png',
        ]

        speed = -Vector2(direction.x, direction.y) * 500 * random.random()
        torque = 1 * random.random()
        asteroid = Asteroid(self,
                            position.x,
                            position.y,
                            speed=speed,
                            torque=torque,
                            asset=assets[random.randint(0,
                                                        len(assets) - 1)])
        self.asteroids.append(asteroid)
Exemplo n.º 27
0
    def update(self, game_speed):
        self.stage.update(game_speed)
        for e in self.asteroids:
            e.update(game_speed)
        for e in self.entities:
            e.update(game_speed)

        should_gen_asteroid = random.randint(0, 10000)
        if should_gen_asteroid < 10:
            self.generate_person()
        elif should_gen_asteroid < 20:
            self.generate_derelict()
        elif should_gen_asteroid < 100:
            self.generate_asteroid()

        self.check_asteroids()

        # Check position of physical objects
        for e in self.entities:
            if not isinstance(e, Ship):
                continue

            pos = e._physicsShip.body.position
            force_dir = Vector2()
            if pos.x < 0:
                force_dir = Vector2(1, 0)
            elif pos.x > self.bounds.w / PHYSICS_SCALE:
                force_dir = Vector2(-1, 0)
            elif pos.y < 0:
                force_dir = Vector2(0, 1)
            elif pos.y > self.bounds.h / PHYSICS_SCALE:
                force_dir = Vector2(0, -1)

            intensity = 100
            force_dir *= intensity
            force_apply_pos = e._physicsShip.body.GetWorldPoint(
                localPoint=(0.0, 0.0))
            e._physicsShip.body.ApplyLinearImpulse((force_dir.x, force_dir.y),
                                                   force_apply_pos, True)
Exemplo n.º 28
0
 def __init__(self, bullet_mgr, world):
     super().__init__(world, 0, 0, 0)
     # The visual representation of the bullet.
     self.owner = None
     self._world = world
     self._quad = QuadDrawable()
     self._quad.texture = Texture.load_from_file(
         'resources/images/bullet.png')
     self._quad.size = Vector2(self._quad.texture.width,
                               self._quad.texture.height)
     self._quad.anchor_to_center()
     # Attach physics only in the initialize method
     self.bullet_radius = min(self._quad.size.x,
                              self._quad.size.y) / PHYSICS_SCALE / 2
     self._angle = None
     self.bullet_mgr = bullet_mgr
Exemplo n.º 29
0
    def destroy_ship(self):
        pos = self._physicsShip.body.position * config.PHYSICS_SCALE
        x, y = pos

        self.world.asteroids.append(Asteroid(
            self.world,
            x, y - 30,
            Vector2(random() * 30 - 15, random() * -100),
               random() * 3.0,
            'resources/images/derelict/part_01.png', config.SHIP_SCALE
        ))
        self.world.asteroids.append(Asteroid(
            self.world,
            x + 30, y + 30,
            Vector2(random() * 60 + 30, random() * 60 + 30),
            random() * 3.0,
            'resources/images/derelict/part_02.png', config.SHIP_SCALE
        ))
        self.world.asteroids.append(Asteroid(
            self.world,
            x - 30, y + 30,
            Vector2(random() * -60 - 30, random() * 60 + 30),
            random() * 3.0,
            'resources/images/derelict/part_03.png', config.SHIP_SCALE
        ))

        self.world.asteroids.append(Asteroid(
            self.world,
            x, y - 30,
            Vector2(random() * 3.0 - 1.5, random() * -10),
               random() * 3.0,
            'resources/images/people/pilot.png', config.SHIP_SCALE
        ))
        self.world.asteroids.append(Asteroid(
            self.world,
            x + 30, y + 30,
            Vector2(random() * 6.0 + 3.0, random() * 6.0 + 3.0),
            random() * 3.0,
            'resources/images/people/gunner.png', config.SHIP_SCALE
        ))
        self.world.asteroids.append(Asteroid(
            self.world,
            x - 30, y + 30,
            Vector2(random() * -6.0 - 3.0, random() * 6.0 + 3.0),
            random() * 3.0,
            'resources/images/people/technician.png', config.SHIP_SCALE
        ))
Exemplo n.º 30
0
    def __init__(self, frames_store):
        self._frames_store = frames_store
        self._x = 0
        self._y = 0
        self._flags = 0
        self._angle = 0
        self._scale = Vector2(1, 1)

        # Collision detection
        self._attack_box = None
        self._hit_box = None

        # Frames and animations
        self._frame = None
        self._animation = None
        self._animation_name = None
        self._animation_frame_index = None
        self._animation_frame_delay = 0
        self._animation_speed = 1
        self._animating = False

        # Drawing
        self._drawable = QuadDrawable()