def place_tomatoes(self): cubby_vertices = self.current_maze.maze_graph.all_cubby_vertices() if len(cubby_vertices) > 0: for cubby_vertex in cubby_vertices: tomato = actor_obj.ActorObject( **{ 'x': 0, 'y': 0, 'height': settings.TOMATO_STATE['height'], 'width': settings.TOMATO_STATE['width'], 'sprite_sheet_key': settings.TOMATO_STATE['sprite_sheet_key'], 'name_object': 'tomato', 'animation': AnimationComponent(is_animating=True), 'pickupable': PickupableComponent('tomato') }) x, y = self.current_maze.topleft_sprite_center_in_vertex( cubby_vertex, tomato) tomato.set_pos(x, y) cubby_vertex.has_tomato = True self.current_objects['PICKUPS'].add(tomato)
def set_game_objects(self, game, **kwargs): self.state_kwargs = kwargs self.prior_level_state = self.state_kwargs['prior_level_state'] continue_button = actor_obj.ActorObject( **{ 'x': 300, 'y': 200, 'height': 45, 'width': 190, 'in_hud': False, 'sprite_sheet_key': 4, 'name_object': 'continue_button', 'animation': AnimationComponent(), 'clickable': ClickableComponent('rectangle', self.next_level, ** {"game": game}) }) game.current_objects['UI_BUTTONS'].add(continue_button)
def add_ai_hoggy(self, game, ai_hoggy_name, x, y, starting_vertex, ai_hoggy_type='default', random_start=False): nstates = (self.level_settings['reset_maze']['maze_width'] * self.level_settings['reset_maze']['maze_height']) ai_hoggy_stats = settings.AI_HOGGY_STARTING_STATS[ai_hoggy_type] ai_hoggy = actor_obj.ActorObject( **{ 'x': x - (settings.SPRITE_SIZE / 2), 'y': y - (settings.SPRITE_SIZE / 2), 'height': settings.SPRITE_SIZE, 'width': settings.SPRITE_SIZE, 'sprite_sheet_key': ai_hoggy_stats['sprite_sheet_key'], 'name_object': ai_hoggy_name, 'inventory': InventoryState('tomato'), 'maze': MazeState('maze_state'), 'animation': AnimationComponent(), 'orientation': OrientationComponent('horizontal', 'right'), 'movable': MovableComponent('ai_hoggy_move', ai_hoggy_stats['speed']), 'ai': AIComponent(), 'rilearning': RILearningComponent( name_instance="ril_ai_hoggy", gamma=ai_hoggy_stats['gamma'], nstates=nstates, action_space=game.action_space, actions=game.actions, reward_dict=ai_hoggy_stats['reward_dict'], reward_func=game.current_maze.maze_graph.set_rewards_table, pi_a_s_func=game.current_maze.maze_graph.get_pi_a_s) }) if random_start: random.seed(settings.MAZE_SEED) random_state = random.choice(range(nstates)) starting_vertex = game.current_maze.maze_graph.get_vertex_by_name( random_state) x, y = game.current_maze.topleft_sprite_center_in_vertex( starting_vertex, ai_hoggy) ai_hoggy.coords = (x, y) self.initialize_ai_hog(game, ai_hoggy, starting_vertex)
def set_hud(self, game): tomato = actor_obj.ActorObject( **{ 'x': 10, 'y': 10, 'height': settings.TOMATO_STATE['height'], 'width': settings.TOMATO_STATE['width'], 'sprite_sheet_key': settings.TOMATO_STATE['sprite_sheet_key'], 'in_hud': True, 'name_object': 'hud_tomato' }) game.current_objects['HUD'].add(tomato)
def vertical_wall(self, x, y): vertical_wall = actor_obj.ActorObject( **{ 'x': x, 'y': y, 'width': settings.MAZE_WALL_STATE['width'], 'height': settings.MAZE_WALL_STATE['height'], 'sprite_sheet_key': settings.MAZE_WALL_STATE['sprite_sheet_key'], 'name_object': 'maze_wall' }) topleft = vertical_wall.rect.topleft vertical_wall.image = pygame.transform.scale( vertical_wall.image, (int(math.ceil( self.cell_width / self.wall_scale)), int(self.cell_height))) vertical_wall.rect = vertical_wall.image.get_rect() vertical_wall.rect.topleft = topleft return vertical_wall
def horizontal_wall(self, x, y): horizontal_wall = actor_obj.ActorObject( **{ 'x': x, 'y': y, 'width': settings.MAZE_WALL_STATE['width'], 'height': settings.MAZE_WALL_STATE['height'], 'sprite_sheet_key': settings.MAZE_WALL_STATE['sprite_sheet_key'], 'name_object': 'maze_wall' }) topleft = horizontal_wall.rect.topleft horizontal_wall.image = pygame.transform.rotate( horizontal_wall.image, 90) horizontal_wall.image = pygame.transform.scale( horizontal_wall.image, (int(self.cell_width), int(math.ceil(self.cell_height / self.wall_scale)))) horizontal_wall.rect = horizontal_wall.image.get_rect() horizontal_wall.rect.topleft = topleft return horizontal_wall
def set_game_objects(self, game, **kwargs): self.state_kwargs = kwargs self.level_settings = settings.LEVEL_SETTINGS[game.level] game.reset_maze(**self.level_settings['reset_maze']) starting_vertex = game.current_maze.maze_graph.start_vertex (x, y) = game.current_maze.center_for_vertex(starting_vertex) print("CENTER X: {}, CENTER Y: {}".format(x, y)) if self.level_settings['new_hoggy']: main_player = actor_obj.ActorObject( **{ 'x': x - (settings.SPRITE_SIZE / 2), 'y': y - (settings.SPRITE_SIZE / 2), 'height': settings.SPRITE_SIZE, 'width': settings.SPRITE_SIZE, 'sprite_sheet_key': settings.HOGGY_STARTING_STATS['sprite_sheet_key'], 'name_object': 'hoggy', 'animation': AnimationComponent(), 'player_input': PlayerInputComponent(), 'orientation': OrientationComponent('horizontal', 'right'), 'movable': MovableComponent('hoggy_move', settings.HOGGY_STARTING_STATS['speed']), 'inventory': InventoryState('tomato') }) print("HOGGY X: {}, HOGGY Y: {}".format(main_player.x, main_player.y)) game.main_player = main_player else: game.main_player.get_component("PLAYER_INPUT").reset_keys() randomize_button = actor_obj.ActorObject( **{ 'x': settings.WINDOW_WIDTH - 200, 'y': 0, 'height': settings.SPRITE_SIZE * 2, 'width': settings.SPRITE_SIZE * 2, 'in_hud': True, 'sprite_sheet_key': 2, 'name_object': 'randomize_button', 'animation': AnimationComponent(), 'clickable': ClickableComponent('circle', game.reset_maze, ** self.level_settings['reset_maze']) }) game.current_objects['UI_BUTTONS'].add(randomize_button) for ai_hoggy_name, ai_hoggy_type in self.level_settings[ 'ai_hogs'].items(): self.add_ai_hoggy(game, ai_hoggy_name, x, y, starting_vertex, ai_hoggy_type=ai_hoggy_type) self.set_hud(game)