示例#1
0
def main():
    arcade.open_window(800, 800, "first window example")
    arcade.set_background_color(arcade.color.ALMOND)

    #now create objects
    main_house = arcade.create_rectangle(400, 200, 400, 400,
                                         arcade.color.ANTIQUE_BRASS)
    door = arcade.create_rectangle(400, 75, 100, 150, arcade.color.ARMY_GREEN)
    window_1 = arcade.create_ellipse(300, 300, 50, 50, arcade.color.AERO_BLUE)
    window_2 = arcade.create_ellipse(500, 300, 50, 50, arcade.color.AERO_BLUE)
    roof_points = [(200, 400), (400, 600), (600, 400)]
    roof = arcade.create_polygon(roof_points, arcade.color.DARK_GRAY)
    line = arcade.create_line(200, 730, 510, 730, arcade.color.ROSE)

    #now we will begin to draw
    arcade.start_render()
    #draw everything here
    arcade.draw_text("boy is that an ugly house", 200, 750,
                     arcade.color.ALABAMA_CRIMSON, 22)

    main_house.draw()
    door.draw()
    window_1.draw()
    window_2.draw()
    roof.draw()
    line.draw()

    arcade.finish_render()

    arcade.run()
示例#2
0
def main():
    arcade.open_window(1000, 1000, "My Picture")
    arcade.set_background_color(arcade.color.WHITE)
    #create objects
    rubrix_cube = arcade.create_rectangle(500, 500, 500, 500, arcade.color.WHITE)
    individual_square_1 = arcade.create_rectangle(500, 500, 175, 175, arcade.color.BLUE)#second row middle piece
    individual_square_2 = arcade.create_rectangle(328, 500, 150, 175, arcade.color.BLUE)#second row left side piece
    individual_square_3 = arcade.create_rectangle(672, 500, 150, 175, arcade.color.BLUE)#second row right side piece
    individual_square_4 = arcade.create_rectangle(500, 670, 175, 150, arcade.color.BLUE)#top row middle peiece
    individual_square_5 = arcade.create_rectangle(672, 670, 150, 150, arcade.color.BLUE)#top row right side piece
    individual_square_6 = arcade.create_rectangle(328, 670, 150, 150, arcade.color.BLUE)#top row left side piece
    individual_square_7 = arcade.create_rectangle(500, 330, 175, 150, arcade.color.BLUE)#bottom row middle piece
    individual_square_8 = arcade.create_rectangle(672, 330, 150, 150, arcade.color.BLUE)#bottom right side piece
    individual_square_9 = arcade.create_rectangle(328, 330, 150, 150, arcade.color.BLUE)#bottom left side piece
    spikes = arcade.draw_triangle_filled(50, 50, 75, 75, 60, 60, arcade.color.RED)



    arcade.start_render()
    #Draw Everything
    rubrix_cube.draw()
    individual_square_1.draw()
    individual_square_2.draw()
    individual_square_3.draw()
    individual_square_4.draw()
    individual_square_5.draw()
    individual_square_6.draw()
    individual_square_7.draw()
    individual_square_8.draw()
    individual_square_9.draw()
    spikes.draw()
    arcade.finish_render()

    arcade.run()
示例#3
0
def main ():
    arcade.open_window(800, 800, "Hey We Have a Window")
    arcade.set_background_color(arcade.color.ALMOND)
    # now create objects
    main_house = arcade.create_rectangle(400, 200, 400, 400, arcade.color.ANTIQUE_BRASS)
    door = arcade.create_rectangle(400, 75, 100, 150, arcade.color.ARMY_GREEN)
    window1 = arcade.create_ellipse(300, 300, 50, 50, arcade.color.BABY_BLUE)
    window2 = arcade.create_ellipse(500, 300, 50, 50, arcade.color.BABY_BLUE)
    roof_points = [(200, 400), (400, 600), (600, 400)]
    roof = arcade.create_polygon(roof_points, arcade.color.DARK_GRAY)
    line = arcade.create_line(175, 725, 550, 725, arcade.color.FALU_RED)

    # now we will begin to draw
    arcade.start_render()
    # draw everything here
    arcade.draw_text("Boy that was an ugly house", 200, 750, arcade.color.ALABAMA_CRIMSON, 22)
    main_house.draw()
    door.draw()
    window1.draw()
    window2.draw()
    roof.draw()
    line.draw()

    arcade.finish_render()

    arcade.run()
