Esempio n. 1
0
    def __init__(
        self,
        username: str,
        score: int,
        timestamp: str,
        center_x: float,
        center_y: float,
        width: float,
        height: float,
        text_color: Tuple[int, int, int, int] = arcade.color.BLACK,
        display_color: Tuple[int, int, int, int] = arcade.color.WHITE,
        outline_color: Tuple[int, int, int, int] = arcade.color.BLACK,
        outline_width: float = 1
    ) -> None:
        self.username = username
        self.score = score
        self.timestamp = datetime.fromisoformat(timestamp).strftime(r'%d/%m/%Y | %I:%M %p')

        self._center_x = center_x
        self._center_y = center_y

        self.width = width
        self.height = height

        self.text_color = text_color
        self.display_color = display_color
        self.outline_color = outline_color
        self.outline_width = outline_width

        self.display = arcade.create_rectangle_filled(
            center_x=center_x,
            center_y=center_y,
            width=width,
            height=height,
            color=display_color
        )

        self.display_outline = arcade.create_rectangle_outline(
            center_x=center_x,
            center_y=center_y,
            width=width,
            height=height,
            color=outline_color,
            border_width=outline_width
        )

        self.elements = arcade.ShapeElementList()
        self.elements.append(self.display)
        self.elements.append(self.display_outline)

        self.username_text = arcade.draw_text(
            text=username,
            start_x=center_x - width / 2 + 20,
            start_y=center_y,
            color=text_color,
            anchor_y='center'
        )

        self.score_text = arcade.draw_text(
            text=str(score),
            start_x=center_x,
            start_y=center_y,
            color=text_color,
            anchor_y='center'
        )

        self.timestamp_text = arcade.draw_text(
            text=self.timestamp,
            start_x=center_x + width / 2 - 200,
            start_y=center_y,
            color=text_color,
            anchor_y='center'
        )

        arcade.text.draw_text_cache.clear()
Esempio n. 2
0
    def __init__(self, width, height, title):
        super().__init__(width, height, title)
        self.set_location(0, 25)

        # variables for coordinate calculation relative to the board and relative to the screen
        self.board_pieces_location = [[0 for i in range(9)] for j in range(9)]
        self.white_captured_location = [[0 for i in range(3)]
                                        for j in range(3)]
        self.black_captured_location = [[0 for i in range(3)]
                                        for j in range(3)]
        self.coordinates_map = [[[x, y] for x in range(170, 845, 75)]
                                for y in range(700, 25, -75)]
        self.white_coordinates = [[[x, y] for x in range(975, 1275, 75)]
                                  for y in range(275, -25, -75)]
        self.black_coordinates = [[[x, y] for x in range(975, 1275, 75)]
                                  for y in range(675, 375, -75)]

        # initialize variables
        self.mouse_x = 0
        self.mouse_y = 0
        self.selected_piece = 0  #stores selected piece object
        self.turn_number = 1

        # booleans and somewhat boolean
        self.pieces_selected = False
        self.turn = "white"
        self.promotion_prompt = False
        self.king_checked = False
        self.king_checkmated = False
        self.capture_done = False
        self.checked_for_promotion = False

        # lists
        self.prev_position = [
            [0, 0], [0, 0], [0, 0], [0, 0]
        ]  #not the prev pos of last turn, but prev pos of last click (which could be from either this or last turn)
        self.new_position = []
        self.possible_moves = []
        self.checking_pieces = []
        self.covered_squares = ["test"]
        self.check_possible_responses = [None]
        self.move_history = [["1"]]

        # sound files
        self.place_sound = arcade.Sound(
            os.path.join(sys.path[0], "sound", "clack.wav"))
        self.disgrace_sound = arcade.Sound(
            os.path.join(sys.path[0], "sound", "disgrace.wav"))

        # sprite files
        self.sprites = os.path.join(sys.path[0], "sprites")
        self.all_pieces = arcade.SpriteList()
        self.highlight = arcade.ShapeElementList()

        # places pieces on their correct locations
        self.initialize_pieces()

        # save file
        name = datetime.now().strftime("%m.%d.%Y,%H;%M;%S") + ".txt"
        saves = os.path.join(sys.path[0], "saves")
        self.save_file = open(os.path.join(saves, name), "w", encoding='utf-8')
 def change_color(self, new_color):
     self.color = new_color
     shape = arcade.create_rectangle_filled(0, 0, self.width, self.height,
                                            self.color, self.angle)
     self.shape_list = arcade.ShapeElementList()
     self.shape_list.append(shape)
    def on_update(self, delta_time):

        self.max_fps = self.target_fps + TARGET_PLUS_MINUS
        self.min_fps = self.target_fps - TARGET_PLUS_MINUS

        self.shape_list = arcade.ShapeElementList()

        floor = arcade.create_rectangle(SCREEN_WIDTH // 2,
                                        int(SCREEN_HEIGHT * 0.25),
                                        SCREEN_WIDTH, SCREEN_HEIGHT // 2,
                                        FLOOR_COLOR)

        ceiling = arcade.create_rectangle(SCREEN_WIDTH // 2,
                                          int(SCREEN_HEIGHT * 0.75),
                                          SCREEN_WIDTH, SCREEN_HEIGHT // 2,
                                          CEILING_COLOR)

        self.shape_list.append(floor)
        self.shape_list.append(ceiling)

        point_list = []
        color_list = []

        # print(f'({self.posX}, {self.posY}) at time {self.time}')

        # arcade.start_render()
        for x in range(0, SCREEN_WIDTH + 1):
            # calculate the ray position and direction
            cameraX = (2 * x / SCREEN_WIDTH) - 1
            if cameraX > 1 or cameraX < -1:
                print('cameraX is too big or too small!')
                sys.exit()
            rayDirX = self.dirX + self.planeX * cameraX
            rayDirY = self.dirY + self.planeY * cameraX

            # which box of the map we're in
            mapX = int(self.posX)
            mapY = int(self.posY)

            # print(f'({mapX}, {mapY})')

            # length of ray from current position to the next x- or y-side
            sideDistX = None
            sideDistY = None

            # length of the ray from one x- or y-side to the next x- or y-side
            try:
                deltaDistX = abs(1 / rayDirX)
            except ZeroDivisionError:
                if rayDirY == 0:
                    deltaDistX = 0
                else:
                    if rayDirX == 0:
                        deltaDistX = 1
                    else:
                        deltaDistX = abs(1 / rayDirX)
            try:
                deltaDistY = abs(1 / rayDirY)
            except ZeroDivisionError:
                if rayDirX == 0:
                    deltaDistY = 0
                else:
                    if rayDirY == 0:
                        deltaDistY = 1
                    else:
                        deltaDistY = abs(1 / rayDirY)
            perpWallDist = None

            # which direction to step in the x direction or y direction (either +1 or -1)
            stepX = None
            stepY = None

            hit = 0  # was there a wall hit?
            side = None  # was a North/South wall hit or an East/West wall hit?
            if rayDirX < 0:
                stepX = -1
                sideDistX = (self.posX - mapX) * deltaDistX
            else:
                stepX = 1
                sideDistX = (mapX + 1.0 - self.posX) * deltaDistX

            if rayDirY < 0:
                stepY = -1
                sideDistY = (self.posY - mapY) * deltaDistY
            else:
                stepY = 1
                sideDistY = (mapY + 1.0 - self.posY) * deltaDistY

            # was a wall hit? 1 = yes. 0 = no.
            while hit == 0:
                if sideDistX < sideDistY:
                    sideDistX += deltaDistX
                    mapX += stepX
                    side = 0
                else:
                    sideDistY += deltaDistY
                    mapY += stepY
                    side = 1
                # check if ray has hit a wall
                if self.world_map[mapX][mapY] > 0:
                    hit = 1

            if side == 0:
                perpWallDist = (mapX - self.posX +
                                (1 - stepX) / 2) / (rayDirX + 0.00000001)
            else:
                perpWallDist = (mapY - self.posY +
                                (1 - stepY) / 2) / (rayDirY + 0.00000001)

            lineHeight = int(SCREEN_HEIGHT / (perpWallDist + 0.00000001))

            drawStart = -lineHeight / 2 + SCREEN_HEIGHT / 2
            if drawStart < 0:
                drawStart = 0

            drawEnd = lineHeight / 2 + SCREEN_HEIGHT / 2
            if drawEnd >= SCREEN_HEIGHT:
                drawEnd = SCREEN_HEIGHT - 1

            # texturing calculations
            tex_num = self.world_map[mapX][
                mapY] - 1  # 1 subtracted from it so that texture 0 acn be used!

            # calculate value of wallX
            wallX = None  # where exactly the wall was hit
            if side == 0:
                wallX = self.posY + perpWallDist * rayDirY
            else:
                wallX = self.posX + perpWallDist * rayDirX

            wallX -= math.floor(wallX)

            # x coordinate on the texture
            texX = int(wallX * TEX_WIDTH)
            if side == 0 and rayDirX > 0:
                texX = TEX_WIDTH - texX - 1
            if side == 1 and rayDirY < 0:
                texX = TEX_WIDTH - texX - 1

            if side == 0:
                try:
                    color = self.color_list[self.world_map[mapX][mapY]]
                except IndexError:
                    color = arcade.color.YELLOW
            elif side == 1:
                try:
                    color = self.dark_color_list[self.world_map[mapX][mapY]]
                except IndexError:
                    color = arcade.color.DARK_YELLOW
            '''# how much to increase the texture coordinate per screen pixel
            step = 1.0 * TEX_HEIGHT / lineHeight
            tex_pos = (drawStart - SCREEN_HEIGHT / 2 + lineHeight / 2) * step
            for y in range(drawStart, drawEnd):
                texY = int(tex_pos)
                tex_pos += step

                if side == 1:
                    tex_to_use = self.alt_texture
                else:
                    tex_to_use = self.texture'''

            draw_start_pos = (x, drawStart)
            draw_end_pos = (x, drawEnd)
            point_list.append(draw_end_pos)
            point_list.append(draw_start_pos)
            for i in range(2):
                color_list.append(color)

            # self.shape_list.append(arcade.create_line(x, drawStart, x, drawEnd, color, self.render_resolution))
        shape = arcade.create_line_generic_with_colors(point_list, color_list,
                                                       3)
        self.shape_list.append(shape)

        self.oldTime = self.time
        self.time += delta_time

        self.frameTime = (
            self.time - self.oldTime
        )  # frameTime is the time this frame has taken in seconds
        # print(1.0 / self.frameTime)  # FPS counter
        FPS = 1 / self.frameTime
        if FPS < self.min_fps:
            self.render_resolution += 1
        elif FPS > self.max_fps:
            self.render_resolution -= 1
        self.move_speed = self.frameTime * MOVE_SPEED  # constant value in squares/second
        self.rotation_speed = self.frameTime * ROTATION_SPEED  # constant value in radians/second

        # print(self.rotation_speed)

        if self.moveForward:
            if not self.world_map[int(self.posX +
                                      self.dirX * self.move_speed)][int(
                                          self.posY)]:
                self.posX += self.dirX * self.move_speed
            if not self.world_map[int(
                    self.posX)][int(self.posY + self.dirY * self.move_speed)]:
                self.posY += self.dirY * self.move_speed
        elif self.moveBackward:
            if not self.world_map[int(self.posX -
                                      self.dirX * self.move_speed)][int(
                                          self.posY)]:
                self.posX -= self.dirX * self.move_speed
            if not self.world_map[int(
                    self.posX)][int(self.posY - self.dirY * self.move_speed)]:
                self.posY -= self.dirY * self.move_speed

        if self.strafeLeft:
            if not self.world_map[int(self.posX -
                                      self.dirY * self.move_speed)][int(
                                          self.posY)]:
                self.posX -= self.dirY * self.move_speed
            if not self.world_map[int(
                    self.posX)][int(self.posY + self.dirX * self.move_speed)]:
                self.posY += self.dirX * self.move_speed
        elif self.strafeRight:
            if not self.world_map[int(self.posX +
                                      self.dirY * self.move_speed)][int(
                                          self.posY)]:
                self.posX += self.dirY * self.move_speed
            if not self.world_map[int(
                    self.posX)][int(self.posY - self.dirX * self.move_speed)]:
                self.posY -= self.dirX * self.move_speed

        if self.rotateLeft:
            # both camera direction and camera plane must be rotated
            oldDirX = self.dirX
            self.dirX = self.dirX * math.cos(
                self.rotation_speed) - self.dirY * math.sin(
                    self.rotation_speed)
            self.dirY = oldDirX * math.sin(
                self.rotation_speed) + self.dirY * math.cos(
                    self.rotation_speed)
            oldPlaneX = self.planeX
            self.planeX = self.planeX * math.cos(
                self.rotation_speed) - self.planeY * math.sin(
                    self.rotation_speed)
            self.planeY = oldPlaneX * math.sin(
                self.rotation_speed) + self.planeY * math.cos(
                    self.rotation_speed)
        elif self.rotateRight:
            # both camera direction and camera plane must be rotated
            oldDirX = self.dirX
            self.dirX = self.dirX * math.cos(
                -self.rotation_speed) - self.dirY * math.sin(
                    -self.rotation_speed)
            self.dirY = oldDirX * math.sin(
                -self.rotation_speed) + self.dirY * math.cos(
                    -self.rotation_speed)
            oldPlaneX = self.planeX
            self.planeX = self.planeX * math.cos(
                -self.rotation_speed) - self.planeY * math.sin(
                    -self.rotation_speed)
            self.planeY = oldPlaneX * math.sin(
                -self.rotation_speed) + self.planeY * math.cos(
                    -self.rotation_speed)
