def add_deco(self, tile_map, max_x, max_y): """ Add the decorative object. Note that the decoration is a GameObject! :param tile_map: :param max_x: :param max_y: :return: nothing """ list_doors = [door_def[0] for door_def in self.doors] for i in range(20): place = random.choice(self.places) weight = self.compute_tile_weight(place[0], place[1], [Tile.FLOOR], tile_map, max_x, max_y) near_door = (place[0], place[1] - 1) in list_doors or \ (place[0], place[1] + 1) in list_doors or \ (place[0] - 1, place[1]) in list_doors or \ (place[0] + 1, place[1]) in list_doors if not (near_door or not (tile_map[place].floor_type == Tile.FLOOR) or tile_map[ place].has_things) and weight == 15: a_deco = random.choice(self.building.decoration_list["1x1"]) decoration = GameObject(a_deco[0], GameObject.DECORATION, town=self.town, weight=random.randint(1, 10), volume=random.randint(1, 5), regular_value=random.randint(2, 10), displayable_object=DisplayableObject(movable=False, blocking=a_deco[1], position_on_tile=place, graphical_representation= AnimatedSpriteObject( Constants.DAWNLIKE_STYLE, "Objects", "Decor", a_deco[2]))) GameData.register_object(decoration)
def start_new_game(cls, number_town): Util.DebugEvent("Initializing Time") GameData.time_ticker = Util.Ticker() Util.DebugEvent("Building new world") GameData.town_graph = Places.TownGraph([Places.Town(random.randint(2, 7)) for x in range(number_town)]) Util.DebugEvent("Choosing the initial town") GameData.current_town = random.choice(GameData.town_graph.towns) GameData.current_town.build_tile_map() Util.DebugEvent("Setting up player") GameData.player = Player.Player(GameData.current_town, graphical_representation=AnimatedSpriteObject(Constants.DAWNLIKE_STYLE, "Characters", "Player", (16, 112)), position_on_tile=GameData.current_town.tile_map.default_start_player_position) Util.DebugEvent("Setting up objects in the towns...") for town in GameData.town_graph.towns: for i in range(5): image_coordinate_x = [x * 16 for x in range(0, 7)] image_coordinate_y = [y * 16 for y in (3, 4, 7, 8)] coordinates = (random.choice(image_coordinate_x), random.choice(image_coordinate_y)) # npc = Player.TraderNPC(town, # position_on_tile=town.tile_map.get_place_in_building(Places.Building.TRADING_POST), # graphical_representation=Player.AnimatedSpriteObject(True, "Characters", "Player", coordinates)) npc = Player.NonPlayableCharacter(town, speed=(1, 3), position_on_tile=(i * 1, i * 2), graphical_representation=AnimatedSpriteObject( Constants.DAWNLIKE_STYLE, "Characters", "Player", coordinates)) GameData.register_object(npc) for i in range(25): """ name, object_type, weight=None, volume=None, regular_value=None, action_when_player=None, equipment=None, usable_part=None, breakable_parts=None, part_of_inventory=None, displayable_object=None): """ an_object = GameObject("A leftover object " + str(i), GameObject.JUNK, town=town, weight=random.randint(1, 10), volume=random.randint(1, 5), regular_value=random.randint(2, 10), displayable_object=DisplayableObject(movable=False, blocking=False, position_on_tile=( random.randint(0, town.tile_map.max_x - 1), random.randint(0, town.tile_map.max_y - 1)), graphical_representation=AnimatedSpriteObject( Constants.DAWNLIKE_STYLE, "Objects", "Ground", (16, 48)))) GameData.register_object(an_object) # a door is an open object for room in town.tile_map.rooms: for door in room.doors: GameData.register_object(Door(town, door[1], door[0], closed=True, locked=False)) Util.DebugEvent("Setting up objects in the other places (To be done later)...")