def draw(self): # Затемнение фона if self.need_to_darken_background: if self.dark_background is None: self.dark_background = Surface((self.window_surface.get_width(), self.window_surface.get_height()), SRCALPHA) self.dark_background.fill(HALF_BLACK) # Наложение полупрозрачного чёрного фона на картинку self.window_surface.blit(self.dark_background, (0, 0)) # Заливка rect-а. if self.fill: if self.transparent: # Если прозрачный цвет заливки if self.transparent_background is None: self.transparent_background = Surface((self.rect.w, self.rect.h), SRCALPHA) self.transparent_background.fill((self.color[0], self.color[1], self.color[2], self.transparent_alpha)) if self.transparent_background_shadow is None: self.transparent_background_shadow = Surface((self.rect.w, self.rect.h), SRCALPHA) self.transparent_background_shadow.fill(HALF_BLACK) # Отрисовка тени: self.window_surface.blit(self.transparent_background_shadow, (self.rect.x + 2, self.rect.y + 2)) # Отрисовка самого PopupBox-а self.window_surface.blit(self.transparent_background, (self.rect.x, self.rect.y)) else: # Если непрозрачный цвет заливки # Отрисовка тени: self.window_surface.fill(BLACK, (self.rect.x + 2, self.rect.y + 2, self.rect.width, self.rect.height)) # Отрисовка самого PopupBox-а self.window_surface.fill(self.color, self.rect) for obj in self.box_objects: obj.draw()
def __init__(self, left: int, top: int, game_player, image_height: int=50): super().__init__() self.game_player = game_player surface = game_player.character.face_image name = game_player.player.name stock = game_player.stock # キャラ画像 image_width = image_height rect = Rect(left, top, image_width, image_height) image = surface_fit_to_rect(surface, rect) self.character_sprite = SimpleSprite(rect, image) self.add(self.character_sprite) # ストックの丸 self.stock = stock self.stock_sprites = [Group() for i in range(stock)] x, y = self.character_sprite.rect.bottomright stock_radius = int(0.05 * image_height) left, top = x, y - stock_radius * 2 for i in range(stock): surface = Surface((stock_radius * 2, stock_radius * 2)).convert_alpha() surface.fill((125, 125, 125)) surface.set_colorkey(surface.get_at((0, 0))) pygame.gfxdraw.filled_circle(surface, stock_radius, stock_radius, stock_radius-1, (255, 255, 255)) stock_sprite = SimpleSprite(Rect(left, top, stock_radius * 2, stock_radius * 2), surface) self.stock_sprites[i].add(stock_sprite) print(self.stock_sprites[i]) left += stock_radius * 2 # プレイヤーネーム font_size = int(0.2 * image_height) font = pygame.font.Font(None, font_size) left, bottom = self.character_sprite.rect.bottomright bottom -= stock_radius * 2 self.player_name_sprite = TextSprite( x=left, y=bottom, align="left", vertical_align="bottom", text=name, font=font, color=(255, 255, 255) ) self.add(self.player_name_sprite) # プレイヤーネームのbg width = self.character_sprite.rect.w + max(stock_radius * 2 * stock, self.player_name_sprite.rect.w) + 10 height = self.character_sprite.rect.h self.base_rect = Rect(*self.character_sprite.rect.topleft, width, height) rect = self.base_rect bg_image = Surface(rect.size).convert_alpha() bg_image.fill((0, 0, 0)) bg_image.set_alpha(225) bg_sprite = SimpleSprite(rect, bg_image) self.bg_group = Group() self.bg_group.add(bg_sprite)
def __init__(self): self.__class__.instance = self self.enabled = True self._source = {} self.size = Vector2(150, 300) self.background = Surface((100, 100)) self.border = Surface((40, 40)) self.border.fill(ColorHelper.GREEN) self.background.fill(ColorHelper.BLACK)
def drawBoatSelector(self): carrier_text = self.carrier player = self.instance.player_1 if self.current_player == PLAYER_1 else self.instance.player_2 if (player.get_boat_count(BOAT_CARRIER) >= self.instance.rules.get_boat_limit(BOAT_CARRIER)): carrier_text = self.carrier_invalid elif (self.instance.selected_boat_type == BOAT_CARRIER): carrier_text = self.carrier_selected battleship_text = self.battleship if (player.get_boat_count(BOAT_BATTLESHIP) >= self.instance.rules.get_boat_limit(BOAT_BATTLESHIP)): battleship_text = self.battleship_invalid elif (self.instance.selected_boat_type == BOAT_BATTLESHIP): battleship_text = self.battleship_selected cruiser_text = self.cruiser if (player.get_boat_count(BOAT_CRUISER) >= self.instance.rules.get_boat_limit(BOAT_CRUISER)): cruiser_text = self.cruiser_invalid elif (self.instance.selected_boat_type == BOAT_CRUISER): cruiser_text = self.cruiser_selected submarine_text = self.submarine if (player.get_boat_count(BOAT_SUBMARINE) >= self.instance.rules.get_boat_limit(BOAT_SUBMARINE)): submarine_text = self.submarine_invalid elif (self.instance.selected_boat_type == BOAT_SUBMARINE): submarine_text = self.submarine_selected destroyer_text = self.destroyer if (player.get_boat_count(BOAT_DESTROYER) >= self.instance.rules.get_boat_limit(BOAT_DESTROYER)): destroyer_text = self.destroyer_invalid elif (self.instance.selected_boat_type == BOAT_DESTROYER): destroyer_text = self.destroyer_selected self.selector.blit(Surface((1, 185)), (0, 0)) self.selector.blit( Surface( (self.instance.grid_scale * 2 + self.render_offset[0] * 2, 1)), (0, 0)) self.selector.blit( Surface((1, 185)), (self.instance.grid_scale * 2 + self.render_offset[0] * 2, 0)) self.selector.blit( Surface( (self.instance.grid_scale * 2 + self.render_offset[0] * 2 + 1, 1)), (0, 185)) self.selector.blit(carrier_text, (10, 10)) self.selector.blit(battleship_text, (10, 65)) self.selector.blit(cruiser_text, (10, 130)) self.selector.blit(submarine_text, (510, 10)) self.selector.blit(destroyer_text, (510, 65)) #On "colle" le selecteur sur la fenetre. self.window.blit(self.selector, self.boat_selector_pos)
def loadImage(self, colour): result = Surface(self.baseImg.get_size(), pygame.SRCALPHA) result.fill((0, 0, 0, 0)) result.blit(self.baseImg, (0, 0)) temp = Surface(self.baseImg.get_size(), pygame.SRCALPHA) temp.fill(colour + (255, )) temp.blit(self.teamImg, (0, 0), special_flags=pygame.BLEND_RGBA_MULT) result.blit(temp, (0, 0)) self.cached[colour] = result
def __init__(self, screen): self.entities = {} self.entity_id = 0 self.energy_stores = {} self.game_map = load_pygame(game_settings.MAP_DIR) self.hero_nums = {"green": 0, "red": 0} self.background_layer = Surface( game_settings.SCREEN_SIZE).convert_alpha() self.player_layer = Surface(game_settings.SCREEN_SIZE).convert_alpha() self.player_layer.fill((0, 0, 0, 0)) # initial double-side heroes draw_background_with_tiled_map(self.background_layer, self.game_map) screen.blit(self.background_layer, game_settings.SCREEN_SIZE)
def update(self): x, y = 0, 0 self.right, self.up = False, False print('m', self.master.coords) print('l', self.coords) chaseX = self.chase[0] - 100 chaseY = self.chase[1] - 100 if [chaseX, chaseY] != self.coords: # offset in order to make the lantern its center if chaseX > self.coords[0]: if self.master.coords[0] - self.coords[0] < 10: x += chaseX - self.coords[0] else: x += 10 elif chaseX < self.coords[0]: if self.coords[0] - chaseX < 10: x -= self.coords[0] - chaseX else: x -= 10 if chaseY > self.coords[1]: if chaseY - self.coords[1] < 10: y += chaseY - self.coords[1] else: y += 10 elif chaseY < self.coords[1]: if self.coords[1] - chaseY < 10: y -= self.coords[1] - chaseY else: y -= 10 self.fill((15, 111, 225)) if x > 0: self.right = True if y < 0: self.right = True for sprite in self.sprites: if sprite != self.master: sprite.renderToLight(self) self.master.renderToLight(self) #light depletion border_size = self.master.deplete // 10 spot = 200 - border_size self.blit(Surface((200, border_size)), (0, 0)) # top self.blit(Surface((border_size, 200)), (0, 0)) # left self.blit(Surface((200, border_size)), (0, spot)) # bottom self.blit(Surface((border_size, 200)), (spot, 0)) # right #other stuffs self.coords[0] += x self.coords[1] += y self.win.blit(self, self.coords)
def __init__(self, sock, user_name: Optional[str]): pygame.init() self._screen: Surface = pygame.display.set_mode((600, 400)) self._font = Font("resources/font.ttf", 14) self._rendered_messages = [] self._input_text = "" self._rendered_input = Surface((1, 1)) self._update_input("") self._people_typing: Set[str] = set() self._rendered_people_typing = Surface((1, 1)) self._client = Client(sock, user_name, self._handle_packet) user_name = self._client.log_in_to_server() self._add_message(f"You logged in as \"{user_name}\"") self._client.start_receiver_thread()
def getEndGameSplash(winnerName = None, winnerColor = None): """If winningName and winnerColor are both None, display a tie game screen. """ screen = Display.get_surface() splashGroup = SpriteGroup() if(winnerName != None and winnerColor != None): # Create winning bomberman image fatalityRect = Rect((0, 0, 500, 500)) fatalityRect.centerx = screen.get_rect().centerx fatalityRect.centery = screen.get_rect().centery fatalityAnimation = WorldlessWidget(Surface((500, 500)), fatalityRect) fatalImage = pygame.image.load('images/fatality.png').convert() fatalImage.set_colorkey(LAVENDER) bmanColor = Surface((fatalImage.get_width(), fatalImage.get_height())) bmanColor.fill(winnerColor) bmanColor.blit(fatalImage, bmanColor.get_rect()) winnerFrames = createFrames(bmanColor) fatalityAnimation.startAnimation(winnerFrames, 0, 12) splashGroup.add(fatalityAnimation) # Create text for winning player winnerText = TextBar(winnerName + \ ' Wins!', (0, 0, 200, 50), 50) imgWidth = winnerText.image.get_width() winnerText.rect.left = (screen.get_size()[X]-imgWidth)/2 splashGroup.add(winnerText) else: tieText = TextBar('TIE GAME!', (0, 20, 250, 50), 35) imgWidth = tieText.image.get_width() tieText.rect.left = (screen.get_size()[X]-imgWidth)/2 splashGroup.add(tieText) escMessage = TextBar("Press Escape to exit.", (0, 60, 250, 50), 25) imgWidth = escMessage.image.get_width() escMessage.rect.left = (screen.get_size()[X] - imgWidth) / 2 splashGroup.add(escMessage) pressKeyText = TextBar('Press a key or button when ready. Next round will start when everyone is ready.', (0, 90, 250, 50), 25) imgWidth = pressKeyText.image.get_width() pressKeyText.rect.left = (screen.get_size()[X] - imgWidth) / 2 splashGroup.add(pressKeyText) return splashGroup
def convert_to_colorkey_alpha(surf, colorkey=Color('magenta')): """Give the surface a colorkeyed background that will be transparent when drawing. Colorkey alpha, unlike per-pixel alpha, will keep the image's transparent background while using methods such as Surface.set_alpha(). Keyword arguments: surf (Surface): Will be converted to alpha using colorkey. colorkey (Color): The color value for the colorkey. The default is magenta or RGB(255, 0, 255). This should be set to a color that isn't present in the image, otherwise those areas with a matching colour will be drawn transparent as well. """ colorkeyed_surf = Surface(surf.get_size()) colorkeyed_surf.fill(colorkey) colorkeyed_surf.blit(surf, (0, 0)) colorkeyed_surf.set_colorkey(colorkey) colorkeyed_surf.convert() colorkeyed_surf.set_alpha(255) return colorkeyed_surf
def __init__(self, side, speed, engine: ControlEngine): super().__init__() self.speed = speed self.engine = engine self.engine.bind_pad(self) self.top_region_pct = 10 self.middle_region_pct = 15 self.width = 25 self.height = 75 self.dy = 0 self.image = Surface((self.width, self.height)) self.image.fill(white) self.rect = self.image.get_rect() if side == 'left': self.margin = 25 else: self.margin = 775 - self.width self.rect.y = 300 self.rect.x = self.margin self.borders = None
def __init__(self, color, pos): Sprite.__init__(self) self.rect = Rect(*pos, CELLS_SIZE, CELLS_SIZE) self.image = Surface((self.rect.width, self.rect.height)) self.image.fill(color) self.state = 'normal' self.color = color
def set_dialog(self, dialog_node: DialogNode): self._dialog_node = dialog_node graphics = dialog_node.graphics if graphics.image_ids: animation = _Animation( [self._images[i] for i in graphics.image_ids], graphics.offset) else: animation = _Animation(self._animations[graphics.animation_id], graphics.offset) margin = 5 dialog_box_size = (self._width - margin * 2, 120) self._components = [(_Picture(Surface(self._picture_size), self._background, animation), (0, 0))] if dialog_node.text: self._dialog_box = _TextBox(self._dialog_font, dialog_box_size, dialog_node.text, border_color=(150, 150, 150), text_color=(255, 255, 255), sound_player=self._sound_player) self._components.append( (self._dialog_box, (margin, self._picture_size[1] - dialog_box_size[1] - margin))) if dialog_node.graphics.instant_text: self._dialog_box.set_cursor_to_end() self._choice_buttons = [] if graphics.screen_shake: self._screen_shake.start(graphics.screen_shake)
def __init__(self, manager: UIManager, x_pos: int, y_pos: int, color: Tuple[int, int, int], width: int, height: int, text='Test Button', disable=False, font_size=15, padding=PADDING): Group.__init__(self) UIComponent.__init__(self, manager) self.color = color self.x_pos = x_pos self.y_pos = y_pos self.width = width self.height = height self.text = text self.disable = disable self.font_size = font_size self.padding = padding self.color = color self.button = Sprite() self.button.image = Surface([width, height]) self.button.image.fill(color) render_inline_text(self.button.image, self.text, self.font_size, (0, 0, 0)) self.button.rect = self.button.image.get_rect() self.button.rect.topleft = (x_pos, y_pos) self.add(self.button)
def refresh_loc(self, field_size): """ updates coordinates on teh table surface :param field_size: float; size of a virtual field that is determined by the size of the window that inhabits the GUI """ # gets surface with fitting size if self.title == "Remaining Ships": self.location = [field_size * 25, field_size * 5 ] # updates location on the game window column_width = 3 else: self.location = [field_size * 10, field_size * 5.5] column_width = 3.75 self.surf = Surface((self.fake_size[0] * 4 * field_size, self.fake_size[1] * 3 * field_size)) self.writing.font = SysFont(None, int(field_size * 3 / 2)) # resizes title's font # calculates title's center self.writing.top_left_corner = [ field_size * self.columns.__len__() * column_width / 2, field_size * 3 / 4 ] for column in self.columns: # goes through every column column.refresh_loc(field_size) # updates its locations
def __init__(self, background_color, font: Font, keyboard_manager: KeyboardManager, state_manager: StateManager, root_object_manager: RootObjectManager, handler_manager: HandlerManager, shutdown): self.background_color = background_color self.font: Font = font self.keyboard_manager: KeyboardManager = keyboard_manager self.state_manager: StateManager = state_manager self.root_object_manager = root_object_manager self.handler_manager = handler_manager self.shutdown = shutdown self.line = '' self.surface = Surface([0, 0]) self.surface_background_width = 0 self.x = 0 self.y = 100 self.backspace_pressed_time = 0 self.backspace_sleep_duration = 0.5 self.backspace_repress_cycle = 0.05 self.backspace_cycle_elapsed = 0 self.last_loop_time = 0
def __init__(self, game_env): Text.__init__(self, game_env, size=20) self.__game_env = game_env seperator = self.font.render(' ', 1, self.color) header = self.font.render('=== HELP ===', 1, self.color) footer = self.font.render('=== GOOD LUCK ===', 1, self.color) all_surfaces = [] all_surfaces.append(seperator) all_surfaces.append(self.font.render('Your objective should you choose to accept is to navigate your jet without getting hit by', 1, self.color)) all_surfaces.append(self.font.render('the incoming missiles. For self-defence you can shoot down the enemy missiles. You are', 1, self.color)) all_surfaces.append(self.font.render('armed with 100 special missiles. Level-up awards you another 50 special missiles and a', 1, self.color)) all_surfaces.append(self.font.render('power-up star which will instantly deactivate all the enemy missiles.', 1, self.color)) all_surfaces.append(self.font.render('Your jet can carry maximum 999 special missiles.', 1, self.color)) all_surfaces.append(seperator) all_surfaces.append(self.font.render('With keyboard input, you should use your keyboard arrow keys to navigate and spacebar', 1, self.color)) all_surfaces.append(self.font.render('to shoot. With mouse as input, you should use your mouse to navigate your jet and', 1, self.color)) all_surfaces.append(self.font.render('mouse click to shoot', 1, self.color)) all_surfaces.append(self.font.render(' ', 1, self.color)) all_surfaces.append(self.font.render('POINTS: Destroy Missle -> 10 pts. Power-up Star -> 100 pts. Level-up -> 10 pts.', 1, self.color)) all_surfaces.append(seperator) self.surf = Surface((all_surfaces[1].get_width(), all_surfaces[0].get_height() * (len(all_surfaces) + 2)), self.__game_env.SRCALPHA) self.surf.blit(header, (self.surf.get_width()/2 - header.get_width()/2, 0)) for index, temp_surf in enumerate(all_surfaces): self.surf.blit(temp_surf, (0, header.get_height() + index * temp_surf.get_height())) self.surf.blit(footer, (self.surf.get_width()/2 - footer.get_width()/2, self.surf.get_height() - footer.get_height())) self.rect = self.surf.get_rect(center=(self.__game_env.static.screen_width/2, self.__game_env.static.screen_height/2))
def _getTexture(self, textureName): """ Return a texture surface from the texture name. """ surface = Surface(TEXTURE_SIZE) self.divisor = 32 for v in range(0, TEXTURE_SIZE[0]): for h in range(0, TEXTURE_SIZE[1]): x = float(h) / self.divisor y = float(v) / self.divisor # Render the correct Texture if (textureName == 'clouds'): colorPoint = self._renderClouds(x, y) elif (textureName == 'marble'): colorPoint = self._randerMarble(x, y) elif (textureName == 'spruce'): colorPoint = self._randerSpruce(x, y) elif (textureName == 'radiation'): colorPoint = self._renderRadiation(x, y) elif (textureName == 'stucco'): colorPoint = self._renderStucco(x, y) elif (textureName == 'water'): colorPoint = self._renderCrappyWater(x, y) elif (textureName == 'leaves'): colorPoint = self._renderLeaves(x, y) else: raise Exception("Unknown texture: %s" % textureName) # Paint the Canvas surface.set_at((h, v), colorPoint) return surface
def __init__(self, x, y): Sprite.__init__(self) self.image = Surface((73, 211)) self.rect = self.image.get_rect() self.rect.x = x self.rect.y = y self.image.set_colorkey(Color(BACKGROUND_COLOR)) self.is_Give = False self.is_Has = False self.is_Fall = False def make_boltAnim(anim_list, delay): boltAnim = [] for anim in anim_list: boltAnim.append((anim, delay)) Anim = pyganim.PygAnimation(boltAnim) return Anim self.boltAnimStay = make_boltAnim(ANIMATION_STAY, ANIMATION_DELAY) self.boltAnimStay.play() self.boltAnimCall = make_boltAnim(ANIMATION_CALL, ANIMATION_DELAY * 3) self.boltAnimCall.play() self.boltAnimJump = make_boltAnim(ANIMATION_JUMP, ANIMATION_DELAY * 3) self.boltAnimJump.play()
def make_counter_btn(x: int, y: int, font: pygame.font.Font, align: str="center", vertical_align: str="middle", min_: int=1, max_: int=5, color: Color=(0, 0, 0)): group = pygame.sprite.Group() counter_sprite = CounterSprite(x, y, font, align, vertical_align, min_, max_, color) group.add(counter_sprite) rect = counter_sprite.base_rect w = h = rect.h w = w // 3 points = [ (0, h//2), (w-1, h*0.8-1), (w-1, h*0.2) ] x, y = rect.topleft left_image = Surface((w, h)).convert_alpha() left_image.fill((255, 255, 255)) left_image.set_colorkey(left_image.get_at((0, 0))) pygame.gfxdraw.filled_polygon(left_image, points, color) # left_image = font.render("<", True, color) btn = RichSprite(x-5, y, align="right", vertical_align="top", image=left_image, press_fnc=counter_sprite._count_down) group.add(btn) x, y = rect.topright right_image = pygame.transform.flip(left_image, True, False) right_image.set_colorkey(right_image.get_at((0, 0))) btn = RichSprite(x+5, y, align="left", vertical_align="top", image=right_image, press_fnc=counter_sprite._count_up) group.add(btn) return group, counter_sprite.get_count
def __init__(self, title, name, x, y, width, height, button_color, font_color, func, background_image=None): self.title = title self.name = name self.id = ControlButton.button_id ControlButton.button_id += 1 self.x = x self.y = y self.abs_x = x self.abs_y = y self.width = width self.height = height self.func = func self.button_color = button_color self.font_color = font_color self.__selected_color = color.white self.background_image = background_image if background_image: img_surf = pygame.image.load(background_image) self.surface = pygame.transform.scale(img_surf, (width, height)) else: self.surface = Surface((self.width, self.height)) self.draw()
def prepare_map(self): map_surface = Surface(self.map_rect.size) # print(self.resource_manager.maps) tile_map = self.resource_manager.maps[self.level_name] tile_size = self.textures["tile0"].get_rect().w tile_list = [] for row_idx, row in enumerate(tile_map): for column_idx, tile in enumerate(row): tile_rect = self.textures["tile" + str(tile)].get_rect().copy() tile_rect.topleft = (column_idx * tile_size, row_idx * tile_size) map_surface.blit(self.textures["tile" + str(tile)], tile_rect) if tile in [2]: tile_list.append([tile_rect, True]) elif tile == 1: spawn_point = tile_rect.topleft spawn_tile = (column_idx, row_idx) elif tile == 4: end_tile = (column_idx, row_idx) paths = self.prepare_paths(tile_map, spawn_tile, end_tile) return map_surface, tile_list, paths, spawn_point
def draw(self): """Draw battle field time. Returns: Surface: Drawn surface """ surface = Surface((self._width, self._height)) _minute, _second = divmod(math.ceil(self._jhclient.bf.time), 60) text = f"{_minute:02d}:{_second:02d}" # change text color by remaining time if _minute >= 1 and _second > 0: text = self.font.render(text, True, config.COLORS["white"]) elif _second > 30: text = self.font.render(text, True, config.COLORS["blue"]) elif _second > 10: text = self.font.render(text, True, config.COLORS["orange"]) else: text = self.font.render(text, True, config.COLORS["red"]) self.text_width, self.text_height = text.get_rect()[2:] _left = (self._width - self.text_width) // 2 _top = (self._height - self.text_height) // 2 surface.blit(text, (_left, _top)) return surface
def create_turn_marker(board, parent_rect, group): MARKER_OFFSET = 20 MARKER_WIDTH = 5 current_turn = board.current_board.current_turn if current_turn % 2 == 0: marker_size = (parent_rect.width - MARKER_OFFSET, MARKER_WIDTH) else: marker_size = (MARKER_WIDTH, parent_rect.width - MARKER_OFFSET) marker_size_half = (marker_size[0] / 2, marker_size[1] / 2) parent_half_width = parent_rect.width / 2 parent_half_height = parent_rect.height / 2 SEAT_OFFSETS = [ (0, parent_half_height - marker_size_half[1]), (parent_half_width - marker_size_half[0], 0), (0, -parent_half_height + marker_size_half[1]), (-parent_half_width + marker_size_half[0], 0), ] turn_marker_surface = Surface(marker_size) turn_marker_surface.fill((255, 255, 255)) sprite = Sprite() sprite.rect = turn_marker_surface.get_rect() sprite.image = turn_marker_surface sprite.rect.center = parent_rect.center sprite.rect.x += SEAT_OFFSETS[current_turn][0] sprite.rect.y += SEAT_OFFSETS[current_turn][1] sprite.layer = 2 group.add(sprite)
def display_dialog(surface: Surface, name: str, dialog: str): WIDTH = 455 HEIGHT = 205 BORDER = 5 IN_WIDTH = WIDTH - BORDER IN_HEIGHT = HEIGHT - BORDER canevas = Surface((WIDTH, HEIGHT)) canevas.fill(color.TEXT_BACKGROUND_COLOR) pos = Vector(dimensions.WINDOW_WIDTH - (30 + IN_WIDTH), dimensions.WINDOW_HEIGHT - (30 + IN_HEIGHT)) sizes = Vector(IN_WIDTH, IN_HEIGHT) rect = pygame.Rect(Vector().to_pos(), sizes.to_pos()) draw.rect(canevas, color.WHITE, rect, 5) font_name = ImagesCache().fonts["dialog"].render("{}: ".format(name), True, color.TEXT_NAME_COLOR) canevas.blit(font_name, (5, 4)) height = 30 for line in break_dialog_lines(dialog): font_text = ImagesCache().fonts["dialog"].render( line, True, color.TEXT_FOREGROUND_COLOR) canevas.blit(font_text, (10, height)) height += 20 return functools.partial(surface.blit, canevas, pos.to_pos())
def __init__(self, location): sprite.Sprite.__init__(self) self.image = Surface((20, 20)) self.image = image.load(location) self.rect = self.image.get_rect() self._x = None self._y = None
def get_surface(room): surface = Surface((800, 600)) room["scrap"] = [] for wall in room["walls"]: pygame.draw.polygon(surface, dark_green, wall) if "ellipses" in room: for ellipse in room["ellipses"]: transparent_beige = (beige[0], beige[1], beige[2], 0) pygame.draw.ellipse(surface, transparent_beige, ellipse) for scrap_center in room["scrap_pile_coords"]: if scrap_center[2] is not None and scrap_center[2] == 1: scrap = pygame.image.load(f"resources/mutter/mutter_{scrap_i}.png") else: scrap = pygame.image.load(f"resources/screw/screw_{scrap_i}.png") scrap.set_colorkey(beige) scrap_rect = scrap.get_rect() scrap_rect.center = (scrap_center[0], scrap_center[1]) room["scrap"].append(scrap_rect) surface.blit(scrap, scrap_rect) return surface
def makeMap(tiles, tileSz): R, C = tiles.shape surf = Surface((int(R * tileSz), int(C * tileSz))) for r in range(R): for c in range(C): surf.blit(tiles[r, c], (int(r * tileSz), int(c * tileSz))) return surf
def activate(self): xsize = 300 ysize = 70 bkg = Surface((xsize, ysize)) bkg.lock() bkg.fill((128, 128, 128)) for i in range(1, 4): draw.rect(bkg, (i * 32, i * 32, i * 32), (4 - i, 4 - i, xsize + (i - 4) * 2, ysize + (i - 4) * 2), 3) corner = (64, 64, 64) bkg.set_at((0, 0), corner) bkg.set_at((xsize, 0), corner) bkg.set_at((xsize, ysize), corner) bkg.set_at((0, ysize), corner) bkg.unlock() bkg.set_alpha(64) self.bkg = bkg if self.title != None: banner = OutlineTextBanner(self.title, (200, 200, 200), 20) self.title_image = banner.render() self.title_image.set_alpha(96) self.arrow = res.loadImage("wait_arrow.png", colorkey=1)
def __init__(self, width, height, runnable_stack, x=0, y=0): self.controls = [] self.x = x self.y = y self.surface = Surface((width, height)) self.runnable_stack = runnable_stack self.events = []