Esempio n. 5
0
    def setup(
        self,
        config: Dict[str, bool],
        attack: ProgramType,
        defend: ProgramType,
        o_attack: ProgramType,
        o_defend: ProgramType,
    ):
        """set up everything"""

        # background
        self.background: arcade.Texture = arcade.load_texture(
            "images/field.jpg")

        # pymunk space
        self.space: pymunk.Space = pymunk.Space()
        self.space.gravity = (0, 0)
        # self.space.damping = 0.4
        self.space.collision_slop = 0.1

        # lists
        self.dynamicSpriteList = arcade.SpriteList()
        self.arrowsList = arcade.ShapeElementList()

        # field elements
        body = pymunk.Body(body_type=pymunk.Body.STATIC)
        self.space.add(body)

        # walls
        walls = [
            pymunk.Segment(body, (0, 0), (SCREEN_WIDTH, 0), 2.0),
            pymunk.Segment(body, (0, 0), (0, SCREEN_HEIGHT), 2.0),
            pymunk.Segment(body, (0, SCREEN_HEIGHT),
                           (SCREEN_WIDTH, SCREEN_HEIGHT), 2.0),
            pymunk.Segment(body, (SCREEN_WIDTH, SCREEN_HEIGHT),
                           (SCREEN_WIDTH, 0), 2.0),
        ]
        for line in walls:
            line.friction = 0.7
            line.elasticity = 0.6
            line.filter = pymunk.ShapeFilter(categories=1)
        self.space.add(*walls)

        # goals
        goals = [
            pymunk.Segment(body, (180, 78), (SCREEN_WIDTH - 180, 78),
                           2.0),  # yellow crossbar
            pymunk.Segment(
                body,
                (180, SCREEN_HEIGHT - 78),
                (SCREEN_WIDTH - 180, SCREEN_HEIGHT - 78),
                2.0,
            ),  # blue crossbar
            pymunk.Segment(body, (180, 60), (SCREEN_WIDTH - 180, 60), 2.0),
            pymunk.Segment(body, (180, 78), (180, 60), 2.0),
            pymunk.Segment(body, (SCREEN_WIDTH - 180, 78),
                           (SCREEN_WIDTH - 180, 60), 2.0),
            pymunk.Segment(
                body,
                (180, SCREEN_HEIGHT - 60),
                (SCREEN_WIDTH - 180, SCREEN_HEIGHT - 60),
                2.0,
            ),
            pymunk.Segment(body, (180, SCREEN_HEIGHT - 78),
                           (180, SCREEN_HEIGHT - 60), 2.0),
            pymunk.Segment(
                body,
                (SCREEN_WIDTH - 180, SCREEN_HEIGHT - 78),
                (SCREEN_WIDTH - 180, SCREEN_HEIGHT - 60),
                2.0,
            ),
        ]
        for idx, line in enumerate(goals):
            line.elasticity = 0.9
            if idx < 2:
                line.friction = 0.2
                line.filter = pymunk.ShapeFilter(categories=2)
            else:
                line.friction = 1
                line.filter = pymunk.ShapeFilter(categories=1)
        self.space.add(*goals)

        # white lines around the field
        self.fieldLines = [
            pymunk.Segment(body, (77, 77), (77, SCREEN_HEIGHT - 77), 4.0),
            pymunk.Segment(
                body,
                (77, SCREEN_HEIGHT - 77),
                (SCREEN_WIDTH - 77, SCREEN_HEIGHT - 77),
                4.0,
            ),
            pymunk.Segment(
                body,
                (SCREEN_WIDTH - 77, SCREEN_HEIGHT - 77),
                (SCREEN_WIDTH - 77, 77),
                4.0,
            ),
            pymunk.Segment(body, (SCREEN_WIDTH - 77, 77), (77, 77), 4.0),
        ]
        for line in self.fieldLines:
            line.filter = pymunk.ShapeFilter(categories=4)
            line.collision_type = 3
        self.space.add(*self.fieldLines)

        # penalty area lines
        self.penaltyLines = [
            pymunk.Circle(body, 40, (210, 110)),
            pymunk.Circle(body, 40, (210, SCREEN_HEIGHT - 110)),
            pymunk.Circle(body, 40, (SCREEN_WIDTH - 210, 110)),
            pymunk.Circle(body, 40, (SCREEN_WIDTH - 210, SCREEN_HEIGHT - 110)),
            pymunk.Segment(body, (171, 77), (171, 112), 4.0),
            pymunk.Segment(body, (211, 152), (SCREEN_WIDTH - 211, 152), 4.0),
            pymunk.Segment(body, (SCREEN_WIDTH - 171, 77),
                           (SCREEN_WIDTH - 171, 112), 4.0),
            pymunk.Segment(body, (171, SCREEN_HEIGHT - 77),
                           (171, SCREEN_HEIGHT - 112), 4.0),
            pymunk.Segment(
                body,
                (211, SCREEN_HEIGHT - 152),
                (SCREEN_WIDTH - 211, SCREEN_HEIGHT - 152),
                4.0,
            ),
            pymunk.Segment(
                body,
                (SCREEN_WIDTH - 171, SCREEN_HEIGHT - 77),
                (SCREEN_WIDTH - 171, SCREEN_HEIGHT - 112),
                4.0,
            ),
        ]
        for line in self.penaltyLines:
            line.filter = pymunk.ShapeFilter(categories=4)
            line.collision_type = 3
        self.space.add(*self.penaltyLines)

        # robots
        self.robots = [
            Robot(
                "images/robot.png",
                0.02176,
                2.1,
                SCREEN_WIDTH / 2,
                SCREEN_HEIGHT * 17 / 40,
                orientation=0,
            ),
            Robot(
                "images/robot.png",
                0.02176,
                2.1,
                SCREEN_WIDTH / 2,
                SCREEN_HEIGHT / 6,
                orientation=0,
            ),
            Robot(
                "images/enemy.png",
                0.01611170784103114930182599355532,
                2.1,
                SCREEN_WIDTH / 2,
                SCREEN_HEIGHT * 7 / 10,
            ),
            Robot(
                "images/enemy.png",
                0.01611170784103114930182599355532,
                2.1,
                SCREEN_WIDTH / 2,
                SCREEN_HEIGHT * 5 / 6,
            ),
        ]
        for i in range(4):
            self.dynamicSpriteList.append(self.robots[i].sprite)
            self.robots[i].sprite.shape.filter = pymunk.ShapeFilter(
                categories=8, mask=pymunk.ShapeFilter.ALL_MASKS() ^ 0b100)
            self.robots[i].sprite.shape.collision_type = 1
            self.j1 = pymunk.constraints.PivotJoint(
                self.robots[i].targetPointBody,
                self.robots[i].sprite.body,
                (0, 0),
                (0, 0),
            )
            self.j1.max_force = 7000
            self.j1.max_bias = 0
            self.j2 = pymunk.constraints.GearJoint(
                self.robots[i].targetPointBody, self.robots[i].sprite.body, 0,
                1)
            self.j2.max_force = 50000
            self.space.add(
                self.robots[i].sprite.body,
                self.robots[i].sprite.shape,
                self.j1,
                self.j2,
            )

        # ball
        self.ball = PymunkSprite(
            "images/ball.png",
            0.01897533206831119544592030360531,
            0.07,
            SCREEN_WIDTH / 2,
            SCREEN_HEIGHT / 2,
        )
        self.dynamicSpriteList.append(self.ball)
        self.ball.shape.filter = pymunk.ShapeFilter(
            categories=16, mask=pymunk.ShapeFilter.ALL_MASKS() ^ 0b110)
        self.ball.shape.collision_type = 2
        self.space.add(self.ball.body, self.ball.shape)
        self.ballAngle = 0
        self.j1 = pymunk.constraints.PivotJoint(self.space.static_body,
                                                self.ball.body, (0, 0), (0, 0))
        self.j1.max_force = 10
        self.j1.max_bias = 0
        self.j2 = pymunk.constraints.GearJoint(self.space.static_body,
                                               self.ball.body, 0, 1)
        self.j2.max_force = 1000
        self.space.add(self.j1, self.j2)

        # programs
        self.pconfig = config
        self.attack = attack
        self.defend = defend
        self.o_attack = o_attack
        self.o_defend = o_defend
 def setup(self):
     self.draw_buffer = arcade.ShapeElementList()
