Exemple #1
0
    def generate_shape_list(self):
        """
        Regenerate the shape list based on the current state of the game
        """
        self.shape_list = arcade.ShapeElementList()
        for row in range(self.game["board_height"]):
            for col in range(self.game["board_width"]):
                cell = self.game["board"][row][col]
                x_px = self.offset_x + (col * CELL_SIZE_PX) + (CELL_SIZE_PX /
                                                               2)
                y_px = SCREEN_HEIGHT - (row * CELL_SIZE_PX) - (
                    CELL_SIZE_PX / 2) - self.offset_y

                if cell["flagged"]:
                    color = arcade.color.RED
                elif cell["visible"] or (self.game["game_over"]
                                         and not self.game["is_win"]):
                    if cell["value"] == 'X':
                        color = arcade.color.BLACK
                    else:
                        color = arcade.color.DARK_GRAY
                else:
                    color = arcade.color.LIGHT_GRAY

                rect = arcade.create_rectangle_filled(x_px, y_px, CELL_SIZE_PX,
                                                      CELL_SIZE_PX, color)
                border = arcade.create_rectangle_outline(
                    x_px, y_px, CELL_SIZE_PX, CELL_SIZE_PX, arcade.color.BLACK)
                self.shape_list.append(rect)
                self.shape_list.append(border)
Exemple #2
0
    def update_next_queue(self, t_next):
        """Update the next queue box with the next piece in the queue.

        Arguments:
            t_next {Shape} -- The next shape that will be in play
        """
        self.minos = arcade.ShapeElementList()
        self.t_next = t_next

        for i, row in enumerate(reversed(self.t_next.value[0])):
            for j, block in enumerate(row):
                if block > 1:
                    x = SIDE_MARGIN + NEXT_QUEUE_X_OFFSET + (j) * 24 + 12
                    y = BOTTOM_MARGIN + NEXT_QUEUE_Y_OFFSET + (i) * 24

                    # Offset the tetrimino pieces to center in next queue box
                    if self.t_next.value[1] in [2, 3]:
                        x = SIDE_MARGIN + NEXT_QUEUE_X_OFFSET + (j) * 24
                    if self.t_next.value[1] == 3:
                        y = BOTTOM_MARGIN + NEXT_QUEUE_Y_OFFSET + (i) * 24 - 12

                    self.minos.append(
                        arcade.create_rectangle_filled(
                            center_x=x,
                            center_y=y,
                            width=24,
                            height=24,
                            color=COLORS[self.t_next.value[1]]))

                    self.minos.append(
                        arcade.create_rectangle_outline(center_x=x,
                                                        center_y=y,
                                                        width=24,
                                                        height=24,
                                                        color=BLACK))
Exemple #3
0
 def __init__(self):
     self.show = 0
     self.shape = arcade.create_rectangle_outline(Const.GAME_WIDTH / 2,
                                                  Const.GAME_HEIGHT / 2,
                                                  Const.GAME_WIDTH - 1,
                                                  Const.GAME_HEIGHT - 2,
                                                  (70, 127, 183), 3)
Exemple #4
0
 def scene3_render(self):
     self.draw_list = arcade.ShapeElementList()
     # self.stars_render()
     self.draw_list.append(
         arcade.create_rectangle_filled(400, 0, 800, 200,
                                        arcade.color.BLUE_GRAY, 0))
     # self.draw_list.append(arcade.create_rectangle_filled(400, 800, 800, 200, arcade.color.BLUE_GRAY, 0))
     self.draw_list.append(
         arcade.create_rectangle_filled(400, 113, 800, 25,
                                        arcade.color.LIGHT_GRAY, 0))
     self.draw_list.append(
         arcade.create_line(2, 0, 2, 124, arcade.color.DARK_BLUE, 4))
     self.draw_list.append(
         arcade.create_line(200, 0, 200, 101, arcade.color.DARK_BLUE, 4))
     self.draw_list.append(
         arcade.create_line(400, 0, 400, 101, arcade.color.DARK_BLUE, 4))
     self.draw_list.append(
         arcade.create_line(600, 0, 600, 101, arcade.color.DARK_BLUE, 4))
     self.draw_list.append(
         arcade.create_line(798, 0, 798, 124, arcade.color.DARK_BLUE, 4))
     self.draw_list.append(
         arcade.create_line(0, 100, 800, 100, arcade.color.DARK_BLUE, 4))
     self.draw_list.append(
         arcade.create_line(0, 124, 800, 124, arcade.color.DARK_BLUE, 4))
     self.draw_list.append(
         arcade.create_rectangle_outline(100 + (self.battle_cursor * 200),
                                         50, 175, 75, colors["black"], 3))
     self.draw_list.append(
         arcade.create_ellipse_outline(400, 600, self.enemy.size_x,
                                       self.enemy.size_y, colors["db"], 4))
     self.draw_list.append(
         arcade.create_ellipse_filled(400, 600, self.enemy.size_x / 3,
                                      self.enemy.size_y / 3, colors["sky"]))
