Beispiel #1
0
    def __init__(self, width, height, title, vm, paused: bool = False):
        super().__init__(width, height, title)

        # from einarf's original
        self.program = self.ctx.program(vertex_shader="""
                    #version 330
                    uniform mat4 projection;
                    in vec2 in_vert;
                    in vec2 in_uv;
                    out vec2 v_uv;
                    void main() {
                        gl_Position = projection * vec4(in_vert, 0.0, 1.0);
                        v_uv = in_uv;
                    }
                    """,
                                        fragment_shader="""
                    #version 330
                    // Unsigned integer sampler for reading uint data from texture
                    uniform usampler2D screen;
                    in vec2 v_uv;
                    out vec4 out_color;
                    void main() {
                        // Calculate the bit position on the x axis
                        uint bit_pos = uint(round((v_uv.x * 64) - 0.5)) % 8u;
                        // Create bit mask we can AND the fragment with to extract the pixel value
                        uint flag = uint(pow(2u, 7u - bit_pos));
                        // Read the fragment value (We reverse the y axis here as well)
                        uint frag = texture(screen, v_uv * vec2(1.0, -1.0)).r;
                        // Write the pixel value. Values above 1 will be clamped to 1.
                        out_color = vec4(vec3(frag & flag), 1.0);
                    }
                    """)
        self.vm: Chip8VirtualMachine = vm
        self.paused = paused
        self.keymap = build_hexkey_mapping()

        # get a bytestring that can be written to GL texture
        self.screen_buffer = memoryview(self.vm.video_ram.pixels)

        self.program['projection'] = get_projection().flatten()
        self.program['screen'] = 0

        self.quad = geometry.screen_rectangle(0, 0, SCREEN_WIDTH,
                                              SCREEN_HEIGHT)
        self.texture = self.ctx.texture((8, 32), components=1, dtype='i1')
        self.update_rate = 1.0 / 30
        self.breakpoints = set()
    def __init__(self, width, height, title):
        """ Initializer """

        # Call the parent class initializer
        super().__init__(width, height, title)

        # Variables that will hold sprite lists
        self.player_list = None
        self.star_sprite_list = None
        self.enemy_sprite_list = None
        self.bullet_sprite_list = None

        # Set up the player info
        self.player_sprite = None

        # Track the current state of what key is pressed
        self.left_pressed = False
        self.right_pressed = False
        self.up_pressed = False
        self.down_pressed = False

        self.view_bottom = 0
        self.view_left = 0

        # Set the background color
        arcade.set_background_color(arcade.color.BLACK)

        # --- Mini-map related ---
        # How big is our screen?
        screen_size = (SCREEN_WIDTH, SCREEN_HEIGHT)
        # How big is the mini-map?
        mini_map_size = (SCREEN_WIDTH, MINIMAP_HEIGHT)
        # Where is the mini-map to be drawn?
        mini_map_pos = (SCREEN_WIDTH / 2, SCREEN_HEIGHT - MINIMAP_HEIGHT / 2)
        # Load a vertex and fragment shader
        self.program = self.ctx.load_program(
            vertex_shader=arcade.resources.shaders.vertex.default_projection,
            fragment_shader=arcade.resources.shaders.fragment.texture)
        # Add a color attachment to store pixel colors
        self.mini_map_color_attachment = self.ctx.texture(screen_size)
        # Create a frame buffer with the needed color attachment
        self.mini_map_screen = self.ctx.framebuffer(
            color_attachments=[self.mini_map_color_attachment])
        # Create a rectangle that will hold where the mini-map goes
        self.mini_map_rect = geometry.screen_rectangle(0, SCREEN_WIDTH,
                                                       MINIMAP_HEIGHT,
                                                       SCREEN_HEIGHT)
