def _change_selection(self, dir): audio.play_sound(audio.SND_MENU_MOVE) self.sel_index += dir if self.sel_index < 0: self.sel_index = len(SELECTIONS) - 1 elif self.sel_index >= len(SELECTIONS): self.sel_index = 0
def on_triggered(self): self.triggered = True if self.triggered_sound is not None: audio.play_sound(self.triggered_sound) if self.particle_system is not None: self.particle_effect_start() return False
def resume_callback(self): """ Begins the process of relinquishing control and resuming the game. """ audio.play_sound(MENU_PAUSE_SOUND, CHANNEL_MENU) self.event_queue.add_event(video.get_time(), self.menu.destroy) self.event_queue.add_event(video.get_time() + 15, self.resume)
def main(): controller = GameController() wechat.game_controller = controller controller.get_ready() play_sound('游戏开始') controller.main_loop()
def input_return(self): """ Returns to the settings menu from the input menu. """ audio.play_sound(MENU_CANCEL_SOUND, CHANNEL_MENU) self.event_queue.add_event(video.get_time(), self.menu.destroy) self.event_queue.add_event(video.get_time() + 15, self.settings_menu)
def input_callback(self): """ Closes the settings menu and goes to the input menu. """ audio.play_sound(MENU_SELECT_SOUND, CHANNEL_MENU) self.event_queue.add_event(video.get_time(), self.menu.destroy) self.event_queue.add_event(video.get_time() + 15, self.input_event)
def pause_menu_callback(self): """ Destroys the current menu and goes back to the main pause one. """ audio.play_sound(MENU_CANCEL_SOUND, CHANNEL_MENU) self.event_queue.add_event(video.get_time(), self.menu.destroy) self.event_queue.add_event(video.get_time() + 15, self.pause_menu)
def cheater_menu(self): """ A menu displayed when a gameplay session that did not use default gameplay settings submits a high score. """ self.current_score = None self.current_rank = None audio.play_sound(MENU_ERROR_SOUND, CHANNEL_MENU) self.name_box = video.Textbox(FONT_FILE, (16, 120), (26, 4)) self.name_box.write("\n".join(("SCORE NOT RECORDED".center(26), "", "PLAY WITH DEFAULT GAMEPLAY", "SETTINGS TO SAVE SCORE".center(26))), color=(0xFF, 0x40, 0x40)) self.score_background = video.RectSprite((119, 135), (0, 39)) self.score_background.width = video.Lerp(0, 215, 15) self.menu = menu.MenuArray((menu.MenuEntry((120, 176), "OK", lambda: (audio.play_sound(MENU_SELECT_SOUND, CHANNEL_MENU), self.exit_score())),)) video.add_renderer(self.score_background.render, LAYER_UI - 1) video.add_renderer(self.menu.render_all, LAYER_UI) self.event_queue.add_event(video.get_time() + 15, self.menu.ready) self.event_queue.add_event(video.get_time() + 15, lambda: video.add_renderer(self.name_box.render, LAYER_UI))
def on_flame_rush_collided(self, player): effect_node = StaticEffectNode(self.sceneManager, player.world, 2) effect_node.position = (player.position[0], 0, player.position[1]) effect_node.set_particle_system( "LavaSplash", (player.position[0], 0, player.position[1])) effect_node.particle_effect_start() audio.play_sound("ringoffire")
def generate_bomb(self): """ Drops da bomb! This'll turn the player invincible and later cause lots of pretty explosions as the screen's cleared of bullets and enemies. """ if self.bombs > 0 and self.bombing == False: # Make sure we can bomb self.bombs -= 1 self.bombing = True # Prevent multiple bombs from going at once self.collisions = False # Invincibility frames! video.add_renderer(self.render_aura, LAYER_PLAYER_AURA) audio.play_sound("pl_bomb") self.parent.event_queue.add_event(video.get_time() + 60, self.bomb_destroy_on) # Trigger the damaging flag self.parent.event_queue.add_event(video.get_time() + 60, self.create_blast) self.parent.event_queue.add_event(video.get_time() + 68, self.create_blast) self.parent.event_queue.add_event(video.get_time() + 76, self.create_blast) self.parent.event_queue.add_event(video.get_time() + 84, self.create_blast) self.parent.event_queue.add_event(video.get_time() + 92, self.create_blast) self.parent.event_queue.add_event(video.get_time() + 100, self.create_blast) self.parent.event_queue.add_event(video.get_time() + 108, self.create_blast) # All of these are explosion effects. self.parent.event_queue.add_event(video.get_time() + 150, self.cancel_bomb)
def on_down(self): """ Moves the cursor forward by ten spaces - see on_up() for reasons why no checks are involved. """ audio.play_sound(MENU_CURSOR_SOUND, CHANNEL_MENU) self.position += 10
def exit_callback(self): """ Quits the game. """ audio.play_sound(MENU_CANCEL_SOUND, CHANNEL_MENU) self.event_queue.add_event(video.get_time(), self.menu.destroy) self.event_queue.add_event(video.get_time() + 15, sys.exit)
def set_position(self, position): """ A basic override since the number of situations where the cursor sound would play were far greater than when it wouldn't. """ audio.play_sound(MENU_CURSOR_SOUND, CHANNEL_MENU) menu.MenuArray.set_position(self, position)
def fade_menu(self): """ Menu-executed frontend to the fadeout callback so that the sound effect can be played. """ audio.play_sound(MENU_CANCEL_SOUND, CHANNEL_MENU) self.fade_out()
def close_eyes(self): ''' Ask the player to close eyes. ''' play_sound('%s请闭眼' % self.__class__.identity) # Clear screen self.message()
def on_right(self): """ Increases the menu entry's bar. """ audio.play_sound(MENU_CURSOR_SOUND, CHANNEL_MENU) self.value = min(10, self.value + 1) self.edit_value() self.callback(self.value)
def on_left(self): """ Decreases the menu entry's bar. """ audio.play_sound(MENU_CURSOR_SOUND, CHANNEL_MENU) self.value = max(0, self.value - 1) self.edit_value() self.callback(self.value)
def destroy(self): """ Plays a basic explosion effect. """ audio.play_sound("en_die0", channel=CHANNEL_ZAKO) self.parent.particles.add_particle(particle.Explosion((self.x, self.y), (self.x_velocity, self.y_velocity))) BaseEnemy.destroy(self)
def settings_callback(self): """ Destroys the current menu and loads up the settings menu from the title screen. """ audio.play_sound(MENU_SELECT_SOUND, CHANNEL_MENU) self.event_queue.add_event(video.get_time(), self.menu.destroy) self.event_queue.add_event(video.get_time() + 15, self.settings_menu)
def quit_menu_callback(self): """ Destroys the current menu and loads up the confirmation menu for quitting. """ audio.play_sound(MENU_SELECT_SOUND, CHANNEL_MENU) self.event_queue.add_event(video.get_time(), self.menu.destroy) self.event_queue.add_event(video.get_time() + 15, self.quit_menu)
def on_up(self): """ Moves the cursor back by ten spaces - no checks are involved here because they're present in the menu array, owing to the need to change active buttons. """ audio.play_sound(MENU_CURSOR_SOUND, CHANNEL_MENU) self.position -= 10
def reset_controls(self): """ Callback for calling the controller API's reset method, and then updates all of the menu entries to reflect the changes. """ audio.play_sound(MENU_SELECT_SOUND, CHANNEL_MENU) control.reset_controls() for entry in self.assignments.values(): entry.write_entries()
def on_right(self): """ Moves the cursor forward a space, blah blah blah, see on_left() """ audio.play_sound(MENU_CURSOR_SOUND, CHANNEL_MENU) if (self.position % 10) == 9: self.position -= 9 else: self.position += 1
def on_activate(self): control.detect_joystick() audio.play_sound(MENU_SELECT_SOUND if control.control_system.joystick else MENU_ERROR_SOUND, CHANNEL_MENU) for button, assignment in self.assignments.items(): if button >= INPUT_FIRE: assignment.write_entries() self.ready()
def settings_return(self): """ Returns to the main menu from the settings menu. """ audio.play_sound(MENU_CANCEL_SOUND, CHANNEL_MENU) this_renderer = self.menu.render_all self.event_queue.add_event(video.get_time(), self.menu.destroy) self.event_queue.add_event(video.get_time() + 15, lambda: video.remove_renderer(this_renderer)) self.event_queue.add_event(video.get_time() + 15, lambda: self.load_main_menu(position=2))
def cancel_erase(self): """ The erase operation is aborted, and the menu restored to normal state. """ audio.play_sound(MENU_CANCEL_SOUND, CHANNEL_MENU) self.menu.entries[1].select() self.event_queue.add_event(0, self.controller.release) self.event_queue.add_event(0, self.menu.controller.acquire) del self.controller
def _do_light_collisions(self, stage): for s in stage.lights: if rect.contains_point(s.x, s.y, 8, 8, self.x, self.y): if s.got_hit() == True: audio.play_sound(audio.SND_HIT_TARGET) if stage.is_complete(): self.state = STATE_STAGE_COMPLETE globals.add_score(globals.SCORE_STAGE_COMPLETE) return
def cancel_callback(self): """ Moves the cursor back to the resume button, or if it's already on it, goes straight to resuming. """ if self.menu.position == 0: self.resume_callback() else: audio.play_sound(MENU_CANCEL_SOUND, CHANNEL_MENU) self.menu.set_position(0)
def on_left(self): """ Moves the cursor back a space, unless it's on the far left column, to which it loops to the other side. """ audio.play_sound(MENU_CURSOR_SOUND, CHANNEL_MENU) if self.position % 10 == 0: self.position += 9 else: self.position -= 1
def move_up(self): """ Changes which menu option is in focus - the one behind it, or the one at the bottom if it loops. """ self.entries[self.position].deselect() self.position -= 1 self.position %= len(self.entries) self.entries[self.position].select() audio.play_sound(MENU_CURSOR_SOUND, CHANNEL_MENU)
def move_down(self): """ Changes which menu option is in focus - the one ahead of it, or the one at the top if it loops. """ self.entries[self.position].deselect() self.position += 1 self.position %= len(self.entries) self.entries[self.position].select() audio.play_sound(MENU_CURSOR_SOUND, CHANNEL_MENU)
def score_callback(self): """ Closes the menu and begins the process to go to the high score table. """ audio.play_sound(MENU_SELECT_SOUND, CHANNEL_MENU) self.event_queue.add_event(video.get_time(), self.menu.destroy) self.event_queue.add_event(video.get_time() + 15, self.score_event) self.fader = video.AlphaRect((0, 0), SCREEN_SIZE) self.fader.a = video.Lerp(0, 255, 15) video.add_renderer(self.fader.render, LAYER_OVERLAY_1)
def on_right(self): """ Moves the value to the next in the list, looping around if it passes the threshold. """ audio.play_sound(MENU_CURSOR_SOUND, CHANNEL_MENU) self.value += 1 self.value %= len(self.value_list) self.edit_value() self.callback(self.value_list[self.value][1])
def pause_callback(self): """ Changes the active cursor to the exit entry if the cancel or pause button's pressed on the main menu, or activates it if it's already there. """ if self.menu.position == 3: self.exit_callback() else: audio.play_sound(MENU_CANCEL_SOUND, CHANNEL_MENU) self.menu.set_position(3)
def _pressed_select(self): audio.play_sound(audio.SND_MENU_SELECT) if self.sel_index == SEL_START_GAME: self.game.add_fade(palette.FADE_STEP_TICKS_DEFAULT, palette.FADE_LEVEL_6, self.game.start_game) elif self.sel_index == SEL_PALETTE: self.game.add_fade(palette.FADE_STEP_TICKS_DEFAULT, palette.FADE_LEVEL_6, self.game.cycle_palette) elif self.sel_index == SEL_EXIT_GAME: self.game.add_fade(palette.FADE_STEP_TICKS_DEFAULT, palette.FADE_LEVEL_0, pyxel.quit)
def destroy(self): """ Destroys the link node with a small explosion. """ audio.play_sound("en_die0", channel=CHANNEL_ZAKO) if self.motive_state == self.forward_state: self.create_bullet() self.parent.particles.add_particle(particle.Explosion((self.x, self.y), (self.x_velocity, self.y_velocity))) BaseEnemy.destroy(self)
def on_collided(self, object_collided_with): if self.collide_sound is not None: audio.play_sound(self.collide_sound) if self.particle_system is not None: self.particle_effect_stop() if self.secondary_particle_system is not None: if object_collided_with.type == "player": self.set_position((object_collided_with.position[0], 0, object_collided_with.position[1])) self.secondary_particle_effect_start() else: self.secondary_particle_effect_start()
def engine(i, params, data): """ The loop that updates the data and redraws the plots. Called from bottom of video.init_plots. """ video.draw_animations(params, data) #Remove oldest data from backend. data['trace_win'] = np.delete(data['trace_win'], 0) data['trace_vis'] = np.delete(data['trace_vis'], 0) #Deletes col 1 of spectogram matrix. data['spec'] = np.delete(data['spec'], 0, 1) #What to append into the transform window, more signal or 0's at end. fill = data['the_sig'][0] if (np.size(data['the_sig']) > 0) else 0 data['trace_win'] = np.append(data['trace_win'], fill) #Play audio component. data['tone'] = fill / data['max_sig_val'] audio.play_sound(data) #Pull next element out of signal that's not yet visible, add it to the trace. len_non_win = params['LEN_TRACE_VIS'] - params['LEN_TRACE_WIN'] fill = data['the_sig'][len_non_win] if ( np.size(data['the_sig']) > len_non_win) else 0 data['trace_vis'] = np.append(data['trace_vis'], fill) #Removes oldest element of the signal. if np.size(data['the_sig']) > 0: data['the_sig'] = np.delete(data['the_sig'], 0) #Calc rfft of the window. data['trace_win_fft'] = np.abs(np.fft.rfft(data['trace_win'])) #Append the vector of fourier components to the spectrogram. data['spec'] = np.c_[data['spec'], data['trace_win_fft']]
def is_game_ended(self): ''' Show game result if game ends. ''' # if self.nRound == 1: # return # Count players villager_count = 0 god_count = 0 werewolf_count = 0 for player in self.players[1:]: if not player.died: if isinstance(player, Villager): villager_count += 1 elif player.__class__.good: god_count += 1 else: werewolf_count += 1 # Check if the game ends if villager_count == 0: self.status('刀民成功,狼人胜利!', broadcast=True) play_sound('刀民成功') elif god_count == 0: self.status('刀神成功,狼人胜利!', broadcast=True) play_sound('刀神成功') elif werewolf_count == 0: self.status('逐狼成功,平民胜利!', broadcast=True) play_sound('逐狼成功') else: return # End of game self.status('游戏结束', broadcast=True) self.broadcast(self.get_history()) exit()
def player_used_weapon(self): audio.play_sound(audio.SND_USED_WEAPON) self.state = STATE_PLAYER_WEAPON
def main_loop(self): self.game_started = True # Initialize variables self.nRound = 0 # Number of days elapsed seer, savior, witch, silencer, self.werewolves = None, None, None, None, [] self.killed_players = [] # List of players who are killed last night # Find players who have special identities for player in self.players[1:]: if isinstance(player, Seer): seer = player elif isinstance(player, Witch): witch = player elif isinstance(player, Savior): savior = player elif isinstance(player, Silencer): silencer = player elif isinstance(player, WerewolfLeader): self.werewolves.insert( 0, player) # Insert the leader to the front elif isinstance(player, Werewolf): self.werewolves.append(player) # Main loop while True: self.nRound += 1 # Night self.status('-----第%d天晚上-----' % self.nRound, broadcast=True) self.broadcast('天黑请闭眼') play_sound('天黑请闭眼') self.broadcast('') self.move_for(savior) for werewolf in self.werewolves: if not werewolf.died: self.move_for(werewolf) break # Only one werewolf needs to make a choice self.move_for(witch) if witch == None: self.is_game_ended() self.move_for(seer) self.move_for(silencer) # Day self.status('-----第%d天-----' % self.nRound, broadcast=True) self.broadcast('天亮啦') play_sound('天亮了') # Vote for Mayor if self.nRound == 1 and self.config('rules/have_mayor'): self.vote_for_mayor() # Remove players who resurrect self.killed_players = [ player for player in self.killed_players if player.died ] random.shuffle(self.killed_players) # Show the result of last night if self.killed_players: self.broadcast('昨天晚上,%s 死了' % self.player_list_to_str(self.killed_players)) else: self.broadcast('昨天晚上是平安夜~') # Trigger after-dying action for player in self.killed_players: player.after_dying() # Trigger wake-up action player_list = self.survived_players() random.shuffle(player_list) for player in player_list: player.wake_up() # Vote for suspect self.vote_for_suspect() # Reset killed_players self.killed_players = []
def player_hit_solid(self): audio.play_sound(audio.SND_HIT_WALL) self.game.add_screen_shake(5, 1, queue=False)
def close_eyes(self): play_sound('狼人请闭眼') self.message('')
def open_eyes(self): play_sound('狼人请睁眼')
def on_ability_used(self, player, ability_id, ability_instance): if player.element.type == "earth": if ability_id == 101: # Earth : Primary # Play the animation with weight 100 so that it basically overrides # any other animations currently playing. # @todo: use an actual solution instead of weight hack. self.animation_playonce("ability_1", 100) audio.play_sound("weaponswing") elif ability_id == 102: # Earth : Hook # handled elsewhere audio.play_sound("hook") elif ability_id == 103: # Earth : Earthquake # Play the particle animation effect_node = StaticEffectNode(self.sceneManager, player.world, 2) effect_node.set_particle_system( "Earthquake", (player.position[0], 0, player.position[1])) effect_node.particle_effect_start() # Play Sound audio.play_sound("earthquake") elif ability_id == 104: # Earth : Power Swing # Play the animation self.animation_playonce("ability_1", 100) audio.play_sound("weaponswing") elif player.element.type == "fire": if ability_id == 201: # Fire : Primary # Play the animation with weight 100 so that it basically overrides # any other animations currently playing. # @todo: use an actual solution instead of weight hack. self.animation_playonce("ability_1", 100) audio.play_sound("weaponswing") elif ability_id == 202: # Fire : Flame Rush # note: this is handle elsewhere # Play Sound audio.play_sound("flamerush") elif ability_id == 203: # Fire : Lava Splash effect_node = StaticEffectNode(self.sceneManager, player.world, 2) effect_node.set_particle_system( "LavaSplash", (player.position[0], 0, player.position[1])) effect_node.particle_effect_start() # Play Sound audio.play_sound("lavasplash") elif ability_id == 204: # Fire : Ring of Fire effect_node = StaticEffectNode(self.sceneManager, player.world, 3) effect_node.set_particle_system( "RingOfFire", (player.position[0], 0, player.position[1])) effect_node.particle_effect_start() # Play Sound audio.play_sound("ringoffire") elif player.element.type == "air": if ability_id == 301: # Air : Primary # @note: this is why passing the ability_instance to on_ability_used is sloppy # but the effect_node that represents the projectile object on the ogre side of # things NEEDS a reference to the corresponding ProjectileObject. # Find a better way to do this someday. projectile_node = ProjectileNode(self.sceneManager, ability_instance.projectile) projectile_node.set_particle_system("AirShot") projectile_node.set_secondary_particle_system("WaterSplash") projectile_node.particle_effect_start() # Play Sound audio.play_sound("airshot") projectile_node.set_collide_sound("impact") if ability_id == 302: # Air : Gust of Wind effect_node = StaticEffectNode(self.sceneManager, player.world, 0.5) effect_node.set_particle_system( "GustOfWind", (player.position[0], 0, player.position[1]), player.rotation) effect_node.particle_effect_start() audio.play_sound("gustofwind") if ability_id == 303: # Air : Wind Whisk effect_node1 = StaticEffectNode(self.sceneManager, player.world, 0.3) effect_node1.set_particle_system( "WindWhisk", (player.last_position[0], 0, player.last_position[1])) effect_node1.particle_effect_start() effect_node2 = StaticEffectNode(self.sceneManager, player.world, 0.3) effect_node2.set_particle_system( "WindWhisk", (player.position[0], 0, player.position[1])) effect_node2.particle_effect_start() audio.play_sound("windwhisk") if ability_id == 304: # Air : Lightning Bolt if ability_instance.target is None: # event was launched because ability was used, but there was no target in range return effect_node = StaticEffectNode(self.sceneManager, player.world, 0.2) # @todo: come up with a particle effect for this ability dx = -player.position[0] + ability_instance.target.position[0] dz = -player.position[1] + ability_instance.target.position[1] distance = math.sqrt(dx * dx + dz * dz) rotation = math.atan2(dz, dx) x_offset = dx / 2 z_offset = dz / 2 effect_node.set_particle_system( "Lightning", (player.position[0] + x_offset, 10, player.position[1] + z_offset), rotation) effect_node.particle_effect_start() effect_node.particle_system.getEmitter(0).setParameter( "depth", str(distance)) # Play Sound audio.play_sound("lightningbolt") elif player.element.type == "water": if ability_id == 401: # Water : Primary # @note: this is why passing the ability_instance to on_ability_used is sloppy # but the effect_node that represents the projectile object on the ogre side of # things NEEDS a reference to the corresponding ProjectileObject. # Find a better way to do this someday. projectile_node = ProjectileNode(self.sceneManager, ability_instance.projectile) #@todo: make particle effects for these projectile_node.set_particle_system("AirShot") projectile_node.set_secondary_particle_system("WaterSplash") projectile_node.particle_effect_start() projectile_node.set_collide_sound("lavasplash") audio.play_sound("airshot") elif ability_id == 402: # Water : Water Gush effect_node = StaticEffectNode(self.sceneManager, player.world, 0.5) # @todo: come up with a particle effect for this ability dx = -player.position[0] + player.last_position[0] dz = -player.position[1] + player.last_position[1] distance = math.sqrt(dx * dx + dz * dz) rotation = math.atan2(dz, dx) x_offset = dx / 2 z_offset = dz / 2 effect_node.set_particle_system( "WaterTrail", (player.position[0] + x_offset, 5, player.position[1] + z_offset), rotation) effect_node.particle_effect_start() effect_node.particle_system.getEmitter(0).setParameter( "depth", str(distance)) # Play Sound audio.play_sound("watergush") elif ability_id == 403: # Water : Tidal Wave effect_node = StaticEffectNode(self.sceneManager, player.world, 1) effect_node.set_particle_system( "TidalWave", (player.position[0] + 10 * math.cos(player.rotation), 15, player.position[1] + 10 * math.sin(player.rotation)), player.rotation) effect_node.particle_effect_start() audio.play_sound("tidalwave") elif ability_id == 404: # Water : Ice Burst mesh_node = StaticEffectNode(self.sceneManager, player.world, 1) mesh_node.set_mesh( "iceblock.mesh", (player.position[0], 0, player.position[1] + 10), 0, 15) explosion_node = StaticEffectNode(self.sceneManager, player.world, 0.5, True) explosion_node.set_particle_system( "IceBurstExplosion", (player.position[0], 0, player.position[1])) explosion_node.set_triggered_sound("iceburst") mesh_node.static_node_expired += explosion_node.on_triggered # Play Sound audio.play_sound("earthquake")
def open_eyes(self): ''' Ask the player to open eyes. ''' play_sound('%s请睁眼' % self.__class__.identity)