Esempio n. 7
0
    def __init__(self,
                 text: str,
                 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,
                 text_color: Union[Tuple[int, int, int],
                                   Tuple[int, int, int,
                                         int]] = arcade.color.BLACK,
                 bold: bool = False,
                 italic: bool = False,
                 font_name: Union[str, Tuple[str, ...]] = ('calibri', 'arial'),
                 font_size: float = 12,
                 anchor_x: str = 'center',
                 anchor_y: str = 'center',
                 horizontal_margin: float = 5,
                 vertical_margin: float = 5,
                 **kwargs):
        for k, v in kwargs.items():
            setattr(self, k, v)

        self._text = text

        self._orig_cx = center_x
        self._orig_cy = center_y

        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.text_color = text_color
        self.bold = bold
        self.italic = italic
        self.font_name = font_name
        self.font_size = font_size

        self.anchor_x = anchor_x
        self.anchor_y = anchor_y

        self.horizontal_margin = horizontal_margin
        self.vertical_margin = vertical_margin

        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)

        if anchor_x == 'left':
            self.start_x = center_x - (width / 2) + horizontal_margin
        elif anchor_x == 'center':
            self.start_x = center_x
        elif anchor_x == 'right':
            self.start_x = center_x + (width / 2) - horizontal_margin
        else:
            raise ValueError(
                'ListView.start_x must be "left", "center", or "right"')

        if anchor_y == 'bottom':
            self.start_y = center_y - (height / 2) + vertical_margin
        elif anchor_y == 'center':
            self.start_y = center_y
        elif anchor_y == 'top':
            self.start_y = center_y + (height / 2) - vertical_margin
        else:
            raise ValueError(
                'ListView.start_y must be "bottom", "center", or "top"')

        self.text_sprite = arcade.draw_text(text=text,
                                            start_x=self.start_x,
                                            start_y=self.start_y,
                                            color=text_color,
                                            font_name=font_name,
                                            font_size=font_size,
                                            bold=bold,
                                            italic=italic,
                                            anchor_x=anchor_x,
                                            anchor_y=anchor_y)
        arcade.text.draw_text_cache.clear()
