def tiled_npc_set(self): tiled_npc_sprite = arcade.SpriteList(use_spatial_hash=True, spatial_hash_cell_size=32) villager_list = arcade.process_layer(self.my_map, "villager", scaling=2, use_spatial_hash=True, hit_box_algorithm="None") for v in villager_list: x, y = pixel_to_grid(v.center_x, v.center_y) villager = Villager(x=x, y=y) tiled_npc_sprite.append(villager) citizen_list = arcade.process_layer(self.my_map, "citizen", scaling=2, use_spatial_hash=True, hit_box_algorithm="None") for c in citizen_list: x, y = pixel_to_grid(c.center_x, c.center_y) citizen = Citizen(x=x, y=y) tiled_npc_sprite.append(citizen) return tiled_npc_sprite
def tiled_map_obj_set(self): tiled_map_obj_sprite = arcade.SpriteList(use_spatial_hash=True, spatial_hash_cell_size=32) door = arcade.process_layer(self.my_map, "door", scaling=2, use_spatial_hash=True, hit_box_algorithm="None") up_stairs = arcade.process_layer(self.my_map, "up_stairs", scaling=2, use_spatial_hash=True, hit_box_algorithm="None") down_stairs = arcade.process_layer(self.my_map, "down_stairs", scaling=2, use_spatial_hash=True, hit_box_algorithm="None") for m in door: x, y = pixel_to_grid(m.center_x, m.center_y) obj = DoorH(x=x, y=y) obj.scale = 2 obj.texture = m.texture obj.blocks = True tiled_map_obj_sprite.append(obj) for m in up_stairs: x, y = pixel_to_grid(m.center_x, m.center_y) obj = Up_Stairs(x=x, y=y) obj.scale = 2 # obj.texture = m.texture obj.blocks = True tiled_map_obj_sprite.append(obj) for m in down_stairs: x, y = pixel_to_grid(m.center_x, m.center_y) obj = Down_Stairs(x=x, y=y) obj.scale = 2 # obj.texture = m.texture obj.blocks = True tiled_map_obj_sprite.append(obj) return tiled_map_obj_sprite
def setup_combate(): """ Create la habitación donde ocurriran los combates """ room = Room() # Lista de Sprites room.wall_list = arcade.SpriteList() room.textura = arcade.SpriteList() map = arcade.tilemap.read_tmx("resources" + os.path.sep + "maps" + os.path.sep + "combate.tmx") carga = arcade.process_layer(map, "Nivel", 1) wall = arcade.process_layer(map, "Muros Invisibles", 1) room.textura = carga room.wall_list = wall return room
def setup_room_1(): """ Crea la habitacion 1. """ room = Room() # Lista de Sprites room.wall_list = arcade.SpriteList() room.textura = arcade.SpriteList() map = arcade.tilemap.read_tmx("resources" + os.path.sep + "maps" + os.path.sep + "nivel1.tmx") carga = arcade.process_layer(map, "Nivel", 1) wall = arcade.process_layer(map, "Muros Invisibles", 1) room.textura = carga room.wall_list = wall return room
def tiled_floor_set(self): tiled_floor_sprite = arcade.SpriteList(use_spatial_hash=True, spatial_hash_cell_size=32) floors = arcade.process_layer(self.my_map, "floor", scaling=2, use_spatial_hash=True, hit_box_algorithm="None") for f in floors: x, y = pixel_to_grid(f.center_x, f.center_y) floor = Floor(x=x, y=y) floor.scale = 2 floor.texture = f.texture floor.color = COLORS.get("dark_ground") tiled_floor_sprite.append(floor) return tiled_floor_sprite
def tiled_wall_set(self): tiled_wall_sprite = arcade.SpriteList(use_spatial_hash=True, spatial_hash_cell_size=32) walls = arcade.process_layer(self.my_map, "wall", scaling=2, use_spatial_hash=True, hit_box_algorithm="None") for w in walls: x, y = pixel_to_grid(w.center_x, w.center_y) wall = Wall(x=x, y=y) wall.scale = 2 wall.texture = w.texture wall.blocks = True wall.color = COLORS.get("dark_ground") tiled_wall_sprite.append(wall) return tiled_wall_sprite
def setup(self): # This function permit the restart of the game # Used to keep track of our scrolling self.view_bottom = 0 self.view_left = 0 # Create the Sprite lists # Spatial hash speed up collision detection but slow down movement # The player move often so don't use Spatial Hash self.wall_list = arcade.SpriteList(use_spatial_hash=True, is_static=True) self.coin_list = arcade.SpriteList(use_spatial_hash=True, is_static=True) self.death_list = arcade.SpriteList(use_spatial_hash=True, is_static=True) self.background_list = arcade.SpriteList(use_spatial_hash=True, is_static=True) # Keep track of the score # Start background music self.media_player = self.backgroud_sound.play(volume=DEFAULT_VOLUME, loop=True) # Set up the player self.player_list = arcade.SpriteList() self.player_sprite = Player() self.player_list.append(self.player_sprite) # Name of map file to load map_name = "maps/chapter1.tmx" # Name of the layers platforms_layer_name = "Platforms" coins_layer_name = "Coins" death_layer_name = "Death" background_layer_name = "Background" # Read in the tiled map my_map = arcade.tilemap.read_tmx(map_name) # -- Platforms self.wall_list = arcade.tilemap.process_layer(my_map, platforms_layer_name, TILE_SCALING, use_spatial_hash=True) # -- Coins self.coin_list = arcade.tilemap.process_layer(my_map, coins_layer_name, TILE_SCALING, use_spatial_hash=True) # -- Touch to die object self.death_list = arcade.tilemap.process_layer(my_map, death_layer_name, TILE_SCALING, use_spatial_hash=True) # -- Background and untouchable item self.background_list = arcade.process_layer(my_map, background_layer_name, TILE_SCALING, use_spatial_hash=True) # Create the 'physics engine' self.physics_engine = arcade.PhysicsEnginePlatformer( self.player_sprite, self.wall_list, GRAVITY) # After all base setup try load save.dat try: self.load_data() except FileNotFoundError: # If not found any save file set initial value self.coins = 0 self.lifes = 3 self.level = 1 self.player_sprite.center_x = PLAYER_START_X self.player_sprite.center_y = PLAYER_START_Y
def setup(self, niveau=1): """ Configurer le jeu ici. Appeler cette fonction pour (re)démarrer le jeu.""" self.niveau = niveau # Sprite: Image animée # SpriteList: Groupement d'images animées self.personnages = arcade.SpriteList() # Sprite pour le personnage self.personnage = Personnage() # positionner le personnage dans la fenêtre (pixel) self.personnage.center_x = 64 self.personnage.center_y = 128 # l'ajouter à sa SpriteList self.personnages.append(self.personnage) # Utilisation d'une carte (tilemap) carte = arcade.read_tmx(":resources:tmx_maps/map_with_ladders.tmx") # extraction des calques # ouvrir le fichier tmx avec Tiled pour en prendre connaissance ... # (voir fichier joint «resources.zip») self.pieces = arcade.process_layer( carte, "Coins", scaling=ECHELLE_TUILE, # options use_spatial_hash=True ) self.plateformes = arcade.process_layer( carte, "Platforms", scaling=ECHELLE_TUILE, # options use_spatial_hash=True ) self.arriere_plan = arcade.process_layer( carte, "Background", scaling=ECHELLE_TUILE, use_spatial_hash=True ) self.echelles = arcade.process_layer( carte, "Ladders", scaling=ECHELLE_TUILE, use_spatial_hash=True ) plateformes_mobiles = arcade.process_layer( carte, "Moving Platforms", scaling=ECHELLE_TUILE ) # Ce sont des plateformes donc ... for plateforme in plateformes_mobiles: self.plateformes.append(plateforme) self.x_max_carte = carte.map_size.width * carte.tile_size.width * ECHELLE_TUILE if carte.background_color: arcade.set_background_color(carte.background_color) # Configurer le «moteur physique» # attention: on passe de `PhysicsEngineSimple` à `PhysicsEnginePlatformer` self.physics_engine = arcade.PhysicsEnginePlatformer( self.personnage, # personnage self.plateformes, # obstacles ou sols gravity_constant=GRAVITE, # force de la gravité ladders=self.echelles ) self.xmin = 0 self.ymin = 0
def setup(self): self.view_bottom = 0 self.view_left = 0 #* Создаём спрайт листы self.player_list = arcade.SpriteList() self.player_sprite = arcade.SpriteList() self.coin_list = arcade.SpriteList() self.enemy_list = arcade.SpriteList() self.goblin_sprite = arcade.SpriteList() self.fireball_list = arcade.SpriteList() self.dont_touch_list = arcade.SpriteList() self.flag_list = arcade.SpriteList() #* Ссылаемся что список игрока равен классу что мы уже описали self.player_sprite = PlayerCharacter() # self.goblin_sprite = Goblin() #* Задаём начальные координаты старта персонажа, его размеры. self.player_sprite.center_x = PLAYER_START_X self.player_sprite.center_y = PLAYER_START_Y self.player_sprite.scale = PLAYER_SCALING self.player_list.append(self.player_sprite) #* Задаём какую карту загружать и где она расположена map_name = "test4.tmx" my_map = arcade.tilemap.read_tmx(map_name) #* Вычисляем правый конец карты в пикселях # self.end_of_map = my_map.map_size.width * GRID_PIXEL_SIZE #* --- Слой земли и декораций--- self.background_list = arcade.process_layer(my_map, "background", TILE_SCALING) self.vilage_list = arcade.process_layer(my_map, "vilage", TILE_SCALING) self.wall_list = arcade.process_layer(my_map, "platforms", TILE_SCALING) self.dont_touch_list = arcade.process_layer(my_map, "dont_touch", TILE_SCALING) self.flag_list = arcade.process_layer(my_map, "flags", TILE_SCALING) #* --- Слой монеток --- coin_layer_name = "coins" self.coin_list = arcade.process_layer(my_map, coin_layer_name, COIN_SCALE) #* --- Слой врагов --- enemy_layer_name = "enemies" e_list = arcade.process_layer(my_map, enemy_layer_name, TILE_SCALING) for e in e_list: enemy = Goblin() enemy.stand_right_textures = [] enemy.stand_left_textures = [] enemy.walk_right_textures = [] enemy.walk_left_textures = [] for i in range(4): enemy.stand_right_textures.append( arcade.load_texture( f"resources/enemies/Knight Skeleton/idle_{i}.png")) for i in range(4): enemy.stand_left_textures.append( arcade.load_texture( f"resources/enemies/Knight Skeleton/idle_{i}.png", mirrored=True)) for i in range(6): enemy.walk_right_textures.append( arcade.load_texture( f"resources/enemies/Knight Skeleton/walk_{i}.png")) for i in range(6): enemy.walk_left_textures.append( arcade.load_texture( f"resources/enemies/Knight Skeleton/walk_{i}.png", mirrored=True)) enemy.texture_change_distance = 20 enemy.center_x = e.center_x enemy.center_y = e.center_y enemy.scale = 1 enemy.change_x = ENEMY_SPEED enemy.goblin_physics_engine = arcade.PhysicsEnginePlatformer( self.goblin_sprite, self.wall_list, gravity_constant=GRAVITY) self.enemy_list.append(enemy) #* Создаём физический движок self.physics_engine = arcade.PhysicsEnginePlatformer( self.player_sprite, self.wall_list, gravity_constant=GRAVITY ) #TODO: ещё нужно будет добавить ladder=self.ladder_list
def __init__(self): super().__init__() self.matrix = pathfinding.layer_to_grid( path['maps'] / 'test_map_islands.csv') arcade.set_background_color(arcade.color.AMAZON) # Track the current state of what key is pressed self.left_pressed = False self.right_pressed = False self.up_pressed = False self.down_pressed = False self.enemy_list = arcade.SpriteList() self.player_ship = Ship(path['img'] / 'ship' / 'ship.png') # self.enemy_ship = EnemyShip(path['img'] / 'enemy_ship' / 'ship.png') for i in range(3): self.enemy_list.append(EnemyShip( path['img'] / 'enemy_ship' / 'ship.png') ) self.cannonballs = arcade.SpriteList() self.player_ship.set_position(800, 800) # self.enemy_ship.set_position(1600, 1200) # self.enemy_list.append(self.enemy_ship) self.layer_shift_count = 0 self.seafoam_shift_count = 64 self.map = arcade.tilemap.read_tmx(path['maps'] / "test_map.tmx") self.map_layers = [arcade.process_layer( self.map, layer.name) for layer in self.map.layers] # Use spatial hashing with the static layers for layer in range(len(self.map_layers)): if self.map_layers[layer] in (2, 3): layer.use_spatial_hash = True layer.spatial_hash = arcade.sprite_list._SpatialHash( cell_size=128 ) layer._recalculate_spatial_hashes() self.physics_engine = arcade.PhysicsEngineSimple( self.player_ship, self.map_layers[2]) # self.enemy_engines = [arcade.PhysicsEngineSimple( # enemy, self.map_layers[2]) for enemy in self.enemy_list] # Used to keep track of our scrolling self.view_right = 0 self.view_left = 0 self.view_bottom = 0 self.view_top = 0 # self.player_view = PlayerView() self.player_ship.target_angle = 0 self.SAIL_SPEED_FACTOR = 0 self.audio_list = [] self.music = arcade.Sound( str(path['sound'] / "shanty1.mp3") ) self.ambient_track = arcade.Sound( str(path['sound'] / "ship_ambient.mp3") ) self.audio_list.append(self.music) self.audio_list.append(self.ambient_track) for audio in self.audio_list: audio.play() self.music.set_volume(MUSIC_VOLUME*0.2) self.ambient_track.set_volume(MUSIC_VOLUME*0.4) self.viewport_scale = 1 self.collision_time = 0 self.time_diff = 20 self.cannon_cooldown = 5 self.cannon_fired_time = 0
def __init__(self): super().__init__() self.formation = 0 self.matrix = pathfinding.layer_to_grid( path['maps'] / 'dungeon_test_walls.csv') self.paused = True self.mouse_position = (0, 0) self.cursor = arcade.Sprite(path['img'] / 'cursor' / 'sword.png') arcade.set_background_color(arcade.color.AMAZON) # Track the current state of what key is pressed self.left_pressed = False self.right_pressed = False self.up_pressed = False self.down_pressed = False self.player_sprites = arcade.SpriteList() self.player_sprites.append(Pirate('brawn')) self.player_sprites.append(Pirate('captain')) self.player_sprites.append(Pirate('bald')) self.selected_character = 0 self.player_sprite = self.player_sprites[self.selected_character] self.player_sprites[1].set_position(200, 200) self.player_sprites[2].set_position(200, 200) self.player_sprite.set_position(200, 200) self.enemy_list = arcade.SpriteList() for i in range(5): self.enemy_list.append( Enemy_SpriteSheet('undead')) self.enemy_list[i].scale = 1.25 self.enemy_list[i].set_position( random.randint(0, 500), random.randint(0, 500) ) # self.enemy_list[0].set_position(800, 200) # self.enemy_list[0].scale = 1.25 self.map = arcade.tilemap.read_tmx(path['maps'] / "dungeon_test.tmx") self.map_layers = [arcade.process_layer( self.map, layer.name) for layer in self.map.layers] # Use spatial hashing with the static layers for layer in self.map_layers: layer.use_spatial_hash = True layer.spatial_hash = arcade.sprite_list._SpatialHash(cell_size=128) layer._recalculate_spatial_hashes() self.physics_engine = arcade.PhysicsEngineSimple( self.player_sprite, self.map_layers[2] ) # Used to keep track of our scrolling self.view_bottom = 0 self.view_left = 0 self.viewport_scale = 0.5 self.level_sprites = arcade.SpriteList() self.player_sprite.weapon = Weapon('sword') self.player_sprite.weapon.center_x = self.player_sprite.center_x-10 self.player_sprite.weapon.center_x = self.player_sprite.center_y self.level_sprites.append(self.player_sprite.weapon)