示例#1
0
    def __init__(self, rect: t.Union[Rect, t.Tuple[int, int, int, int]], grid: int = None, style: dict = None):
        self.__rect: Rect = Rect(rect)  # Положение и размер доски на экране
        self.__surface: Surface = Surface(self.__rect.size)  # Изображение доски
        self.__scale: float = 1  # Отношение размера видимой области к размеру доски
        self.__pos: t.Tuple[float, float] = 0, 0  # Локальная позиция центра видимой области

        self.__objects: t.List[BoardObject] = []
        self.__zoom_presets: t.Tuple[float, ...] = (2.0, 1.5, 1.0, 0.5, 0.25, 0.2)
        self.__grid: t.Optional[int] = grid

        self.__rl_cache: t.List[t.Optional[Surface]] = []
        self.__render_layers: t.List[RenderLayer] = []
        self.__background_layer: RenderLayer = self.add_render_layer(RL_BACKGROUND, flags=RLFLAG_STATIC_LAYER)
        self.__grid_layer: RenderLayer = self.add_render_layer(RL_GRID_DOTS, flags=RLFLAG_SCALE_DEP | RLFLAG_BOARD_MOVEMENT_DEP)
        self.__object_layer: RenderLayer = self.add_render_layer(RL_OBJECT_RENDERER, flags=RLFLAG_SCALE_DEP | RLFLAG_BOARD_MOVEMENT_DEP | RLFLAG_OBJECT_MOVEMENT_DEP)
        self.__selection_layer: RenderLayer = self.add_render_layer(RL_SELECTION, flags=RLFLAG_SCALE_DEP | RLFLAG_BOARD_MOVEMENT_DEP | RLFLAG_OBJECT_MOVEMENT_DEP | RLFLAG_SELECTION_DEP)

        self.__dirty = True

        self.style = style or DEFAULT_STYLE
示例#2
0
    def __init__(self, size=[20, 12], lineType=None):
        Sprite.__init__(self)
        width = size[0] * simulation.pixelsPerMeter
        height = size[1] * simulation.pixelsPerMeter
        self.rect = Rect(0, 0, width, height)
        self.image = Surface(self.rect.size, pygame.SRCALPHA, 32)
        self.image.fill((10, 10, 10, 50))
        pygame.draw.rect(self.image, (20, 0, 200, 200), self.rect, 8)

        self.visitors = []
        self.ride = None
        self.hotspot = self.rect.center

        self.analysisGuess = 0
        self.trendGuessDict = {0: 0}
        self.durationGuess = 0

        if lineType == None:
            lineType = longSparseLine
        self._mMatrix = MoveMatrix(lineType)
示例#3
0
    def main(self, screen):
        clock = pygame.time.Clock()

        self.matris = Matris()
        
        screen.blit(construct_nightmare(screen.get_size()), (0,0))
        
        matris_border = Surface((MATRIX_WIDTH*BLOCKSIZE+BORDERWIDTH*2, VISIBLE_MATRIX_HEIGHT*BLOCKSIZE+BORDERWIDTH*2))
        matris_border.fill(BORDERCOLOR)
        screen.blit(matris_border, (MATRIS_OFFSET,MATRIS_OFFSET))
        
        self.redraw()

        while True:
            try:
                timepassed = clock.tick(50)
                if self.matris.update((timepassed / 1000.) if not self.matris.paused else 0):
                    self.redraw()
            except GameOver:
                return
示例#4
0
    def __init__(self):
        pygame.init()
        self.screen = pygame.display.set_mode((WIDTH, HEIGHT))
        self.done = False

        # Create Background Surface
        self.background = Surface(self.screen.get_size())
        self.background.fill(BACKGROUND_COLOR)

        # Create Dirty Sprites
        self.weather_widget = WeatherWidget()

        self.weather_widget.clear(self.screen, self.background)

        # Set event timers
        self.set_timers()
        # add events to queue
        for event in EventTimer:
            my_event = pygame.event.Event(event.get_event())
            pygame.event.post(my_event)
示例#5
0
    def _hollow(self, message, antialias, color):
        notcolor = [c^0xFF for c in color]
        base = super().render(message, antialias, color, notcolor)

        size = base.get_width() + 2, base.get_height() + 2
        img = Surface(size, 16)

        img.fill(notcolor)
        base.set_colorkey(0)
        img.blit(base, (0, 0))
        img.blit(base, (3, 0))
        img.blit(base, (0, 3))
        img.blit(base, (3, 3))

        base.set_colorkey(0)
        base.set_palette_at(1, notcolor)
        img.blit(base, (1, 1))
        img.set_colorkey(notcolor)

        return img