Esempio n. 8
0
    def __init__(self, width, height, title):
        """
        Set up the application.
        """
        super().__init__(width, height, title)

        self.shape_list = arcade.ShapeElementList()
        self.shape_list.center_x = SCREEN_WIDTH // 2
        self.shape_list.center_y = SCREEN_HEIGHT // 2
        self.shape_list.angle = 0
        point_list = ((0, 50),
                      (10, 10),
                      (50, 0),
                      (10, -10),
                      (0, -50),
                      (-10, -10),
                      (-50, 0),
                      (-10, 10),
                      (0, 50))
        colors = [
            getattr(arcade.color, color)
            for color in dir(arcade.color)
            if not color.startswith("__")
        ]
        for i in range(5):
            x = SCREEN_WIDTH // 2 - random.randrange(SCREEN_WIDTH - 50)
            y = SCREEN_HEIGHT // 2 - random.randrange(SCREEN_HEIGHT - 50)
            color = random.choice(colors)
            points = [(px + x, py + y) for px, py in point_list]

            my_line_strip = arcade.create_line_strip(points, color, 5)
            self.shape_list.append(my_line_strip)

        point_list = ((-50, -50),
                      (0, 40),
                      (50, -50))
        for i in range(5):
            x = SCREEN_WIDTH // 2 - random.randrange(SCREEN_WIDTH - 50)
            y = SCREEN_HEIGHT // 2 - random.randrange(SCREEN_HEIGHT - 50)
            points = [(px + x, py + y) for px, py in point_list]
            triangle_filled = arcade.create_triangles_filled_with_colors(
                points,
                random.sample(colors, 3)
            )
            self.shape_list.append(triangle_filled)

        point_list = ((-50, -70),
                      (-50, 70),
                      (50, 70),
                      (50, -70))
        for i in range(5):
            x = SCREEN_WIDTH // 2 - random.randrange(SCREEN_WIDTH - 50)
            y = SCREEN_HEIGHT // 2 - random.randrange(SCREEN_HEIGHT - 50)
            points = [(px + x, py + y) for px, py in point_list]
            rect_filled = arcade.create_rectangle_filled_with_colors(
                points,
                random.sample(colors, 4)
            )
            self.shape_list.append(rect_filled)

        point_list = ((100, 100),
                      (50, 150),
                      (100, 200),
                      (200, 200),
                      (250, 150),
                      (200, 100))
        poly = arcade.create_polygon(point_list, (255, 10, 10))
        self.shape_list.append(poly)

        ellipse = arcade.create_ellipse(20, 30, 50, 20, (230, 230, 0))
        self.shape_list.append(ellipse)

        arcade.set_background_color(arcade.color.BLACK)

        self.offscreen = self.ctx.framebuffer(
            color_attachments=self.ctx.texture((SCREEN_WIDTH, SCREEN_HEIGHT), wrap_x=gl.GL_CLAMP_TO_EDGE, wrap_y=gl.GL_CLAMP_TO_EDGE))
        self.glow = postprocessing.BloomEffect((SCREEN_WIDTH, SCREEN_HEIGHT))
Esempio n. 9
0
def make_pool(center_x, center_y, width, height):
    radius = 50

    top_right_x = center_x + width / 2
    top_right_y = center_y + height / 2

    bottom_right_x = center_x + width / 2
    bottom_right_y = center_y - height / 2

    center_left_x = center_x - width / 2
    center_left_y = center_y

    offset_x = center_x - width / 2
    offset_y = center_y - height / 2

    a = height * (1 / 5)
    p_width = width * (1 - a / height)
    p_height = height - 2 * a
    p_center_x = offset_x + p_width / 2
    p_center_y = center_y

    b = height / 3
    g_width = width * (1 - b / height)
    g_height = height - 2 * b
    g_center_x = offset_x + g_width / 2
    g_center_y = center_y

    shape_list = arcade.ShapeElementList()

    shape = arcade.create_rectangle_filled(center_x, center_y, width, height,
                                           arcade.color.WHITE)
    shape_list.append(shape)

    shape = arcade.create_ellipse_outline(center_x, center_y, radius, radius,
                                          arcade.color.BLACK)

    shape_list.append(shape)

    shape = arcade.create_line(center_x, center_y, top_right_x, top_right_y,
                               arcade.color.BLACK)

    shape_list.append(shape)

    shape = arcade.create_line(center_x, center_y, bottom_right_x,
                               bottom_right_y, arcade.color.BLACK)

    shape_list.append(shape)

    shape = arcade.create_line(center_x, center_y, center_left_x,
                               center_left_y, arcade.color.BLACK)

    shape_list.append(shape)

    shape = arcade.create_rectangle_outline(p_center_x, p_center_y, p_width,
                                            p_height, arcade.color.BLACK)

    shape_list.append(shape)

    shape = arcade.create_rectangle_outline(g_center_x, g_center_y, g_width,
                                            g_height, arcade.color.BLACK)

    shape_list.append(shape)

    shape = arcade.create_line(p_center_x, offset_y, p_center_x, offset_y + a,
                               arcade.color.BLACK)

    shape_list.append(shape)

    shape = arcade.create_line(p_center_x, offset_y + a + p_height, p_center_x,
                               offset_y + 2 * a + p_height, arcade.color.BLACK)

    shape_list.append(shape)

    shape = arcade.create_line(offset_x + p_width, center_y, offset_x + width,
                               center_y, arcade.color.BLACK)

    shape_list.append(shape)

    return shape_list
Esempio n. 10
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
Esempio n. 11
0
 def __init__(self, width, height, title):
     super().__init__(width, height, title)
     self.shape_list = arcade.ShapeElementList()
     arcade.set_background_color(arcade.color.ASH_GREY)
     self.setup()
Esempio n. 12
0
import arcade, random

# setting variables
SCREEN_WIDTH = 500
SCREEN_HEIGHT = 500

WIDTH = 1500
HEIGHT = 100

ROW_COUNT = 5
COLUMN_COUNT = 1

finish = 1500

box = arcade.ShapeElementList()

box_x_position = []
box_y_position = []
grid = []

up_pressed = False
down_pressed = False
left_pressed = False
right_pressed = False
collision = False

player_x = 50
player_y = 250

# setting images
Esempio n. 13
0
arcade.start_render()

arcade.draw_lrtb_rectangle_filled(10, 200, 300, 10, arcade.color.BLACK)
arcade.draw_rectangle_filled(390, 150, 45, 105, arcade.color.BLUSH)

arcade.draw_triangle_filled(500, 500, 400, 300, 600, 300, arcade.color.BLACK)
arcade.draw_xywh_rectangle_filled(500, 200, 100, 100, arcade.color.BLACK)

arcade.finish_render()
arcade.quick_run(3)

import arcade

arcade.open_window(800, 600, "Drawing Example")
arcade.set_background_color(arcade.color.WHITE)
my_list = arcade.ShapeElementList()
my_shape = arcade.create_ellipse_outline(50, 50, 20, 20, arcade.color.RED, 45)
my_list.append(my_shape)
my_shape = arcade.create_ellipse_filled(50, 50, 20, 20, arcade.color.RED, 2,
                                        45)
my_list.append(my_shape)
my_shape = arcade.create_rectangle_filled(250, 50, 20, 20, arcade.color.RED,
                                          45)
my_list.append(my_shape)
my_shape = arcade.create_rectangle_outline(450, 50, 20, 20, (127, 0, 27, 127),
                                           2, 45)
my_list.append(my_shape)
my_shape = arcade.create_lines_with_colors(
    ([0, 400], [700, 400]), ((127, 0, 27, 127), arcade.color.GREEN), 2)
my_list.append(my_shape)
my_list.move(5, 5)
Esempio n. 14
0
 def __init__(self):
     self.shapes: Dict[Tuple[int, int], Shape] = {}
     self.shape_list = arcade.ShapeElementList()
     self.meta = {}
     self._dirty = False