示例#4
0
def solve():
    with open('input.txt') as f:
        _input: List = f.read()

    width = 25
    tall = 6
    layers = list()
    data = _input

    while data:
        layer = list()
        for y in range(tall):
            row, data = data[:width], data[width:]
            layer.append(row)
        layers.append(layer)

    # Check sum
    counts = []
    for layer in layers:
        print(layer)
        c = Counter(''.join(layer))
        counts.append((c['0'], c['1'] * c['2']))
    print(sorted(counts)[0][1])

    # pic
    # 0 is black, 1 is white, and 2 is transparent
    SIZE = 50
    PADDING = 50
    arcade.open_window(width * SIZE + PADDING, tall * SIZE + PADDING, 'Image')

    shapes = arcade.ShapeElementList()
    for layer in reversed(layers):
        for y, row in enumerate(reversed(layer)):
            for x, pixel in enumerate(row):
                px = x * SIZE + SIZE / 2 + PADDING / 2
                py = y * SIZE + SIZE / 2 + PADDING / 2

                if pixel == '0':
                    rect = arcade.create_rectangle(px,
                                                   py,
                                                   SIZE,
                                                   SIZE,
                                                   arcade.color.BLACK,
                                                   filled=True)
                elif pixel == '1':
                    rect = arcade.create_rectangle(px,
                                                   py,
                                                   SIZE,
                                                   SIZE,
                                                   arcade.color.WHITE,
                                                   filled=True)
                else:
                    continue
                shapes.append(rect)

    arcade.set_background_color(arcade.color.BLACK)
    arcade.start_render()
    shapes.draw()
    arcade.finish_render()
    arcade.run()
示例#5
0
文件: box.py 项目: beardad1975/pie4t
    def make_dynamic_shape(self):
        # dynamic  circle

        s = arcade.create_rectangle_filled(0, 0, self.box_width,
                                           self.box_height, self.box_color)
        self.dynamic_shape_element.append(s)

        r = self.box_color[0] + 50
        r = r if r <= 255 else 255
        g = self.box_color[1] + 50
        g = g if g <= 255 else 255
        b = self.box_color[2] + 50
        b = b if b <= 255 else 255

        border_color = (r, g, b)

        s = arcade.create_rectangle(0,
                                    0,
                                    self.box_width,
                                    self.box_height,
                                    border_color,
                                    3,
                                    filled=False)
        self.dynamic_shape_element.append(s)

        s = arcade.create_rectangle_filled(int(self.box_width * 0.35), 0, 3,
                                           int(self.box_height * 0.8),
                                           border_color)
        self.dynamic_shape_element.append(s)
示例#6
0
def main():

    arcade.open_window(800, 800, "Stripes")
    arcade.set_background_color(arcade.color.WHITE)
    arcade.start_render()

    stripe = arcade.create_rectangle(800, 0, 100, 1600, arcade.color.BLACK)

    stripe.draw()

    arcade.finish_render()
    arcade.run()
示例#7
0
    def _draw_keyboard(self):
        """ Draw keyboard """
        keyboard = self._keyboard

        if not keyboard.change_resolved:
            keyboard.shape = arcade.create_rectangle(
                keyboard.center_x, keyboard.center_y, keyboard.width, keyboard.height, keyboard.rgba,
                border_width=keyboard.border_width, tilt_angle=keyboard.tilt_angle, filled=keyboard.filled)
            keyboard.change_resolved = True

        for key in self._keyboard.keys.values():
            if not key.change_resolved:
                key.shape = arcade.create_rectangle(
                    key.center_x, key.center_y, key.width, key.height, key.rgba,
                    border_width=key.border_width, tilt_angle=key.tilt_angle, filled=key.filled)
                key.change_resolved = True

        for shape in [keyboard.shape] + [key.shape for key in keyboard.keys.values()]:
            shape.draw()

        for key in keyboard.keys.values():
            # FIXME pyglet draw doesn't work in arcade
            if key.graphic:
                key.graphic.draw()
            else:
                if key.graphic is None:
                    try:
                        text = key_.MAP_SYMBOL_TEXT[key.symbol]
                        multiline = False
                        if '\n' in text:
                            multiline = True
                        label = pyglet.text.Label(
                            text, 'Montserrat', key.height // 2, color=(255, 255, 255, 255),
                            x=key.position[0], y=key.position[1], anchor_x='center', anchor_y='center',
                            multiline=multiline)
                        key.graphic = label
                        key.graphic.draw()
                    except KeyError:
                        key.graphic = 0
