def init(self, *args, **kwds): self.logger: Logger = getLogger(__name__) self._gameEngine: GameEngine = GameEngine() self._gameState: GameState = GameState() self._gameSettings: GameSettings = GameSettings() self._computer: Computer = Computer() self._intelligence: Intelligence = Intelligence() self._ktm: KlingonTorpedoMediator = KlingonTorpedoMediator() self._ctm: CommanderTorpedoMediator = CommanderTorpedoMediator() self._ptm: EnterpriseTorpedoMediator = EnterpriseTorpedoMediator() self._stm: SuperCommanderTorpedoMediator = SuperCommanderTorpedoMediator( ) self._km: KlingonMediator = KlingonMediator() self._cm: CommanderMediator = CommanderMediator() self._scm: SuperCommanderMediator = SuperCommanderMediator() self._epm: EnterprisePhaserMediator = EnterprisePhaserMediator() self._messageConsole: MessageConsole = MessageConsole() self._soundMachine: SoundMachine = SoundMachine() self._playerList: SpriteList = SpriteList() self._klingonList: SpriteList = SpriteList() self._commanderList: SpriteList = SpriteList() self._superCommanderList: SpriteList = SpriteList()
def process_layer(map_object: pytiled_parser.objects.TileMap, layer_name: str, scaling: float = 1, base_directory: str = "") -> SpriteList: """ This takes a map layer returned by the read_tmx function, and creates Sprites for it. :param map_object: The TileMap read in by read_tmx. :param layer_name: The name of the layer that we are creating sprites for. :param scaling: Scaling the layer up or down. (Note, any number besides 1 can create a tearing effect, if numbers don't evenly divide.) :param base_directory: Base directory of the file, that we start from to load images. :returns: A SpriteList. """ if len(base_directory) > 0 and not base_directory.endswith("/"): base_directory += "/" layer = get_tilemap_layer(map_object, layer_name) if layer is None: print(f"Warning, no layer named '{layer_name}'.") return SpriteList() if isinstance(layer, pytiled_parser.objects.TileLayer): return _process_tile_layer(map_object, layer, scaling, base_directory) elif isinstance(layer, pytiled_parser.objects.ObjectLayer): return _process_object_layer(map_object, layer, scaling, base_directory) print(f"Warning, layer '{layer_name}' has unexpected type. '{type(layer)}'") return SpriteList()
def __init__(self): super().__init__() self.logger: Logger = getLogger(TestShooting.MADE_UP_PRETTY_MAIN_NAME) set_background_color(color.WHITE) self.background: Texture = cast(Texture, None) self._enterprise: Enterprise = cast(Enterprise, None) self._galaxy: Galaxy = cast(Galaxy, None) self._quadrant: Quadrant = cast(Quadrant, None) self._quadrantMediator: QuadrantMediator = cast(QuadrantMediator, None) self._statusConsole: StatusConsole = cast(StatusConsole, None) self._messageConsole: MessageConsole = cast(MessageConsole, None) self._gameState: GameState = cast(GameState, None) self._gameSettings: GameSettings = cast(GameSettings, None) self._gameEngine: GameEngine = cast(GameEngine, None) self._intelligence: Intelligence = cast(Intelligence, None) self._computer: Computer = cast(Computer, None) self._sprites: SpriteList = SpriteList() self._staticSprites: SpriteList = SpriteList() self._selectedGamePiece: GamePiece = cast(GamePiece, None)
def init_enemies(self): self.enemies = SpriteList(is_static=True) self.moving_enemies_list_in_x = SpriteList(is_static=False) self.moving_enemies_list_in_y = SpriteList(is_static=False) def create_enemy(x, y, condition, direction_x): if condition: if direction_x: enemy = self.create_object( 'enemy/enemySwimming_1', (x, y), at=self.moving_enemies_list_in_x) else: enemy = self.create_object( 'enemy/enemyFlyingAlt_1', (x, y), at=self.moving_enemies_list_in_y) else: enemy = self.create_object('enemy/enemyFloating_1', (x, y), at=self.enemies) # Parâmetro True caso seja um Inimigo que se move create_enemy(35, 7, True, True) create_enemy(35, 10, True, True) create_enemy(35, 8, True, True) create_enemy(35, 9, True, True) #create_enemy(21, 10, False, False) create_enemy(34, 6, True, False) #create_enemy(40, 4, False, False) create_enemy(46, 6, True, False) create_enemy(72, 6, True, False) create_enemy(66, 6, True, False) create_enemy(18, 6, True, False) create_enemy(23, 6, True, False) create_enemy(60, 6, True, False)
def setup(self): self.player_ships = SpriteList() self.enemy_ships = SpriteList() self.explosions_list = SpriteList() self.player_base = Base(PLAYER_BASE_POSITION_X, PLAYER_BASE_POSITION_Y, PLAYER_BAR_POSITION_X, PLAYER_BAR_POSITION_Y) self.enemy_base = Base(ENEMY_BASE_POSITION_X, ENEMY_BASE_POSITION_Y, ENEMY_BAR_POSITION_X, ENEMY_BAR_POSITION_Y)
def __makeKlingonSpriteList(self): if self._quadrant.klingonCount > 0: self._gameState.shipCondition = ShipCondition.Red klingonSprites: SpriteList = SpriteList() for klingon in self._quadrant.klingons: klingonSprites.append(klingon) self._quadrantMediator.klingonList = klingonSprites else: self._quadrantMediator.klingonList = SpriteList()
def __makeCommanderSpriteList(self): if self._quadrant.commanderCount > 0: self._gameState.shipCondition = ShipCondition.Red commanderSprites: SpriteList = SpriteList() for commander in self._quadrant.commanders: commanderSprites.append(commander) self._quadrantMediator.commanderList = commanderSprites else: self._quadrantMediator.commanderList = SpriteList()
def __makeSuperCommanderSpriteList(self): if self._quadrant.superCommanderCount > 0: self._gameState.shipCondition = ShipCondition.Red superCommanderSprites: SpriteList = SpriteList() for superCommander in self._quadrant.superCommanders: superCommanderSprites.append(superCommander) self._quadrantMediator.superCommanderList = superCommanderSprites else: self._quadrantMediator.superCommanderList = SpriteList()
def __makeKlingonSpriteList(self, quadrant: Quadrant): if quadrant.klingonCount > 0: self._gameState.shipCondition = ShipCondition.Red klingonSprites: SpriteList = SpriteList() for klingon in quadrant.klingons: klingonSprites.append(klingon) self.klingonList = klingonSprites else: self.klingonList = SpriteList()
def __init__(self): self.logger: Logger = getLogger(__name__) self._soundMachine: SoundMachine = SoundMachine() super().__init__() self._torpedoes: SpriteList = SpriteList() self._misses: SpriteList = SpriteList() self._explosions: SpriteList = SpriteList() self._torpedoExplosionTextures: TextureList = self._loadPhotonTorpedoExplosions( )
def generate_sprites(map_object, layer_name, scaling, base_directory=""): sprite_list = SpriteList() if layer_name not in map_object.layers_int_data: print(f"Warning, no layer named '{layer_name}'.") return sprite_list map_array = map_object.layers_int_data[layer_name] # Loop through the layer and add in the wall list for row_index, row in enumerate(map_array): for column_index, item in enumerate(row): if str(item) in map_object.global_tile_set: tile_info = map_object.global_tile_set[str(item)] filename = base_directory + tile_info.source my_sprite = Sprite(filename, scaling) my_sprite.right = column_index * (map_object.tilewidth * scaling) my_sprite.top = (map_object.height - row_index) * (map_object.tileheight * scaling) if tile_info.points is not None: my_sprite.set_points(tile_info.points) sprite_list.append(my_sprite) elif item != 0: print(f"Warning, could not find {item} image to load.") return sprite_list
def _process_tile_layer(map_object: pytiled_parser.objects.TileMap, layer: pytiled_parser.objects.TileLayer, scaling: float = 1, base_directory: str = "") -> SpriteList: sprite_list: SpriteList = SpriteList() map_array = layer.data # Loop through the layer and add in the wall list for row_index, row in enumerate(map_array): for column_index, item in enumerate(row): # Check for empty square if item == 0: continue tile = _get_tile_by_gid(map_object, item) if tile is None: print(f"Warning, couldn't find tile for item {item} in layer " f"'{layer.name}' in file '{map_object.tmx_file}'.") continue my_sprite = _create_sprite_from_tile(map_object, tile, scaling=scaling, base_directory=base_directory) if my_sprite is None: print(f"Warning: Could not create sprite number {item} in layer '{layer.name}' {tile.image.source}") else: my_sprite.center_x = column_index * (map_object.tile_size[0] * scaling) + my_sprite.width / 2 my_sprite.center_y = (map_object.map_size.height - row_index - 1) \ * (map_object.tile_size[1] * scaling) + my_sprite.height / 2 sprite_list.append(my_sprite) return sprite_list
def _doWeHaveLineOfSight(self, quadrant: Quadrant, startingPoint: ArcadePoint, endPoint: ArcadePoint) -> LineOfSightResponse: """ Check to see if a planet or a StarBase prevents the Enterprise from shooting at the enemy Args: startingPoint: Returns: `True` if no obstructions, else `False` """ obstacles: SpriteList = SpriteList() if quadrant.hasPlanet is True: obstacles.append(quadrant.planet) if quadrant.hasStarBase is True: obstacles.append(quadrant.starBase) results: LineOfSightResponse = self._hasLineOfSight( startingPoint=startingPoint, endPoint=endPoint, obstacles=obstacles) self.logger.info(f'{results=}') return results
def __init__(self, width: int, height: int, title: str): super().__init__(width, height, title) set_background_color(color.BLACK) self._sprites: SpriteList = SpriteList() em: EnterpriseTorpedoMediator = EnterpriseTorpedoMediator() km: KlingonTorpedoMediator = KlingonTorpedoMediator() cm: CommanderTorpedoMediator = CommanderTorpedoMediator() sm: SuperCommanderTorpedoMediator = SuperCommanderTorpedoMediator() epm: EnterprisePhaserMediator = EnterprisePhaserMediator() self._enterpriseTorpedoExplosionTextures: TextureList = em.torpedoExplosionTextures self._klingonTorpedoExplosionTextures: TextureList = km.torpedoExplosionTextures self._commanderTorpedoExplosionTextures: TextureList = cm.torpedoExplosionTextures self._superCommanderTorpedoExplosionTextures: TextureList = sm.torpedoExplosionTextures self._phaserFireTextures: TextureList = epm.phaserFireTextures() self._etxPoint: ArcadePoint = cast(ArcadePoint, None) self._ktxPoint: ArcadePoint = cast(ArcadePoint, None) self._ctxPoint: ArcadePoint = cast(ArcadePoint, None) self._stxPoint: ArcadePoint = cast(ArcadePoint, None) self._phaserFirePoint: ArcadePoint = cast(ArcadePoint, None)
def __init__(self, window: Window, *args, **kwargs): super().__init__() self.window: Window = window self._focused_element: Optional[UIElement] = None self._hovered_element: Optional[UIElement] = None self._ui_elements: SpriteList = SpriteList(use_spatial_hash=True) self._id_cache: Dict[str, UIElement] = {} self.register_event_type('on_ui_event') # self.window.push_handlers(self) # Not as explicit as following self.window.push_handlers( self.on_draw, self.on_mouse_press, self.on_mouse_release, self.on_mouse_scroll, self.on_mouse_motion, self.on_key_press, self.on_key_release, self.on_text, self.on_text_motion, self.on_text_motion_select, )
def __init__(self): super().__init__() self._baseTorpedoMediatorLogger: Logger = getLogger(__name__) self._soundMachine: SoundMachine = SoundMachine() self._devices: Devices = Devices() self._torpedoes: SpriteList = SpriteList() self._explosions: SpriteList = SpriteList() self._torpedoFollowers: SpriteList = SpriteList(is_static=True) self._misses: SpriteList = SpriteList() self._lastTimeCheck: float = self._gameEngine.gameClock / MILLISECONDS self._baseTorpedoMediatorLogger.info(f'{self._lastTimeCheck=}')
def __init__(self, window=None, attach_callbacks=True, **kwargs): """ Creates a new :py:class:`arcade.gui.UIManager` and registers the corresponding handlers to the current window. The UIManager has to be created, before :py:meth:`arcade.Window.show_view()` has been called. To support multiple views a singleton UIManager should be passed to all views. As an alternative you can remove all registered handlers of a UIManager by calling :py:meth:`arcade.gui.UIManager.unregister_handlers()` within :py:meth:`arcade.View.on_hide_view()`. :param arcade.Window window: Window to register handlers to, defaults to :py:meth:`arcade.get_window()` :param kwargs: catches unsupported named parameters """ super().__init__() # TODO really needed? self.window: Window = window if window else arcade.get_window() self._focused_element: Optional[UIElement] = None self._hovered_element: Optional[UIElement] = None self._ui_elements: SpriteList = SpriteList(use_spatial_hash=True) self._id_cache: Dict[str, UIElement] = {} self.register_event_type('on_ui_event') if attach_callbacks: self.register_handlers()
def _process_tile_layer(sprite_class, map_object, layer, scaling=1, base_directory=""): sprite_list = SpriteList() map_array = layer.layer_data for row_index, row in enumerate(map_array): for column_index, item in enumerate(row): if item == 0: continue tile = _get_tile_by_gid(map_object, item) if tile is None: print(f"Warning, couldn't find tile for item {item} in layer " f"'{layer.name}' in file '{map_object.tmx_file}'.") continue my_sprite = _create_sprite_from_tile(sprite_class, map_object, tile, scaling=scaling, base_directory=base_directory) if my_sprite is None: print( f"Warning: Could not create sprite number {item} in layer '{layer.name}' {tile.image.source}" ) else: my_sprite.center_x = column_index * ( map_object.tile_size[0] * scaling) + my_sprite.width / 2 my_sprite.center_y = (map_object.map_size.height - row_index - 1) \ * (map_object.tile_size[1] * scaling) + my_sprite.height / 2 sprite_list.append(my_sprite) return sprite_list
def draw(self, **kwargs): """ Draw the sprite. """ if self._sprite_list is None: from arcade import SpriteList self._sprite_list = SpriteList() self._sprite_list.append(self) self._sprite_list.draw(**kwargs)
def _process_object_layer(map_object: pytiled_parser.objects.TileMap, layer: pytiled_parser.objects.ObjectLayer, scaling: float = 1, base_directory: str = "") -> SpriteList: sprite_list: SpriteList = SpriteList() for cur_object in layer.tiled_objects: if cur_object.gid is None: print("Warning: Currently only tiles (not objects) are supported in object layers.") continue tile = _get_tile_by_gid(map_object, cur_object.gid) my_sprite = _create_sprite_from_tile(map_object, tile, scaling=scaling, base_directory=base_directory) x = cur_object.location.x * scaling y = (map_object.map_size.height * map_object.tile_size[1] - cur_object.location.y) * scaling my_sprite.width = width = cur_object.size[0] * scaling my_sprite.height = height = cur_object.size[1] * scaling centerX = width / 2 centerY = height / 2 rotation = -math.radians(cur_object.rotation) cosRotation = math.cos(rotation) sinRotation = math.sin(rotation) rotatedCenterX = centerX * cosRotation - centerY * sinRotation rotatedCenterY = centerX * sinRotation + centerY * cosRotation my_sprite.position = (x + rotatedCenterX, y + rotatedCenterY) my_sprite.angle = math.degrees(rotation) if cur_object.properties is not None and 'change_x' in cur_object.properties: my_sprite.change_x = float(cur_object.properties['change_x']) if cur_object.properties is not None and 'change_y' in cur_object.properties: my_sprite.change_y = float(cur_object.properties['change_y']) if cur_object.properties is not None and 'boundary_bottom' in cur_object.properties: my_sprite.boundary_bottom = float(cur_object.properties['boundary_bottom']) if cur_object.properties is not None and 'boundary_top' in cur_object.properties: my_sprite.boundary_top = float(cur_object.properties['boundary_top']) if cur_object.properties is not None and 'boundary_left' in cur_object.properties: my_sprite.boundary_left = float(cur_object.properties['boundary_left']) if cur_object.properties is not None and 'boundary_right' in cur_object.properties: my_sprite.boundary_right = float(cur_object.properties['boundary_right']) if cur_object.properties is not None: my_sprite.properties.update(cur_object.properties) # sprite.properties sprite_list.append(my_sprite) return sprite_list
def process_layer(sprite_class, map_object, layer_name, scaling=1, base_directory=""): if len(base_directory) > 0 and not base_directory.endswith("/"): base_directory += "/" layer = get_tilemap_layer(map_object, layer_name) if layer is None: print(f"Warning, no layer named '{layer_name}'.") return SpriteList() if isinstance(layer, pytiled_parser.objects.TileLayer): return _process_tile_layer(sprite_class, map_object, layer, scaling, base_directory) elif isinstance(layer, pytiled_parser.objects.ObjectLayer): raise NotImplementedError( "This shim does not include _process_object_layer") print( f"Warning, layer '{layer_name}' has unexpected type. '{type(layer)}'") return SpriteList()
def __init__(self): super().__init__() self.objects: List[Moon] = [] self.obj_sprite: Dict[Moon, arcade.Sprite] = {} self.sprites = SpriteList() self.SCALE = 10 self.UPS = 60 self._last_update = 0
def _process_object_layer(map_object: pytiled_parser.objects.TileMap, layer: pytiled_parser.objects.ObjectLayer, scaling: float = 1, base_directory: str = "") -> SpriteList: sprite_list: SpriteList = SpriteList() for cur_object in layer.tiled_objects: if cur_object.gid is None: print( "Warning: Currently only tiles (not objects) are supported in object layers." ) continue tile = _get_tile_by_gid(map_object, cur_object.gid) my_sprite = _create_sprite_from_tile(map_object, tile, scaling=scaling, base_directory=base_directory) my_sprite.left = cur_object.location.x * scaling my_sprite.bottom = ( map_object.map_size.height * map_object.tile_size[1] - cur_object.location.y) * scaling if cur_object.properties is not None and 'change_x' in cur_object.properties: my_sprite.change_x = float(cur_object.properties['change_x']) if cur_object.properties is not None and 'change_y' in cur_object.properties: my_sprite.change_y = float(cur_object.properties['change_y']) if cur_object.properties is not None and 'boundary_bottom' in cur_object.properties: my_sprite.boundary_bottom = float( cur_object.properties['boundary_bottom']) if cur_object.properties is not None and 'boundary_top' in cur_object.properties: my_sprite.boundary_top = float( cur_object.properties['boundary_top']) if cur_object.properties is not None and 'boundary_left' in cur_object.properties: my_sprite.boundary_left = float( cur_object.properties['boundary_left']) if cur_object.properties is not None and 'boundary_right' in cur_object.properties: my_sprite.boundary_right = float( cur_object.properties['boundary_right']) if cur_object.properties is not None: my_sprite.properties.update(cur_object.properties) # sprite.properties sprite_list.append(my_sprite) return sprite_list
def __init__(self): super().__init__() self.logger: Logger = getLogger(__name__) self._gameSettings: GameSettings = GameSettings() self._gameEngine: GameEngine = GameEngine() self._gameState: GameState = GameState() self._messageConsole: MessageConsole = MessageConsole() self._soundMachine: SoundMachine = SoundMachine() self._phaserBolts: SpriteList = SpriteList() self._phaserFireTextures: TextureList = self._loadFirePhaserTextures()
def init_items(self): self.coins = SpriteList() def create_coin(x, y, *args): if args: for i in range(args[0]): coin = self.create_object('other/items/yellowGem', (x, y), at=self.coins) self.coins.append(coin) x += 1 else: coin = self.create_object('other/items/yellowGem', (x, y), at=self.coins) self.coins.append(coin) #Coins create_coin(6, 4, 3) create_coin(9, 7, 3) create_coin(14, 5, 3) create_coin(12, 10, 3) create_coin(20, 10, 3) create_coin(24, 3, 2) create_coin(26, 5, 3) create_coin(33, 4, 1) create_coin(35, 4, 1) create_coin(39, 4, 1) create_coin(41, 4, 1) create_coin(45, 4, 1) create_coin(47, 4, 1) create_coin(54, 6, 3) create_coin(62, 6, 3) create_coin(67, 4, 3) create_coin(78, 1, 3) create_coin(81, 1, 3) create_coin(84, 1, 3) self.items = SpriteList()
def _process_tile_layer(map_object: pytiled_parser.objects.TileMap, layer: pytiled_parser.objects.TileLayer, scaling: float = 1, base_directory: str = "", use_spatial_hash: Optional[bool] = None, hit_box_algorithm="Simple", hit_box_detail: float = 4.5) -> SpriteList: sprite_list: SpriteList = SpriteList(use_spatial_hash=use_spatial_hash) map_array = layer.layer_data # Loop through the layer and add in the wall list for row_index, row in enumerate(map_array): for column_index, item in enumerate(row): # Check for empty square if item == 0: continue tile = _get_tile_by_gid(map_object, item) if tile is None: error_msg = f"Warning, couldn't find tile for item {item} in layer " \ f"'{layer.name}' in file '{map_object.tmx_file}'." raise ValueError(error_msg) my_sprite = _create_sprite_from_tile( map_object, tile, scaling=scaling, base_directory=base_directory, hit_box_algorithm=hit_box_algorithm, hit_box_detail=hit_box_detail) if my_sprite is None: print( f"Warning: Could not create sprite number {item} in layer '{layer.name}' {tile.image.source}" ) else: my_sprite.center_x = column_index * ( map_object.tile_size[0] * scaling) + my_sprite.width / 2 my_sprite.center_y = (map_object.map_size.height - row_index - 1) \ * (map_object.tile_size[1] * scaling) + my_sprite.height / 2 # Opacity opacity = layer.opacity if opacity: my_sprite.alpha = int(opacity * 255) sprite_list.append(my_sprite) return sprite_list
def __init__(self, world_state: Dict[Vector, int], queue: Queue): super().__init__() self.world_state = world_state self.key_queue = queue self._sprites = SpriteList() self._obj_sprite = dict() self.score = 0 self.SCALE = 64 # shoul_update self.UPS = 60 self._last_update = 0
def __init__(self, loaded_view: Optional[LoadableWindowView] = None, loading_text: str = 'Loading', background_name: Optional[str] = None): super().__init__() self.sprite_list = SpriteList() self.loading_text = loading_text self.progress = 0 self.progress_bar = self.create_progress_bar() self.loading_background = Sprite(background_name) if \ background_name is not None else None self.sprite_list.extend( [e for e in (self.progress_bar, self.loading_background) if e] ) self.set_updated_and_drawn_lists() self.loaded_view = loaded_view
def generate_sprites(map_object: TiledMap, layer_name: str, scaling: float, base_directory="") -> SpriteList: """ generate_sprites has been deprecated. Use arcade.tilemap.process_layer instead. Generate the sprites for a layer in a map. :param TiledMap map_object: Map previously read in from read_tiled_map function :param layer_name: Name of the layer we want to generate sprites from. Case sensitive. :param scaling: Scaling factor. :param base_directory: Directory to read images from. Defaults to current directory. :return: List of sprites :rtype: SpriteList """ sprite_list = SpriteList() if layer_name not in map_object.layers_int_data: print(f"Warning, no layer named '{layer_name}'.") return sprite_list map_array = map_object.layers_int_data[layer_name] # Loop through the layer and add in the wall list for row_index, row in enumerate(map_array): for column_index, item in enumerate(row): if str(item) in map_object.global_tile_set: tile_info = map_object.global_tile_set[str(item)] tmx_file = base_directory + tile_info.source my_sprite = Sprite(tmx_file, scaling) my_sprite.center_x = column_index * ( map_object.tilewidth * scaling) - map_object.tilewidth / 2 * scaling my_sprite.center_y = (map_object.height - row_index) * ( map_object.tileheight * scaling) - map_object.tileheight / 2 * scaling if tile_info.points is not None: my_sprite.set_points(tile_info.points) sprite_list.append(my_sprite) elif item != 0: print(f"Warning, could not find {item} image to load.") return sprite_list
def enterQuadrant(self, quadrant: Quadrant, enterprise): currentSectorCoordinates: Coordinates = self._intelligence.generateSectorCoordinates( ) if self._gameSettings.debugManualPlaceShipInQuadrant is True: currentSectorCoordinates = self._gameSettings.manualSectorCoordinates playerList: SpriteList = SpriteList() playerList.append(enterprise) self._gameState.currentSectorCoordinates = currentSectorCoordinates quadrant.placeEnterprise(enterprise, currentSectorCoordinates) self.playerList = playerList # Don't do this until we have set up the current quadrant self._makeEnemySpriteLists(quadrant=quadrant) self._doDebugActions(quadrant=quadrant)