示例#1
0
def set_rgba_masks():
    """
    This rebuilds the sample surfaces, to ones that use the given
    masks.
    """

    # Annoyingly, the value for the big mask seems to vary from
    # platform to platform. So we read it out of a surface.

    global sample_alpha
    global sample_noalpha

    # Create a sample surface.
    s = pygame.Surface((10, 10), 0, 32)
    sample_alpha = s.convert_alpha()

    # Sort the components by absolute value.
    masks = list(sample_alpha.get_masks())
    masks.sort(key=abs)

    # Choose the masks.
    if sys.byteorder == 'big':
        masks = (masks[3], masks[2], masks[1], masks[0])
    else:
        masks = (masks[0], masks[1], masks[2], masks[3])

    # Create the sample surface.
    sample_alpha = pygame.Surface((10, 10), 0, 32, masks)
    sample_noalpha = pygame.Surface((10, 10), 0, 32, masks[:3] + (0, ))

    renpy.audio.audio.sample_surfaces(sample_noalpha, sample_alpha)
示例#2
0
    def __init__(self,
                 size,
                 offset,
                 border=1,
                 border_color='#FFFFFF',
                 color='#111111',
                 protected=False):
        super().__init__()
        self.protected = protected
        self.is_active = False

        self.text = ''
        self.font = pygame.font.Font('./fonts/space_invaders.ttf', 24)
        self.text_label = self.font.render(self.text, 1, (255, 255, 255))

        self.border = border
        self.bottom_image = pygame.Surface(size)
        self.bottom_image.fill(pygame.Color(border_color))

        width, height = size
        self.top_image = pygame.Surface(
            (width - 2 * border, height - 2 * border))
        self.top_image.fill(pygame.Color(color))

        self.rect = pygame.Rect(*offset, *size)
示例#3
0
def surface(w, h, alpha):
    """
    Creates a surface that shares a pixel format with the screen. The created
    surface will
    """

    if alpha:
        rv = pygame.Surface((w + 4, h + 4), pygame.SRCALPHA)
    else:
        rv = pygame.Surface((w + 4, h + 4), 0)

    return rv.subsurface((2, 2, w, h))
示例#4
0
 def __init__(self, foreground, background):
     super(ProgressBar, self).__init__()
     self.foreground = pygame_sdl2.image.load(foreground)
     self.background = pygame_sdl2.image.load(background)
     self.width, self.height = self.background.get_size()
     self.image = pygame_sdl2.Surface((self.width, self.height))
     self.counter = 0.0
示例#5
0
    def write_cache(self, filename):

        if filename in cached:
            return

        cached.add(filename)

        if renpy.loader.loadable(filename):
            return

        fn = os.path.join(renpy.config.gamedir, filename)
        dir = os.path.dirname(fn)  #@ReservedAssignment

        if not os.path.exists(dir):
            os.makedirs(dir)

        cache = pygame.Surface((self.cache_width, self.cache_height),
                               pygame.SRCALPHA, 32)

        for i, (d, rect) in enumerate(self.imagerect):
            x, y, _w, _h = self.cache_rect[i]

            surf = renpy.display.im.cache.get(d).subsurface(rect)
            cache.blit(surf, (x, y))

        pygame.image.save(cache, renpy.exports.fsencode(fn))