Exemple #5
0
 def next_state(self):
     # Set goal as new start colour
     spot = self.GOAL
     self.spots_list[spot.x * DIV +
                     spot.y] = arcade.create_rectangle_filled(
                         spot.x * G_W + G_W / 2, spot.y * G_H + G_H / 2,
                         G_W, G_H, arcade.color.BITTER_LEMON)
     # Reset previous start colour
     spot = self.START
     self.spots_list[spot.x * DIV +
                     spot.y] = arcade.create_rectangle_filled(
                         spot.x * G_W + G_W / 2, spot.y * G_H + G_H / 2,
                         G_W, G_H, arcade.color.WHITE)
     # Update changes
     self.__recalculate_grid()
     # Add new outline
     self.spots_list[spot.x * DIV +
                     spot.y] = arcade.create_rectangle_outline(
                         spot.x * G_W + G_W / 2, spot.y * G_H + G_H / 2,
                         G_W, G_H, arcade.color.BLACK)
     # Set goal as new start
     self.START = self.GOAL
     self.START.reset()
     self.GOAL = None
     self.reset_goal()
Exemple #6
0
 def create_grid_rect(self, x, y):
     rect = arcade.create_rectangle_outline(
                     center_x=x,
                     center_y=y,
                     width=24,
                     height=24,
                     color=BLACK)
     self.rect_list.append(rect)
Exemple #7
0
 def calculate_inital_grid(self):
     for col in self.spots:
         for spot in col:
             shape = arcade.create_rectangle_outline(
                 spot.x * G_W + G_W / 2, spot.y * G_H + G_H / 2, G_W, G_H,
                 arcade.color.BLACK)
             self.spots_list.append(shape)
     for shape in self.spots_list:
         self.spots_shape_list.append(shape)
    def create_border_wall(self, colour):
        """
        Create a border wall around the game board & scoreboard.

        Return an object that can be rendered to the screen efficiently.
        """
        border_wall = arcade.create_rectangle_outline(
            settings.WINDOW_WIDTH / 2, settings.WINDOW_HEIGHT / 2,
            settings.WINDOW_WIDTH - (settings.CELL * 2),
            settings.WINDOW_HEIGHT - (settings.CELL * 2), colour, 8)
        return border_wall
 def _SetupOutline(self):
   
   """Sets up outline."""
   
   # End here if no outline wanted
   if self.outlineColor is None:
     self.outline = None
     return
   
   # Get shape as a list with two (so one side is not thiner)
   outline = arcade.ShapeElementList()
   shape = arcade.create_rectangle_outline(self.center_x,self.center_y,self.width,self.height,self.outlineColor,self.outlineThick)
   outline.append(shape)
   shape = arcade.create_rectangle_outline(self.center_x,self.center_y,self.width,self.height,self.outlineColor,self.outlineThick,180.0)
   outline.append(shape)
   
   # Save shape
   self.outline = outline
   
   return
Exemple #10
0
 def create_segment_border(self, position, colour, width=settings.CELL,
                           height=settings.CELL):
     """Create the colour border for one segment of the snake."""
     segment_border = arcade.create_rectangle_outline(
         position[0],
         position[1],
         width,
         height,
         colour,
         2
         )
     return segment_border
Exemple #11
0
 def scene4_render(self):
     self.draw_list = arcade.ShapeElementList()
     self.draw_list.append(
         arcade.create_rectangle_filled(400, 400, 600, 600, colors["db"],
                                        0))
     self.draw_list.append(
         arcade.create_line(200, 100, 200, 700, arcade.color.DARK_BLUE, 4))
     self.draw_list.append(
         arcade.create_rectangle_outline(
             menu_slots[self.station_cursor]["x"],
             menu_slots[self.station_cursor]["y"], 140, 140,
             arcade.color.DARK_BLUE, 3))
    def create_menu_board_outline(self, colour):
        """
        Create a small outline around the menu board.

        Keep a visual gap between snake objects & the border wall.

        Return an object that can be rendered to the screen efficiently.
        """
        menu_board_outline = arcade.create_rectangle_outline(
            settings.WINDOW_WIDTH / 2, settings.WINDOW_HEIGHT / 2,
            settings.WINDOW_WIDTH - (settings.CELL * 2),
            settings.WINDOW_HEIGHT - (settings.CELL * 2), colour, 2)
        return menu_board_outline
Exemple #13
0
    def setup(self) -> None:
        for y in range(0, s.WINDOW_SIZE[1], Tile.SCALED):
            for x in range(0, s.WINDOW_SIZE[0], Tile.SCALED):
                center_x, center_y = find_grid_box(x, y)

                box = arcade.create_rectangle_outline(center_x=center_x,
                                                      center_y=center_y,
                                                      width=Tile.SCALED,
                                                      height=Tile.SCALED,
                                                      color=arcade.color.BLACK)
                self.boxes.append(box)
                self.boxes_hash_map[(center_x, center_y)] = box

                yield
