def draw_ghost(self, ghost, agent_index): """Draw the given ghost.""" pos = self.get_position(ghost) dir = self.get_direction(ghost) (screen_x, screen_y) = (self.to_screen(pos)) coords = [] for (x, y) in GHOST_SHAPE: coords.append((x * self.grid_size * GHOST_SIZE + screen_x, y * self.grid_size * GHOST_SIZE + screen_y)) colour = self.get_ghost_color(ghost, agent_index) body = gu.polygon(coords, colour, filled=1) dx = 0 dy = 0 if dir == 'North': dy = -0.2 if dir == 'South': dy = 0.2 if dir == 'East': dx = 0.2 if dir == 'West': dx = -0.2 left_eye = gu.circle( (screen_x + self.grid_size * GHOST_SIZE * (-0.3 + dx / 1.5), screen_y - self.grid_size * GHOST_SIZE * (0.3 - dy / 1.5)), self.grid_size * GHOST_SIZE * 0.2, WHITE, WHITE) right_eye = gu.circle( (screen_x + self.grid_size * GHOST_SIZE * (0.3 + dx / 1.5), screen_y - self.grid_size * GHOST_SIZE * (0.3 - dy / 1.5)), self.grid_size * GHOST_SIZE * 0.2, WHITE, WHITE) left_pupil = gu.circle( (screen_x + self.grid_size * GHOST_SIZE * (-0.3 + dx), screen_y - self.grid_size * GHOST_SIZE * (0.3 - dy)), self.grid_size * GHOST_SIZE * 0.08, BLACK, BLACK) right_pupil = gu.circle( (screen_x + self.grid_size * GHOST_SIZE * (0.3 + dx), screen_y - self.grid_size * GHOST_SIZE * (0.3 - dy)), self.grid_size * GHOST_SIZE * 0.08, BLACK, BLACK) ghost_image_parts = [] ghost_image_parts.append(body) ghost_image_parts.append(left_eye) ghost_image_parts.append(right_eye) ghost_image_parts.append(left_pupil) ghost_image_parts.append(right_pupil) return ghost_image_parts
def draw_capsules(self, capsules): """Draw capsules (power pellets).""" capsule_images = {} for capsule in capsules: (screen_x, screen_y) = self.to_screen(capsule) dot = gu.circle((screen_x, screen_y), CAPSULE_SIZE * self.grid_size, outline_color=CAPSULE_COLOR, fill_color=CAPSULE_COLOR, width=1) capsule_images[capsule] = dot return capsule_images
def draw_pacman(self, pacman, index): """Draw pacman on screen.""" position = self.get_position(pacman) screen_point = self.to_screen(position) endpoints = self.get_endpoints(self.get_direction(pacman)) width = PACMAN_OUTLINE_WIDTH outline_color = PACMAN_COLOR fill_color = PACMAN_COLOR if self.capture: outline_color = TEAM_COLORS[index % 2] fill_color = GHOST_COLORS[index] width = PACMAN_CAPTURE_OUTLINE_WIDTH return [gu.circle(screen_point, PACMAN_SCALE * self.grid_size, fill_color=fill_color, outline_color=outline_color, endpoints=endpoints, width=width)]
def add_food(self, pos, food_images, layout): """Add food to display. only called with capture / contest mode, so assume its red for now """ x, y = pos color = TEAM_COLORS[0] if (x * 2) >= layout.width: color = TEAM_COLORS[1] screen = self.to_screen(pos) dot = gu.circle(screen, FOOD_SIZE * self.grid_size, outline_color=color, fill_color=color, width=1) food_images[x][y] = dot
def draw_food(self, food_matrix): """Draw the food dats.""" food_images = [] color = FOOD_COLOR for x_num, x in enumerate(food_matrix): if self.capture and (x_num * 2) <= food_matrix.width: color = TEAM_COLORS[0] if self.capture and (x_num * 2) > food_matrix.width: color = TEAM_COLORS[1] image_row = [] food_images.append(image_row) for y_num, cell in enumerate(x): if cell: # There's food here screen = self.to_screen((x_num, y_num)) dot = gu.circle(screen, FOOD_SIZE * self.grid_size, outline_color=color, fill_color=color, width=1) image_row.append(dot) else: image_row.append(None) return food_images
def draw_walls(self, wall_matrix): """Draw the walls.""" wall_color = WALL_COLOR for x_num, x in enumerate(wall_matrix): if self.capture and (x_num * 2) < wall_matrix.width: wall_color = TEAM_COLORS[0] if self.capture and (x_num * 2) >= wall_matrix.width: wall_color = TEAM_COLORS[1] for y_num, cell in enumerate(x): if cell: # There's a wall here pos = (x_num, y_num) screen = self.to_screen(pos) screen2 = self.to_screen2(pos) # draw each quadrant of the square based on adjacent walls w_is_wall = self.is_wall(x_num - 1, y_num, wall_matrix) e_is_wall = self.is_wall(x_num + 1, y_num, wall_matrix) n_is_wall = self.is_wall(x_num, y_num + 1, wall_matrix) s_is_wall = self.is_wall(x_num, y_num - 1, wall_matrix) nw_is_wall = self.is_wall(x_num - 1, y_num + 1, wall_matrix) sw_is_wall = self.is_wall(x_num - 1, y_num - 1, wall_matrix) ne_is_wall = self.is_wall(x_num + 1, y_num + 1, wall_matrix) se_is_wall = self.is_wall(x_num + 1, y_num - 1, wall_matrix) # NE quadrant if (not n_is_wall) and (not e_is_wall): # inner circle gu.circle(screen2, WALL_RADIUS * self.grid_size, wall_color, wall_color, (0, 91), 'arc') if (n_is_wall) and (not e_is_wall): # vertical line gu.line( add(screen, (self.grid_size * WALL_RADIUS, 0)), add(screen, (self.grid_size * WALL_RADIUS, self.grid_size * (-0.5) - 1)), wall_color) if (not n_is_wall) and (e_is_wall): # horizontal line gu.line( add(screen, (0, self.grid_size * (-1) * WALL_RADIUS)), add(screen, (self.grid_size * 0.5 + 1, self.grid_size * (-1) * WALL_RADIUS)), wall_color) if (n_is_wall) and (e_is_wall) and (not ne_is_wall): # outer circle gu.circle( add(screen2, (self.grid_size * 2 * WALL_RADIUS, self.grid_size * (-2) * WALL_RADIUS)), WALL_RADIUS * self.grid_size - 1, wall_color, wall_color, (180, 271), 'arc') gu.line( add(screen, (self.grid_size * 2 * WALL_RADIUS - 1, self.grid_size * (-1) * WALL_RADIUS)), add(screen, (self.grid_size * 0.5 + 1, self.grid_size * (-1) * WALL_RADIUS)), wall_color) gu.line( add(screen, (self.grid_size * WALL_RADIUS, self.grid_size * (-2) * WALL_RADIUS + 1)), add(screen, (self.grid_size * WALL_RADIUS, self.grid_size * (-0.5))), wall_color) # NW quadrant if (not n_is_wall) and (not w_is_wall): # inner circle gu.circle(screen2, WALL_RADIUS * self.grid_size, wall_color, wall_color, (90, 181), 'arc') if (n_is_wall) and (not w_is_wall): # vertical line gu.line( add(screen, (self.grid_size * (-1) * WALL_RADIUS, 0)), add(screen, (self.grid_size * (-1) * WALL_RADIUS, self.grid_size * (-0.5) - 1)), wall_color) if (not n_is_wall) and (w_is_wall): # horizontal line gu.line( add(screen, (0, self.grid_size * (-1) * WALL_RADIUS)), add(screen, (self.grid_size * (-0.5) - 1, self.grid_size * (-1) * WALL_RADIUS)), wall_color) if (n_is_wall) and (w_is_wall) and (not nw_is_wall): # outer circle gu.circle( add(screen2, (self.grid_size * (-2) * WALL_RADIUS, self.grid_size * (-2) * WALL_RADIUS)), WALL_RADIUS * self.grid_size - 1, wall_color, wall_color, (270, 361), 'arc') gu.line( add(screen, (self.grid_size * (-2) * WALL_RADIUS + 1, self.grid_size * (-1) * WALL_RADIUS)), add(screen, (self.grid_size * (-0.5), self.grid_size * (-1) * WALL_RADIUS)), wall_color) gu.line( add(screen, (self.grid_size * (-1) * WALL_RADIUS, self.grid_size * (-2) * WALL_RADIUS + 1)), add(screen, (self.grid_size * (-1) * WALL_RADIUS, self.grid_size * (-0.5))), wall_color) # SE quadrant if (not s_is_wall) and (not e_is_wall): # inner circle gu.circle(screen2, WALL_RADIUS * self.grid_size, wall_color, wall_color, (270, 361), 'arc') if (s_is_wall) and (not e_is_wall): # vertical line gu.line( add(screen, (self.grid_size * WALL_RADIUS, 0)), add(screen, (self.grid_size * WALL_RADIUS, self.grid_size * (0.5) + 1)), wall_color) if (not s_is_wall) and (e_is_wall): # horizontal line gu.line( add(screen, (0, self.grid_size * (1) * WALL_RADIUS)), add(screen, (self.grid_size * 0.5 + 1, self.grid_size * (1) * WALL_RADIUS)), wall_color) if (s_is_wall) and (e_is_wall) and (not se_is_wall): # outer circle gu.circle( add(screen2, (self.grid_size * 2 * WALL_RADIUS, self.grid_size * (2) * WALL_RADIUS)), WALL_RADIUS * self.grid_size - 1, wall_color, wall_color, (90, 181), 'arc') gu.line( add(screen, (self.grid_size * 2 * WALL_RADIUS - 1, self.grid_size * (1) * WALL_RADIUS)), add(screen, (self.grid_size * 0.5, self.grid_size * (1) * WALL_RADIUS)), wall_color) gu.line( add(screen, (self.grid_size * WALL_RADIUS, self.grid_size * (2) * WALL_RADIUS - 1)), add(screen, (self.grid_size * WALL_RADIUS, self.grid_size * (0.5))), wall_color) # SW quadrant if (not s_is_wall) and (not w_is_wall): # inner circle gu.circle(screen2, WALL_RADIUS * self.grid_size, wall_color, wall_color, (180, 271), 'arc') if (s_is_wall) and (not w_is_wall): # vertical line gu.line( add(screen, (self.grid_size * (-1) * WALL_RADIUS, 0)), add(screen, (self.grid_size * (-1) * WALL_RADIUS, self.grid_size * (0.5) + 1)), wall_color) if (not s_is_wall) and (w_is_wall): # horizontal line gu.line( add(screen, (0, self.grid_size * (1) * WALL_RADIUS)), add(screen, (self.grid_size * (-0.5) - 1, self.grid_size * (1) * WALL_RADIUS)), wall_color) if (s_is_wall) and (w_is_wall) and (not sw_is_wall): # outer circle gu.circle( add(screen2, (self.grid_size * (-2) * WALL_RADIUS, self.grid_size * (2) * WALL_RADIUS)), WALL_RADIUS * self.grid_size - 1, wall_color, wall_color, (0, 91), 'arc') gu.line( add(screen, (self.grid_size * (-2) * WALL_RADIUS + 1, self.grid_size * (1) * WALL_RADIUS)), add(screen, (self.grid_size * (-0.5), self.grid_size * (1) * WALL_RADIUS)), wall_color) gu.line( add(screen, (self.grid_size * (-1) * WALL_RADIUS, self.grid_size * (2) * WALL_RADIUS - 1)), add(screen, (self.grid_size * (-1) * WALL_RADIUS, self.grid_size * (0.5))), wall_color)