示例#1
0
    def _draw_action_panel(self):
        action_panel_surface = pg.Surface(c.action_panel_size)
        action_panel_surface.fill(c.black)

        icon_width, icon_height = c.action_icon_size
        panel_width, panel_height = c.action_panel_size
        panel_count_x = panel_width // icon_width
        panel_count_y = panel_height // icon_height

        if self.board.selected_cell != None:
            selected_card = self.board.building_cards[self.board.selected_cell]
            if selected_card != None:
                for i, action in enumerate(selected_card.active_actions):
                    row = i // panel_count_x
                    col = i % panel_count_y

                    cell_pos = (col * icon_width, row * icon_height)
                    pg.draw.rect(action_panel_surface, c.dark_grey,
                                 (cell_pos, c.action_icon_size))
                    pg.draw.rect(action_panel_surface, c.light_grey,
                                 (cell_pos, c.action_icon_size), 1)
                    draw.draw_surface_aligned(
                        target=action_panel_surface,
                        source=fonts.action_font.render(action, True, c.white),
                        pos=(cell_pos[0] + icon_width // 2,
                             cell_pos[1] + icon_height // 2),
                        align=('center', 'center'))

        pg.draw.rect(action_panel_surface, c.white,
                     ((0, 0), c.action_panel_size), 1)
        draw.screen.blit(action_panel_surface, self.action_panel_rect.topleft)
示例#2
0
文件: board.py 项目: boulware/puzzle
    def reveal_cells(self, cells, player):
        for cell in cells:
            if cell not in self._fow_visible_cells[player]:
                self._fow_visible_cells[player].append(cell)

        transparent_cell = pg.Surface(
            (self.grid.cell_size[0] + 1, self.grid.cell_size[1] + 1))
        transparent_cell.fill(c.pink)
        for cell in cells:
            if player == 1:
                # Adjusted for player perspective
                relative_cell = (cell[0], self.size[1] - 1 - cell[1])
            else:
                relative_cell = cell

            cell_pos = self.grid.get_cell_pos(cell=relative_cell,
                                              align=('center', 'center'))
            cell_pos = [
                cell_pos[0] - self.grid.origin[0],
                cell_pos[1] - self.grid.origin[1]
            ]
            draw.draw_surface_aligned(target=self.fow_surfaces[player],
                                      source=transparent_cell,
                                      pos=cell_pos,
                                      align=('center', 'center'))
示例#3
0
文件: board.py 项目: boulware/puzzle
    def draw_surface_in_cell(self,
                             source,
                             cell,
                             align=('left', 'up'),
                             stretch=False,
                             offset=(0, 0)):
        surface = source

        if stretch == True:
            width_ratio = source.get_width() / self.cell_size[0]
            height_ratio = source.get_height() / self.cell_size[1]

            if width_ratio != 1 or height_ratio != 1:
                width_ratio_distance = (1 - width_ratio)  # "distance" from 1
                height_ratio_distance = (1 - height_ratio)

                if abs(width_ratio_distance) > abs(height_ratio_distance):
                    scale_ratio = width_ratio  # Scale width to cell width, retaining aspect ratio
                else:
                    scale_ratio = height_ratio  # Scale height

                new_width = int(source.get_width() / scale_ratio)
                new_height = int(source.get_height() / scale_ratio)
                surface = pg.transform.scale(
                    source, (new_width, new_height))  # new scaled surface

        cell_pos = self.get_cell_pos(cell, align)
        draw.draw_surface_aligned(target=screen,
                                  source=surface,
                                  pos=cell_pos,
                                  align=align,
                                  offset=offset)
示例#4
0
文件: board.py 项目: boulware/puzzle
    def _generate_default_fow_surfaces(self):
        self.fow_surfaces = [
            pg.Surface((self.grid.rect.width + 1, self.grid.rect.height + 1))
            for player in range(2)
        ]
        for surface in self.fow_surfaces:
            surface.fill(c.black)
            surface.set_alpha(200)
            # We'll draw c.pink squares on top of visible squares to remove the FOW
            surface.set_colorkey(c.pink)

        # The cells that are visible by default (closest 2 ranks to your side, as of writing this comment)
        fow_rank_count = 3
        p0_fow_default_visible_cells = [
            (x, y) for x in range(0, self.size[0] + 1)
            for y in range(self.size[1] - fow_rank_count, self.size[1])
        ]
        p1_fow_default_visible_cells = [(x, y)
                                        for x in range(0, self.size[0] + 1)
                                        for y in range(0, fow_rank_count)]

        # for card in self:
        # 	if card != None and card.owner == player_perspective:
        # 		fow_visible_cells += card.visible_cells()

        self._fow_visible_cells[0] = p0_fow_default_visible_cells
        self._fow_visible_cells[1] = p1_fow_default_visible_cells

        transparent_cell = pg.Surface(
            (self.grid.cell_size[0] + 1, self.grid.cell_size[1] + 1))
        transparent_cell.fill(c.pink)
        for player in range(2):
            for cell in self._fow_visible_cells[player]:
                if player == 1:
                    # Adjusted for player perspective
                    relative_cell = (cell[0], self.size[1] - 1 - cell[1])
                else:
                    relative_cell = cell

                cell_pos = self.grid.get_cell_pos(cell=relative_cell,
                                                  align=('center', 'center'))
                cell_pos = [
                    cell_pos[0] - self.grid.origin[0],
                    cell_pos[1] - self.grid.origin[1]
                ]
                draw.draw_surface_aligned(target=self.fow_surfaces[player],
                                          source=transparent_cell,
                                          pos=cell_pos,
                                          align=('center', 'center'))
示例#5
0
文件: UI.py 项目: boulware/trait-game
    def draw(self, screen):
        draw.draw_surface_aligned(target=screen,
                                  source=self.box_surface,
                                  pos=self.pos,
                                  align=self.align,
                                  alpha=self.alpha)

        draw.draw_surface_aligned(target=screen,
                                  source=self.label_surface,
                                  pos=self.pos,
                                  align=('left', 'down'),
                                  alpha=self.alpha)

        self._draw_text(screen=screen)

        if self.selected:
            self._draw_cursor(screen=screen)
示例#6
0
文件: card.py 项目: boulware/puzzle
	def _generate_hand_surface(self):
		Card._generate_hand_surface(self)

		# Draw power value
		power_text = fonts.card_text_sm.render(str(self.power), True, c.green)
		bottomleft = self.hand_surface.get_rect().bottomleft
		draw.draw_surface_aligned(	target=self.hand_surface,
								source=power_text,
								pos=bottomleft,
								align=('left','down'),
								offset=(6,-4))

		health_text = fonts.card_text_med.render(str(self.health), True, c.red)
		draw.draw_surface_aligned(	target=self.hand_surface,
								source=health_text,
								pos=c.hand_card_size,
								align=('right','down'),
								offset=(-20,1))
示例#7
0
文件: card.py 项目: boulware/puzzle
	def _generate_hand_surface(self):
		bg_color = c.dark_grey
		if self.owner == 0:
			bg_color = c.dark_red
		elif self.owner == 1:
			bg_color = c.dark_blue

		self._hand_surface = pg.Surface(c.hand_card_size)

		pg.draw.rect(self.hand_surface, bg_color, ((0,0), c.hand_card_size))
		pg.draw.rect(self.hand_surface, c.light_grey, ((0,0), c.hand_card_size), 1)
		title_surface = fonts.card_text_sm.render(self.name, True, c.white)
		self.hand_surface.blit(title_surface, (5,0))
		cost_surface = fonts.card_text_lg.render(str(self.cost), True, c.light_grey)
		draw.draw_surface_aligned(target=self.hand_surface, source=cost_surface, pos=self.hand_surface.get_rect().center, align=('center','center'))

		if self._health_component != None:
			# Draw health bar
			draw.draw_surface_aligned(	target=self.hand_surface,
										source=self._health_component.health_bar.surface,
										pos=c.hand_card_size,
										align=('right','down'),
										offset=(-1,-1))
示例#8
0
文件: UI.py 项目: boulware/trait-game
 def draw(self, screen):
     draw_offset = draw.draw_surface_aligned(
         target=screen,
         source=self.surfaces[self.state],
         pos=self.pos,
         align=self.align)
示例#9
0
文件: UI.py 项目: boulware/trait-game
 def draw(self, screen):
     draw.draw_surface_aligned(target=screen,
                               source=self.surface,
                               pos=self.pos,
                               align=self.align)
示例#10
0
    def draw(self):
        if self.player_number == 0:
            current_player_color = c.red
            other_player_color = c.blue
        elif self.player_number == 1:
            current_player_color = c.blue
            other_player_color = c.red

        if self.player_turn == 0:
            active_player_color = c.red
        elif self.player_turn == 1:
            active_player_color = c.blue

        self.board.draw(screen=self.game.screen,
                        player_perspective=self.player_number)

        # Draw queued cards
        for lane_number, queued_card in enumerate(
                self.board.queued_cards[self.player_number]):
            if queued_card != None:
                pos = self.board.grid.get_cell_pos(
                    cell=(lane_number, self.board.size[1] - 1),
                    align=('left', 'down'))
                pos[0] += c.board_card_size[0]
                queued_card.draw(pos=pos)

        self._draw_action_panel()
        if self.board.selected_cell != None:
            self.board.building_cards[self.board.selected_cell]

        # pg.draw.rect(self.action_panel_surface, c.white, ((0,0), c.action_panel_size), 1)

        # Calculate colors for card areas based on which player is active
        if self.is_current_player_active():
            my_card_area_color = util.darken_color(current_player_color, 0.65)
            other_card_area_color = c.dark_grey
        else:
            my_card_area_color = c.dark_grey
            other_card_area_color = util.darken_color(other_player_color, 0.65)

        # Draw my card area
        pg.draw.rect(draw.screen, my_card_area_color,
                     ((0, c.screen_size[1] - self.hand_area_height),
                      (c.screen_size[0], self.hand_area_height)))
        pg.draw.line(
            draw.screen, util.lighten_color(my_card_area_color, 0.5),
            (0, c.screen_size[1] - self.hand_area_height),
            (c.screen_size[0], c.screen_size[1] - self.hand_area_height))
        # Draw enemy card area
        pg.draw.rect(draw.screen, other_card_area_color,
                     ((0, 0), (c.screen_size[0], self.hand_area_height)))
        pg.draw.line(draw.screen, util.lighten_color(other_card_area_color,
                                                     0.5),
                     (0, self.hand_area_height),
                     (c.screen_size[0], self.hand_area_height))

        # Draw cards in hand
        for i, card_pos in enumerate(self.generate_hand_card_positions()):
            if i == self.hovered_card_index:
                hover = True
            else:
                hover = False

            self.active_hand[i].draw(pos=card_pos, hover=hover)

        # Draw active player text and circle
        active_player_text = "Player %d" % self.player_turn
        text_h_padding = 10
        text_size = fonts.ui_font.size(active_player_text)
        padded_size = (text_size[0] + 2 * text_h_padding, text_size[1])
        active_player_text_surface = pg.Surface(padded_size)
        pg.draw.rect(active_player_text_surface, c.white,
                     ((0, 0), (padded_size)))
        active_player_text_surface.blit(
            fonts.ui_font.render(active_player_text, True,
                                 active_player_color), (text_h_padding, 0))
        draw_pos = (20, c.screen_size[1] // 2)
        offset = draw.draw_surface_aligned(target=draw.screen,
                                           source=active_player_text_surface,
                                           pos=draw_pos,
                                           align=('left', 'down'))
        pg.draw.circle(draw.screen, active_player_color,
                       (int(draw_pos[0] + offset[0] +
                            active_player_text_surface.get_width() + 20),
                        int(draw_pos[1] + offset[1] +
                            active_player_text_surface.get_height() // 2)), 15)
        pg.draw.circle(draw.screen, c.white,
                       (int(draw_pos[0] + offset[0] +
                            active_player_text_surface.get_width() + 20),
                        int(draw_pos[1] + offset[1] +
                            active_player_text_surface.get_height() // 2)), 15,
                       1)

        # Draw turn display
        self.turn_display.draw(target=draw.screen,
                               pos=self.board.grid.get_grid_pos(
                                   align=('left', 'center'), offset=(-150, 0)))

        # Draw card being dragged
        if self.drag_card:
            drawn_in_board = False  # True if the drag card gets drawn in the board this frame rather than floating on screen

            if self.is_current_player_active() and self.phase.name == 'Build':
                if isinstance(self.drag_card, CreatureCard):
                    # TODO: Shouldn't be getting the mouse position in this way. Fetch it in update()
                    cell = self.board.grid.get_cell_at_pos(
                        pos=pg.mouse.get_pos(), player=self.player_number)
                    if cell != None:
                        lane = cell[0]
                        lane_down_center = self.board.grid.get_cell_pos(
                            cell=(lane, self.board.size[1] - 1),
                            align=('left', 'down'))
                        lane_down_center[0] += c.board_card_size[0]
                        self.drag_card.draw(pos=lane_down_center)
                        drawn_in_board = True
                elif isinstance(self.drag_card, BuildingCard):
                    cell = self.board.grid.get_cell_at_pos(
                        pos=pg.mouse.get_pos(), player=self.player_number)
                    if cell != None:
                        if self.player_number == 0:
                            pos = cell
                        elif self.player_number == 1:
                            pos = (cell[0], self.board.size[1] - 1 - cell[1])

                        if self.board.building_cards[pos] == None:
                            cell_top_center = self.board.grid.get_cell_pos(
                                cell, align=('left', 'top'))
                            self.drag_card.draw(pos=cell_top_center)
                            drawn_in_board = True

            if drawn_in_board == False:
                mouse_coords = pg.mouse.get_pos()
                pos = (mouse_coords[0] - self.card_grab_point[0],
                       mouse_coords[1] - self.card_grab_point[1])
                self.drag_card.draw(pos=pos)