Exemple #14
0
def draw_map(bodies, window_width, window_height):

    map_shape_list = arcade.ShapeElementList()

    view = arcade.get_viewport()
    map_width = window_width / 3.5
    map_height = window_height / 3.5
    map_padding = window_height / 80
    map_center_x = view[1] - (map_width / 2 + map_padding)
    map_center_y = view[2] + (map_height / 2 + map_padding)
    #view[0] = left, view[1] = right, view[2] = bottom, view[3] = top
    rec = arcade.create_rectangle_filled(map_center_x, map_center_y, map_width,
                                         map_height, arcade.color.BLACK)
    rec2 = arcade.create_rectangle_outline(map_center_x, map_center_y,
                                           map_width, map_height,
                                           arcade.color.WHITE,
                                           window_width / 400)

    map_shape_list.append(rec)
    map_shape_list.append(rec2)

    max_mass = 0
    cm = None  # find_center_of_mass(bodies)
    for bodie in bodies:
        if max_mass < bodie.mass:
            max_mass = bodie.mass
            cm = bodie.pos

    max_dist = 1
    for bodie in bodies:
        this_dist = (cm - bodie.pos).get_mag()
        if max_dist < this_dist:
            max_dist = this_dist

    scaler = max_dist / ((map_height - map_padding) / 2)
    # print(scaler)
    # scaler = 60

    for bodie in bodies:
        map_pos = (bodie.pos - cm)
        map_pos.x /= scaler
        map_pos.y /= scaler
        map_pos += Vec2D(map_center_x, map_center_y)
        map_shape_list.append(
            arcade.create_ellipse_filled(map_pos.x, map_pos.y,
                                         window_width / 300,
                                         window_width / 300, bodie.color))
        # map_shpe_list.append( arcade. )

    map_shape_list.draw()
Exemple #15
0
    def create_message_box_outline(self, colour):
        """
        Create a small outline around the message box.

        Return an object that can be rendered to the screen efficiently.
        """
        message_box_outline = arcade.create_rectangle_outline(
            settings.WINDOW_WIDTH / 2,
            settings.WINDOW_HEIGHT / 2 + settings.CELL,
            settings.WINDOW_WIDTH - (settings.CELL * 10),
            (settings.WINDOW_HEIGHT / 2) - (settings.CELL * 7),
            colour,
            6
            )
        return message_box_outline
Exemple #16
0
 def scene2_render(self):
     self.draw_list = arcade.ShapeElementList()
     #  self.stars_render()
     #  self.draw_list.append(arcade.create_rectangle_filled(400, 400, 800, 800, arcade.color.DARK_BLUE, 0))
     self.draw_list.append(
         arcade.create_rectangle_filled(400, 400, 600, 600, colors["white"],
                                        0))
     self.draw_list.append(
         arcade.create_line(300, 100, 300, 700, colors["black"], 4))
     for i in range(0, 5):
         self.draw_list.append(
             arcade.create_rectangle_filled(200, 600 - (100 * i), 50, 75,
                                            arcade.color.SILVER_LAKE_BLUE))
     self.draw_list.append(
         arcade.create_rectangle_outline(200, 200 + (self.cursor * 100), 50,
                                         75, colors["black"], 3))
Exemple #17
0
    def __init__(self,
                 center_x: float,
                 center_y: float,
                 width: float,
                 height: float,
                 fill_color: Union[Tuple[int, int, int],
                                   Tuple[int, int, int,
                                         int]] = arcade.color.WHITE,
                 border_color: Union[Tuple[int, int, int],
                                     Tuple[int, int, int,
                                           int]] = arcade.color.BLACK,
                 border_width: float = 1,
                 **kwargs):
        super().__init__(**kwargs)

        self.center_x = center_x
        self.center_y = center_y

        self.width = width
        self.height = height

        self.fill_color = fill_color
        self.border_color = border_color
        self.border_width = border_width

        self.fill_box = arcade.create_rectangle_filled(center_x=center_x,
                                                       center_y=center_y,
                                                       width=width,
                                                       height=height,
                                                       color=fill_color)
        self.outline_box = arcade.create_rectangle_outline(
            center_x=center_x,
            center_y=center_y,
            width=width,
            height=height,
            color=border_color,
            border_width=border_width)

        self.shapes = arcade.ShapeElementList()
        self.shapes.append(self.fill_box)
        self.shapes.append(self.outline_box)

        self.elements: List[Type[InteractiveWidget]] = list()
 def create_shape(self, x, y):
     if self.is_active:
         return arcade.create_rectangle_filled(
             x,
             y,
             self.settings.cell_size,
             self.settings.cell_size,
             self.palette.active_cell_background_color,
         )
     cell_size = self.settings.cell_size
     outline = self.settings.passive_cell_outline_width
     return arcade.create_rectangle_outline(
         x,
         y,
         cell_size - outline,
         cell_size - outline,
         self.palette.passive_cell_background_color,
         outline,
     )
Exemple #19
0
    def hallways(self):
        try:
            if len(self.neighbors) == 0:
                return []
            return self._hallways
        except AttributeError:
            pass
        self._hallways = []

        for neighbor in self.neighbors:
            A = pymunk.Vec2d(*self.position)
            B = pymunk.Vec2d(*neighbor.position)
            C = (A + B) / 2
            w, h = A - B
            shape = arcade.create_rectangle_outline(*C, w, h, (0, 127, 0, 127),
                                                    1)
            self._hallways.append(shape)

        return self._hallways
Exemple #20
0
 def __init__(
     self,
     text: str,
     center_x: float,
     center_y: float,
     width: float = None,
     height: float = None,
     scale: float = 1.0,
     on_click: Callable[[], None] = None,
 ) -> None:
     self.text: str = text
     self.center_x = center_x
     self.center_y = center_y
     self.width = width if width is not None else len(
         text) * scale * self.font_size * 0.6
     self.height = height if height is not None else scale * self.font_size * 1.4
     self.scale: float = scale
     self._on_click: Callable[
         [], None] = on_click if on_click is not None else lambda: None
     self.state: ButtonState = ButtonState.NORMAL
     self.background: Dict[ButtonState, arcade.ShapeElementList] = {
         state: arcade.ShapeElementList()
         for state in ButtonState
     }
     for state in ButtonState:
         self.background[state].append(
             arcade.create_rectangle_filled(
                 center_x=center_x,
                 center_y=center_y,
                 width=self.width,
                 height=self.height,
                 color=self.color[state]["background"],
             ))
         self.background[state].append(
             arcade.create_rectangle_outline(
                 center_x=center_x,
                 center_y=center_y,
                 width=self.width,
                 height=self.height,
                 color=self.color[state]["outline"],
                 border_width=2.0 * self.scale,
             ))
