def draw_map(self): self.map_surface.blit(self.game_canvas, scale_pair((0, 0))) for i, line in enumerate(self.map_matrix): for j, cell in enumerate(line): pos = scale_pair((j * 48, i * 48)) for code in cell: layer = self.map_layers[code] self.map_surface.blit(self.map_tiles[layer['tile']], pos)
def get_selection_arrow_position(self): x, y = 204, 348 if self.current_selection_index == 0: return scale_pair((x, y)) elif self.current_selection_index == 1: return scale_pair( (x, y + self.button_height + self.button_space_between)) else: return scale_pair( (x, y + (self.button_height + self.button_space_between) * 2))
def render(self, **args): for event in args['events']: if event.type == pygame.KEYDOWN: if event.key == pygame.K_ESCAPE: return {'goto': START_SCENE} elif event.key == pygame.K_UP: time.set_timer(self.walk_event_id, 400) self.move_player('up') elif event.key == pygame.K_RIGHT: time.set_timer(self.walk_event_id, 400) self.move_player('right') elif event.key == pygame.K_DOWN: time.set_timer(self.walk_event_id, 400) self.move_player('down') elif event.key == pygame.K_LEFT: time.set_timer(self.walk_event_id, 400) self.move_player('left') elif event.key == pygame.K_SPACE: self.handle_interaction() elif event.type == pygame.KEYUP: if event.key in (pygame.K_UP, pygame.K_RIGHT, pygame.K_DOWN, pygame.K_LEFT): self.stop_player() elif event.type == self.time_event_id: self.handle_gauges() elif event.type == self.walk_event_id: self.move_player() self.win.blit(self.background, scale_pair((0, 0))) self.win.blit(self.marble, scale_pair((110, 24))) self.win.blit(self.map_surface, scale_pair((129, 40))) for component in self.components: component.draw() self.draw_map() if self.is_game_over(): return { 'goto': GAME_OVER_SCENE, 'more_args': { 'clock': self.clock.tick(), 'food_eaten': self.count_eaten_food } } return {'goto': GAME_SCENE, 'more_args': args['more_args']}
def render(self, **args): for event in args['events']: if event.type == pygame.KEYDOWN: if event.key == pygame.K_ESCAPE: return {'goto': START_SCENE} self.win.blit(self.background, scale_pair((0, 0))) return {'goto': CREDITS_SCENE}
def __init__(self, win): self.win = win self.satiety_gauge = Gauge(self.win, Gauge.TYPE_HIGH_IS_GOOD, load_image(images.PLATE_EMOJI), scale_pair((144, 595))) self.hygiene_gauge = Gauge(self.win, Gauge.TYPE_HIGH_IS_GOOD, load_image(images.SHOWER_EMOJI), scale_pair((439, 595))) self.toilet_gauge = Gauge(self.win, Gauge.TYPE_LOW_IS_GOOD, load_image(images.TOILET_EMOJI), scale_pair((748, 595))) self.components = [ self.satiety_gauge, self.hygiene_gauge, self.toilet_gauge ] self.background = load_image(images.BRICK_WALL_BACKGROUND) self.marble = load_image(images.MARBLE) self.game_canvas = load_image(images.GAME_CANVAS) self.map_tiles = get_tiles() self.map_layers = LAYERS self.map_matrix = get_map() self.current_player_pos = (6, 7) self.map_surface = pygame.Surface(self.game_canvas.get_size()) self.is_player_moving = False self.last_player_moving_direction = None self.time_event_id = pygame.USEREVENT + 1 self.walk_event_id = pygame.USEREVENT + 2 time.set_timer(self.time_event_id, 3000) self.clock = time.Clock() self.count_eaten_food = 0 self.spawned_food = [] self.spawn_food()
def render(self, **args): for event in args['events']: if event.type == pygame.KEYDOWN: if event.key == pygame.K_ESCAPE: return {'goto': START_SCENE} elif event.key == pygame.K_LEFT and self.selected_button_index > 0: self.selected_button_index -= 1 elif event.key == pygame.K_RIGHT and self.selected_button_index < 1: self.selected_button_index += 1 elif event.key == pygame.K_RETURN: if self.selected_button_index == 0: if self.current_image_index == 0: return {'goto': START_SCENE} else: self.current_image_index -= 1 elif self.selected_button_index == 1: if self.current_image_index == len(self.images) - 1: return {'goto': START_SCENE} else: self.current_image_index += 1 self.win.blit(self.background, scale_pair((0, 0))) self.win.blit(self.images[self.current_image_index], scale_pair((110, 30))) if self.selected_button_index == 0: self.win.blit(self.selection_border, scale_pair((40, 630))) else: self.win.blit(self.selection_border, scale_pair((819, 630))) self.win.blit(self.arrow_left, scale_pair((61, 642))) self.win.blit(self.arrow_right, scale_pair((860, 642))) return {'goto': HOW_TO_PLAY_SCENE}
def render(self, **args): for event in args['events']: if event.type == pygame.KEYDOWN: if event.key == pygame.K_ESCAPE: sys.exit() if event.key == pygame.K_UP and self.current_selection_index > 0: self.current_selection_index -= 1 elif event.key == pygame.K_DOWN and self.current_selection_index < 2: self.current_selection_index += 1 elif event.key == pygame.K_RETURN: return {'goto': self.get_selected_scene()} background = load_image(images.BACKGROUND) self.win.blit(background, (0, 0)) start_game_button = load_image(images.START_GAME_BUTTON) self.win.blit( start_game_button, scale_pair((self.button_init_pos_x, self.button_init_pos_y))) how_to_play_button = load_image(images.HOW_TO_PLAY_BUTTON) self.win.blit( how_to_play_button, scale_pair((self.button_init_pos_x, self.button_init_pos_y + self.button_height + self.button_space_between))) credits_button = load_image(images.CREDITS_BUTTON) self.win.blit( credits_button, scale_pair((self.button_init_pos_x, self.button_init_pos_y + (self.button_height + self.button_space_between) * 2))) selection_arrow = load_image(images.SELECTION_ARROW) self.win.blit(selection_arrow, self.get_selection_arrow_position()) return {'goto': START_SCENE}
def render(self, **args): for event in args['events']: if event.type == pygame.KEYDOWN: if event.key == pygame.K_ESCAPE: return {'goto': START_SCENE} elif event.key == pygame.K_LEFT and self.selected_button_index > 0: self.selected_button_index -= 1 elif event.key == pygame.K_RIGHT and self.selected_button_index < 1: self.selected_button_index += 1 elif event.key == pygame.K_RETURN: if self.selected_button_index == 0: return {'goto': GAME_SCENE} elif self.selected_button_index == 1: return {'goto': START_SCENE} self.win.blit(self.background, scale_pair((0, 0))) font = pygame.font.SysFont('Comic Sans MS', 30) clock = args['more_args']['clock'] // 1000 clock_str = "Tempo: {0}s".format(clock) clock_surf = font.render(clock_str, True, (0, 0, 0)) food_eaten = args['more_args']['food_eaten'] food_eaten_str = "Itens consumidos: {0}".format(food_eaten) food_eaten_surf = font.render(food_eaten_str, True, (0, 0, 0)) self.win.blit(clock_surf, scale_pair((413, 612))) self.win.blit(food_eaten_surf, scale_pair((345, 652))) if self.selected_button_index == 0: self.win.blit(self.selection_border, scale_pair((25, 630))) else: self.win.blit(self.selection_border, scale_pair((845, 630))) self.win.blit(self.replayarrow, scale_pair((51, 642))) self.win.blit(self.checkmark, scale_pair((870, 642))) return {'goto': GAME_OVER_SCENE, 'more_args': args['more_args']}
def draw(self): self.base.blit(self.background, scale_pair((0, 0))) self.base.blit(self.icon, scale_pair((7, 52))) self.base.blit(self.vessel, scale_pair((68, 17))) self.base.blit(self.get_filling(), scale_pair((76, 26))) self.win.blit(self.base, self.pos)