def __init__(self, filename: str = None, scale: Number = 1, x: Number = 0, y: Number = 0, width: Number = 0, height: Number = 0): """ Create a new sprite. Args: filename (str): Filename of an image that represents the sprite. scale (float): Scale the image up or down. Scale of 1.0 is none. width (float): Width of the sprite height (float): Height of the sprite """ if width < 0: raise SystemError("Width of image can't be less than zero.") if height < 0: raise SystemError("Height of image can't be less than zero.") if width == 0 and height != 0: raise SystemError("Width can't be zero.") if height == 0 and width != 0: raise SystemError("Height can't be zero.") if filename is not None: self.texture = load_texture(filename, x, y, width, height) self.textures = [self.texture] self.width = self.texture.width * scale self.height = self.texture.height * scale else: self.textures = [] self.width = 0 self.height = 0 self.cur_texture_index = 0 self.scale = scale self._center_x = 0 self._center_y = 0 self._angle = 0.0 self.change_x = 0 self.change_y = 0 self.change_angle = 0 self.boundary_left = None self.boundary_right = None self.boundary_top = None self.boundary_bottom = None self.alpha = 1.0 self.sprite_lists = [] self.transparent = True self.can_cache = True self._points = None self._point_list_cache = None
def update_animation(self, delta_time: float = 1/60): """ Logic for selecting the proper texture to use. """ self.time_counter += delta_time while self.time_counter > self.frames[self.cur_frame].duration / 1000.0: self.time_counter -= self.frames[self.cur_frame].duration / 1000.0 self.cur_frame += 1 if self.cur_frame >= len(self.frames): self.cur_frame = 0 source = self.frames[self.cur_frame].image.source # print(f"Advance to frame {self.cur_frame}: {source}") self.texture = load_texture(source, scale=self.scale)
def spawn_ball(self): ball = SmashBall('lollipop_green.png', BALL_SIZE_FACTOR) texture = load_texture('lollipop_red.png') width = texture.width * BALL_SIZE_FACTOR height = texture.height * BALL_SIZE_FACTOR texture.scale = BALL_SIZE_FACTOR ball.append_texture(texture) ball.center_x = random.randrange(SCREEN_WIDTH * .1, SCREEN_WIDTH * .9) ball.center_y = random.randrange(SCREEN_HEIGHT * .1, SCREEN_HEIGHT * .9) ball.change_x = random.randrange(MAX_BALL_SPEED // 2, MAX_BALL_SPEED) ball.change_y = random.randrange(MAX_BALL_SPEED // 2, MAX_BALL_SPEED) self.ball_sprite = ball self.ball_has_spawn = True
""" Flucht aus dem Labyrinth """ import arcade from arcade.draw_commands import load_texture from arcade.key import MOTION_UP, MOTION_DOWN, MOTION_LEFT, MOTION_RIGHT from arcade.key import ESCAPE wand = load_texture("tiles.png", 0, 0, 32, 32) boden = load_texture("tiles.png", 0, 32, 32, 32) pac = load_texture("tiles.png", 0, 96, 32, 32) LABYRINTH = """ ########## #........# #.#.####.# #.#......# #.#....#.# #.#....#.# #......#.# #.####.#.# #........# ##########""" LEVEL = [] for zeile in LABYRINTH.strip().split(): LEVEL.append(list(zeile)) class Labyrinth(arcade.Window): def __init__(self):
def __init__(self, filename: str=None, scale: float=1, image_x: float=0, image_y: float=0, image_width: float=0, image_height: float=0, center_x: float=0, center_y: float=0, repeat_count_x=1, repeat_count_y=1): """ Create a new sprite. Args: filename (str): Filename of an image that represents the sprite. scale (float): Scale the image up or down. Scale of 1.0 is none. image_x (float): Scale the image up or down. Scale of 1.0 is none. image_y (float): Scale the image up or down. Scale of 1.0 is none. image_width (float): Width of the sprite image_height (float): Height of the sprite center_x (float): Location of the sprite center_y (float): Location of the sprite """ if image_width < 0: raise ValueError("Width of image can't be less than zero.") if image_height < 0: raise ValueError("Height entered is less than zero. Height must be a positive float.") if image_width == 0 and image_height != 0: raise ValueError("Width can't be zero.") if image_height == 0 and image_width != 0: raise ValueError("Height can't be zero.") self.sprite_lists = [] if filename is not None: self._texture = load_texture(filename, image_x, image_y, image_width, image_height) self.textures = [self._texture] self._width = self._texture.width * scale self._height = self._texture.height * scale self._texture.scale = scale else: self.textures = [] self._texture = None self._width = 0 self._height = 0 self.cur_texture_index = 0 self._scale = scale self._position = [center_x, center_y] self._angle = 0.0 self.velocity = [0, 0] self.change_angle = 0 self.boundary_left = None self.boundary_right = None self.boundary_top = None self.boundary_bottom = None self._alpha = 255 self._collision_radius = None self._color = (255, 255, 255) self._points = None self._point_list_cache = None self.force = [0, 0] self.guid = None self.repeat_count_x = repeat_count_x self.repeat_count_y = repeat_count_y
def __init__(self, filename: str = None, scale: float = 1, image_x: float = 0, image_y: float = 0, image_width: float = 0, image_height: float = 0, center_x: float = 0, center_y: float = 0, repeat_count_x: int = 1, repeat_count_y: int = 1): """ Create a new sprite. Args: filename (str): Filename of an image that represents the sprite. scale (float): Scale the image up or down. Scale of 1.0 is none. image_x (float): X offset to sprite within sprite sheet. image_y (float): Y offset to sprite within sprite sheet. image_width (float): Width of the sprite image_height (float): Height of the sprite center_x (float): Location of the sprite center_y (float): Location of the sprite """ if image_width < 0: raise ValueError("Width of image can't be less than zero.") if image_height < 0: raise ValueError( "Height entered is less than zero. Height must be a positive float." ) if image_width == 0 and image_height != 0: raise ValueError("Width can't be zero.") if image_height == 0 and image_width != 0: raise ValueError("Height can't be zero.") self.sprite_lists: List[Any] = [] self._texture: Optional[Texture] if filename is not None: try: self._texture = load_texture(filename, image_x, image_y, image_width, image_height) except Exception as e: print(f"Unable to load {filename} {e}") self._texture = None if self._texture: self.textures = [self._texture] self._width = self._texture.width * scale self._height = self._texture.height * scale self._texture.scale = scale else: self.textures = [] self._width = 0 self._height = 0 else: self.textures = [] self._texture = None self._width = 0 self._height = 0 self.cur_texture_index = 0 self._scale = scale self._position = (center_x, center_y) self._angle = 0.0 self.velocity = [0.0, 0.0] self.change_angle = 0.0 self.boundary_left = None self.boundary_right = None self.boundary_top = None self.boundary_bottom = None self.properties: Dict[str, Any] = {} self._alpha = 255 self._collision_radius: Optional[float] = None self._color: RGB = (255, 255, 255) if self._texture: points = self._texture.unscaled_hitbox_points scaled_points = [[value * scale for value in point] for point in points] self._points = scaled_points else: self._points: Optional[Sequence[Sequence[float]]] = None self._point_list_cache: Optional[Tuple[Tuple[float, float], ...]] = None self.force = [0, 0] self.guid = None self.repeat_count_x = repeat_count_x self.repeat_count_y = repeat_count_y
def __init__(self, filename: str=None, scale: float=1, image_x: float=0, image_y: float=0, image_width: float=0, image_height: float=0, center_x: float=0, center_y: float=0): """ Create a new sprite. Args: filename (str): Filename of an image that represents the sprite. scale (float): Scale the image up or down. Scale of 1.0 is none. image_x (float): Scale the image up or down. Scale of 1.0 is none. image_y (float): Scale the image up or down. Scale of 1.0 is none. image_width (float): Width of the sprite image_height (float): Height of the sprite center_x (float): Location of the sprite center_y (float): Location of the sprite """ if image_width < 0: raise ValueError("Width of image can't be less than zero.") if image_height < 0: raise ValueError("Height entered is less than zero. Height must be a positive float.") if image_width == 0 and image_height != 0: raise ValueError("Width can't be zero.") if image_height == 0 and image_width != 0: raise ValueError("Height can't be zero.") if filename is not None: self.texture = load_texture(filename, image_x, image_y, image_width, image_height) self.textures = [self.texture] self.width = self.texture.width * scale self.height = self.texture.height * scale else: self.textures = [] self.width = 0 self.height = 0 self.cur_texture_index = 0 self.scale = scale self.position = [center_x, center_y] self._angle = 0.0 self.velocity = [0, 0] self.change_angle = 0 self.boundary_left = None self.boundary_right = None self.boundary_top = None self.boundary_bottom = None self.alpha = 1.0 self.sprite_lists = [] self.transparent = True self.can_cache = True self._points = None self._point_list_cache = None self.force = [0, 0]
def draw_background(): map_texture = draw_commands.load_texture(config.MAP_BACKGROUND) draw_commands.draw_texture_rectangle(center_x=config.SCREEN_WIDTH / 2, center_y=config.SCREEN_HEIGHT / 2, width=config.SCREEN_WIDTH, height=config.SCREEN_HEIGHT, texture=map_texture)