示例#6
0
def setup():
    global clock, screen, bg, horizon, dino, font, nn, strips, image
    pygame.init()
    clock = pygame.time.Clock()
    screen = pygame.display.set_mode(DISPLAY)
    strips.append(SpriteStripAnim('./assets/200-offline-sprite.png', (927,0,44,54), 2, 0, True, frames))
    strips.append(SpriteStripAnim('./assets/200-offline-sprite.png', (1015,0,44,54), 1, 0, False, frames))
    strips[sp_n].iter()
    image = strips[sp_n].next()
    font = pygame.font.Font(None, 30)
    pygame.display.set_caption("T-Rex game")
    bg = Surface((WIN_WIDTH,WIN_HEIGHT))
    bg.fill(BACKGROUND_COLOR)
    restart()
    horizon = WIN_HEIGHT - 40
    radius = 20
    dino = Trex(radius * 2, horizon-radius*2, radius, screen)

    if IS_NN_ACTIVE:
        nn = pickle.load(open( "nn.bin", "rb" ))
示例#7
0
def main():
    window = set_mode((WIN_WIDHT, WIN_HEIGHT))
    #setting caption for window
    set_caption("Flappy bird")
    screen = Surface((WIN_WIDHT, WIN_HEIGHT))
    fin = open("score.txt", "r")
    global best_score
    for i in fin:
        best_score = int(i)
    print(best_score)
    mainmenu = Menu()
    while mainmenu.main(
            window, screen, "bird/menu.png",
            "bird/patterns/skeleton/skeleton-animation_00.png") and level(
                window, screen):
        pass
    fin.close()
    fout = open("score.txt", "w")
    fout.write(str(best_score))
    fout.close()
示例#8
0
def create_img_from_tile(tile_surface, width, height):

    tile_w = tile_surface.get_width()
    tile_h = tile_surface.get_height()

    size = (width, height)
    dst_surface = Surface(size).convert()

    # make the dst_surface transparent
    color_mask = (7, 13, 17)
    dst_surface.fill(color_mask)
    dst_surface.set_colorkey(color_mask)

    # fill the dst_surface horizontally first with the tile, once we get to the edge
    # go down a column and repeat.
    for y in range(0, height, tile_h):
        for x in range(0, width, tile_w):
            dst_surface.blit(tile_surface, (x, y))

    return dst_surface
示例#9
0
    def blit_next_tetromino(self, tetromino_surf):
        """
        Draws the next tetromino in a box to the side of the board
        """
        area = Surface((BLOCKSIZE * 5, BLOCKSIZE * 5))
        area.fill(BORDERCOLOR)
        area.fill(
            BGCOLOR,
            Rect(BORDERWIDTH, BORDERWIDTH, BLOCKSIZE * 5 - BORDERWIDTH * 2,
                 BLOCKSIZE * 5 - BORDERWIDTH * 2))

        areasize = area.get_size()[0]
        tetromino_surf_size = tetromino_surf.get_size()[0]
        # ^^ I'm assuming width and height are the same

        center = areasize / 2 - tetromino_surf_size / 2
        area.blit(tetromino_surf, (center, center))

        screen.blit(area,
                    area.get_rect(top=MATRIS_OFFSET, centerx=TRICKY_CENTERX))
示例#10
0
文件: game.py 项目: wushiwang/MaType
    def create_word_surf(self, word, color):
        w, h = self.prompt_font.size(word)
        w += 8
        size = (w, h)

        being_written = len(self.prompt_content) > 0 and word.startswith(self.prompt_content)
        start = self.prompt_content if being_written else ''
        end = word[len(self.prompt_content):] if being_written else word

        start_surf = self.prompt_font.render(start, True, pg.Color("black"))
        end_surf = self.prompt_font.render(end, True, color)

        together = Surface(size, pg.SRCALPHA, 32)

        together.fill((50,50,50, 190))

        together.blit(start_surf, (4, 0))
        together.blit(end_surf, end_surf.get_rect(right=w-4))

        return together
