Exemplo n.º 1
0
 def __init__(self):
     self._dummy_vao = glGenVertexArrays(1)
     self._circle_program = ShaderProgram.from_sources(vert_source=self.vert_shader_base,
                                                       geom_source=self.geom_circle_shader,
                                                       frag_source=self.frag_shader_solid)
     self._polyline_program = ShaderProgram.from_sources(vert_source=self.vert_shader_base,
                                                         geom_source=self.geom_polyline_shader,
                                                         frag_source=self.frag_shader_solid)
Exemplo n.º 2
0
    def _setup_default_shader(self):
        vertex_shader = """
        #version 330 core

        uniform mat4 model;
        uniform mat4 projection;

        layout(location=0) in vec2 vertex;
        layout(location=1) in vec2 uv;

        out vec2 uv_out;

        void main() {
            vec4 vertex_world = model * vec4(vertex, 0, 1);
            gl_Position = projection * vertex_world;
            uv_out = uv;
        }
        """

        fragment_shader = """
        #version 330 core

        in vec2 uv_out;
        out vec4 color;

        uniform sampler2D tex;

        void main() {
            color = texture(tex, uv_out);
        }
        """

        self._default_shader = ShaderProgram.from_sources(
            vert_source=vertex_shader, frag_source=fragment_shader)
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,
            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.º 5
0
 def __init__(self):
     self._font_faces = {}
     self._page_textures = {}
     self._character_program = ShaderProgram.from_sources(
         vert_source=self.vert_shader_base,
         frag_source=self.frag_shader_texture)
     self._quad = QuadDrawable()
     self._quad.shader = self._character_program
Exemplo n.º 6
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.º 7
0
def create_cloud_quad(cloud, size, cloud_list, cloud_picked):
    cloud.quad = QuadDrawable(cloud.pos.x,
                              cloud.pos.y,
                              size,
                              size,
                              angle=random.random() * math.pi * 2)
    cloud.quad.texture = Texture.load_from_file('resources/images/clouds/' +
                                                cloud_list[cloud_picked - 1])
    cloud.quad.shader = ShaderProgram.from_files(
        vert_file='resources/shaders/base.vert',
        frag_file='resources/shaders/rgba.frag')
    cloud.quad.anchor_to_center()
Exemplo n.º 8
0
def create_planet_quad(planet, size, planet_list, planet_picked):
    planet.quad = QuadDrawable(planet.pos.x,
                               planet.pos.y,
                               size,
                               size,
                               angle=random.random() * math.pi * 2)
    planet.quad.texture = Texture.load_from_file('resources/images/planets/' +
                                                 planet_list[planet_picked -
                                                             1])
    planet.quad.shader = ShaderProgram.from_files(
        vert_file='resources/shaders/base.vert',
        frag_file='resources/shaders/rgba.frag')
    planet.quad.anchor_to_center()
Exemplo n.º 9
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)