Exemple #1
0
    def draw_ghost(self, ghost, ghost_index):
        position = self.get_position(ghost)
        direction = self.get_direction(ghost)
        (screen_x, screen_y) = (self.to_screen(position))
        coordinates = []

        for (x, y) in GHOST_SHAPE:
            coordinates.append((x * self.grid_size * GHOST_SIZE + screen_x,
                                y * self.grid_size * GHOST_SIZE + screen_y))

        color = self.get_ghost_color(ghost, ghost_index)
        body = polygon(coordinates, color, filled=1)

        dx = 0
        dy = 0

        if direction == 'North':
            dy = -0.2
        if direction == 'South':
            dy = 0.2
        if direction == 'East':
            dx = 0.2
        if direction == 'West':
            dx = -0.2

        left_eye = 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 = 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 = 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 = 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 = [
            body, left_eye, right_eye, left_pupil, right_pupil
        ]

        return ghost_image_parts
Exemple #2
0
    def draw_southwest_quadrant(self, screen, s_is_wall, w_is_wall,
                                sw_is_wall):
        if (not s_is_wall) and (not w_is_wall):
            circle(screen, WALL_RADIUS * self.grid_size, WALL_COLOR,
                   WALL_COLOR, (180, 271), 'arc')

        if s_is_wall and (not w_is_wall):
            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:
            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):
            circle(
                add(screen,
                    (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')

            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)

            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)
Exemple #3
0
    def draw_northwest_quadrant(self, screen, n_is_wall, w_is_wall,
                                nw_is_wall):
        if (not n_is_wall) and (not w_is_wall):
            circle(screen, WALL_RADIUS * self.grid_size, WALL_COLOR,
                   WALL_COLOR, (90, 181), 'arc')

        if n_is_wall and (not w_is_wall):
            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:
            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):
            circle(
                add(screen,
                    (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')

            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)

            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)
Exemple #4
0
    def draw_southeast_quadrant(self, screen, s_is_wall, e_is_wall,
                                se_is_wall):
        if (not s_is_wall) and (not e_is_wall):
            circle(screen, WALL_RADIUS * self.grid_size, WALL_COLOR,
                   WALL_COLOR, (270, 361), 'arc')

        if s_is_wall and (not e_is_wall):
            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:
            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):
            circle(
                add(screen, (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')

            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)

            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)
Exemple #5
0
    def draw_pacumen(self, pacumen):
        position = self.get_position(pacumen)
        screen_point = self.to_screen(position)
        endpoints = self.get_endpoints(self.get_direction(pacumen))

        return [
            circle(screen_point,
                   PACUMEN_SCALE * self.grid_size,
                   fill_color=PACUMEN_COLOR,
                   outline_color=PACUMEN_COLOR,
                   endpoints=endpoints,
                   width=PACUMEN_OUTLINE_WIDTH)
        ]
Exemple #6
0
    def draw_northeast_quadrant(self, screen, n_is_wall, e_is_wall,
                                ne_is_wall):
        if (not n_is_wall) and (not e_is_wall):
            circle(screen, WALL_RADIUS * self.grid_size, WALL_COLOR,
                   WALL_COLOR, (0, 91), 'arc')

        if n_is_wall and (not e_is_wall):
            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:
            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):
            circle(
                add(screen,
                    (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')

            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)

            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)
Exemple #7
0
    def draw_pellets(self, pellets):
        pellet_images = {}

        for pellet in pellets:
            (screen_x, screen_y) = self.to_screen(pellet)

            power_pellet = circle((screen_x, screen_y),
                                  PELLET_SIZE * self.grid_size,
                                  outline_color=PELLET_COLOR,
                                  fill_color=PELLET_COLOR,
                                  width=1)

            pellet_images[pellet] = power_pellet

        return pellet_images
Exemple #8
0
    def draw_dots(self, dot_matrix):
        dot_images = []

        for x_num, x in enumerate(dot_matrix):
            image_row = []
            dot_images.append(image_row)

            for y_num, cell in enumerate(x):
                if cell:
                    # If there is a cell, that means there is a dot.
                    screen = self.to_screen((x_num, y_num))

                    dot = circle(screen,
                                 DOT_SIZE * self.grid_size,
                                 outline_color=DOT_COLOR,
                                 fill_color=DOT_COLOR,
                                 width=1)

                    image_row.append(dot)
                else:
                    image_row.append(None)

        return dot_images