示例#11
0
    def __init__(self, xpos, ypos, image):
        Sprite.__init__(self)
        self.yvel = 0
        self.up = False
        self.wasup = False
        self.end = False
        self.score = 0
        x = load("bird/skeleton-animation_00.png")
        h, w = x.get_size()
        self.image = Surface((h, w))
        self.rect = self.image.get_rect()
        self.rect.x = xpos
        self.rect.y = ypos

        self.image.set_colorkey(COLOR)
        animations = []
        for anim in ANIMATION:
            animations.append((anim, ANIMATION_DELAY))
        self.anim = PygAnimation(animations)
        self.anim.play()
示例#12
0
    def __init__(self, left, top, width, height, noise_width, noise_height,
                 delay):
        Sprite.__init__(self)

        self.top = top
        self.left = left
        self.width = width
        self.height = height

        self.image = Surface((self.width, self.height))
        self.rect = Rect(left, top, self.width, self.height)
        self.rect = Rect(left, top, 0, 0)
        self.mask = Mask((self.width, self.height))
        self.mask.fill()

        self.noise_width = noise_width
        self.noise_height = noise_height

        self.tick = 0
        self.delay = delay
示例#13
0
    def render(self, text, antialias, forecolor, backcolor=(0,0,0,255)):
        size = self.size(text)
        img = NSImage.alloc().initWithSize_(size)
        img.lockFocus()

        NSString.drawAtPoint_withAttributes_(text, (0.0, 0.0), {
            NSFontAttributeName: self._font,
            NSUnderlineStyleAttributeName: self._isUnderline and 1.0 or None,
            NSBackgroundColorAttributeName: backcolor and _getColor(backcolor) or None,
            NSForegroundColorAttributeName: _getColor(forecolor),
        })

        rep = NSBitmapImageRep.alloc().initWithFocusedViewRect_(((0.0, 0.0), size))
        img.unlockFocus()
        if rep.samplesPerPixel() == 4:
            s = Surface(size, SRCALPHA|SWSURFACE, 32, [-1<<24,0xff<<16,0xff<<8,0xff])
            
            a = Numeric.reshape(Numeric.fromstring(rep.bitmapData(), typecode=Numeric.Int32), (size[1], size[0]))
            blit_array(s, Numeric.swapaxes(a,0,1))
            return s.convert_alpha()
示例#14
0
    def __init__(
        self, position, status=StatusHealth.healthy
    ):
        super(Person, self).__init__()
        self.__status = None
        self.image: Surface = Surface([4, 4])
        self.__speed = 0  # 0 to 100
        self.__pause = 0
        self.__time_to_sick = parameters['time_to_sick'] * 50
        self.__time_after_sick = parameters['time_after_sick'] * 50
        self.report = Report()

        self.set_status(status)
        self.image.fill(THECOLORS['white'])
        self.image.set_colorkey(THECOLORS['white'])
        self.rect = self.image.get_rect()
        self.rect.x = position[0]
        self.rect.y = position[1]
        self.direction_x = randint(5 * (-1), 5)
        self.direction_y = randint(5 * (-1), 5)
示例#15
0
    def __init__(self, image, zero_position=(0, 0)):
        '''
        image must be a pygame surface
        '''
        BackgroundEntity.__init__(self, zero_position)

        real_siz = image.get_size()
        self._real_size = real_siz
        self._virtual_size = (real_siz[0] * 2, real_siz[1] * 2)

        from pygame import Surface, Rect
        v_i = self._virtual_image = Surface(self._virtual_size)
        v_i.blit(image, (0, 0))
        v_i.blit(image, (real_siz[0], 0))
        v_i.blit(image, (0, real_siz[1]))
        v_i.blit(image, (real_siz[0], real_siz[1]))

        viewport = Rect(zero_position, real_siz)
        self._vp = viewport
        self.image = self._virtual_image.subsurface(viewport)
示例#16
0
def generate_minimap(bitmap, pieces=None):
    height = len(bitmap)
    width = len(bitmap[0])

    minimap = Surface((width * 4, height * 4), SRCALPHA, 32)

    for x in range(width):
        for y in range(height):
            minimap.blit(spr_tiles_mini[bitmap[y][x]], (x * 4, y * 4))

    # Generate team-colored blips on the map for each piece
    if pieces:
        for piece in pieces:
            data = piece.split(' ')
            team = Team[data[2]]
            x, y = int(data[0]), int(data[1])
            minimap.fill(team_color[team], (x * 4 + 1, y * 4 + 1, 2, 2))
            minimap.fill(clear_color[team], (x * 4 + 1, y * 4 + 3, 2, 1))

    return minimap
