def setup(self, win): left, self.screen_width, bottom, self.screen_height = win.get_viewport( ) self.coils = ActorList() self.light_layer = LightLayer(self.screen_width, self.screen_height) # self.light_layer.set_background_color(arcade.color.BLACK) radius = 1000 b = arcade.color.MIDNIGHT_BLUE darken = 0.2 light_color = b[0] * darken, b[1] * darken, b[2] * darken self.light1 = Light(0, 0, radius=radius, mode='soft', color=light_color) self.light_layer.add(self.light1) self.light2 = Light(0, 0, radius=radius, mode='soft', color=light_color) self.light_layer.add(self.light2) self.light3 = Light(0, 0, radius=radius, mode='soft', color=light_color) self.light_layer.add(self.light3) self.light4 = Light(0, 0, radius=radius, mode='soft', color=light_color) self.light_layer.add(self.light4)
def flower_light(self): self.light_layer = LightLayer(SCREEN_WIDTH, SCREEN_HEIGHT) self.light_layer.set_background_color(arcade.color.BLACK) self.player_light = Light(0, 0, 390, arcade.color.WHITE, mode="soft") self.light_layer.add(self.player_light) for i, flower in enumerate(self.player.equipment.flower_slot): flower.light = Light(0, 0, radius=flower.texture.width / 3, color=flower.flower_color, mode="soft") self.light_layer.add(flower.light)
def toggle_torch(self): # get closest unlit torch unlit_torch = arcade.get_closest_sprite(self.player, self.unlit_lights) dist = unlit_torch[1] unlit_torch = unlit_torch[0] # if torch is within action range, turn it on if dist < ACTION_RANGE: # create new lit torch to replace unlit torch new_torch = items.Torch(unlit_torch.center_x, unlit_torch.center_y, SCALE) # get rid of unlit torch unlit_torch.kill() # add torch to list of torches self.light_list.append(new_torch) # create a new light source and assign it to the torch light = Light(new_torch.center_x, new_torch.center_y, TORCH_RADIUS, TORCH_LIGHT, 'soft') self.torches[new_torch] = light self.light_layer.add(light) else: lit_torch = arcade.get_closest_sprite(self.player, self.light_list) dist = lit_torch[1] lit_torch = lit_torch[0] # self.torches.pop(lit_torch) # if there isnt an unlit torch in range, but there is a lit torch, turn it off if dist < ACTION_RANGE: # make new unlit torch new_torch = items.UnlitTorch(lit_torch.center_x, lit_torch.center_y, SCALE) # get rid of light source light = self.torches[lit_torch] self.light_layer.remove(light) # get rid of lit torch and add unlit torch lit_torch.kill() self.unlit_lights.append(new_torch)
def setup(self): # create the light layer (width and height of screen) self.light_layer = LightLayer(SW, SH) # set background color self.light_layer.set_background_color(arcade.color.BLACK) # create the player light radius = 100 * SCALE mode = 'soft' color = arcade.csscolor.WHITE self.player_light = Light(0, 0, radius, color, mode) # add the light layer self.light_layer.add(self.player_light) # create a light for each torch for torch in self.light_list: light = TorchLight(torch.center_x, torch.center_y, TORCH_RADIUS) self.light_layer.add(light) self.torches[torch] = light # lighting for torches that cant be unlit for torch in self.perma_torches: light = TorchLight(torch.center_x, torch.center_y, TORCH_RADIUS) self.light_layer.add(light) self.torches[torch] = light # add loot to chests loot = [] for room in self.room_loot: loot += room for chest, loot in zip(self.chests, loot): chest.loot = loot
def __init__(self): if GameEngine.__instance != None: raise Exception("singleton! class") else: GameEngine.__instance == self self.stories = {} # 階層を格納する変数 self.cur_level = None self.player = None self.game_map = None self.action_queue = [] self.messages = deque(maxlen=8) self.selected_item = 0 # キー押下で直接選択したアイテム self.turn_check = [] self.game_state = GAME_STATE.NORMAL self.skill_shape = None self.grid_select_handlers = [] self.move_switch = True self.damage_pop = [] self.pop_position = 30 self.messenger = None self.found_item = [] # 発見済みのアイテム self.player = Player(inventory=Inventory(capacity=18)) # 光源システム self.light_layer = LightLayer(SCREEN_WIDTH, SCREEN_HEIGHT) self.light_layer.set_background_color(arcade.color.BLACK) self.player_light = Light(0, 0, 390, (230, 230, 230), mode="soft") self.light_layer.add(self.player_light)
def __init__(self, width, height, title): """ Set up the application. """ super().__init__(width, height, title) self.time = 0 self.background = arcade.load_texture(":resources:images/backgrounds/abstract_1.jpg") self.torch_list = arcade.SpriteList(is_static=True) self.torch_list.extend([ arcade.Sprite(":resources:images/tiles/torch1.png", scale=0.4, center_x=100, center_y=150), arcade.Sprite(":resources:images/tiles/torch1.png", scale=0.4, center_x=300, center_y=150), arcade.Sprite(":resources:images/tiles/torch1.png", scale=0.4, center_x=500, center_y=150), arcade.Sprite(":resources:images/tiles/torch1.png", scale=0.4, center_x=700, center_y=150), arcade.Sprite(":resources:images/tiles/torch1.png", scale=0.4, center_x=100, center_y=450), arcade.Sprite(":resources:images/tiles/torch1.png", scale=0.4, center_x=300, center_y=450), arcade.Sprite(":resources:images/tiles/torch1.png", scale=0.4, center_x=500, center_y=450), arcade.Sprite(":resources:images/tiles/torch1.png", scale=0.4, center_x=700, center_y=450), ]) self.light_layer = LightLayer(SCREEN_WIDTH, SCREEN_HEIGHT) # Add lights to the location of the torches. We're just using hacky tweak value list here params = ( (100, 'hard'), (100, 'hard'), (100, 'hard'), (100, 'hard'), (120, 'soft'), (120, 'soft'), (120, 'soft'), (120, 'soft'), ) for sprite, p in zip(self.torch_list, params): self.light_layer.add( Light(sprite.center_x, sprite.center_y, radius=p[0], mode=p[1]), ) self.moving_light = Light(400, 300, radius=300, mode='soft') self.light_layer.add(self.moving_light)
def on_key_press(self, symbol: int, modifiers: int): global SCALE key = chr(symbol) # if key in movement controls add to keys pressed if key in list(self.controls.keys()): self.keys_pressed.append(key) elif key == 'q': # toggle torches on the wall on/off if not self.loot_chest(): self.toggle_torch() elif key == 'e': if self.show_inv: self.show_inv = False else: self.show_inv = True elif symbol == arcade.key.SPACE and self.show_text: self.show_text = False self.text = None elif key == 'm': print("mouse_pos:", self.mouse_pos) print("playerpos:", self.player.position) self.scroll_manager.output_values() # toggle the players candle elif symbol == arcade.key.SPACE: # if the player is holding a candle, toggle it off if self.player.holding_candle: self.player.toggle_candle() # toggle self.light_layer.remove(self.candle_light) # remove light source self.perma_torches.remove(self.candle) # remove from torches (it will not draw anymore) self.player_light.radius = 100 * SCALE # re-enable player default light self.candle = None # set candle to None # if player isn't holding candle, toggle it on else: # toggle self.player.toggle_candle() # create lightsource object light = Light(self.player.candle.center_x, self.player.candle.center_y, 400 * SCALE, TORCH_LIGHT, 'soft') self.perma_torches.append(self.player.candle) # add player candle to perma_torches (cant be toggled by pressing q) self.candle = self.player.candle # set the candle to the players candle self.candle_light = light # set candle light to light object self.player_light.radius = 0 # disable the players default light self.light_layer.add(self.candle_light) # add light source to light layer self.key_change()
def setup(self): """ Set up the game and initialize the variables. """ # Sprite lists self.player_list = arcade.SpriteList() self.coin_list = arcade.SpriteList() self.bullet_list = arcade.SpriteList() self.explosions_list = arcade.SpriteList() self.wall_list = maps.create_walls() # Set up the player self.score = 0 # Image from kenney.nl self.player = player.PlayerCharacter() self.player.center_x = 0 self.player.center_y = 0 self.player_list.append(self.player) self.physics_engine = arcade.PhysicsEngineSimple( self.player, self.wall_list) # Create the coins for coin_index in range(COIN_COUNT): # Create the coin instance # Coin image from kenney.nl coin = arcade.Sprite(":resources:images/items/coinGold.png", SPRITE_SCALING_COIN) # Position the coin coin.center_x = random.randrange(SCREEN_WIDTH) coin.center_y = random.randrange(150, SCREEN_HEIGHT) # Add the coin to the lists self.coin_list.append(coin) # Set the background color #arcade.set_background_color(arcade.color.CELESTIAL_BLUE) # Lighting self.light_layer = LightLayer(SCREEN_WIDTH, SCREEN_HEIGHT) self.light_layer.set_background_color(arcade.color.CELESTIAL_BLUE) # Player lighting self.player_light = Light(0, 0, self.player_radius, arcade.csscolor.WHITE, 'soft') self.light_layer.add(self.player_light)
def __init__(self, map_list): super().__init__() arcade.set_background_color(arcade.color.AMAZON) # Player sprite self.player_sprite = None self.player_sprite_list = None # 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 # Physics engine self.physics_engine = None # Maps self.map_list = map_list # Name of map we are on self.cur_map_name = None self.message_box = None self.selected_item = 1 f = open("item_dictionary.json") self.item_dictionary = json.load(f) f = open("characters_dictionary.json") self.enemy_dictionary = json.load(f) # Cameras self.camera_sprites = arcade.Camera(self.window.width, self.window.height) self.camera_gui = arcade.Camera(self.window.width, self.window.height) # Create a small white light x = 100 y = 200 radius = 150 mode = 'soft' color = arcade.csscolor.WHITE self.player_light = Light(x, y, radius, color, mode)
def __init__(self, width, height, title): """ Set up the application. """ super().__init__(width, height, title) self.time = 0 self.frame = 0 self.background = arcade.load_texture( ":resources:images/backgrounds/abstract_1.jpg") self.light_layer = LightLayer(SCREEN_WIDTH, SCREEN_HEIGHT) self.light_layer.set_background_color(arcade.color.WHITE) # Add some random lights for _ in range(500): self.light_layer.add( Light(random.randrange(0, SCREEN_WIDTH), random.randrange(0, SCREEN_HEIGHT), radius=50, mode='soft', color=(random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))), )
def setup(self): """ Create everything """ # Create sprite lists self.background_sprite_list = arcade.SpriteList() self.player_list = arcade.SpriteList() self.wall_list = arcade.SpriteList() # Create player sprite self.player_sprite = arcade.Sprite( ":resources:images/animated_characters/female_person/femalePerson_idle.png", 0.4) self.player_sprite.center_x = 64 self.player_sprite.center_y = 270 self.player_list.append(self.player_sprite) # --- Light related --- # Lights must shine on something. If there is no background sprite or color, # you will just see black. Therefore, we use a loop to create a whole bunch of brick tiles to go in the # background. for x in range(-128, 2000, 128): for y in range(-128, 1000, 128): sprite = arcade.Sprite( ":resources:images/tiles/brickTextureWhite.png") sprite.position = x, y self.background_sprite_list.append(sprite) # Create a light layer, used to render things to, then post-process and # add lights. This must match the screen size. self.light_layer = LightLayer(SCREEN_WIDTH, SCREEN_HEIGHT) # We can also set the background color that will be lit by lights, # but in this instance we just want a black background self.light_layer.set_background_color(arcade.color.BLACK) # Here we create a bunch of lights. # Create a small white light x = 100 y = 200 radius = 100 mode = 'soft' color = arcade.csscolor.WHITE light = Light(x, y, radius, color, mode) self.light_layer.add(light) # Create an overlapping, large white light x = 300 y = 150 radius = 200 color = arcade.csscolor.WHITE mode = 'soft' light = Light(x, y, radius, color, mode) self.light_layer.add(light) # Create three, non-overlapping RGB lights x = 50 y = 450 radius = 100 mode = 'soft' color = arcade.csscolor.RED light = Light(x, y, radius, color, mode) self.light_layer.add(light) x = 250 y = 450 radius = 100 mode = 'soft' color = arcade.csscolor.GREEN light = Light(x, y, radius, color, mode) self.light_layer.add(light) x = 450 y = 450 radius = 100 mode = 'soft' color = arcade.csscolor.BLUE light = Light(x, y, radius, color, mode) self.light_layer.add(light) # Create three, overlapping RGB lights x = 650 y = 450 radius = 100 mode = 'soft' color = arcade.csscolor.RED light = Light(x, y, radius, color, mode) self.light_layer.add(light) x = 750 y = 450 radius = 100 mode = 'soft' color = arcade.csscolor.GREEN light = Light(x, y, radius, color, mode) self.light_layer.add(light) x = 850 y = 450 radius = 100 mode = 'soft' color = arcade.csscolor.BLUE light = Light(x, y, radius, color, mode) self.light_layer.add(light) # Create three, overlapping RGB lights # But 'hard' lights that don't fade out. x = 650 y = 150 radius = 100 mode = 'hard' color = arcade.csscolor.RED light = Light(x, y, radius, color, mode) self.light_layer.add(light) x = 750 y = 150 radius = 100 mode = 'hard' color = arcade.csscolor.GREEN light = Light(x, y, radius, color, mode) self.light_layer.add(light) x = 850 y = 150 radius = 100 mode = 'hard' color = arcade.csscolor.BLUE light = Light(x, y, radius, color, mode) self.light_layer.add(light) # Create a light to follow the player around. # We'll position it later, when the player moves. # We'll only add it to the light layer when the player turns the light # on. We start with the light off. radius = 150 mode = 'soft' color = arcade.csscolor.WHITE self.player_light = Light(0, 0, radius, color, mode) # Create the physics engine self.physics_engine = arcade.PhysicsEngineSimple( self.player_sprite, self.wall_list) # Set the viewport boundaries # These numbers set where we have 'scrolled' to. self.view_left = 0 self.view_bottom = 0
def load_map(map_name): """ Load a map """ game_map = GameMap() game_map.map_layers = OrderedDict() game_map.characters = arcade.SpriteList() game_map.light_layer = LightLayer(100, 100) # List of blocking sprites game_map.wall_list = arcade.SpriteList() layer_options = { 'trees_blocking': { "use_spatial_hash": True, }, 'misc_blocking': { "use_spatial_hash": True, }, 'bridges': { "use_spatial_hash": True, }, 'water_blocking': { "use_spatial_hash": True, }, } # Read in the tiled map print(f"Loading map: {map_name}") my_map = arcade.tilemap.load_tilemap(map_name, scaling=TILE_SCALING, layer_options=layer_options) if 'characters' in my_map.object_lists: f = open("characters_dictionary.json") character_dictionary = json.load(f) character_object_list = my_map.object_lists['characters'] for character_object in character_object_list: if 'type' not in character_object.properties: print( f"No 'type' field for character in map {map_name}. {character_object.properties}" ) continue character_type = character_object.properties['type'] if character_type not in character_dictionary: print( f"Unable to find '{character_type}' in characters_dictionary.json." ) continue character_data = character_dictionary[character_type] shape = character_object.shape if isinstance(shape, list) and len(shape) == 2: # Point character_sprite = CharacterSprite( f"characters/{character_data['images']}") character_sprite.position = shape elif isinstance(shape, list) and len(shape[0]) == 2: # Rect or polygon. location = [shape[0][0], shape[0][1]] character_sprite = PathFollowingSprite( f"characters/{character_data['images']}") character_sprite.position = location path = [] for point in shape: location = [point[0], point[1]] path.append(location) character_sprite.path = path else: print( f"Unknown shape type for character with shape '{shape}' in map {map_name}." ) continue print( f"Adding character {character_type} at {character_sprite.position}" ) game_map.characters.append(character_sprite) if 'lights' in my_map.object_lists: lights_object_list = my_map.object_lists['lights'] for light_object in lights_object_list: if 'color' not in light_object.properties: print(f"No color for light in map {map_name}.") continue shape = light_object.shape if isinstance(shape, list) and len(shape) == 2: # Point if 'radius' in light_object.properties: radius = light_object.properties['radius'] else: radius = 150 mode = 'soft' color = light_object.properties['color'] color = (color.red, color.green, color.blue) light = Light(shape[0], shape[1], radius, color, mode) game_map.light_layer.add(light) print("Added light", color, "radius", radius) else: print("Failed to add light") else: # Hack x = 0 y = 0 radius = 1 mode = 'soft' color = arcade.csscolor.WHITE dummy_light = Light(x, y, radius, color, mode) game_map.light_layer.add(dummy_light) print("Added default light") # Get all the tiled sprite lists # Get all the tiled sprite lists game_map.map_layers = my_map.sprite_lists # Define the size of the map, in tiles game_map.map_size = my_map.width, my_map.height # Set the background color game_map.background_color = my_map.background_color game_map.properties = my_map.properties # Any layer with '_blocking' in it, will be a wall for layer in game_map.map_layers: if '_blocking' in layer: game_map.wall_list.extend(game_map.map_layers[layer]) return game_map