Exemple #21
0
 def __init__(self):
     """Initialize the Next Queue which displays the next Tetrimino that
     will be in play.
     """
     self.t_next = None
     self.rects = arcade.ShapeElementList()
     self.minos = arcade.ShapeElementList()
     self.box = arcade.create_rectangle_filled(
         center_x=SIDE_MARGIN + NEXT_QUEUE_CX,
         center_y=BOTTOM_MARGIN + NEXT_QUEUE_CY,
         width=NEXT_QUEUE_WIDTH,
         height=NEXT_QUEUE_HEIGHT,
         color=WHITE)
     self.outline = arcade.create_rectangle_outline(
         center_x=SIDE_MARGIN + NEXT_QUEUE_CX,
         center_y=BOTTOM_MARGIN + NEXT_QUEUE_CY,
         width=NEXT_QUEUE_WIDTH,
         height=NEXT_QUEUE_HEIGHT,
         color=BLACK)
     self.rects.append(self.box)
     self.rects.append(self.outline)
Exemple #22
0
    def setup(self):

        self.not_navigable += [(x, 200) for x in range(100, 600, TILE_SIZE)]
        self.not_navigable += [(x, 600) for x in range(40, 800, TILE_SIZE)]
        self.not_navigable += [(x, 780) for x in range(800, 1200, TILE_SIZE)]
        self.not_navigable += [(800, y) for y in range(780, 900, TILE_SIZE)]
        self.not_navigable += [(500, y) for y in range(0, 200, TILE_SIZE)]
        self.not_navigable += [(x, 900) for x in range(800, 1200, TILE_SIZE)]
        self.not_navigable += [(x, 100) for x in range(900, 1200, TILE_SIZE)]

        self.navigable = [
            item for item in self.tiles if item not in self.not_navigable
        ]

        self.agents_pos = [
            self.navigable[randint(0,
                                   len(self.navigable) - 1)]
            for i in range(0, TOTAL_AGENTS)
        ]

        for tile in self.tiles:
            shape = arcade.create_rectangle_outline(tile[0] + TILE_SIZE / 2,
                                                    tile[1] + TILE_SIZE / 2,
                                                    TILE_SIZE, TILE_SIZE,
                                                    arcade.color.BLUE, 1)
            self.shape_list.append(shape)

        self.collectable_pos = self.navigable[randint(0,
                                                      len(self.navigable) - 1)]
        self.agents_path = [
            self.pathfind_astar(self.agents_pos[i], self.collectable_pos)
            for i in range(0, TOTAL_AGENTS)
        ]

        for tile in self.not_navigable:
            shape = arcade.create_rectangle_filled(tile[0] + TILE_SIZE / 2,
                                                   tile[1] + TILE_SIZE / 2,
                                                   TILE_SIZE, TILE_SIZE,
                                                   arcade.color.BLACK, 1)
            self.shape_list.append(shape)
Exemple #23
0
    def setup(self):

        # Create the sprite lists.
        self.tetrimino = Arcade.SpriteList()
        self.blocks_list = Arcade.SpriteList()

        # The tallest occupied space by column.
        # The lower the number, the higher the block is on the screen.
        self.max_by_col = self.find_max_by_col()

        # Generate first queue of tetriminos.
        self.tetrimino_queue = self.generate_queue()

        # Get the first tetrimino and add it to the field.
        self.tetrimino = tetrimino.Tetrimino(type=tetrimino.Tetrimino.Type[
            self.tetrimino_queue.get()]).to_sprite_list()
        self.add_tetrimino_to_field(self.tetrimino)

        # Game area (with grid)
        self.game_area = Arcade.ShapeElementList()
        self.game_area.append(
            Arcade.create_rectangle_outline(
                Const.AREA_LEFT + (Const.AREA_RIGHT - Const.AREA_LEFT) / 2,
                Const.AREA_BOTTOM + (Const.AREA_TOP - Const.AREA_BOTTOM) / 2,
                Const.AREA_RIGHT - Const.AREA_LEFT,
                Const.AREA_TOP - Const.AREA_BOTTOM, Arcade.color.WHITE, 2))

        for x in range(Const.AREA_LEFT + Const.BLOCK_SIZE, Const.AREA_RIGHT,
                       Const.BLOCK_SIZE):
            self.game_area.append(
                Arcade.create_line(
                    x, Const.AREA_TOP, x, Const.AREA_BOTTOM,
                    (128, 128, 128, 128)))  # Gray with 50% opacity

        for y in range(Const.AREA_BOTTOM + Const.BLOCK_SIZE, Const.AREA_TOP,
                       Const.BLOCK_SIZE):
            self.game_area.append(
                Arcade.create_line(Const.AREA_LEFT, y, Const.AREA_RIGHT, y,
                                   (128, 128, 128, 128)))