Beispiel #3
0
    def __init__(self, width, height, title):
        super().__init__(width, height, title)
        self.time = 0
        self.program = self.ctx.program(vertex_shader="""
            #version 330

            in vec2 in_vert;
            in vec2 in_uv;
            out vec2 v_uv;

            void main() {
                gl_Position = vec4(in_vert, 0.0, 1.0);
                v_uv = in_uv;
            }
            """,
                                        fragment_shader="""
            #version 330

            uniform sampler2D background;
            uniform float time;

            in vec2 v_uv;
            out vec4 out_color;

            void main() {
                vec2 pos = v_uv * 1.0 - vec2(0.5);
                vec2 uv = v_uv + normalize(pos) + sin(length(pos) * 10 - time);
                out_color = texture(background, uv);
            }
            """)
        self.quad = geometry.screen_rectangle(-1, -1, 2, 2)
        image = Image.open(
            resolve_resource_path(
                ":resources:images/backgrounds/abstract_1.jpg")).convert(
                    "RGBA")
        image = image.transpose(Image.FLIP_TOP_BOTTOM)
        self.texture = self.ctx.texture(image.size,
                                        components=4,
                                        data=image.tobytes())
Beispiel #4
0
    def __init__(self, width, height, title):
        """CHIP-8 Screen"""
        super().__init__(width, height, title)
        self.program = self.ctx.program(vertex_shader="""
            #version 330

            uniform mat4 projection;

            in vec2 in_vert;
            in vec2 in_uv;
            out vec2 v_uv;

            void main() {
                gl_Position = projection * vec4(in_vert, 0.0, 1.0);
                v_uv = in_uv;
            }
            """,
                                        fragment_shader="""
            #version 330

            // Unsigned integer sampler for reading uint data from texture
            uniform usampler2D screen;

            in vec2 v_uv;
            out vec4 out_color;

            void main() {
                // Calculate the bit position on the x axis
                uint bit_pos = uint(round((v_uv.x * 64) - 0.5)) % 8u;
                // Create bit mask we can AND the fragment with to extract the pixel value
                uint flag = uint(pow(2u, 7u - bit_pos));
                // Read the fragment value (We reverse the y axis here as well)
                uint frag = texture(screen, v_uv * vec2(1.0, -1.0)).r;
                // Write the pixel value. Values above 1 will be clamped to 1.
                out_color = vec4(vec3(frag & flag), 1.0);
            }
            """)
        # 8 x 4
        self.program['projection'] = get_projection().flatten()
        self.program['screen'] = 0
        b = 0  # border to test scale
        self.quad = geometry.screen_rectangle(b, b, SCREEN_WIDTH - b * 2,
                                              SCREEN_HEIGHT - b * 2)
        self.texture = self.ctx.texture((8, 32), components=1, dtype='i1')
        self.texture.write(
            array(
                'B',
                [
                    # 64 x 32 screen
                    0xAA,
                    0xAA,
                    0xF0,
                    0xF0,
                    0xFF,
                    0x00,
                    0xFF,
                    0xFF,
                    0x55,
                    0x55,
                    0xF0,
                    0xF0,
                    0xFF,
                    0x00,
                    0xFF,
                    0xFF,
                    0xAA,
                    0xAA,
                    0xF0,
                    0xF0,
                    0xFF,
                    0x00,
                    0xFF,
                    0xFF,
                    0x55,
                    0x55,
                    0xF0,
                    0xF0,
                    0xFF,
                    0x00,
                    0xFF,
                    0xFF,
                    0xAA,
                    0xAA,
                    0x0F,
                    0x0F,
                    0xFF,
                    0x00,
                    0xFF,
                    0xFF,
                    0x55,
                    0x55,
                    0x0F,
                    0x0F,
                    0xFF,
                    0x00,
                    0xFF,
                    0xFF,
                    0xAA,
                    0xAA,
                    0x0F,
                    0x0F,
                    0xFF,
                    0x00,
                    0xFF,
                    0xFF,
                    0x55,
                    0x55,
                    0x0F,
                    0x0F,
                    0xFF,
                    0x00,
                    0xFF,
                    0xFF,
                    0xAA,
                    0xAA,
                    0xF0,
                    0xF0,
                    0x00,
                    0xFF,
                    0xFF,
                    0xFF,
                    0x55,
                    0x55,
                    0xF0,
                    0xF0,
                    0x00,
                    0xFF,
                    0xFF,
                    0xFF,
                    0xAA,
                    0xAA,
                    0xF0,
                    0xF0,
                    0x00,
                    0xFF,
                    0xFF,
                    0xFF,
                    0x55,
                    0x55,
                    0xF0,
                    0xF0,
                    0x00,
                    0xFF,
                    0xFF,
                    0xFF,
                    0xAA,
                    0xAA,
                    0x0F,
                    0x0F,
                    0x00,
                    0xFF,
                    0xFF,
                    0xFF,
                    0x55,
                    0x55,
                    0x0F,
                    0x0F,
                    0x00,
                    0xFF,
                    0xFF,
                    0xFF,
                    0xAA,
                    0xAA,
                    0x0F,
                    0x0F,
                    0x00,
                    0xFF,
                    0xFF,
                    0xFF,
                    0x55,
                    0x55,
                    0x0F,
                    0x0F,
                    0x00,
                    0xFF,
                    0xFF,
                    0xFF,
                    0xAA,
                    0xAA,
                    0xCC,
                    0x99,
                    0xbd,
                    0x63,
                    0x80,
                    0x00,
                    0x55,
                    0x55,
                    0xCC,
                    0x99,
                    0xbd,
                    0x63,
                    0x40,
                    0x00,
                    0xAA,
                    0xAA,
                    0xCC,
                    0x99,
                    0xbd,
                    0x63,
                    0x20,
                    0x00,
                    0x55,
                    0x55,
                    0xCC,
                    0x99,
                    0xbd,
                    0x63,
                    0x10,
                    0x00,
                    0xAA,
                    0xAA,
                    0xCC,
                    0x99,
                    0xbd,
                    0x63,
                    0x08,
                    0x00,
                    0x55,
                    0x55,
                    0xCC,
                    0x99,
                    0xbd,
                    0x63,
                    0x04,
                    0x00,
                    0xAA,
                    0xAA,
                    0xCC,
                    0x99,
                    0xbd,
                    0x63,
                    0x02,
                    0x00,
                    0x55,
                    0x55,
                    0xCC,
                    0x99,
                    0xbd,
                    0x63,
                    0x01,
                    0x00,
                    0xAA,
                    0xAA,
                    0xCC,
                    0x99,
                    0xbd,
                    0x63,
                    0x00,
                    0x80,
                    0x55,
                    0x55,
                    0xCC,
                    0x99,
                    0xbd,
                    0x63,
                    0x00,
                    0x40,
                    0xAA,
                    0xAA,
                    0xCC,
                    0x99,
                    0xbd,
                    0x63,
                    0x00,
                    0x20,
                    0x55,
                    0x55,
                    0xCC,
                    0x99,
                    0xbd,
                    0x63,
                    0x00,
                    0x10,
                    0xAA,
                    0xAA,
                    0xCC,
                    0x99,
                    0xbd,
                    0x63,
                    0x00,
                    0x08,
                    0x55,
                    0x55,
                    0xCC,
                    0x99,
                    0xbd,
                    0x63,
                    0x00,
                    0x04,
                    0xAA,
                    0xAA,
                    0xCC,
                    0x99,
                    0xbd,
                    0x63,
                    0x00,
                    0x02,
                    0x55,
                    0x55,
                    0xCC,
                    0x99,
                    0xbd,
                    0x63,
                    0x00,
                    0x01,
                ]))
Beispiel #5
0
def test_screen_rectangle(ctx):
    geometry.screen_rectangle(0, 100, 0, 100)