Esempio n. 15
0
 def draw(self):
     print('draw', len(self.debug_list))
     self.debug_list.draw()
     self.debug_list = arcade.ShapeElementList()
def make_skyline(width,
                 skyline_height,
                 skyline_color,
                 gap_chance=0.70,
                 window_chance=0.30,
                 light_on_chance=0.5,
                 window_color=(255, 255, 200),
                 window_margin=3,
                 window_gap=2,
                 cap_chance=0.20):
    """ Make a skyline """

    shape_list = arcade.ShapeElementList()

    # Add the "base" that we build the buildings on
    shape = arcade.create_rectangle_filled(width / 2, skyline_height / 2,
                                           width, skyline_height,
                                           skyline_color)
    shape_list.append(shape)

    building_center_x = 0

    skyline_point_list = []
    color_list = []

    while building_center_x < width:

        # Is there a gap between the buildings?
        if random.random() < gap_chance:
            gap_width = random.randrange(10, 50)
        else:
            gap_width = 0

        # Figure out location and size of building
        building_width = random.randrange(20, 70)
        building_height = random.randrange(40, 150)
        building_center_x += gap_width + (building_width / 2)
        building_center_y = skyline_height + (building_height / 2)

        x1 = building_center_x - building_width / 2
        x2 = building_center_x + building_width / 2
        y1 = skyline_height
        y2 = skyline_height + building_height

        skyline_point_list.append([x1, y1])

        skyline_point_list.append([x1, y2])

        skyline_point_list.append([x2, y2])

        skyline_point_list.append([x2, y1])

        for i in range(4):
            color_list.append(
                [skyline_color[0], skyline_color[1], skyline_color[2]])

        if random.random() < cap_chance:
            x1 = building_center_x - building_width / 2
            x2 = building_center_x + building_width / 2
            x3 = building_center_x

            y1 = y2 = building_center_y + building_height / 2
            y3 = y1 + building_width / 2

            shape = arcade.create_polygon([[x1, y1], [x2, y2], [x3, y3]],
                                          skyline_color)
            shape_list.append(shape)

        # See if we should have some windows
        if random.random() < window_chance:
            # Yes windows! How many windows?
            window_rows = random.randrange(10, 15)
            window_columns = random.randrange(1, 7)

            # Based on that, how big should they be?
            window_height = (building_height - window_margin * 2) / window_rows
            window_width = (building_width - window_margin * 2 - window_gap *
                            (window_columns - 1)) / window_columns

            # Find the bottom left of the building so we can start adding widows
            building_base_y = building_center_y - building_height / 2
            building_left_x = building_center_x - building_width / 2

            # Loop through each window
            for row in range(window_rows):
                for column in range(window_columns):
                    if random.random() < light_on_chance:
                        x1 = building_left_x + column * (
                            window_width + window_gap) + window_margin
                        x2 = building_left_x + column * (
                            window_width +
                            window_gap) + window_width + window_margin
                        y1 = building_base_y + row * window_height
                        y2 = building_base_y + row * window_height + window_height * .8

                        skyline_point_list.append([x1, y1])
                        skyline_point_list.append([x1, y2])
                        skyline_point_list.append([x2, y2])
                        skyline_point_list.append([x2, y1])

                        for i in range(4):
                            color_list.append(
                                (window_color[0], window_color[1],
                                 window_color[2]))

        building_center_x += (building_width / 2)

    shape = arcade.create_rectangles_filled_with_colors(
        skyline_point_list, color_list)
    shape_list.append(shape)

    return shape_list
Esempio n. 17
0
 def __init__(self, level, name):
     super().__init__(level, name)
     badwing.app.debug_layer = self
     self.debug_list = arcade.ShapeElementList()
Esempio n. 18
0
    def __init__(self, width, height, title):
        """
        Set up the application.
        """

        super().__init__(width, height, title)

        arcade.set_background_color(arcade.color.BLACK)

        self.shapes = arcade.ShapeElementList()

        # This is a large rectangle that fills the whole
        # background. The gradient goes between the two colors
        # top to bottom.
        color1 = (215, 214, 165)
        color2 = (219, 166, 123)
        points = (0, 0), (SCREEN_WIDTH, 0), (SCREEN_WIDTH,
                                             SCREEN_HEIGHT), (0, SCREEN_HEIGHT)
        colors = (color1, color1, color2, color2)
        rect = arcade.create_rectangle_filled_with_colors(points, colors)
        self.shapes.append(rect)

        # Another rectangle, but in this case the color doesn't change. Just the
        # transparency. This time it goes from left to right.
        color1 = (165, 92, 85, 255)
        color2 = (165, 92, 85, 0)
        points = (100, 100), (SCREEN_WIDTH - 100, 100), (SCREEN_WIDTH - 100,
                                                         300), (100, 300)
        colors = (color2, color1, color1, color2)
        rect = arcade.create_rectangle_filled_with_colors(points, colors)
        self.shapes.append(rect)

        # Two lines
        color1 = (7, 67, 88)
        color2 = (69, 137, 133)
        points = (100, 400), (SCREEN_WIDTH - 100, 400), (SCREEN_WIDTH - 100,
                                                         500), (100, 500)
        colors = (color2, color1, color2, color1)
        shape = arcade.create_lines_with_colors(points, colors, line_width=5)
        self.shapes.append(shape)

        # Triangle
        color1 = (215, 214, 165)
        color2 = (219, 166, 123)
        color3 = (165, 92, 85)
        points = (SCREEN_WIDTH // 2, 500), (SCREEN_WIDTH // 2 - 100,
                                            400), (SCREEN_WIDTH // 2 + 100,
                                                   400)
        colors = (color1, color2, color3)
        shape = arcade.create_triangles_filled_with_colors(points, colors)
        self.shapes.append(shape)

        # Ellipse, gradient between center and outside
        color1 = (69, 137, 133, 127)
        color2 = (7, 67, 88, 127)
        shape = arcade.create_ellipse_filled_with_colors(SCREEN_WIDTH // 2,
                                                         350,
                                                         50,
                                                         50,
                                                         inside_color=color1,
                                                         outside_color=color2)
        self.shapes.append(shape)