Exemple #24
0
    def generate_shapes(self):
        size = sqrt(len(self.tiles))

        shapes = []
        for i, tile in enumerate(self.tiles):
            tx = i % size
            ty = i // size

            cx = TILE_SIZE + tx * TILE_SIZE
            cy = TILE_SIZE + ty * TILE_SIZE

            shape = ShapeElementList()
            for y, row in enumerate(reversed(tile.lines)):
                for x, pxl in enumerate(row):
                    if pxl == "#":
                        shape.append(
                            create_rectangle_filled(
                                cx + x * PIXEL,
                                cy + y * PIXEL,
                                PIXEL,
                                PIXEL,
                                color=WHITE,
                            ))
            shapes.append(shape)

            # Add border
            print(shape.center_x, shape.center_y)
            rect = create_rectangle_outline(
                shape.center_x,
                shape.center_y,
                len(tile.lines) * PIXEL,
                len(tile.lines) * PIXEL,
                RED,
                # border_width=1,
            )
            shapes.append(rect)

        return shapes
 def generate_shape_list(self):
     """
     Regenerate the shape list based on the current state of the game
     """
     cells = self.ui_data["board"]["cells"]
     self.board_shape_list = arcade.ShapeElementList()
     for row in cells:
         for cell in row:
             rect = arcade.create_rectangle_filled(
                 cell["x"],
                 cell["y"],
                 cell["width"],
                 cell["height"],
                 cell["color"]
             )
             border = arcade.create_rectangle_outline(
                 cell["x"],
                 cell["y"],
                 cell["width"],
                 cell["height"],
                 self.ui_data["colors"]["border"]
             )
             self.board_shape_list.append(rect)
             self.board_shape_list.append(border)
Exemple #26
0
    def __init__(
            self,
            center_x: float,
            center_y: float,
            width: float = 300,
            height: float = 25,
            box_color: Tuple[int, int, int, int] = arcade.color.WHITE,
            border_color: Tuple[int, int, int, int] = arcade.color.BLACK,
            border_width: float = 1,
            text_color: Tuple[int, int, int, int] = arcade.color.BLACK,
            bold: bool = False,
            italic: bool = False,
            font_size: float = 12,
            horizontal_margin: float = 5,
            vertical_margin: float = 5,
            cursor_color: Tuple[int, int, int,
                                int] = arcade.color.BLACK) -> None:
        self.center_x = center_x
        self.center_y = center_y

        self.width = width
        self.height = height

        self.box_color = box_color
        self.border_color = border_color
        self.border_width = border_width

        self.text = ''
        self.text_color = text_color
        self.bold = bold
        self.italic = italic
        self.font_size = font_size

        self.horizontal_margin = horizontal_margin
        self.vertical_margin = vertical_margin

        self.shapes = arcade.ShapeElementList()
        self.shapes.append(
            arcade.create_rectangle_filled(center_x=center_x,
                                           center_y=center_y,
                                           width=width,
                                           height=height,
                                           color=box_color), )
        self.shapes.append(
            arcade.create_rectangle_outline(center_x=center_x,
                                            center_y=center_y,
                                            width=width,
                                            height=height,
                                            color=border_color,
                                            border_width=border_width))

        self.text_sprites = arcade.SpriteList(is_static=True,
                                              use_spatial_hash=True)
        self.text_sprites.append(
            arcade.draw_text(text='',
                             start_x=center_x - (width / 2) +
                             horizontal_margin,
                             start_y=center_y - (height / 2) + vertical_margin,
                             color=text_color,
                             font_size=font_size,
                             bold=bold,
                             italic=italic))

        self.cursor_sprites = arcade.ShapeElementList()
        self.cursor = arcade.create_rectangle_filled(
            center_x=center_x - (width / 2) + horizontal_margin,
            center_y=center_y - (height / 2) + vertical_margin +
            self.text_sprites[0].height / 2,
            width=1,
            height=self.text_sprites[0].height,
            color=self.box_color)
        self.cursor_sprites.append(self.cursor)

        self.cursor_color = cursor_color
        self.prev_cursor_idx = 0
        self.cursor_idx = 0

        self.cursor_is_active = False
        self._cursor_blink_delta = 0

        self._active = False

        self._current_key_pressed = None
        self._key_hold_delta = 0

        self.KEY_SHIFTS = {
            arcade.key.GRAVE: arcade.key.ASCIITILDE,
            arcade.key.KEY_2: arcade.key.AT,
            arcade.key.KEY_6: arcade.key.ASCIICIRCUM,
            arcade.key.KEY_7: arcade.key.AMPERSAND,
            arcade.key.KEY_8: arcade.key.ASTERISK,
            arcade.key.KEY_9: arcade.key.PARENLEFT,
            arcade.key.KEY_0: arcade.key.PARENRIGHT,
            arcade.key.MINUS: arcade.key.UNDERSCORE,
            arcade.key.EQUAL: arcade.key.PLUS,
            arcade.key.BRACKETLEFT: arcade.key.BRACELEFT,
            arcade.key.BRACKETRIGHT: arcade.key.BRACERIGHT,
            arcade.key.BACKSLASH: arcade.key.BAR,
            arcade.key.SEMICOLON: arcade.key.COLON,
            arcade.key.APOSTROPHE: arcade.key.DOUBLEQUOTE,
            arcade.key.COMMA: arcade.key.LESS,
            arcade.key.PERIOD: arcade.key.GREATER,
            arcade.key.SLASH: arcade.key.QUESTION
        }

        self.KEY_NUMS = {
            arcade.key.NUM_1: arcade.key.KEY_1,
            arcade.key.NUM_2: arcade.key.KEY_2,
            arcade.key.NUM_3: arcade.key.KEY_3,
            arcade.key.NUM_4: arcade.key.KEY_4,
            arcade.key.NUM_5: arcade.key.KEY_5,
            arcade.key.NUM_6: arcade.key.KEY_6,
            arcade.key.NUM_7: arcade.key.KEY_7,
            arcade.key.NUM_8: arcade.key.KEY_8,
            arcade.key.NUM_9: arcade.key.KEY_9,
            arcade.key.NUM_0: arcade.key.KEY_0,
            arcade.key.NUM_DIVIDE: arcade.key.SLASH,
            arcade.key.NUM_MULTIPLY: arcade.key.ASTERISK,
            arcade.key.NUM_SUBTRACT: arcade.key.MINUS,
            arcade.key.NUM_ADD: arcade.key.PLUS,
            arcade.key.NUM_DECIMAL: arcade.key.PERIOD
        }