示例#6
0
文件: images.py 项目: uyjulian/renpy
    def generate_icon(self):

        icon_fn = os.path.join(config.renpy_base, "launcher", "game", "gui7",
                               "icon.png")
        icon = pygame_sdl2.image.load(icon_fn)

        width, height = icon.get_size()
        surf = pygame_sdl2.Surface((width, height), pygame_sdl2.SRCALPHA)

        ro, go, bo, _ao = tuple(self.accent_color)

        ro -= 23
        go -= 23
        bo -= 23

        for y in range(height):
            for x in range(width):
                r, g, b, a = icon.get_at((x, y))

                r = max(0, min(r + ro, 255))
                g = max(0, min(g + go, 255))
                b = max(0, min(b + bo, 255))

                surf.set_at((x, y), (r, g, b, a))

        self.save(surf, "window_icon", overwrite=False)
 def run(self):
     pygame.init()
     pygame.display.set_caption('Space Invaders')
     self.screen = pygame.display.set_mode(GAME_CONFIG['DISPLAY_SIZE'],
                                           pygame.DOUBLEBUF, 32)
     flags = pygame.SRCALPHA if USING_SDL2 else 0
     self.background = pygame.Surface(GAME_CONFIG['DISPLAY_SIZE'], flags)
     self.background.fill(pygame.Color(GAME_CONFIG['BACKGROUND_COLOR']))
    def __init__(self, size, offset, color=None):
        super().__init__()
        self.health = None

        # If color exists - create Surface
        if color is not None:
            self.image = pygame.Surface(size)
            self.image.fill(pygame.Color(color))
        else:
            self.image = None

        self.rect = pygame.Rect(*offset, *size)
示例#9
0
    def __init__(self, websocket):

        self.websocket = websocket

        pygame.init()
        pygame.font.init()

        self.screen = pygame.display.set_mode((600, 480))
        self.background = pygame.Surface((600, 480))
        self.background.fill(pygame.Color('#111111'))
        pygame.display.set_caption('Authorization')

        self.create_objects()
示例#10
0
def read_dump():
    global init
    surf = pygame.Surface(SIZE)
    dump = open(DUMP_PATH, "rb").read(0x6000)
    base_x, base_y = sym["wVertArrayX"], sym["wVertArrayY"]
    vert_tab = [(dump[i + base_x], dump[i + base_y]) for i in range(256)]
    # verts
    for i in vert_tab:
        if 0 <= i[0] < 128 and 0 <= i[1] < 128:
            surf.set_at(i, 0x7f7f7f)

    # expected face
    cnt = dump[sym["wVertCount"]]
    base = sym["hVertTabX"]
    verts = [(dump[i+base], dump[i+base+16]) for i in range(cnt)]
    prevs = [surf.get_at(i) for i in verts]
    pygame.draw.polygon(surf, (255, 255, 255), verts)
    for i in range(cnt):
        pos = verts[i]
        ref = prevs[i]
        col = 0x00ff00
        if ref == col:
            col = 0xff0000
        elif ref == 0:
            col = 0x0000ff
        surf.set_at(pos, col)

    # render buffer
    base = sym["sRenderBuf"]
    cur_col = dump[sym["wCurColor"]]
    addr = 0
    for i in range(16):
        for j in range(128):
            base2 = base + i*256 + j*2
            bits = int.from_bytes(dump[base2:base2+2]+dump[base2+0x1000:base2+0x1002], "little", signed=False)
            delta = 0 if init else render_buf[addr] ^ bits
            render_buf[addr] = bits
            for k in range(8):
                sh = 7 - k
                pix = bits >> sh
                pix = (pix & 1) | ((pix & 0x100) >> 7) | ((pix & 0x10000) >> 14) | ((pix & 0x1000000) >> 21)
                col = (pix*0x11, pix*0x11, pix*0x11)
                if (delta >> sh) & 0x01010101 != 0:
                    col = COL_NEW if pix == cur_col else COL_NOT
                surf.set_at((i*8+k, j+128), col)
            addr += 1

    pygame.transform.scale(surf, (WIDTH*SCALE, HEIGHT*SCALE), screen)
    # screen.blit(surf, (0, 0))
    init = False
示例#11
0
    def write_cache(self, filename):

        if filename in cached:
            return

        cached.add(filename)

        if renpy.loader.loadable(filename):
            return

        fn = renpy.loader.get_path(filename)

        cache = pygame.Surface((self.cache_width, self.cache_height), pygame.SRCALPHA, 32)

        for i, (d, rect) in enumerate(self.imagerect):
            x, y, _w, _h = self.cache_rect[i]

            surf = renpy.display.im.cache.get(d).subsurface(rect)
            cache.blit(surf, (x, y))

        pygame.image.save(cache, renpy.exports.fsencode(fn))