Esempio n. 19
0
    def __init__(self, client):
        super().__init__(width=SCREEN_WIDTH,
                         height=SCREEN_HEIGHT,
                         title=SCREEN_TITLE)
        arcade.set_background_color(arcade.color.AMAZON)

        self.client = client  # Client used to send events to the server and to receive game state updates.
        self.GS = None  # Current game state

        self.connection: bool = False  # Server connection
        self.player_name: str = ""  # Player's name
        self.player_id = None  # Player's integer id assigned by the server

        # GUI Elements:
        self.shapes = arcade.ShapeElementList()
        self.center_x = int(SCREEN_WIDTH / 2)
        self.center_y = int(SCREEN_HEIGHT / 2)
        self.third_line_y = int(2 * SCREEN_HEIGHT / 3) + 50

        # Gradient Background:
        self.generate_gradient_background()

        # Player Names and Locations:
        self.name_tabs = {}  # store NameTab objects
        self.name_loc = {
            'bot': (self.center_x,
                    int(NAME_HEIGHT / 2)),  # locations of NameTab objects
            'left': (int(NAME_WIDTH / 2), self.third_line_y),
            'top': (self.center_x, int(SCREEN_HEIGHT - NAME_HEIGHT / 2)),
            'right': (int(SCREEN_WIDTH - NAME_WIDTH / 2), self.third_line_y)
        }
        self.player_locations = {}  # KEY: int   VALUE: (x, y)

        # Buttons:
        self.info_btn = TextButton(center_x=SCREEN_WIDTH - BUTTON_WIDTH / 2 -
                                   MARGIN,
                                   center_y=BUTTON_HEIGHT / 2 + MARGIN,
                                   width=BUTTON_WIDTH,
                                   height=BUTTON_HEIGHT,
                                   text='Info',
                                   action_function=self.info_btn_click,
                                   face_color=arcade.color.AIR_FORCE_BLUE)
        self.burn_btn = TextButton(center_x=SCREEN_WIDTH -
                                   5 * BUTTON_WIDTH / 2 - 3 * MARGIN,
                                   center_y=BUTTON_HEIGHT / 2 + MARGIN,
                                   width=BUTTON_WIDTH,
                                   height=BUTTON_HEIGHT,
                                   text='Burn',
                                   action_function=self.burn_btn_click,
                                   face_color=arcade.color.ALMOND)
        self.place_btn = TextButton(center_x=SCREEN_WIDTH -
                                    3 * BUTTON_WIDTH / 2 - 2 * MARGIN,
                                    center_y=BUTTON_HEIGHT / 2 + MARGIN,
                                    width=BUTTON_WIDTH,
                                    height=BUTTON_HEIGHT,
                                    text='Place',
                                    action_function=self.place_btn_click,
                                    face_color=arcade.color.BLOND)
        self.pull_btn = TextButton(center_x=BUTTON_WIDTH / 2 + MARGIN,
                                   center_y=BUTTON_HEIGHT / 2 + MARGIN,
                                   width=BUTTON_WIDTH,
                                   height=BUTTON_HEIGHT,
                                   text='PULL',
                                   action_function=self.pull_btn_click,
                                   face_color=arcade.color.ORANGE)
        self.next_btn = TextButton(center_x=3 * BUTTON_WIDTH / 2 + 2 * MARGIN,
                                   center_y=BUTTON_HEIGHT / 2 + MARGIN,
                                   width=BUTTON_WIDTH,
                                   height=BUTTON_HEIGHT,
                                   text='NEXT',
                                   action_function=self.next_btn_click,
                                   face_color=arcade.color.BARBIE_PINK)

        self.buttons = [
            self.info_btn, self.burn_btn, self.place_btn, self.pull_btn,
            self.next_btn
        ]

        # Cards:
        self.cards_generated = False
        self.card_tab_list = CardTabList()  # Card Tab arcade.Spritelist
        self.selected_card_tab = None

        # Message Pop-up:
        self.message_text = None  # text to display as a message
        self.message_timer = None  # time of the message popup start
        self.message_duration = 2.0  # seconds for the message to disappear

        # Some game state logic on the client side:
        self.action_done = False

        # Keep track of the top card in the discard pile and the number of cards here to keep track.
        self.discard_pile_card_tabs_top = None
        self.discard_pile_size = 0
    def on_draw(self):
        arcade.start_render()
        if self.state == "GameMenu":
            arcade.draw_text("Snail Game", 400, 300,
                             arcade.color.WHITE, font_size=60, anchor_x="center")
            arcade.draw_text("Press  'ENTER' To Start Game",
                             400, 250, arcade.color.WHITE, font_size=30, anchor_x="center")
        elif self.state == "GameOn":
            self.shape_list = arcade.ShapeElementList()
            # updating scores on screen
            ouput1 = f"Score: {self.score_1}"
            ouput2 = f"Score: {self.score_2}"
            # drawing scores for both players
            arcade.draw_text(ouput1,
                             630, 160, arcade.color.WHITE, font_size=26)
            arcade.draw_text(ouput2,
                             630, 390, arcade.color.WHITE, font_size=26)

            # drawing for Player 1
            arcade.draw_text("Player 1 ",
                             640, 540, arcade.color.WHITE, font_size=30)
            arcade.draw_lrwh_rectangle_textured(640, 440, 100, 80, display)
            arcade.draw_rectangle_outline(700, 490, 178, 200,
                                          arcade.color.GREEN, 4)
            # drawing for Player 2
            arcade.draw_rectangle_outline(700, 260, 178, 210,
                                          arcade.color.GREEN, 4)
            arcade.draw_text("Player 2",
                             640, 310, arcade.color.WHITE, font_size=30)
            arcade.draw_lrwh_rectangle_textured(640, 200, 100, 100, circle)
            # drawing  turn
            arcade.draw_rectangle_outline(700, 70, 178, 115,
                                          arcade.color.GREEN, 4)

            arcade.draw_text("TURN",
                             655, 90, arcade.color.BABY_BLUE, font_size=25)
            #displaying turn of player                 
            if self.turn == "Human":
                arcade.draw_text("Player '2'",
                                 645, 40, arcade.color.RASPBERRY, font_size=24)
            elif self.turn == "bot":
                arcade.draw_text("Player '1'",
                                 645, 40, arcade.color.RAJAH, font_size=24)
            #drawing lines                     
            for i in range(0, 600, 60):
                arcade.draw_line(0, i, 600, i, arcade.color.WHITE, 2)

            for i in range(0, 660, 60):
                arcade.draw_line(i, 0, i, 600, arcade.color.WHITE, 2)
            #checking where to have snails and their splashes
            x = 0
            y = 540
            for i in range(10):
                for j in range(10):
                    if self.board[i][j] == 1:
                        arcade.draw_lrwh_rectangle_textured(
                            x, y, 60, 60, splash1)
                    elif self.board[i][j] == 2:
                        arcade.draw_lrwh_rectangle_textured(
                            x, y, 60, 60, splash2)
                    elif self.board[i][j] == 10:
                        arcade.draw_lrwh_rectangle_textured(
                            x, y, 60, 60, cross)
                    elif self.board[i][j] == 20:
                        arcade.draw_lrwh_rectangle_textured(
                            x, y, 60, 60, circle)
                    x = x+60
                x = 0
                y = y-60
                #win condition  
            if self.score_1 > 50 or self.score_2 > 50:
                self.state="win"
        #changing game state
        elif self.state == "win":
            if self.score_1 > self.score_2 :
                arcade.draw_text("Player '2' WON",
                                 400, 300, arcade.color.RAJAH, font_size=40, anchor_x="center")
            elif self.score_1 < self.score_2 :
                arcade.draw_text("Player '1' WON",
                                 400, 300, arcade.color.RAJAH, font_size=40, anchor_x="center")
            else:
                arcade.draw_text("DRAW",
                                 400, 300, arcade.color.RAJAH, font_size=40, anchor_x="center")
left_pressed = False
right_pressed = False
up_pressed = False
down_pressed = False
collision = False
shoot = False

player_x = 250
player_y = 100

texture_spaceship = arcade.load_texture("spaceship2 (1).jpg")
texture_background = arcade.load_texture("TWGty9.jpg")
texture_gameover = arcade.load_texture("background.png")
texture_ALien = arcade.load_texture("ALIEN2.png")
ALIEN = arcade.ShapeElementList()

texture_ALien_x_positions = []
texture_ALien_y_positions = []

for _ in range(20):
    x = random.randrange(0, WIDTH)
    y = random.randrange(HEIGHT, HEIGHT * 2)

    texture_ALien_x_positions.append(x)
    texture_ALien_y_positions.append(y)


def setup():
    arcade.open_window(WIDTH, HEIGHT, "My Arcade Game")
    arcade.draw_texture_rectangle(320, 240, 640, 480, texture_background, 0)