示例#8
0
	def __init__(self, GRID_W: int = 0, GRID_H:int = 0, GRID_MARGIN:int = 1,SIZE:int = 0):
		self.GRID_W = GRID_W
		self.GRID_H = GRID_H
		self.GRID_MARGIN = GRID_MARGIN
		self.SIZE = SIZE
		self.GRID = []
		self.SHAPE_LIST = []
		for row in range(20):
			self.GRID.append([])
			for col in range(20):
				self.GRID[row].append([])
				x = (self.GRID_MARGIN + self.GRID_W ) * col + self.GRID_MARGIN + self.GRID_W //2
				y = (self.GRID_MARGIN + self.GRID_H ) * row + self.GRID_MARGIN + self.GRID_H //2
				self.SHAPE_LIST.append(create_rectangle(self.GRID_W,self.GRID_H,GREEN))
示例#9
0
def create_shapes(win_width, win_height):
    x_scale = win_width / 4
    win_height = win_height / 4
    shape_list = []
    rectangle = arcade.create_rectangle(x_scale, win_height, 100, win_height,
                                        arcade.color.COPPER_PENNY)
    circle = arcade.create_ellipse(x_scale * 3, win_height, 50, 50,
                                   arcade.color.DARK_TANGERINE)
    shape_list.append(rectangle)
    shape_list.append(circle)
    line = arcade.create_line(x_scale, 600, x_scale * 3, win_height,
                              arcade.color.ENGLISH_LAVENDER, 3)
    shape_list.append(line)
    return shape_list
示例#10
0
def main():

    arcade.open_window(800, 800, "Rocketship")
    arcade.set_background_color(arcade.color.AFRICAN_VIOLET)

    arcade.start_render()

    rocketship_body = arcade.create_rectangle(200, 300, 100, 100,
                                              arcade.color.ALMOND)

    thruster = arcade.create_p

    rocketship_body.draw()

    arcade.finish_render()
    arcade.run()
示例#11
0
    def shapes(self, draw_event):
        """
        Paint a basic beam
        """
        shapes = [self.background_shape()]

        rect = self.geometry

        if self._mode == Bar.RIGHT_TO_LEFT:
            rect = Rect(rect.x, rect.y, rect.w * self._percent,
                        rect.h).to_arcade_rect()
        elif self._mode == Bar.MIDDLE_OUT:
            rect = rect.to_arcade_rect()
            rect = Rect(rect.x, rect.y, rect.w * self._percent, rect.h)

        shapes.append(arcade.create_rectangle(*(rect), self._color))

        return shapes
示例#12
0
文件: box.py 项目: beardad1975/pie4t
    def make_kinematic_shape(self):
        # dynamic  circle

        s = arcade.create_rectangle_filled(0, 0, self.box_width,
                                           self.box_height, arcade.color.GRAY)
        self.kinematic_shape_element.append(s)

        s = arcade.create_rectangle(0,
                                    0,
                                    self.box_width,
                                    self.box_height,
                                    arcade.color.LAVENDER_GRAY,
                                    3,
                                    filled=False)
        self.kinematic_shape_element.append(s)

        s = arcade.create_rectangle_filled(int(self.box_width * 0.35), 0, 3,
                                           int(self.box_height * 0.8),
                                           arcade.color.LAVENDER_GRAY)
        self.kinematic_shape_element.append(s)