Exemple #27
0
    def __init__(
        self,
        center_x: float,
        center_y: float,
        width: float,
        height: float,
        nodes: List[Type[InteractiveWidget]] = list(),
        node_margin: float = 10,
        scroll_speed: float = 10,
        fill: bool = False,
        fill_color: Union[Tuple[int, int, int], Tuple[int, int, int, int]] = arcade.csscolor.WHITE,
        border: bool = False,
        border_color: Union[Tuple[int, int, int], Tuple[int, int, int, int]] = arcade.color.BLACK,
        border_width: float = 1
    ) -> None:
        self.center_x = center_x
        self.center_y = center_y

        self.width = width
        self.height = height

        self.nodes = nodes
        self.node_margin = node_margin

        for node in self.nodes:
            node.active = (
                node.center_y - node.height / 2 > self.center_y - self.height / 2 and
                node.center_y + node.height / 2 < self.center_y + self.height / 2
            )

        self.scroll_speed = scroll_speed

        self.fill = fill
        self.fill_color = fill_color

        self.border = border
        self.border_color = border_color
        self.border_width = border_width

        self.mouse_pos = (0, 0)

        self.shapes = arcade.ShapeElementList()

        if self.fill:
            self.fill_box = arcade.create_rectangle_filled(
                center_x=center_x,
                center_y=center_y,
                width=width,
                height=height,
                color=fill_color
            )
            self.shapes.append(self.fill_box)

        if self.border:
            self.border_box = arcade.create_rectangle_outline(
                center_x=center_x,
                center_y=center_y,
                width=width,
                height=height,
                color=border_color,
                border_width=border_width
            )
            self.shapes.append(self.border_box)