示例#17
0
文件: game.py 项目: Gaming32/COP.EXE
 def render(self, surf: Surface):
     player_pos = LEVEL.get(self.player)
     enemy_pos = LEVEL.get(self.enemy)
     if global_vars.intro_part > 1:
         psurf = Surface(surf.get_size()).convert_alpha()
         psurf.fill((0, 0, 0, 0))
         if self.show_enemy and self.enemy == self.player:
             pygame.draw.circle(
                 psurf,
                 PLAYER_COLOR if global_vars.blink_on else ENEMY_COLOR,
                 enemy_pos.render, 10)
         else:
             if self.show_enemy and enemy_pos is not None:
                 pygame.draw.circle(psurf, ENEMY_COLOR, enemy_pos.render,
                                    10)
             if player_pos is not None:
                 pygame.draw.circle(psurf, PLAYER_COLOR, player_pos.render,
                                    10)
         psurf.set_alpha(CHARACTER_OPACITY)
         surf.blit(psurf, (0, 0))
示例#18
0
文件: tmxloader.py 项目: z9484/PyTMX
def pygame_convert(original, colorkey, force_colorkey, pixelalpha):
    """
    this method does several tests on a surface to determine the optimal
    flags and pixel format for each tile.

    this is done for the best rendering speeds and removes the need to
    convert() the images on your own

    original is a surface and MUST NOT HAVE AN ALPHA CHANNEL
    """

    tile_size = original.get_size()

    # count the number of pixels in the tile that are not transparent
    px = mask.from_surface(original).count()

    # there are no transparent pixels in the image
    if px == tile_size[0] * tile_size[1]:
        tile = original.convert()

    # there are transparent pixels, and set to force a colorkey
    elif force_colorkey:
        tile = Surface(tile_size)
        tile.fill(force_colorkey)
        tile.blit(original, (0,0))
        tile.set_colorkey(force_colorkey, RLEACCEL)

    # there are transparent pixels, and tiled set a colorkey
    elif colorkey:
        tile = original.convert()
        tile.set_colorkey(colorkey, RLEACCEL)

    # there are transparent pixels, and set for perpixel alpha
    elif pixelalpha:
        tile = original.convert_alpha()

    # there are transparent pixels, and we won't handle them
    else:
        tile = original.convert()

    return tile
示例#19
0
def get_shadow(target_img,
               shadow_radius=2,
               black=255,
               color_format="RGBA",
               alpha_factor=0.85,
               decay_mode="exponential",
               color=(0, 0, 0),
               sun_angle=30.,
               vertical=True,
               angle_mode="flip",
               mode_value=(False, True)):
    r = target_img.get_rect()
    #the shadow will be larger in order to make free space for fadeout.
    r.inflate_ip(2 * shadow_radius, 2 * shadow_radius)
    img = Surface(r.size)
    img.fill((255, 255, 255, 255))
    img.blit(target_img, (shadow_radius, shadow_radius))
    if sun_angle <= 0.:
        raise Exception("Sun angle must be greater than zero.")
    elif sun_angle != 45. and vertical:
        w, h = img.get_size()
        new_h = h / tan(sun_angle * pi / 180.)
        screen_size = functions.get_screen().get_size()
        new_h = abs(int(min(new_h, max(screen_size))))
        img = scale(img, (w, new_h))
    if angle_mode == "flip":
        img = flip(img, mode_value[0], mode_value[1])
    elif self.angle_mode == "rotate":
        img = rotate(img, mode_value)
    else:
        raise Exception("angle_mode not available: " + str(angle_mode))
    shadow = _pilshadow(img,
                        radius=shadow_radius,
                        black=black,
                        alpha_factor=alpha_factor,
                        decay_mode=decay_mode,
                        color=color)
    #
    W, H = functions.get_screen_size()
    shadow.set_alpha(-1, RLEACCEL)
    return shadow.convert_alpha()