示例#13
0
 def recreate_vbo(self):
     self._shape = arcade.create_rectangle(self.center_x, self.center_y,
                                           self.width, self.height,
                                           self.rgba, self._border_width,
                                           self._tilt_angle, self._filled)
     self.change_resolved = True
    def setup(self):
        """
        Set up all the necessary shapes and sprites which are used in the simulation.
        These elements are added to lists to make buffered rendering possible to improve performance.
        """

        self.robot_elements = arcade.SpriteList()
        self.obstacle_elements = arcade.ShapeElementList()

        if self.large_sim_type:
            self.robot = RobotLarge(self.cfg, self.robot_pos[0],
                                    self.robot_pos[1], self.robot_pos[2])
        else:
            self.robot = RobotSmall(self.cfg, self.robot_pos[0],
                                    self.robot_pos[1], self.robot_pos[2])

        for s in self.robot.get_sprites():
            self.robot_elements.append(s)

        for s in self.robot.get_sensors():
            self.robot_state.load_sensor(s)

        self.blue_lake = BlueLake(self.cfg)
        self.green_lake = GreenLake(self.cfg)
        self.red_lake = RedLake(self.cfg)

        self.obstacle_elements.append(self.blue_lake.shape)
        self.obstacle_elements.append(self.green_lake.shape)
        self.obstacle_elements.append(self.red_lake.shape)

        self.border = Border(
            self.cfg,
            eval(self.cfg['obstacle_settings']['border_settings']
                 ['border_color']))
        self.edge = Edge(self.cfg)

        for s in self.border.shapes:
            self.obstacle_elements.append(s)

        self.space = Space()

        if self.large_sim_type:
            self.rock1 = Rock(apply_scaling(825), apply_scaling(1050),
                              apply_scaling(150), apply_scaling(60),
                              arcade.color.DARK_GRAY, 10)
            self.rock2 = Rock(apply_scaling(975), apply_scaling(375),
                              apply_scaling(300), apply_scaling(90),
                              arcade.color.DARK_GRAY, 130)

            self.ground = arcade.create_rectangle(apply_scaling(1460),
                                                  apply_scaling(950),
                                                  apply_scaling(300),
                                                  apply_scaling(10),
                                                  arcade.color.BLACK)

            self.obstacle_elements.append(self.rock1.shape)
            self.obstacle_elements.append(self.rock2.shape)
            self.obstacle_elements.append(self.ground)

            touch_obstacles = [self.rock1, self.rock2]
            falling_obstacles = [
                self.blue_lake.hole, self.green_lake.hole, self.red_lake.hole,
                self.edge
            ]

            self.space.add(self.rock1.poly)
            self.space.add(self.rock2.poly)

        else:
            self.bottle1 = Bottle(apply_scaling(1000), apply_scaling(300),
                                  apply_scaling(40),
                                  arcade.color.DARK_OLIVE_GREEN)
            self.obstacle_elements.append(self.bottle1.shape)

            touch_obstacles = [self.bottle1]
            falling_obstacles = [self.edge]

            self.space.add(self.bottle1.poly)

        color_obstacles = [
            self.blue_lake, self.green_lake, self.red_lake, self.border
        ]

        self.robot.set_color_obstacles(color_obstacles)
        self.robot.set_touch_obstacles(touch_obstacles)
        self.robot.set_falling_obstacles(falling_obstacles)
