def load(self): self.all_sprites = pg.sprite.Group() self.solid = pg.sprite.Group() self.items_on_floor = pg.sprite.Group() self.doors = pg.sprite.Group() assets_folder = path.join(getcwd(), 'assets') self.map = Map(path.join(assets_folder, 'maps/map1.json')) self.spritesheet = Spritesheet( path.join(assets_folder, 'spritesheet.png'), 32) wall_img = self.spritesheet.get_image_at_col_row(0, 0) apple_img = self.spritesheet.get_image_alpha_at_col_row(1, 0) keycard_img = self.spritesheet.get_image_alpha_at_col_row(0, 3) self.background_surface = pg.Surface( (self.map.width * TILE_SIZE, self.map.height * TILE_SIZE)) self.visibility_data = [[True] * self.map.height for i in range(self.map.width)] self.fov_data = [[True] * self.map.height for i in range(self.map.width)] for node in self.map.objects: x, y = node['x'], node['y'] if node["name"] == 'WALL': #self.collisions.append(pg.Rect(x, y, TILE_SIZE, TILE_SIZE)) # TODO big rectangles wall = Wall(self, x, y, wall_img) if not LIMIT_FOV_FOR_STATIC_SPRITES: wall.remove(self.all_sprites) # skip drawing self.background_surface.blit( wall_img, (x * TILE_SIZE, y * TILE_SIZE)) self.visibility_data[x][y] = False elif node["name"] == 'PLAYER': self.player = Player(self, x, y) elif node["name"] == 'APPLE': item = Item(self, x, y, apple_img) item.pickable = Pickable(item, 'apple', False, 1, False) elif node["name"] == 'KEYCARD': # key card item = Item(self, x, y, keycard_img) item.pickable = Pickable(item, 'keycard', False, 1, False) elif node["name"] == "DOOR": Door(self, x, y, node["dir"]) self.visibility_data[x][ y] = False # TODO opened doors visibility for trigger in self.map.triggers: TextTrigger( self, pg.Rect(trigger["x"], trigger["y"], trigger["width"], trigger["height"]), trigger["text"]) self.camera = Camera(self.map.width_screen, self.map.height_screen)
def load(self, map_name): """ Loads new map with the given name :param map_name: map to be loaded :return: nothing """ assets_folder = path.join(getcwd(), 'assets') self.__map__ = Map(path.join(assets_folder, 'maps/' + map_name + '.json')) self.spritesheet = Spritesheet(path.join(assets_folder, 'spritesheet.png'), 32) wall_img = self.spritesheet.get_image_at_row_col(0, 0) apple_img = self.spritesheet.get_image_alpha_at_row_col(1, 0) self.__visibility_data__ = [[True] * self.__map__.height for i in range(self.__map__.width)] self.__fov_data__ = [[True] * self.__map__.height for i in range(self.__map__.width)] for node in self.__map__.objects: x, y = node['x'], node['y'] if node["name"] == 'WALL': Wall(self, x, y, wall_img) self.__visibility_data__[x][y] = False elif node["name"] == 'PLAYER': self.player = Player(self, x, y) elif node["name"] == 'APPLE': item = Item(self, x, y, apple_img) item.pickable = Pickable(item, 'apple', False, 1, False) elif node["name"] == "DOOR": Door(self, x, y, node["dir"]) self.__visibility_data__[x][y] = False # TODO opened doors visibility for trigger in self.__map__.triggers: TextTrigger(self, pg.Rect(trigger["x"], trigger["y"], trigger["width"], trigger["height"]), trigger["text"]) self.__camera__ = Camera(self.__map__.width_screen, self.__map__.height_screen)
def setDoors(x, y): doors.append(Door()) doors[len(doors) - 1].set_dimensions(70, 100) doors[len(doors) - 1].y_pos = y doors[len(doors) - 1].x_pos = x