示例#20
0
    def __init__(self, x, y):
        Sprite.__init__(self)
        self.image = Surface((96, 86))
        #self.image.fill((27, 27, 27))
        #self.rect = self.image.get_rect()
        self.rect = Rect(33, 10, 40, 50)
        self.Right = True
        self.Left = False
        self.Walk = False
        self.Fly = False
        self.Down = False
        self.comment = False
        self.message = False
        self.counter = 0
        self.score = 0
        self.FlyCounter = 0
        self.yvel = 0
        self.xvel = 0
        self.rect.x = x
        self.rect.y = y
        self.onGround = False

        self.image.set_colorkey((0, 255, 40))
        '''Анимация когда песонаж стоит (направо)'''
        self.AnimStayRight = pyganim.PygAnimation(animation.PONY_STAY_RIGHT)
        self.AnimStayRight.play()
        '''Анимация когда песонаж стоит (налево)'''
        self.AnimStayLeft = pyganim.PygAnimation(animation.PONY_STAY_LEFT)
        self.AnimStayLeft.play()
        '''Анимация ходьбы направо'''
        self.AnimWalkRight = pyganim.PygAnimation(animation.PONY_WALK_RIGHT)
        self.AnimWalkRight.play()
        '''Анимация ходьбы навлево'''
        self.AnimWalkLeft = pyganim.PygAnimation(animation.PONY_WALK_LEFT)
        self.AnimWalkLeft.play()
        '''Анимация Полета (направо)'''
        self.AnimFlyRight = pyganim.PygAnimation(animation.PONY_FLY_RIGHT)
        self.AnimFlyRight.play()
        '''Анимация Полета (налево)'''
        self.AnimFlyLeft = pyganim.PygAnimation(animation.PONY_FLY_LEFT)
        self.AnimFlyLeft.play()
示例#21
0
    def blit_info(self):
        """
        Draws information panel
        """
        textcolor = (255, 255, 255)
        font = pygame.font.Font(None, 30)
        width = (WIDTH-(MATRIS_OFFSET+BLOCKSIZE*MATRIX_WIDTH+BORDERWIDTH*2)) - MATRIS_OFFSET*2

        def renderpair(text, val):
            text = font.render(text, True, textcolor)
            val = font.render(str(val), True, textcolor)

            surf = Surface((width, text.get_rect().height + BORDERWIDTH*2), pygame.SRCALPHA, 32)

            surf.blit(text, text.get_rect(top=BORDERWIDTH+10, left=BORDERWIDTH+10))
            surf.blit(val, val.get_rect(top=BORDERWIDTH+10, right=width-(BORDERWIDTH+10)))
            return surf
        
        #Resizes side panel to allow for all information to be display there.
        scoresurf = renderpair("Score", self.matris.score)
        levelsurf = renderpair("Level", self.matris.level)
        linessurf = renderpair("Lines", self.matris.lines)
        combosurf = renderpair("Combo", "x{}".format(self.matris.combo))

        height = 20 + (levelsurf.get_rect().height + 
                       scoresurf.get_rect().height +
                       linessurf.get_rect().height + 
                       combosurf.get_rect().height )
        
        #Colours side panel
        area = Surface((width, height))
        area.fill(BORDERCOLOR)
        area.fill(BGCOLOR, Rect(BORDERWIDTH, BORDERWIDTH, width-BORDERWIDTH*2, height-BORDERWIDTH*2))
        
        #Draws side panel
        area.blit(levelsurf, (0,0))
        area.blit(scoresurf, (0, levelsurf.get_rect().height))
        area.blit(linessurf, (0, levelsurf.get_rect().height + scoresurf.get_rect().height))
        area.blit(combosurf, (0, levelsurf.get_rect().height + scoresurf.get_rect().height + linessurf.get_rect().height))

        screen.blit(area, area.get_rect(bottom=HEIGHT-MATRIS_OFFSET, centerx=TRICKY_CENTERX))