Esempio n. 22
0
    def on_draw(self):
        """
        Render the screen.
        """

        # This command has to happen before we start drawing
        arcade.start_render()
        self._frames += 1

        #         arcade.draw_text("Test", 50, 50)

        if self.box.field is not None and self.box.field.equation != self.box.field.nofield:
            self.draw_field()

        if self.left_mouse_down:
            arcade.draw_line(self.mouse_x, self.mouse_y, self.mouse_dx,
                             self.mouse_dy, arcade.color.WHITE, 1)

        # draw avg impuls vector
        start = self.box.box_sizes / 2
        avg_impuls = self.box.avg_momentum()
        end = start + avg_impuls
        arcade.draw_line(*start[:2],
                         *end[:2],
                         color=arcade.color.WHITE,
                         line_width=1)

        self.arrow_list = None
        self.arrow_list = arcade.ShapeElementList()
        # if self.box.trail > 0:
        self.trail_list = None
        self.trail_list = arcade.ShapeElementList()

        while self.box.delete_particles:
            ball = self.box.delete_particles.pop()
            ball.object.kill()

        while self.box.merged_particles:
            ball = self.box.merged_particles.pop()
            ball.object.kill()
            # +D_SPRITE_RADIUS
            ball.object = arcade.SpriteCircle(
                int(ball.radius) + D_SPRITE_RADIUS, ball.color, True)
            self.ball_list.append(ball.object)

        for _, ball in enumerate(self.box.particles):
            #arcade.draw_circle_filled(ball.position[0], ball.position[1], ball.radius, ball.color)
            end = ball.position + ball.speed
            # arcade.draw_line(ball.position[0], ball.position[1], end[0], end[1], arcade.color.GRAY_ASPARAGUS, 2)
            arrow = arcade.create_line(ball.position[0], ball.position[1],
                                       end[0], end[1],
                                       arcade.color.GRAY_ASPARAGUS, 2)
            self.arrow_list.append(arrow)
            if ball.positions:
                positions = [(p[0], p[1]) for p in ball.positions]
                trail = arcade.create_line_strip(positions, arcade.color.GRAY,
                                                 1)
                self.trail_list.append(trail)

            output = ""
            if ball.charge < 0:
                output = "-"
            elif ball.charge > 0:
                output = "+"
            if ball.charge != 0 and len(
                    output) > 0 and self.box.interaction != 0:
                arcade.draw_text(output,
                                 ball.position[0] + 5,
                                 ball.position[1] - 10,
                                 arcade.color.WHITE,
                                 20,
                                 font_name="Calibri Bold")

            # output = str(i)
            # arcade.draw_text(output, ball.position[0]-0, ball.position[1]+0, arcade.color.WHITE, 8, font_name="Calibri Bold")

            ball.object.center_x = ball.position[0]
            ball.object.center_y = ball.position[1]
            if self.box.dimensions > DSIZE:
                ball.object.scale = ball.position[DSIZE] / self.box.box_sizes[
                    DSIZE]
            if self.box.dimensions > DALPHA:
                ball.object.alpha = 255 * (ball.position[DALPHA] /
                                           self.box.box_sizes[DALPHA]) % 255

        # draw springs
        for _, spring in enumerate(self.box.springs):
            v = MAXCOLOR + 1 / ((spring.dlength() / 10000) - INVMAXCOLOR)
            color = self.getcolor(v, 0, 255)
            if self.box.dimensions > DALPHA:
                pos = (spring.p1.position[DALPHA] +
                       spring.p2.position[DALPHA]) / 2
                alpha = 255 * (pos / self.box.box_sizes[DALPHA]) % 255
                color.append(alpha)
            arcade.draw_line(*spring.p1.position[:2],
                             *spring.p2.position[:2],
                             color=color,
                             line_width=1)

            # dpos = self.box.displacement(spring.p1.position, spring.p2.position)
            # # start = spring.p1.position
            # # end = spring.p1.position + dpos
            # start = self.box.center
            # end = self.box.center + dpos
            # arcade.draw_line(*start[:2], *end[:2], color=(255,0,0), line_width=2)

            # dpos = self.box._displacement(spring.p1.position, spring.p2.position)
            # # start = spring.p1.position
            # # end = spring.p1.position + dpos
            # start = self.box.center
            # end = self.box.center + dpos
            # arcade.draw_line(*start[:2], *end[:2], color=(0,255,0), line_width=2)

        # draw rods
        for _, rod in enumerate(self.box.rods):
            arcade.draw_line(*rod.p1.position[:2],
                             *rod.p2.position[:2],
                             color=arcade.color.GRAY,
                             line_width=2)

        self.arrow_list.draw()
        self.ball_list.draw()
        self.trail_list.draw()
        if self._draw_planes:
            self.plane_list.draw()
            self.hole_list.draw()
        #self.sprite_list.draw_hit_boxes((255,255,255), 2)

        if self.text:
            # Put the text on the screen.

            charge = sum(p.charge for p in self.box.particles)
            output = f"Ticks: {self.box.ticks}, Dimensions: {self.box.dimensions}, Balls: {len(self.box.particles)}, Charge: {charge}"
            arcade.draw_text(output, 10, 20, arcade.color.WHITE, 14)

            if self._frames < TEXT_REFRESH or self._frames % TEXT_REFRESH == 0:
                KE = self.box.energy["KE"]
                self._output["KE"] = f"Kinetic energy: {KE:.2f}"

                PE = self.box.energy["PE"]
                self._output["PE"] = f"Potential Energy: {PE:.2f}"

                SE = self.box.energy["SE"]
                self._output["SE"] = f"Spring Energy: {SE:.2f}"

                TE = KE + PE + SE
                self._output["TE"] = f"Total Energy: {TE:.2f}"

            try:
                arcade.draw_text(self._output["KE"], 10, 50,
                                 arcade.color.WHITE, 14)
                arcade.draw_text(self._output["PE"], 10, 80,
                                 arcade.color.WHITE, 14)
                arcade.draw_text(self._output["SE"], 10, 120,
                                 arcade.color.WHITE, 14)
                arcade.draw_text(self._output["TE"], 10, 150,
                                 arcade.color.WHITE, 14)
                # arcade.draw_text(self._output["R"], 10, 180, arcade.color.WHITE, 14)
            except KeyError:
                pass

            # output = "Avg Impuls: {}".format(self.box.avg_momentum())
            # arcade.draw_text(output, 10, 80, arcade.color.WHITE, 14)

            # P = self.box.pressure()
            # output = "pressure: {:}".format(P)
            # arcade.draw_text(output, 10, 110, arcade.color.WHITE, 14)

            # PV = self.box.pressure() * self.box.volume()
            # output = "PV: {:.2f}".format(PV)
            # arcade.draw_text(output, 10, 150, arcade.color.WHITE, 14)

            # try:
            #     output = "PV/nE: {}".format(PV/(E*len(self.box.particles)))
            #     arcade.draw_text(output, 10, 180, arcade.color.WHITE, 14)
            # except:
            #     raise

            # output = "Avg position: {}".format(self.box.avg_position())
            # arcade.draw_text(output, 10, 110, arcade.color.WHITE, 14)

        #play sound
        if self.bounced and not self.quiet:
            arcade.play_sound(self.sound, 0.1)
Esempio n. 23
0
 def update_grid_cell_list(self):
     self.grid_cell_list = arcade.ShapeElementList()
     for grid_pos, cell in self.grid_map.items():
         current_cell = cell.create_cell_poly()
         self.grid_cell_list.append(current_cell)
    def setup(self):
        self.map_width = len(self.world_map)
        self.map_height = 0
        for row in self.world_map:
            self.map_height = max(self.map_height, len(row))
        '''
        self.world_map = np.array([
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 8, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0],
            [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0]
        ])
        '''
        '''self.point_list = []

        for y in range(len(self.world_map)):
            for x in range(len(self.world_map[y])):
                if self.world_map[x][y] != 0:
                    point = [x, y]
                    while True:
                        try:
                            self.point_list[self.world_map[x][y]].append(point)
                            break
                        except IndexError:
                            self.point_list.append([])'''

        # initialize and declare position variables
        self.posX = 22
        self.posY = 12

        # initialize and declare the look-direction variables
        self.dirX = -1.0
        self.dirY = 0.0

        # initialize and declare the
        self.planeX = 0
        self.planeY = 1

        self.drawStart = []
        self.drawEnd = []

        # initialize and declare movement boolean flags to false
        self.moveForward = False
        self.moveBackward = False
        self.strafeLeft = False
        self.strafeRight = False
        self.rotateLeft = False
        self.rotateRight = False

        # initialize and declare the game time to 0
        self.time = 0

        # start with the default target FPS
        self.target_fps = TARGET_FPS

        # initialize an empty ShapeElementList to store the line objects in
        self.shape_list = arcade.ShapeElementList()
        self.color_list = [
            arcade.color.RED, arcade.color.GREEN, arcade.color.BLUE,
            arcade.color.WHITE, arcade.color.YELLOW, arcade.color.PURPLE,
            arcade.color.ORANGE, arcade.color.PINK
        ]

        self.dark_color_list = [
            arcade.color.DARK_RED, arcade.color.DARK_GREEN,
            arcade.color.DARK_BLUE, arcade.color.GRAY,
            arcade.color.DARK_YELLOW, arcade.color.DARK_PASTEL_PURPLE,
            arcade.color.DARK_ORANGE, arcade.color.DARK_PINK
        ]

        self.render_resolution = RENDER_RESOLUTION

        self.texture = 'bricks.png'
        self.alt_texture = 'darker_bricks.png'

        self.xy_square = arcade.load_texture('bricks.png')

        self.set_exclusive_mouse(exclusive=True)
        self.set_exclusive_keyboard(exclusive=True)
