def drawGhost(self, ghost, agentIndex): pos = self.getPosition(ghost) dir = self.getDirection(ghost) (screen_x, screen_y) = (self.to_screen(pos)) coords = [] for (x, y) in GHOST_SHAPE: coords.append((x * self.gridSize * GHOST_SIZE + screen_x, y * self.gridSize * GHOST_SIZE + screen_y)) colour = self.getGhostColor(ghost, agentIndex) body = gU.polygon(coords, colour, filled=1) WHITE = gU.formatColor(1.0, 1.0, 1.0) BLACK = gU.formatColor(0.0, 0.0, 0.0) 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 leftEye = gU.circle((screen_x + self.gridSize * GHOST_SIZE * (-0.3 + dx / 1.5), screen_y - self.gridSize * GHOST_SIZE * (0.3 - dy / 1.5)), self.gridSize * GHOST_SIZE * 0.2, WHITE, WHITE) rightEye = gU.circle((screen_x + self.gridSize * GHOST_SIZE * (0.3 + dx / 1.5), screen_y - self.gridSize * GHOST_SIZE * (0.3 - dy / 1.5)), self.gridSize * GHOST_SIZE * 0.2, WHITE, WHITE) leftPupil = gU.circle((screen_x + self.gridSize * GHOST_SIZE * (-0.3 + dx), screen_y - self.gridSize * GHOST_SIZE * (0.3 - dy)), self.gridSize * GHOST_SIZE * 0.08, BLACK, BLACK) rightPupil = gU.circle((screen_x + self.gridSize * GHOST_SIZE * (0.3 + dx), screen_y - self.gridSize * GHOST_SIZE * (0.3 - dy)), self.gridSize * GHOST_SIZE * 0.08, BLACK, BLACK) ghostImageParts = [] ghostImageParts.append(body) ghostImageParts.append(leftEye) ghostImageParts.append(rightEye) ghostImageParts.append(leftPupil) ghostImageParts.append(rightPupil) return ghostImageParts
def drawCapsules(self, capsules): capsuleImages = {} for capsule in capsules: (screen_x, screen_y) = self.to_screen(capsule) dot = gU.circle((screen_x, screen_y), CAPSULE_SIZE * self.gridSize, outlineColor=CAPSULE_COLOR, fillColor=CAPSULE_COLOR, width=1) capsuleImages[capsule] = dot return capsuleImages
def drawPacman(self, pacman, index): position = self.getPosition(pacman) screen_point = self.to_screen(position) endpoints = self.getEndpoints(self.getDirection(pacman)) width = PACMAN_OUTLINE_WIDTH outlineColor = PACMAN_COLOR fillColor = PACMAN_COLOR if self.capture: outlineColor = TEAM_COLORS[index % 2] fillColor = GHOST_COLORS[index] width = PACMAN_CAPTURE_OUTLINE_WIDTH return [gU.circle(screen_point, PACMAN_SCALE * self.gridSize, fillColor=fillColor, outlineColor=outlineColor, endpoints=endpoints, width=width)]
def drawFood(self, foodMatrix): foodImages = [] color = FOOD_COLOR for xNum, x in enumerate(foodMatrix): if self.capture and (xNum * 2) <= foodMatrix.width: color = TEAM_COLORS[0] if self.capture and (xNum * 2) > foodMatrix.width: color = TEAM_COLORS[1] imageRow = [] foodImages.append(imageRow) for yNum, cell in enumerate(x): if cell: # There's food here screen = self.to_screen((xNum, yNum)) dot = gU.circle(screen, FOOD_SIZE * self.gridSize, outlineColor=color, fillColor=color, width=1) imageRow.append(dot) else: imageRow.append(None) return foodImages
def drawWalls(self, wallMatrix): wallColor = WALL_COLOR for xNum, x in enumerate(wallMatrix): if self.capture and (xNum * 2) < wallMatrix.width: wallColor = TEAM_COLORS[0] if self.capture and (xNum * 2) >= wallMatrix.width: wallColor = TEAM_COLORS[1] for yNum, cell in enumerate(x): if cell: # There's a wall here pos = (xNum, yNum) screen = self.to_screen(pos) screen2 = self.to_screen2(pos) # Draw each quadrant of the square based on adjacent walls wIsWall = self.isWall(xNum - 1, yNum, wallMatrix) eIsWall = self.isWall(xNum + 1, yNum, wallMatrix) nIsWall = self.isWall(xNum, yNum + 1, wallMatrix) sIsWall = self.isWall(xNum, yNum - 1, wallMatrix) nwIsWall = self.isWall(xNum - 1, yNum + 1, wallMatrix) swIsWall = self.isWall(xNum - 1, yNum - 1, wallMatrix) neIsWall = self.isWall(xNum + 1, yNum + 1, wallMatrix) seIsWall = self.isWall(xNum + 1, yNum - 1, wallMatrix) # NE quadrant if (not nIsWall) and (not eIsWall): # inner circle gU.circle(screen2, WALL_RADIUS * self.gridSize, wallColor, wallColor, (0, 91), 'arc') if (nIsWall) and (not eIsWall): # vertical line gU.line(add(screen, (self.gridSize * WALL_RADIUS, 0)), add(screen, (self.gridSize * WALL_RADIUS, self.gridSize * (-0.5) - 1)), wallColor) if (not nIsWall) and (eIsWall): # horizontal line gU.line(add(screen, (0, self.gridSize * (-1) * WALL_RADIUS)), add(screen, (self.gridSize * 0.5 + 1, self.gridSize * (-1) * WALL_RADIUS)), wallColor) if (nIsWall) and (eIsWall) and (not neIsWall): # outer circle gU.circle(add(screen2, (self.gridSize * 2 * WALL_RADIUS, self.gridSize * (-2) * WALL_RADIUS)), WALL_RADIUS * self.gridSize - 1, wallColor, wallColor, (180, 271), 'arc') gU.line(add(screen, (self.gridSize * 2 * WALL_RADIUS - 1, self.gridSize * (-1) * WALL_RADIUS)), add(screen, (self.gridSize * 0.5 + 1, self.gridSize * (-1) * WALL_RADIUS)), wallColor) gU.line(add(screen, (self.gridSize * WALL_RADIUS, self.gridSize * (-2) * WALL_RADIUS + 1)), add(screen, (self.gridSize * WALL_RADIUS, self.gridSize * (-0.5))), wallColor) # NW quadrant if (not nIsWall) and (not wIsWall): # inner circle gU.circle(screen2, WALL_RADIUS * self.gridSize, wallColor, wallColor, (90, 181), 'arc') if (nIsWall) and (not wIsWall): # vertical line gU.line(add(screen, (self.gridSize * (-1) * WALL_RADIUS, 0)), add(screen, (self.gridSize * (-1) * WALL_RADIUS, self.gridSize * (-0.5) - 1)), wallColor) if (not nIsWall) and (wIsWall): # horizontal line gU.line(add(screen, (0, self.gridSize * (-1) * WALL_RADIUS)), add(screen, (self.gridSize * (-0.5) - 1, self.gridSize * (-1) * WALL_RADIUS)), wallColor) if (nIsWall) and (wIsWall) and (not nwIsWall): # outer circle gU.circle(add(screen2, (self.gridSize * (-2) * WALL_RADIUS, self.gridSize * (-2) * WALL_RADIUS)), WALL_RADIUS * self.gridSize - 1, wallColor, wallColor, (270, 361), 'arc') gU.line(add(screen, (self.gridSize * (-2) * WALL_RADIUS + 1, self.gridSize * (-1) * WALL_RADIUS)), add(screen, (self.gridSize * (-0.5), self.gridSize * (-1) * WALL_RADIUS)), wallColor) gU.line(add(screen, (self.gridSize * (-1) * WALL_RADIUS, self.gridSize * (-2) * WALL_RADIUS + 1)), add(screen, (self.gridSize * (-1) * WALL_RADIUS, self.gridSize * (-0.5))), wallColor) # SE quadrant if (not sIsWall) and (not eIsWall): # inner circle gU.circle(screen2, WALL_RADIUS * self.gridSize, wallColor, wallColor, (270, 361), 'arc') if (sIsWall) and (not eIsWall): # vertical line gU.line(add(screen, (self.gridSize * WALL_RADIUS, 0)), add(screen, (self.gridSize * WALL_RADIUS, self.gridSize * (0.5) + 1)), wallColor) if (not sIsWall) and (eIsWall): # horizontal line gU.line(add(screen, (0, self.gridSize * (1) * WALL_RADIUS)), add(screen, (self.gridSize * 0.5 + 1, self.gridSize * (1) * WALL_RADIUS)), wallColor) if (sIsWall) and (eIsWall) and (not seIsWall): # outer circle gU.circle(add(screen2, (self.gridSize * 2 * WALL_RADIUS, self.gridSize * (2) * WALL_RADIUS)), WALL_RADIUS * self.gridSize - 1, wallColor, wallColor, (90, 181), 'arc') gU.line(add(screen, (self.gridSize * 2 * WALL_RADIUS - 1, self.gridSize * (1) * WALL_RADIUS)), add(screen, (self.gridSize * 0.5, self.gridSize * (1) * WALL_RADIUS)), wallColor) gU.line(add(screen, (self.gridSize * WALL_RADIUS, self.gridSize * (2) * WALL_RADIUS - 1)), add(screen, (self.gridSize * WALL_RADIUS, self.gridSize * (0.5))), wallColor) # SW quadrant if (not sIsWall) and (not wIsWall): # inner circle gU.circle(screen2, WALL_RADIUS * self.gridSize, wallColor, wallColor, (180, 271), 'arc') if (sIsWall) and (not wIsWall): # vertical line gU.line(add(screen, (self.gridSize * (-1) * WALL_RADIUS, 0)), add(screen, (self.gridSize * (-1) * WALL_RADIUS, self.gridSize * (0.5) + 1)), wallColor) if (not sIsWall) and (wIsWall): # horizontal line gU.line(add(screen, (0, self.gridSize * (1) * WALL_RADIUS)), add(screen, (self.gridSize * (-0.5) - 1, self.gridSize * (1) * WALL_RADIUS)), wallColor) if (sIsWall) and (wIsWall) and (not swIsWall): # outer circle gU.circle(add(screen2, (self.gridSize * (-2) * WALL_RADIUS, self.gridSize * (2) * WALL_RADIUS)), WALL_RADIUS * self.gridSize - 1, wallColor, wallColor, (0, 91), 'arc') gU.line(add(screen, (self.gridSize * (-2) * WALL_RADIUS + 1, self.gridSize * (1) * WALL_RADIUS)), add(screen, (self.gridSize * (-0.5), self.gridSize * (1) * WALL_RADIUS)), wallColor) gU.line(add(screen, (self.gridSize * (-1) * WALL_RADIUS, self.gridSize * (2) * WALL_RADIUS - 1)), add(screen, (self.gridSize * (-1) * WALL_RADIUS, self.gridSize * (0.5))), wallColor)
def drawCircle(pos, radius): return graphicsUtils.circle(pos, radius, Display.RED, Display.RED)