示例#12
0
文件: imagemap.py 项目: Allowed/renpy
    def write_cache(self, filename):

        if filename in cached:
            return

        cached.add(filename)

        # If all of our dependencies are of the same age or less,
        # we don't need to rebuild the cache.

        if renpy.loader.loadable(filename):
            d_set = set()
            mtime = 0

            for i, rect in self.imagerect:
                if i in d_set:
                    continue

                d_set.add(i)
                mtime = max(i.get_mtime(), mtime)

            if renpy.loader.get_mtime(filename) >= mtime:
                return

        fn = os.path.join(renpy.config.gamedir, filename)
        dir = os.path.dirname(fn)  #@ReservedAssignment

        if not os.path.exists(dir):
            os.makedirs(dir)

        cache = pygame.Surface((self.cache_width, self.cache_height),
                               pygame.SRCALPHA, 32)

        for i, (d, rect) in enumerate(self.imagerect):
            x, y, _w, _h = self.cache_rect[i]

            surf = renpy.display.im.cache.get(d).subsurface(rect)
            cache.blit(surf, (x, y))

        pygame.image.save(cache, renpy.exports.fsencode(fn))
示例#13
0
def surface(rect, alpha):
    """
    Constructs a new surface. The allocated surface is actually a subsurface
    of a surface that has a 2 pixel border in all directions.

    `alpha` - True if the new surface should have an alpha channel.
    """
    (width, height) = rect
    if isinstance(alpha, pygame.Surface):
        alpha = alpha.get_masks()[3]

    if alpha:
        sample = sample_alpha
    else:
        sample = sample_noalpha

    # We might not have initialized properly yet. This is enough
    # to get us underway.
    if sample is None:
        sample = pygame.Surface((4, 4), pygame.SRCALPHA, 32)

    surf = Surface((width + 4, height + 4), 0, sample)
    return surf.subsurface((2, 2, width, height))  # E1101
示例#14
0
    def go(self):
        '''This is the main game method'''
        self.load_map()
        self.load_sprites()

        # Define keystroke event delay and interval
        # pygame.key.set_repeat(500, 30)

        # Create the background
        self.background = pygame.Surface(self.screen.get_size())
        self.background = self.background.convert()
        self.background.fill((0, 0, 0))

        # Define font
        if pygame.font:
            font = pygame.font.Font(None, 36)

        # The main game loop contains all in-game actions
        while True:

            # Event handling
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    sys.exit()

            # Keyboard input handling
            pressed = pygame.key.get_pressed()
            pressed_move_keys = [key for key in MOVE_KEYS if pressed[key]]
            if pressed_move_keys:
                self.snake.move(pressed_move_keys)

            # Collision handling
            self.handle_collisions()

            # Rendering
            self.render(font)
示例#15
0
文件: images.py 项目: uyjulian/renpy
 def make_surface(self, width, height):
     return pygame_sdl2.Surface((width, height), pygame_sdl2.SRCALPHA)
示例#16
0
 def cropSurface(self, surface, rect):
     cropped = pygame.Surface((rect[2], rect[3]), 0, surface)
     cropped.blit(surface, (0, 0), rect)
     return cropped
示例#17
0
    `alpha` - True if the new surface should have an alpha channel.
    """

    if isinstance(alpha, pygame.Surface):
        alpha = alpha.get_masks()[3]

    if alpha:
        sample = sample_alpha
    else:
        sample = sample_noalpha

    # We might not have initialized properly yet. This is enough
    # to get us underway.
    if sample is None:
        sample = pygame.Surface((4, 4), pygame.SRCALPHA, 32)

    surf = Surface((width + 4, height + 4), 0, sample)
    return surf.subsurface((2, 2, width, height))  # E1101


surface_unscaled = surface


def copy_surface(surf, alpha=True):
    """
    Creates a copy of the surface.
    """

    rv = surface_unscaled(surf.get_size(), alpha)
    renpy.display.accelerator.nogil_copy(surf, rv)  # @UndefinedVariable