示例#15
0
    def on_update(self, delta_time):
        # clear the shape list for the new frame
        self.shape_list = arcade.ShapeElementList()
        # self.minimap_shape_list = arcade.ShapeElementList()

        # set the floor and ceiling colors
        floor = arcade.create_rectangle(
            self.screen_width // 2, int(self.screen_height * 0.25),
            self.screen_width, self.screen_height // 2,
            self.floor_color
        )

        ceiling = arcade.create_rectangle(
            self.screen_width // 2, int(self.screen_height * 0.75),
            self.screen_width, self.screen_height // 2,
            self.ceiling_color
        )

        # add the floor and ceiling shapes to the shape_list
        self.shape_list.append(floor)
        self.shape_list.append(ceiling)

        # create the point_list and color_list for raycasting
        point_list = []
        color_list = []

        # begin raycasting
        for x in range(0, self.screen_width + 1):
            # calculate the ray position and direction
            camera_x = (2 * x / self.screen_width) - 1
            if camera_x > 1 or camera_x < -1:
                print('camera_x is too big or too small!')
                print(f'camera_x = {camera_x}')
            ray_dir_x = self.dir_x + self.plane_x * camera_x
            ray_dir_y = self.dir_y + self.plane_y * camera_x

            # determine which grid-square of the map we're in
            map_x = int(self.pos_x)
            map_y = int(self.pos_y)

            # length of ray from the current position to the next vertical gridline
            side_dist_x = None
            # length of ray from the current position to the next horizontal gridline
            side_dist_y = None

            # length of the ray from one horizontal or vertical gridline to the next one
            try:
                delta_dist_x = abs(1 / ray_dir_x)
            except ZeroDivisionError:
                if ray_dir_y == 0:
                    delta_dist_x = 0
                elif ray_dir_x == 0:
                    delta_dist_x = 1
                else:
                    delta_dist_x = abs(1 / ray_dir_x)

            try:
                delta_dist_y = abs(1 / ray_dir_y)
            except ZeroDivisionError:
                if ray_dir_x == 0:
                    delta_dist_y = 0
                elif ray_dir_y == 0:
                    delta_dist_y = 1
                else:
                    delta_dist_y = abs(1 / ray_dir_y)

            # the distance to the next perpendicular wall
            perpendicular_wall_dist = None

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

            # was a there a wall hit?
            hit = 0

            # was a North/South wall hit or an East/West wall hit?
            side = None

            if ray_dir_x < 0:
                step_x = -1
                side_dist_x = (self.pos_x - map_x) * delta_dist_x
            else:
                step_x = 1
                side_dist_x = (map_x + 1 - self.pos_x) * delta_dist_x

            if ray_dir_y < 0:
                step_y = -1
                side_dist_y = (self.pos_y - map_y) * delta_dist_y
            else:
                step_y = 1
                side_dist_y = (map_y + 1 - self.pos_y) * delta_dist_y

            new_map_x = False
            new_map_y = False

            # continually cast the ray out into the distance until it hits a wall
            while hit == 0:
                if side_dist_x < side_dist_y:
                    side_dist_x += delta_dist_x
                    map_x += step_x
                    side = 0
                else:
                    side_dist_y += delta_dist_y
                    map_y += step_y
                    side = 1

                # check if the ray has hit a wall yet
                if 0 < self.map[map_x][map_y] < 10:
                    hit = 1
                    if map_x != self.last_map_x:
                        new_map_x = True
                        self.last_map_x = map_x
                    if map_y != self.last_map_y:
                        new_map_y = True
                        self.last_map_y = map_y
                    if not self.minimap[map_x][map_y]:
                        self.minimap[map_x][map_y] = True
                        # top-left
                        self.mm_point_list.append(
                            (MINIMAP_POS_X + map_x * MINIMAP_SIZE, MINIMAP_POS_Y + map_y * MINIMAP_SIZE + MINIMAP_SIZE))
                        self.mm_color_list.append(arcade.color.BLACK)
                        # top-right
                        self.mm_point_list.append((MINIMAP_POS_X + map_x * MINIMAP_SIZE + MINIMAP_SIZE,
                                                   MINIMAP_POS_Y + map_y * MINIMAP_SIZE + MINIMAP_SIZE))
                        self.mm_color_list.append(arcade.color.BLACK)
                        # bottom-right
                        self.mm_point_list.append(
                            (MINIMAP_POS_X + map_x * MINIMAP_SIZE + MINIMAP_SIZE, MINIMAP_POS_Y + map_y * MINIMAP_SIZE))
                        self.mm_color_list.append(arcade.color.BLACK)
                        # bottom-left
                        self.mm_point_list.append(
                            (MINIMAP_POS_X + map_x * MINIMAP_SIZE, MINIMAP_POS_Y + map_y * MINIMAP_SIZE))
                        self.mm_color_list.append(arcade.color.BLACK)
                elif 10 <= self.map[map_x][map_y] < 20:
                    hit = 2

            if side == 0:
                perpendicular_wall_dist = (map_x - self.pos_x + (1 - step_x) / 2) / (ray_dir_x + 0.00000001)
            else:
                perpendicular_wall_dist = (map_y - self.pos_y + (1 - step_y) / 2) / (ray_dir_y + 0.00000001)

            """
            **********************************************
            MODIFY CODE BELOW FOR ALLOWING PITS/HIGH WALLS
            **********************************************
            """

            # the height of the wall at the given pixel column
            line_height = int(self.screen_height / (perpendicular_wall_dist + 0.00000001))

            # the pixel (height) at which to start drawing the wall
            draw_start = -line_height / 2 + self.screen_height / 2

            if draw_start < 0:
                draw_start = 0

            if hit == 1:  # if the wall is single-height
                draw_end = line_height / 2 + self.screen_height / 2
            elif hit == 2:  # otherwise, if the wall is double-height
                draw_end = line_height + self.screen_height / 2
            if draw_end >= self.screen_height:
                draw_end = self.screen_height - 1

            # set the color with which to draw the given pixel column
            if side == 0:
                try:
                    color = self.main_wall_color_list[self.map[map_x][map_y] % 10]
                except IndexError:
                    color = arcade.color.YELLOW
            elif side == 1:
                try:
                    color = self.dark_wall_color_list[self.map[map_x][map_y] % 10]
                except IndexError:
                    color = arcade.color.DARK_YELLOW

            draw_start_pos = (x, draw_start)
            draw_end_pos = (x, draw_end)
            point_list.append(draw_start_pos)
            point_list.append(draw_end_pos)
            if new_map_x or new_map_y:
                color = arcade.color.BLACK
            for i in range(2):
                color_list.append(color)

        shape = arcade.create_line_generic_with_colors(point_list, color_list, 3)
        self.shape_list.append(shape)

        minimap_background = arcade.create_rectangle_filled_with_colors(self.mm_bg_points, self.mm_bg_colors)
        self.shape_list.append(minimap_background)

        minimap_shape = arcade.create_rectangles_filled_with_colors(self.mm_point_list, self.mm_color_list)
        self.shape_list.append(minimap_shape)

        ppos_point_list = []
        ppos_color_list = []

        # top-left
        ppos_point_list.append(
            (MINIMAP_POS_X + self.pos_x * MINIMAP_SIZE, MINIMAP_POS_Y + self.pos_y * MINIMAP_SIZE + MINIMAP_SIZE))
        ppos_color_list.append(arcade.color.BLUE)
        # top-right
        ppos_point_list.append((MINIMAP_POS_X + self.pos_x * MINIMAP_SIZE + MINIMAP_SIZE,
                                MINIMAP_POS_Y + self.pos_y * MINIMAP_SIZE + MINIMAP_SIZE))
        ppos_color_list.append(arcade.color.RED)
        # bottom-right
        ppos_point_list.append(
            (MINIMAP_POS_X + self.pos_x * MINIMAP_SIZE + MINIMAP_SIZE, MINIMAP_POS_Y + self.pos_y * MINIMAP_SIZE))
        ppos_color_list.append(arcade.color.BLUE)
        # bottom-left
        ppos_point_list.append((MINIMAP_POS_X + self.pos_x * MINIMAP_SIZE, MINIMAP_POS_Y + self.pos_y * MINIMAP_SIZE))
        ppos_color_list.append(arcade.color.BLUE)

        player_shape = arcade.create_rectangle_filled_with_colors(ppos_point_list, ppos_color_list)
        self.shape_list.append(player_shape)

        self.old_time = self.time
        self.time += delta_time

        # frame_time is the amount of time this frame spent on screen (in seconds)
        self.frame_time = (self.time - self.old_time)

        FPS = 1 / self.frame_time
        """
        ********************************************************
        HERE IS WHERE THE CODE FOR AUTO QUALITY ADJUST SHOULD GO
        ********************************************************
        """
        if FPS < 60 and self.render_resolution > 2:
            self.render_resolution -= 1
        if FPS > 60:
            self.render_resolution += 1

        self.move_speed = self.frame_time * self.constant_move_speed
        self.rotation_speed = self.frame_time * self.constant_rotation_speed
        # print(f'constant rotation speed: {self.constant_rotation_speed}\nframe time: {frame_time}\nadjusted rotation speed: {self.rotation_speed}')
        self.rotation_speed *= (self.rotate_x_magnitude / 100)

        if self.move_forward:
            if not self.map[int(self.pos_x + self.dir_x * self.move_speed)][int(self.pos_y)]:
                self.pos_x += self.dir_x * self.move_speed
            if not self.map[int(self.pos_x)][int(self.pos_y + self.dir_y * self.move_speed)]:
                self.pos_y += self.dir_y * self.move_speed
        elif self.move_backward:
            if not self.map[int(self.pos_x - self.dir_x * self.move_speed)][int(self.pos_y)]:
                self.pos_x -= self.dir_x * self.move_speed
            if not self.map[int(self.pos_x)][int(self.pos_y - self.dir_y * self.move_speed)]:
                self.pos_y -= self.dir_y * self.move_speed

        if self.strafe_left:
            if not self.map[int(self.pos_x - self.dir_y * self.move_speed)][int(self.pos_y)]:
                self.pos_x -= self.dir_y * self.move_speed
            if not self.map[int(self.pos_x)][int(self.pos_y + self.dir_x * self.move_speed)]:
                self.pos_y += self.dir_x * self.move_speed
        elif self.strafe_right:
            if not self.map[int(self.pos_x + self.dir_y * self.move_speed)][int(self.pos_y)]:
                self.pos_x += self.dir_y * self.move_speed
            if not self.map[int(self.pos_x)][int(self.pos_y - self.dir_x * self.move_speed)]:
                self.pos_y -= self.dir_x * self.move_speed

        if self.rotate_left:
            # both camera direction and camera plane must be rotated
            old_dir_x = self.dir_x
            self.dir_x = self.dir_x * math.cos(self.rotation_speed) - self.dir_y * math.sin(self.rotation_speed)
            self.dir_y = old_dir_x * math.sin(self.rotation_speed) + self.dir_y * math.cos(self.rotation_speed)
            old_plane_x = self.plane_x
            self.plane_x = self.plane_x * math.cos(self.rotation_speed) - self.plane_y * math.sin(self.rotation_speed)
            self.plane_y = old_plane_x * math.sin(self.rotation_speed) + self.plane_y * math.cos(self.rotation_speed)
        elif self.rotate_right:
            # both camera direction and camera plane must be rotated
            old_dir_x = self.dir_x
            self.dir_x = self.dir_x * math.cos(-self.rotation_speed) - self.dir_y * math.sin(-self.rotation_speed)
            self.dir_y = old_dir_x * math.sin(-self.rotation_speed) + self.dir_y * math.cos(-self.rotation_speed)
            old_plane_x = self.plane_x
            self.plane_x = self.plane_x * math.cos(-self.rotation_speed) - self.plane_y * math.sin(-self.rotation_speed)
            self.plane_y = old_plane_x * math.sin(-self.rotation_speed) + self.plane_y * math.cos(-self.rotation_speed)
        if self.mouse_look:
            self.mouse_look = False
            self.rotate_right = False
            self.rotate_left = False
示例#16
0
 def create_shape(self, x, y, width, height):
     """
     Create the small and long rectangle shown below the sidebar arm.
     """
     self.shape = create_rectangle(x, y, width, height, self.color)
示例#17
0
import arcade

arcade.open_window(800, 600, "Drawing Example")
arcade.start_render()
my_rect = arcade.create_rectangle(200, 200, 50, 50, (255, 255, 0), 3, 45)
arcade.render(my_rect)
arcade.finish_render()
arcade.run()
    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)
示例#19
0
 def create_shape(self, x, y, width, height):
     self.shape = create_rectangle(x, y, width, height, self.color)
示例#20
0
 def background_shape(self):
     """
     Have arcade paint our rect
     """
     return arcade.create_rectangle(*(self.geometry.to_arcade_rect()),
                                    self._background_color)