Exemple #28
0
    def on_update(self, delta_time: float):
        if self.music:
            position = self.music.get_stream_position()

            if position == 0.0:
                self.play_song()
        hang_test = [False, 0]
        self.frame_count += 1
        self.player_sprite.current_background = self.window.background_color
        for item in self.primitive_list:
            self.primitive_list.remove(item)
        if self.w_pressed:
            jump_test = self.physics_engine.can_jump()
            if jump_test[0] and not self.jump_needs_reset:
                self.physics_engine.jump(12 + jump_test[1])
                if self.sounds_enabled:
                    arcade.play_sound(self.jump_sound, 0.01)
                self.jump_needs_reset = True
                self.hang_timer = 40
        if self.space_pressed:
            hang_test = self.physics_engine.can_hang(self.hang_timer)
            if hang_test[0]:
                if self.hang_timer == 40:
                    if self.sounds_enabled:
                        arcade.play_sound(self.hang_sound, 0.05)
                self.hang_timer = self.physics_engine.hang(hang_test[1], self.hang_timer)
        if self.a_pressed and not self.d_pressed:
            if self.player_sprite.change_x > - C.MAX_SPEED:
                self.player_sprite.change_x -= 0.1 * self.player_sprite.speed_multiplier
        elif self.d_pressed and not self.a_pressed:
            if self.player_sprite.change_x < C.MAX_SPEED:
                self.player_sprite.change_x += 0.1 * self.player_sprite.speed_multiplier
        else:
            if self.player_sprite.change_x > C.FRICTION * self.player_sprite.speed_multiplier:
                self.player_sprite.change_x -= C.FRICTION * self.player_sprite.speed_multiplier
            elif self.player_sprite.change_x < - C.FRICTION * self.player_sprite.speed_multiplier:
                self.player_sprite.change_x += C.FRICTION * self.player_sprite.speed_multiplier
            else:
                self.player_sprite.change_x = 0

        self.physics_engine.update(delta_time)

        if hang_test[0]:
            if self.player_sprite.change_x > 0:
                x_offset = self.player_sprite.change_x
            else:
                x_offset = 0
            self.primitive_list.append(arcade.create_rectangle_filled(
                self.player_sprite.center_x + 20 + (self.hang_timer // 2) + x_offset,
                self.player_sprite.center_y + 30,
                self.hang_timer,
                5,
                (255 - int(self.hang_timer * (255 / 40)), int(self.hang_timer * (255 / 40)), 0)))
            self.primitive_list.append(arcade.create_rectangle_outline(
                self.player_sprite.center_x + 40,
                self.player_sprite.center_y + 30,
                40,
                5,
                arcade.color.WHITE))

        for enemy in self.ennemies:
            if arcade.has_line_of_sight(enemy.position, self.player_sprite.position, self.platforms):
                start_x = enemy.center_x
                start_y = enemy.center_y

                dest_x = self.player_sprite.center_x
                dest_y = self.player_sprite.center_y

                x_diff = dest_x - start_x
                y_diff = dest_y - start_y
                angle = math.atan2(y_diff, x_diff)

                enemy.angle = math.degrees(angle) - 90

                # if self.frame_count % 30 == 0:
                #    bullet = arcade.Sprite(":resources:images/space_shooter/laserBlue01.png", 0.5)
                #    bullet.center_x = start_x
                #    bullet.center_y = start_y

                #    bullet.angle = math.degrees(angle)

                #    bullet.change_x = math.cos(angle) * C.BULLET_SPEED
                #    bullet.change_y = math.sin(angle) * C.BULLET_SPEED

                #    self.bullet_list.append(bullet)

        for bullet in self.bullet_list:
            if self.view_left > bullet.center_x or bullet.center_x > C.SCREEN_WIDTH + self.view_left or \
                    self.view_bottom > bullet.center_y or bullet.center_y > C.SCREEN_HEIGHT + self.view_bottom:
                bullet.remove_from_sprite_lists()

        self.bullet_list.update()
        changed = False

        # Scroll left
        left_boundary = self.view_left + C.LEFT_VIEWPORT_MARGIN
        if self.player_sprite.left < left_boundary:
            self.view_left -= left_boundary - self.player_sprite.left
            changed = True

        # Scroll right
        right_boundary = self.view_left + C.SCREEN_WIDTH - C.RIGHT_VIEWPORT_MARGIN
        if self.player_sprite.right > right_boundary:
            self.view_left += self.player_sprite.right - right_boundary
            changed = True

        # Scroll up
        top_boundary = self.view_bottom + C.SCREEN_HEIGHT - C.TOP_VIEWPORT_MARGIN
        if self.player_sprite.top > top_boundary:
            self.view_bottom += self.player_sprite.top - top_boundary
            changed = True

        # Scroll down

        if changed:
            # Only scroll to integers. Otherwise we end up with pixels that
            # don't line up on the screen
            self.view_bottom = int(self.view_bottom)
            self.view_left = int(self.view_left)

            # Do the scrolling
            arcade.set_viewport(self.view_left,
                                C.SCREEN_WIDTH + self.view_left,
                                self.view_bottom,
                                C.SCREEN_HEIGHT + self.view_bottom)

        if self.player_sprite.top >= self.platforms[0].center_y + 125 and self.platforms[
            0].left < self.player_sprite.center_x < self.platforms[0].right:
            if self.level_manager:
                if self.seed.lvl_id + 1 < len(self.level_manager.levels):
                    self.seed = self.level_manager.levels[self.seed.lvl_id + 1]
                    if self.seed.lvl_id == self.level_manager.current_level.lvl_id + 1:
                        self.level_manager.current_level = self.level_manager.levels[self.seed.lvl_id]
                        pickle_out = open(resource_path('data/current_level.save'), 'wb')
                        pickle.dump(self.seed.lvl_id, pickle_out)
                        pickle_out.close()
                    self.setup()
                else:
                    from main import Victory
                    pickle_out = open(resource_path('data/current_level.save'), 'wb')
                    pickle.dump(self.seed.lvl_id + 1, pickle_out)
                    pickle_out.close()
                    self.window.show_view(Victory(self.window))
            else:
                self.seed.seed = None
                self.setup()

        if self.player_sprite.top <= self.view_bottom:
            self.setup()

        self.fps.tick()
Exemple #29
0
def make_objects():
    shape_list = arcade.ShapeElementList()

    center_x = 0
    center_y = 0
    width = 20
    height = 20
    shape = arcade.create_ellipse_filled(center_x, center_y, width, height,
                                         arcade.color.WHITE)
    shape_list.append(shape)

    center_x += 40
    shape = arcade.create_ellipse_outline(center_x,
                                          center_y,
                                          width,
                                          height,
                                          arcade.color.RED,
                                          border_width=1)
    shape_list.append(shape)

    center_x += 40
    shape = arcade.create_ellipse_outline(center_x,
                                          center_y,
                                          width,
                                          height,
                                          arcade.color.DARK_RED,
                                          border_width=1)
    shape_list.append(shape)

    shape = arcade.create_line(0, 0, 80, 0, arcade.color.BLUE, line_width=1)
    shape_list.append(shape)

    shape = arcade.create_line(0,
                               0,
                               80,
                               0,
                               arcade.color.LIGHT_BLUE,
                               line_width=1)
    shape_list.append(shape)

    center_x = 0
    center_y = 50
    width = 20
    height = 20
    outside_color = arcade.color.AERO_BLUE
    inside_color = arcade.color.AFRICAN_VIOLET
    tilt_angle = 45
    shape = arcade.create_ellipse_filled_with_colors(center_x, center_y, width,
                                                     height, outside_color,
                                                     inside_color, tilt_angle)
    shape_list.append(shape)

    center_x = 0
    center_y = -50
    width = 20
    height = 20
    shape = arcade.create_rectangle_filled(center_x, center_y, width, height,
                                           arcade.color.WHITE)
    shape_list.append(shape)
    shape = arcade.create_rectangle_outline(center_x,
                                            center_y,
                                            width,
                                            height,
                                            arcade.color.BLACK,
                                            border_width=1)
    shape_list.append(shape)
    shape = arcade.create_rectangle_outline(center_x,
                                            center_y,
                                            width,
                                            height,
                                            arcade.color.AMERICAN_ROSE,
                                            border_width=1)
    shape_list.append(shape)

    color1 = (215, 214, 165)
    color2 = (219, 166, 123)
    points = (70, 70), (150, 70), (150, 150), (70, 150)
    colors = (color1, color1, color2, color2)
    shape = arcade.create_rectangle_filled_with_colors(points, colors)
    shape_list.append(shape)

    points = (0, 0), (150, 150), (0, 150), (0, 250)
    shape = arcade.create_line_strip(points, arcade.color.AFRICAN_VIOLET)
    shape_list.append(shape)

    points = (0, 0), (75, 90), (60, 150), (90, 250)
    shape = arcade.create_line_generic(points, arcade.color.ALIZARIN_CRIMSON,
                                       gl.GL_TRIANGLE_FAN)
    shape_list.append(shape)

    return shape_list
Exemple #30
0
 def draw(self, game, x, y):
     game.draw_list.append(
         arcade.create_ellipse_outline(x, y, self.size_x, self.size_y,
                                       colors["sky"], 10, 0))
     game.draw_list.append(
         arcade.create_rectangle_filled(x, y, self.size_x / 2,
                                        self.size_y / 2, colors["sky"], 45))
     game.draw_list.append(
         arcade.create_ellipse_outline(x - 20, y + 20, 10, 10, colors["db"],
                                       5, 0))
     game.draw_list.append(
         arcade.create_ellipse_outline(x - 20, y - 20, 10, 10, colors["db"],
                                       5, 0))
     game.draw_list.append(
         arcade.create_ellipse_outline(x + 20, y + 20, 10, 10, colors["db"],
                                       5, 0))
     game.draw_list.append(
         arcade.create_ellipse_outline(x + 20, y - 20, 10, 10, colors["db"],
                                       5, 0))
     game.draw_list.append(
         arcade.create_rectangle_outline(x, y + 30, 10, 10, colors["db"], 4,
                                         45))
     game.draw_list.append(
         arcade.create_rectangle_outline(x, y - 30, 10, 10, colors["db"], 4,
                                         45))
     game.draw_list.append(
         arcade.create_rectangle_outline(x + 30, y, 10, 10, colors["db"], 4,
                                         45))
     game.draw_list.append(
         arcade.create_rectangle_outline(x - 30, y, 10, 10, colors["db"], 4,
                                         45))
     game.draw_list.append(
         arcade.create_line(x - 80, y, x + 80, y, colors["db"], 2))
     game.draw_list.append(
         arcade.create_line(x, y - 80, x, y + 80, colors["db"], 2))
     game.draw_list.append(
         arcade.create_line(x - 60, y + 60, x + 60, y - 60, colors["db"],
                            1))
     game.draw_list.append(
         arcade.create_line(x - 60, y - 60, x + 60, y + 60, colors["db"],
                            1))
     game.draw_list.append(
         arcade.create_ellipse_filled(x - 60, y + 60, 14, 14, colors["db"]))
     game.draw_list.append(
         arcade.create_ellipse_filled(x + 60, y + 60, 14, 14, colors["db"]))
     game.draw_list.append(
         arcade.create_ellipse_filled(x - 60, y - 60, 14, 14, colors["db"]))
     game.draw_list.append(
         arcade.create_ellipse_filled(x + 60, y - 60, 14, 14, colors["db"]))
     game.draw_list.append(
         arcade.create_ellipse_filled(x - 80, y, 14, 14, colors["db"]))
     game.draw_list.append(
         arcade.create_ellipse_filled(x + 80, y, 14, 14, colors["db"]))
     game.draw_list.append(
         arcade.create_ellipse_filled(x, y + 80, 14, 14, colors["db"]))
     game.draw_list.append(
         arcade.create_ellipse_filled(x, y - 80, 14, 14, colors["db"]))
     game.draw_list.append(
         arcade.create_ellipse_filled(x - 60, y + 60, 6, 6,
                                      colors["white"]))
     game.draw_list.append(
         arcade.create_ellipse_filled(x + 60, y + 60, 6, 6,
                                      colors["white"]))
     game.draw_list.append(
         arcade.create_ellipse_filled(x - 60, y - 60, 6, 6,
                                      colors["white"]))
     game.draw_list.append(
         arcade.create_ellipse_filled(x + 60, y - 60, 6, 6,
                                      colors["white"]))
     game.draw_list.append(
         arcade.create_ellipse_filled(x - 80, y, 6, 6, colors["white"]))
     game.draw_list.append(
         arcade.create_ellipse_filled(x + 80, y, 6, 6, colors["white"]))
     game.draw_list.append(
         arcade.create_ellipse_filled(x, y + 80, 6, 6, colors["white"]))
     game.draw_list.append(
         arcade.create_ellipse_filled(x, y - 80, 6, 6, colors["white"]))
     game.draw_list.append(
         arcade.create_ellipse_filled(x, y, 10, 10, colors["white"]))