示例#22
0
文件: matris.py 项目: cstaicu/MaTris
    def __init__(self,
                 size=(MATRIX_WIDTH, MATRIX_HEIGHT),
                 blocksize=BLOCKSIZE):
        self.size = {'width': size[0], 'height': size[1]}
        self.blocksize = blocksize
        self.surface = Surface((self.size['width'] * self.blocksize,
                                (self.size['height'] - 2) * self.blocksize))

        self.matrix = dict()
        for y in range(self.size['height']):
            for x in range(self.size['width']):
                self.matrix[(y, x)] = None

        self.next_tetromino = random.choice(list_of_tetrominoes)
        self.set_tetrominoes()
        self.tetromino_rotation = 0
        self.downwards_timer = 0
        self.base_downwards_speed = 0.4  # Move down every 400 ms

        self.movement_keys = {'left': 0, 'right': 0}
        self.movement_keys_speed = 0.05
        self.movement_keys_timer = (-self.movement_keys_speed) * 2

        self.level = 1
        self.score = 0
        self.lines = 0

        self.combo = 1  # Combo will increase when you clear lines with several tetrominos in a row

        self.paused = False
        self.gameover = False

        self.highscore = load_score()
        self.played_highscorebeaten_sound = False

        self.levelup_sound = pygame.mixer.Sound("resources/levelup.wav")
        self.linescleared_sound = pygame.mixer.Sound(
            "resources/linecleared.wav")
        self.gameover_sound = pygame.mixer.Sound("resources/gameover.wav")
        self.highscorebeaten_sound = pygame.mixer.Sound(
            "resources/highscorebeaten.wav")
