def check_for_portals(self): for portal in self.portals: if self.player.rect.colliderect(portal.rect): self.next = portal.name self.state = 'transition_out' if portal.sound == 'door': play_sfx('door')
def do_step(self): if self.right: play_sfx('step_grass_r') self.right = False else: play_sfx('step_grass_l') self.right = True
def check_for_input(self, events): for event in events: if event.type == pg.KEYDOWN: if event.key == pg.K_DOWN: self.begin_moving('down') play_sfx('select', 0.5) elif event.key == pg.K_UP: self.begin_moving('up') play_sfx('select', 0.5) elif event.key == pg.K_RETURN or event.key == pg.K_SPACE: if self.rect.y == 96: self.start_game = True if self.rect.y == 112: pass if self.rect.y == 128: pg.quit() sys.exit()
def chicken_catched(self, sprite): if (sprite.name == 'chicken_move' and self.inventory['chickens']['catch'] and self.name == c.SANDY_COVE): if self.player.rect.colliderect(sprite.rect): play_sfx('chicken', 0.4) self.inventory['catched_chickens'].add(sprite.tiled_id) self.inventory['chickens']['amount'] += 1 sprite.kill() return True if (sprite.name == 'red_move' or sprite.name == 'green_move' or sprite.name == 'blue_move'): if self.player.rect.colliderect(sprite.rect): play_sfx('chicken', 0.4) self.inventory['found_items'].add(sprite.tiled_id) self.inventory['chickens']['amount'] += 1 sprite.kill() return True return False
def check_for_items(self): found_items = self.inventory['found_items'] for item in self.map_items: if self.player.rect.colliderect(item.rect): if item.name == 'coin': play_sfx('coin') found_items.add(item.tiled_id) self.inventory['gold'] += 1 item.kill() if item.name == 'hidden': if item.obj_type == 'monster1': play_sfx('monster1', 1.0) found_items.add(item.tiled_id) item.kill() if item.obj_type == 'monster2': play_sfx('monster2', 1.0) found_items.add(item.tiled_id) item.kill() if item.name == 'heart': play_sfx('heartbeat', 1.0) found_items.add(item.tiled_id) self.inventory['hearts'] += 1 item.kill()
def scroll_text_box(self, events, n_lines): for event in events: if event.type == pg.KEYDOWN and event.key == pg.K_SPACE: if self.show: if self.index < (n_lines - 3) and n_lines > 5: self.index += 3 if self.index > n_lines - 3: self.index = n_lines - 3 self.clear() play_sfx('text_flip') else: self.index = 0 self.clear() self.active = False self.show = False play_sfx('text_close') else: self.show = True self.clear() self.index = 0 play_sfx('text_open')