Esempio n. 25
0
    def on_mouse_press(self, x, y, button, modifiers):
        # calculates the square on the board you've pressed
        square_location = [
            int((x - 132.5) // 75),
            int(8 - ((y - 62.5) // 75))
        ]  #[board_x, board_y]
        white_small_board = [
            int((x - 937.5) // 75),
            int(2 - ((y - 87.5) // 75))
        ]
        black_small_board = [
            int((x - 937.5) // 75),
            int(2 - ((y - 487.7) // 75))
        ]

        if not self.promotion_prompt:  #if there's no prompt

            #if clicking on the main board
            if 0 <= square_location[0] <= 8 and 0 <= square_location[1] <= 8:

                #if there is a piece on tile
                if self.board_pieces_location[square_location[1]][
                        square_location[0]] != 0:

                    #if you already have a piece selected
                    if self.pieces_selected:
                        if square_location in self.possible_moves[0]:
                            #enemy piece removed from board and put into your dictionary
                            taken_piece = self.board_pieces_location[
                                square_location[1]][square_location[0]]
                            if taken_piece.promoted:
                                self.all_pieces.remove(taken_piece.sprite)
                                taken_piece = taken_piece.demote()
                                self.all_pieces.append(taken_piece.sprite)

                            #enemy piece put outside the board
                            taken_piece.taken(self.white_captured_location,
                                              self.black_captured_location)

                            #adding the enemy piece to your captives dictionary
                            if self.turn == "white":
                                self.white_captives[
                                    taken_piece.piece_type].append(taken_piece)
                            else:
                                self.black_captives[
                                    taken_piece.piece_type].append(taken_piece)

                            #reset the tile
                            self.board_pieces_location[square_location[1]][
                                square_location[0]] = 0

                            #placing the piece
                            self.capture_done = True
                            self.place_and_check_promotion(square_location)

                    #if you don't have a piece selected
                    else:
                        #checks if you're using the right pieces
                        self.select_piece(square_location)

                #if tile is empty
                else:
                    #if you have a piece selected
                    if self.pieces_selected and square_location in self.possible_moves[
                            0]:
                        if self.selected_piece.captured:
                            self.selected_piece.just_placed = True
                            self.selected_piece.captured = False
                            if self.turn == "white":
                                self.white_captives[
                                    self.selected_piece.piece_type].pop()
                            else:
                                self.black_captives[
                                    self.selected_piece.piece_type].pop()

                        self.place_and_check_promotion(square_location)
                        self.selected_piece.just_placed = False

            #clicking on the smaller board
            else:
                if not self.pieces_selected:
                    if self.turn == "white":
                        if 0 <= white_small_board[
                                0] <= 2 and 0 <= white_small_board[1] <= 2:
                            if self.white_captured_location[white_small_board[
                                    1]][white_small_board[0]] != 0:
                                self.selected_piece = self.white_captured_location[
                                    white_small_board[1]][
                                        white_small_board[0]].pop()
                                if len(self.white_captured_location[
                                        white_small_board[1]]) == 0:
                                    self.white_captured_location[
                                        white_small_board[1]][
                                            white_small_board[0]] = 0
                                self.possible_moves = self.selected_piece.highlight_moves(
                                    self.highlight, self.board_pieces_location,
                                    self.covered_squares, self.king_checked,
                                    self.checking_pieces)
                                self.prev_position[1] = white_small_board
                                self.pieces_selected = True
                    else:
                        if 0 <= black_small_board[
                                0] <= 2 and 0 <= black_small_board[1] <= 2:
                            if self.black_captured_location[black_small_board[
                                    1]][black_small_board[0]] != 0:
                                self.selected_piece = self.black_captured_location[
                                    black_small_board[1]][
                                        black_small_board[0]].pop()
                                if len(self.black_captured_location[
                                        black_small_board[1]]) == 0:
                                    self.black_captured_location[
                                        black_small_board[1]][
                                            black_small_board[0]] = 0
                                self.possible_moves = self.selected_piece.highlight_moves(
                                    self.highlight, self.board_pieces_location,
                                    self.covered_squares, self.king_checked,
                                    self.checking_pieces)
                                self.prev_position[2] = black_small_board
                                self.pieces_selected = True

                #if you have a piece selected
                else:
                    if self.turn == "white":
                        if white_small_board == self.prev_position[1]:
                            self.white_captured_location[white_small_board[1]][
                                white_small_board[0]].append(
                                    self.selected_piece)
                            self.selected_piece.sprite.set_position(
                                self.white_coordinates[white_small_board[1]][
                                    white_small_board[0]][0],
                                self.white_coordinates[white_small_board[1]][
                                    white_small_board[0]][1])
                            self.selected_piece.pos = self.white_coordinates[
                                white_small_board[1]][white_small_board[0]]
                            self.pieces_selected = False

                            #if you're putting it back into place, don't switch turns
                            if white_small_board != self.prev_position[1]:
                                self.switch_turns()

                            self.highlight = arcade.ShapeElementList()
                    else:
                        if black_small_board == self.prev_position[2]:
                            self.black_captured_location[black_small_board[1]][
                                black_small_board[0]].append(
                                    self.selected_piece)
                            self.selected_piece.sprite.set_position(
                                self.black_coordinates[black_small_board[1]][
                                    black_small_board[0]][0],
                                self.black_coordinates[black_small_board[1]][
                                    black_small_board[0]][1])
                            self.selected_piece.pos = self.black_coordinates[
                                black_small_board[1]][black_small_board[0]]
                            self.pieces_selected = False

                            #if you're putting it back into place, don't switch turns
                            if black_small_board != self.prev_position[2]:
                                self.switch_turns()

                            self.highlight = arcade.ShapeElementList()

        else:  #if there is a prompt
            self.checked_for_promotion = True
            if 385 <= x <= 455 and 345 <= y <= 375:  #yes is picked
                #promote
                self.promote()

                self.highlight = arcade.ShapeElementList()
                self.promotion_prompt = False
                self.switch_turns()

            elif 485 <= x <= 555 and 345 <= y <= 375:  #no is picked
                self.place(self.prev_position[0])
                self.highlight = arcade.ShapeElementList()
                self.promotion_prompt = False
                self.switch_turns()
Esempio n. 26
0
"""
1. Use a loop to generate a lot of rain.
"""
import random
import arcade


WIDTH = 640
HEIGHT = 480

rain = arcade.ShapeElementList()

# first set up empty lists
rain_x_positions = []
rain_y_positions = []

tunnel_x_positions = []
tunnel_y_positions = []

for _ in range(0,100,30):
    x = random.randrange(WIDTH + 50)
    y = random.randrange(-50,HEIGHT)

    tunnel_x_positions.append(x)
    tunnel_y_positions.append(y)

# loop 100 times
for _ in range(0,100,30):
    # generate random x and y values
    x = random.randrange(WIDTH+50)
    y = random.randrange(HEIGHT, HEIGHT+50)
Esempio n. 27
0
 def __create_shapes__(self):
     self.all_shapes = arcade.ShapeElementList()
     bg_rect = arcade.create_rectangle_filled(0, 0, 150, 150,
                                              arcade.color.GREEN)
     self.all_shapes.append(bg_rect)