示例#23
0
    def __init__(self, image_file, speed, snowconfig=None):
        self._asset = pygame.image.load(image_file).convert_alpha()
        self._asset = transform.scale(
            self._asset,
            (self._asset.get_width() // 2, self._asset.get_height() // 2))

        self._width = self._asset.get_width()

        self._speed = speed
        self._offset = 0

        if snowconfig:
            self._snow_config = snowconfig
            self._snow_baseline = []
            self._snow_height = []
            self._flakes = []

            for i in range(self._width):
                height = 0
                color = self._asset.get_at((i, 0))[3]
                j = 0
                found = False
                while j < self._asset.get_height() and found == False:

                    sample = self._asset.get_at((i, j))[3]
                    if sample != color:
                        found = True
                    else:
                        j += 1

                if found:
                    self._snow_baseline.append(j)
                    self._snow_height.append(j)

            for i in range(snowconfig.number_of_flakes):
                x = random.randint(0, self._width - 1)
                y = random.randint(0, self._snow_height[x])

                self._flakes.append([x, y])

        self.sub_surf = Surface(self._asset.get_size(), pygame.SRCALPHA)
示例#24
0
    def tick(self, dt):
        if self.engine.gameMgr.game_status == 'IN_GAME' or self.engine.gameMgr.game_status == 'ENTRY_ANIMATION':
            if self.show_fps:
                self.engine.gfxMgr.uiScreen.blit(
                    self.engine.gfxMgr.update_fps(), (10, 0))
            if self.show_grounded:
                self.engine.gfxMgr.uiScreen.blit(
                    self.engine.gfxMgr.update_is_grounded(), (300, 0))
            if self.show_jumps_left:
                self.engine.gfxMgr.uiScreen.blit(
                    self.engine.gfxMgr.update_show_jumps(), (600, 0))
            if self.show_bullet_count:
                self.engine.gfxMgr.uiScreen.blit(
                    self.engine.gfxMgr.update_bullet_count(), (900, 0))
            if self.show_platforms_rendered:
                self.engine.gfxMgr.uiScreen.blit(
                    self.engine.gfxMgr.update_platforms_rendered(), (10, 50))
            if self.show_total_enemy_count:
                self.engine.gfxMgr.uiScreen.blit(
                    self.engine.gfxMgr.update_enemy_count(), (300, 50))
            if self.show_total_enemy_rendered:
                self.engine.gfxMgr.uiScreen.blit(
                    self.engine.gfxMgr.update_enemy_rendered_count(),
                    (600, 50))
            if self.show_game_status:
                self.engine.gfxMgr.uiScreen.blit(
                    self.engine.gfxMgr.update_game_status(), (900, 50))

            self.engine.gfxMgr.uiScreen.blit(
                self.engine.gfxMgr.update_player_lives_left(), (10, 100))

        elif self.engine.gameMgr.game_status == 'MENU':
            transparent_background = Surface(
                (self.engine.config.window_size[0],
                 self.engine.config.window_size[1]))
            transparent_background = transparent_background.convert_alpha()
            transparent_background.fill((0, 0, 0, 60))
            self.engine.gfxMgr.uiScreen.blit(transparent_background, (0, 0))

            for button in self.main_menu_buttons:
                button.draw()
示例#25
0
    def __init__(self, tag, initial_position, fontname=DEFAULT_FONT):
        Sprite.__init__(self)
        self.tag = copy(tag)
        self.rotation = 0

        self.font_spec = load_font(fontname)
        self.font = get_font(self.font_spec, self.tag['size'])
        fonter = self.font.render(tag['tag'], True, tag['color'])
        frect = fonter.get_bounding_rect()
        frect.x = -frect.x
        frect.y = -frect.y
        self.fontoffset = (-frect.x, -frect.y)
        font_sf = Surface((frect.width, frect.height), pygame.SRCALPHA, 32)
        font_sf.blit(fonter, frect)
        self.image = font_sf
        self.rect = font_sf.get_rect()
        self.rect.width += TAG_PADDING
        self.rect.height += TAG_PADDING
        self.rect.x = initial_position[0]
        self.rect.y = initial_position[1]
        self._update_mask()
示例#26
0
def construct_nightmare(size):
    surf = Surface(size)

    boxsize = 8
    bordersize = 1
    vals = '1235'  # only the lower values, for darker colors and greater fear
    arr = pygame.PixelArray(surf)
    for x in range(0, len(arr), boxsize):
        for y in range(0, len(arr[x]), boxsize):

            color = int(
                ''.join([
                    random.choice(vals) + random.choice(vals) for _ in range(3)
                ]), 16)

            for LX in range(x, x + (boxsize - bordersize)):
                for LY in range(y, y + (boxsize - bordersize)):
                    if LX < len(arr) and LY < len(arr[x]):
                        arr[LX][LY] = color
    del arr
    return surf
示例#27
0
def regular_polygon(radius,
                    sides,
                    thickness=0,
                    angle=0.,
                    color=constants.BLACK):
    """Angle is the offset angle in degrees"""
    surface = Surface((2 * radius, 2 * radius))
    different = different_color(color)
    surface.fill(different)
    surface.set_colorkey(different, RLEACCEL)
    angle = radians(angle)
    alpha = 2 * pi / sides  # constant
    # building points
    points = list()
    for i in range(sides):
        ai = i * alpha + angle
        pix = cos(ai) * radius + radius
        piy = sin(ai) * radius + radius
        points.append((pix, piy))
    pygame.draw.polygon(surface, color, points, thickness)
    return surface.convert()
示例#28
0
def get_not_already_illuminated_title(hoverable, state, color=None):
    color = style.COLOR_TXT_HOVER if color is None else color
    #produce illumination then blit it on the painter not fusionned.
    fusionner = hoverable._states[state].fusionner
    target_img = hoverable.get_image(state)
    r = target_img.get_rect()
    #the shadow will be larger in order to make free space for fadeout.
    shadow_radius = 2
    r.inflate_ip(2 * shadow_radius, 2 * shadow_radius)
    img = Surface(r.size)
    img.fill((255, 255, 255, 255))
    img.blit(target_img, (shadow_radius, shadow_radius))
    shadow = pilgraphics.get_shadow(img,
                                    radius=shadow_radius,
                                    black=255,
                                    alpha_factor=0.95,
                                    decay_mode="exponential",
                                    color=color)
    shadow = shadow.subsurface(shadow.get_rect().inflate(
        (-2 * shadow_radius, -2 * shadow_radius)))
    return shadow
示例#29
0
 def __init__(self,
              x=0,
              y=0,
              width=10,
              height=10,
              text='',
              text_size=0,
              color=(10, 20, 130),
              alt_text=''):
     Sprite.__init__(self)
     self.image = Surface((width, height))
     self.rect = self.image.get_rect()
     self.rect.x = x
     self.rect.y = y
     self.text = text
     self.alt_text = alt_text
     if text_size == 0:
         self.font = font.Font(None, width)
     elif text_size > 0:
         self.font = font.Font(None, text_size)
     self.color = color
示例#30
0
    def render(self, surface):
        # not going for effeciency here

        for l in xrange(0, len(self.tiledmap.layers)):
            for y in xrange(0, self.tiledmap.height):
                for x in xrange(0, self.tiledmap.width):
                    tile = self.tiledmap.getTileImage(x, y, l)
                    xx = x * self.tiledmap.tilewidth
                    yy = y * self.tiledmap.tileheight
                    if not tile == 0:
                        surface.blit(tile, (xx, yy))

        for t in self.entities:
            env, (x, y) = self.get_position(t)
            x *= self.tiledmap.tilewidth
            y *= self.tiledmap.tileheight

            s = Surface((self.tiledmap.tilewidth, self.tiledmap.tileheight))
            s.fill((128, 0, 0))

            surface.blit(s, (x, y))