class Joust: def __init__(self, game_mode, moves, teams): self.move_serials = moves self.game_mode = game_mode self.tracked_moves = {} self.dead_moves = {} self.music_speed = Value("d", 1.5) self.running = True self.force_move_colors = {} self.teams = teams self.team_num = 6 self.game_mode = game_mode self.werewolf_timer = 35 self.start_timer = time.time() self.audio_cue = 0 self.num_dead = 0 self.werewolf_reveal = Value("i", 2) if game_mode == common.Games.JoustFFA.value: self.team_num = len(moves) if game_mode == common.Games.JoustRandomTeams.value: # this should be 3 for smaller number of controllers self.team_num = 4 if game_mode == common.Games.WereJoust.value: self.werewolf_reveal.value = 0 self.team_num = 1 if game_mode != common.Games.JoustTeams.value: self.generate_random_teams(self.team_num) if game_mode == common.Games.WereJoust.value: # were_num = int((len(moves)+2)/4) were_num = int((len(moves) * 7) / 16) if were_num <= 0: were_num = 1 self.choose_werewolf(were_num) music = "audio/Joust/music/" + random.choice(os.listdir("audio/Joust/music")) self.start_beep = Audio("audio/Joust/sounds/start.wav") self.start_game = Audio("audio/Joust/sounds/start3.wav") self.explosion = Audio("audio/Joust/sounds/Explosion34.wav") fast_resample = False end = False self.audio = Audio(music, end) # self.change_time = self.get_change_time(speed_up = True) self.change_time = time.time() + 8 self.speed_up = True self.currently_changing = False self.game_end = False self.winning_moves = [] self.game_loop() def choose_werewolf(self, were_num): for were in range(were_num): werewolf = random.choice(self.move_serials) while self.teams[werewolf] < 0: werewolf = random.choice(self.move_serials) self.teams[werewolf] = (self.teams[werewolf] * -1) - 1 def generate_random_teams(self, team_num): team_pick = list(range(team_num)) print(str(team_pick)) for serial in self.move_serials: random_choice = random.choice(team_pick) self.teams[serial] = random_choice team_pick.remove(random_choice) if not team_pick: team_pick = list(range(team_num)) def track_moves(self): for move_num, move_serial in enumerate(self.move_serials): time.sleep(0.02) dead_move = Value("i", 1) force_color = Array("i", [1] * 3) proc = Process( target=track_move, args=( move_serial, move_num, self.game_mode, self.teams[move_serial], self.team_num, dead_move, force_color, self.music_speed, self.werewolf_reveal, ), ) proc.start() self.tracked_moves[move_serial] = proc self.dead_moves[move_serial] = dead_move self.force_move_colors[move_serial] = force_color def change_all_move_colors(self, r, g, b): for color in self.force_move_colors.values(): common.change_color(color, r, g, b) # need to do the count_down here def count_down(self): self.change_all_move_colors(80, 0, 0) self.start_beep.start_effect() time.sleep(0.75) self.change_all_move_colors(70, 100, 0) self.start_beep.start_effect() time.sleep(0.75) self.change_all_move_colors(0, 70, 0) self.start_beep.start_effect() time.sleep(0.75) self.change_all_move_colors(0, 0, 0) self.start_game.start_effect() def get_change_time(self, speed_up): min_moves = len(self.move_serials) - 2 if min_moves <= 0: min_moves = 1 game_percent = self.num_dead / min_moves if game_percent > 1.0: game_percent = 1.0 min_music_fast = common.lerp(MIN_MUSIC_FAST_TIME, END_MIN_MUSIC_FAST_TIME, game_percent) max_music_fast = common.lerp(MAX_MUSIC_FAST_TIME, END_MAX_MUSIC_FAST_TIME, game_percent) min_music_slow = common.lerp(MIN_MUSIC_SLOW_TIME, END_MIN_MUSIC_SLOW_TIME, game_percent) max_music_slow = common.lerp(MAX_MUSIC_SLOW_TIME, END_MAX_MUSIC_SLOW_TIME, game_percent) if speed_up: added_time = random.uniform(min_music_fast, max_music_fast) else: added_time = random.uniform(min_music_slow, max_music_slow) return time.time() + added_time def change_music_speed(self, fast): change_percent = numpy.clip((time.time() - self.change_time) / INTERVAL_CHANGE, 0, 1) if fast: self.music_speed.value = common.lerp(FAST_MUSIC_SPEED, SLOW_MUSIC_SPEED, change_percent) elif not fast: self.music_speed.value = common.lerp(SLOW_MUSIC_SPEED, FAST_MUSIC_SPEED, change_percent) self.audio.change_ratio(self.music_speed.value) def check_music_speed(self): if time.time() > self.change_time and time.time() < self.change_time + INTERVAL_CHANGE: self.change_music_speed(self.speed_up) self.currently_changing = True self.audio.change_chunk_size(True) elif time.time() >= self.change_time + INTERVAL_CHANGE and self.currently_changing: self.music_speed.value = SLOW_MUSIC_SPEED if self.speed_up else FAST_MUSIC_SPEED self.speed_up = not self.speed_up self.change_time = self.get_change_time(speed_up=self.speed_up) self.audio.change_ratio(self.music_speed.value) self.currently_changing = False self.audio.change_chunk_size(False) def get_real_team(self, team): if team < 0: return -1 else: return team def reveal(self): self.werewolf_reveal.value = 2 def werewolf_audio_cue(self): if self.game_mode == common.Games.WereJoust.value: # print self.werewolf_timer - (time.time() - self.start_timer) if self.werewolf_timer - (time.time() - self.start_timer) <= 30 and self.audio_cue == 0: Audio("audio/Joust/sounds/30 werewolf.wav").start_effect() self.audio_cue = 1 if self.werewolf_timer - (time.time() - self.start_timer) <= 10 and self.audio_cue == 1: Audio("audio/Joust/sounds/10 werewolf.wav").start_effect() self.audio_cue = 2 if self.werewolf_timer - (time.time() - self.start_timer) <= 0 and self.audio_cue == 2: Audio("audio/Joust/sounds/werewolf reveal 2.wav").start_effect() self.reveal() self.audio_cue = 3 def check_end_game(self): winning_team = -100 team_win = True for move_serial, dead in self.dead_moves.items(): # if we are alive if dead.value == 1: if winning_team == -100: winning_team = self.get_real_team(self.teams[move_serial]) elif self.get_real_team(self.teams[move_serial]) != winning_team: team_win = False if dead.value == 0: # This is to play the sound effect self.num_dead += 1 dead.value = -1 self.explosion.start_effect() if team_win: self.end_game_sound(winning_team) for move_serial in self.teams.keys(): if self.get_real_team(self.teams[move_serial]) == winning_team: self.winning_moves.append(move_serial) self.game_end = True def stop_tracking_moves(self): for proc in self.tracked_moves.values(): proc.terminate() proc.join() time.sleep(0.02) def end_game(self): self.audio.stop_audio() end_time = time.time() + END_GAME_PAUSE h_value = 0 while time.time() < end_time: time.sleep(0.01) win_color = common.hsv2rgb(h_value, 1, 1) for win_move in self.winning_moves: win_color_array = self.force_move_colors[win_move] common.change_color(win_color_array, *win_color) h_value = h_value + 0.01 if h_value >= 1: h_value = 0 self.running = False def end_game_sound(self, winning_team): if self.game_mode == common.Games.JoustTeams.value: if winning_team == 0: team_win = Audio("audio/Joust/sounds/yellow team win.wav") if winning_team == 1: team_win = Audio("audio/Joust/sounds/green team win.wav") if winning_team == 2: team_win = Audio("audio/Joust/sounds/cyan team win.wav") if winning_team == 3: team_win = Audio("audio/Joust/sounds/blue team win.wav") if winning_team == 4: team_win = Audio("audio/Joust/sounds/magenta team win.wav") if winning_team == 5: team_win = Audio("audio/Joust/sounds/red team win.wav") team_win.start_effect() if self.game_mode == common.Games.JoustRandomTeams.value: if winning_team == 0: team_win = Audio("audio/Joust/sounds/yellow team win.wav") if winning_team == 1: team_win = Audio("audio/Joust/sounds/cyan team win.wav") if winning_team == 2: team_win = Audio("audio/Joust/sounds/magenta team win.wav") if winning_team == 3: team_win = Audio("audio/Joust/sounds/red team win.wav") team_win.start_effect() if self.game_mode == common.Games.WereJoust.value: if winning_team == -1: team_win = Audio("audio/Joust/sounds/werewolf win.wav") else: team_win = Audio("audio/Joust/sounds/human win.wav") team_win.start_effect() # self.explosion = Audio('audio/Joust/sounds/Explosion34.wav') def werewolf_intro(self): Audio("audio/Joust/sounds/werewolf intro.wav").start_effect() time.sleep(3) self.change_all_move_colors(80, 0, 0) time.sleep(2) self.change_all_move_colors(30, 0, 0) time.sleep(18) self.change_all_move_colors(20, 20, 20) time.sleep(2) self.start_timer = time.time() def game_loop(self): self.track_moves() if self.game_mode == common.Games.WereJoust.value: self.werewolf_intro() self.werewolf_reveal.value = 1 self.count_down() time.sleep(0.02) self.audio.start_audio_loop() time.sleep(0.8) while self.running: self.check_music_speed() self.check_end_game() self.werewolf_audio_cue() if self.game_end: self.end_game() self.stop_tracking_moves()
class Bubble(): def __init__(self, moves): self.move_serials = moves self.tracked_moves = {} self.dead_moves = {} self.scores = {} self.music_speed = Value('d', 1.5) self.running = True self.force_move_colors = {} self.teams = {} self.win_amount = int(math.ceil((len(moves)/2.0)+2)) self.team_num = 2 self.generate_random_teams(self.team_num) music = 'audio/Joust/music/' + random.choice(os.listdir('audio/Joust/music')) self.start_beep = Audio('audio/Joust/sounds/start.wav') self.start_game = Audio('audio/Joust/sounds/start3.wav') self.explosion = Audio('audio/Joust/sounds/Explosion34.wav') fast_resample = False if len(moves) >= 5: fast_resample = True self.audio = Audio(music, fast_resample) #self.change_time = self.get_change_time(speed_up = True) self.change_time = time.time() + 8 self.speed_up = True self.currently_changing = False self.game_end = False self.winning_moves = [] self.losing_moves = [] self.game_loop() def generate_random_teams(self, team_num): team_pick = range(team_num) for serial in self.move_serials: random_choice = random.choice(team_pick) self.teams[serial] = random_choice team_pick.remove(random_choice) if not team_pick: team_pick = range(team_num) def track_moves(self): for move_num, move_serial in enumerate(self.move_serials): dead_move = Value('i', 1) score = Value('i', 0) force_color = Array('i', [1] * 3) proc = Process(target=track_move, args=(move_serial, move_num, self.teams[move_serial], self.team_num, score, self.win_amount, dead_move, force_color, self.music_speed)) proc.start() self.scores[move_serial] = score self.tracked_moves[move_serial] = proc self.dead_moves[move_serial] = dead_move self.force_move_colors[move_serial] = force_color def change_all_move_colors(self, r, g, b): for color in self.force_move_colors.itervalues(): common.change_color(color, r, g, b) #need to do the count_down here def count_down(self): self.change_all_move_colors(70, 0, 0) self.start_beep.start_effect() time.sleep(0.75) self.change_all_move_colors(70, 100, 0) self.start_beep.start_effect() time.sleep(0.75) self.change_all_move_colors(0, 70, 0) self.start_beep.start_effect() time.sleep(0.75) self.change_all_move_colors(0, 0, 0) self.start_game.start_effect() def get_change_time(self, speed_up): if speed_up: added_time = random.uniform(MIN_MUSIC_FAST_TIME, MAX_MUSIC_FAST_TIME) else: added_time = random.uniform(MIN_MUSIC_SLOW_TIME, MAX_MUSIC_SLOW_TIME) return time.time() + added_time def change_music_speed(self, fast): change_percent = numpy.clip((time.time() - self.change_time)/INTERVAL_CHANGE, 0, 1) if fast: self.music_speed.value = common.lerp(FAST_MUSIC_SPEED, SLOW_MUSIC_SPEED, change_percent) elif not fast: self.music_speed.value = common.lerp(SLOW_MUSIC_SPEED, FAST_MUSIC_SPEED, change_percent) self.audio.change_ratio(self.music_speed.value) def check_music_speed(self): if time.time() > self.change_time and time.time() < self.change_time + INTERVAL_CHANGE: self.change_music_speed(self.speed_up) self.currently_changing = True self.audio.change_chunk_size(True) elif time.time() >= self.change_time + INTERVAL_CHANGE and self.currently_changing: self.music_speed.value = SLOW_MUSIC_SPEED if self.speed_up else FAST_MUSIC_SPEED self.speed_up = not self.speed_up self.change_time = self.get_change_time(speed_up = self.speed_up) self.audio.change_ratio(self.music_speed.value) self.currently_changing = False self.audio.change_chunk_size(False) def get_real_team(self, team): if team < 0: return -1 else: return team def check_end_game(self): team_win = False for move_serial, score in self.scores.iteritems(): #if we are alive if score.value >= self.win_amount: winning_team = self.teams[move_serial] team_win = True if team_win: for move_serial in self.teams.iterkeys(): if self.teams[move_serial] == winning_team: self.winning_moves.append(move_serial) else: self.losing_moves.append(move_serial) self.game_end = True def check_for_points(self): for move_serial, score in self.scores.iteritems(): if score.value == -1: score.value = 0 self.explosion.start_effect() team_increase = self.teams[move_serial] for move_serial_increase, score_increase in self.scores.iteritems(): if self.teams[move_serial_increase] != team_increase: score_increase.value += 1 def stop_tracking_moves(self): for proc in self.tracked_moves.itervalues(): proc.terminate() proc.join() def end_game(self): self.audio.stop_audio() end_time = time.time() + END_GAME_PAUSE h_value = 0 while (time.time() < end_time): time.sleep(0.01) win_color = common.hsv2rgb(h_value, 1, 1) for win_move in self.winning_moves: win_color_array = self.force_move_colors[win_move] common.change_color(win_color_array, *win_color) for lose_move in self.losing_moves: lose_color_array = self.force_move_colors[lose_move] common.change_color(lose_color_array, 1,0,0) h_value = (h_value + 0.01) if h_value >= 1: h_value = 0 self.running = False def game_loop(self): self.track_moves() self.count_down() self.audio.start_audio_loop() while self.running: self.check_music_speed() self.check_for_points() self.check_end_game() if self.game_end: self.end_game() self.stop_tracking_moves()
class Joust(): def __init__(self, game_mode, moves, teams): self.move_serials = moves self.game_mode = game_mode self.tracked_moves = {} self.dead_moves = {} self.music_speed = Value('d', 1.5) self.running = True self.force_move_colors = {} self.teams = teams self.team_num = 6 self.game_mode = game_mode self.werewolf_timer = 35 self.start_timer = time.time() self.audio_cue = 0 self.num_dead = 0 self.werewolf_reveal = Value('i', 2) if game_mode == common.Games.JoustFFA.value: self.team_num = len(moves) if game_mode == common.Games.JoustRandomTeams.value: #this should be 3 for smaller number of controllers self.team_num = 4 if game_mode == common.Games.WereJoust.value: self.werewolf_reveal.value = 0 self.team_num = 1 if game_mode != common.Games.JoustTeams.value: self.generate_random_teams(self.team_num) if game_mode == common.Games.WereJoust.value: #were_num = int((len(moves)+2)/4) were_num = int((len(moves)*7)/16) if were_num <= 0: were_num = 1 self.choose_werewolf(were_num) music = 'audio/Joust/music/' + random.choice(os.listdir('audio/Joust/music')) self.start_beep = Audio('audio/Joust/sounds/start.wav') self.start_game = Audio('audio/Joust/sounds/start3.wav') self.explosion = Audio('audio/Joust/sounds/Explosion34.wav') fast_resample = False end = False self.audio = Audio(music, end) #self.change_time = self.get_change_time(speed_up = True) self.change_time = time.time() + 8 self.speed_up = True self.currently_changing = False self.game_end = False self.winning_moves = [] self.game_loop() def choose_werewolf(self, were_num): for were in range(were_num): werewolf = random.choice(self.move_serials) while self.teams[werewolf] < 0: werewolf = random.choice(self.move_serials) self.teams[werewolf] = (self.teams[werewolf] * -1) - 1 def generate_random_teams(self, team_num): team_pick = list(range(team_num)) print (str(team_pick)) for serial in self.move_serials: random_choice = random.choice(team_pick) self.teams[serial] = random_choice team_pick.remove(random_choice) if not team_pick: team_pick = list(range(team_num)) def track_moves(self): for move_num, move_serial in enumerate(self.move_serials): time.sleep(0.02) dead_move = Value('i', 1) force_color = Array('i', [1] * 3) proc = Process(target=track_move, args=(move_serial, move_num, self.game_mode, self.teams[move_serial], self.team_num, dead_move, force_color, self.music_speed, self.werewolf_reveal)) proc.start() self.tracked_moves[move_serial] = proc self.dead_moves[move_serial] = dead_move self.force_move_colors[move_serial] = force_color def change_all_move_colors(self, r, g, b): for color in self.force_move_colors.values(): common.change_color(color, r, g, b) #need to do the count_down here def count_down(self): self.change_all_move_colors(80, 0, 0) self.start_beep.start_effect() time.sleep(0.75) self.change_all_move_colors(70, 100, 0) self.start_beep.start_effect() time.sleep(0.75) self.change_all_move_colors(0, 70, 0) self.start_beep.start_effect() time.sleep(0.75) self.change_all_move_colors(0, 0, 0) self.start_game.start_effect() def get_change_time(self, speed_up): min_moves = len(self.move_serials) - 2 if min_moves <= 0: min_moves = 1 game_percent = (self.num_dead/min_moves) if game_percent > 1.0: game_percent = 1.0 min_music_fast = common.lerp(MIN_MUSIC_FAST_TIME, END_MIN_MUSIC_FAST_TIME, game_percent) max_music_fast = common.lerp(MAX_MUSIC_FAST_TIME, END_MAX_MUSIC_FAST_TIME, game_percent) min_music_slow = common.lerp(MIN_MUSIC_SLOW_TIME, END_MIN_MUSIC_SLOW_TIME, game_percent) max_music_slow = common.lerp(MAX_MUSIC_SLOW_TIME, END_MAX_MUSIC_SLOW_TIME, game_percent) if speed_up: added_time = random.uniform(min_music_fast, max_music_fast) else: added_time = random.uniform(min_music_slow, max_music_slow) return time.time() + added_time def change_music_speed(self, fast): change_percent = numpy.clip((time.time() - self.change_time)/INTERVAL_CHANGE, 0, 1) if fast: self.music_speed.value = common.lerp(FAST_MUSIC_SPEED, SLOW_MUSIC_SPEED, change_percent) elif not fast: self.music_speed.value = common.lerp(SLOW_MUSIC_SPEED, FAST_MUSIC_SPEED, change_percent) self.audio.change_ratio(self.music_speed.value) def check_music_speed(self): if time.time() > self.change_time and time.time() < self.change_time + INTERVAL_CHANGE: self.change_music_speed(self.speed_up) self.currently_changing = True self.audio.change_chunk_size(True) elif time.time() >= self.change_time + INTERVAL_CHANGE and self.currently_changing: self.music_speed.value = SLOW_MUSIC_SPEED if self.speed_up else FAST_MUSIC_SPEED self.speed_up = not self.speed_up self.change_time = self.get_change_time(speed_up = self.speed_up) self.audio.change_ratio(self.music_speed.value) self.currently_changing = False self.audio.change_chunk_size(False) def get_real_team(self, team): if team < 0: return -1 else: return team def reveal(self): self.werewolf_reveal.value = 2 def werewolf_audio_cue(self): if self.game_mode == common.Games.WereJoust.value: #print self.werewolf_timer - (time.time() - self.start_timer) if self.werewolf_timer - (time.time() - self.start_timer) <= 30 and self.audio_cue == 0: Audio('audio/Joust/sounds/30 werewolf.wav').start_effect() self.audio_cue = 1 if self.werewolf_timer - (time.time() - self.start_timer) <= 10 and self.audio_cue == 1: Audio('audio/Joust/sounds/10 werewolf.wav').start_effect() self.audio_cue = 2 if self.werewolf_timer - (time.time() - self.start_timer) <= 0 and self.audio_cue == 2: Audio('audio/Joust/sounds/werewolf reveal 2.wav').start_effect() self.reveal() self.audio_cue = 3 def check_end_game(self): winning_team = -100 team_win = True for move_serial, dead in self.dead_moves.items(): #if we are alive if dead.value == 1: if winning_team == -100: winning_team = self.get_real_team(self.teams[move_serial]) elif self.get_real_team(self.teams[move_serial]) != winning_team: team_win = False if dead.value == 0: #This is to play the sound effect self.num_dead += 1 dead.value = -1 self.explosion.start_effect() if team_win: self.end_game_sound(winning_team) for move_serial in self.teams.keys(): if self.get_real_team(self.teams[move_serial]) == winning_team: self.winning_moves.append(move_serial) self.game_end = True def stop_tracking_moves(self): for proc in self.tracked_moves.values(): proc.terminate() proc.join() time.sleep(0.02) def end_game(self): self.audio.stop_audio() end_time = time.time() + END_GAME_PAUSE h_value = 0 while (time.time() < end_time): time.sleep(0.01) win_color = common.hsv2rgb(h_value, 1, 1) for win_move in self.winning_moves: win_color_array = self.force_move_colors[win_move] common.change_color(win_color_array, *win_color) h_value = (h_value + 0.01) if h_value >= 1: h_value = 0 self.running = False def end_game_sound(self, winning_team): if self.game_mode == common.Games.JoustTeams.value: if winning_team == 0: team_win = Audio('audio/Joust/sounds/yellow team win.wav') if winning_team == 1: team_win = Audio('audio/Joust/sounds/green team win.wav') if winning_team == 2: team_win = Audio('audio/Joust/sounds/cyan team win.wav') if winning_team == 3: team_win = Audio('audio/Joust/sounds/blue team win.wav') if winning_team == 4: team_win = Audio('audio/Joust/sounds/magenta team win.wav') if winning_team == 5: team_win = Audio('audio/Joust/sounds/red team win.wav') team_win.start_effect() if self.game_mode == common.Games.JoustRandomTeams.value: if winning_team == 0: team_win = Audio('audio/Joust/sounds/yellow team win.wav') if winning_team == 1: team_win = Audio('audio/Joust/sounds/cyan team win.wav') if winning_team == 2: team_win = Audio('audio/Joust/sounds/magenta team win.wav') if winning_team == 3: team_win = Audio('audio/Joust/sounds/red team win.wav') team_win.start_effect() if self.game_mode == common.Games.WereJoust.value: if winning_team == -1: team_win = Audio('audio/Joust/sounds/werewolf win.wav') else: team_win = Audio('audio/Joust/sounds/human win.wav') team_win.start_effect() #self.explosion = Audio('audio/Joust/sounds/Explosion34.wav') def werewolf_intro(self): Audio('audio/Joust/sounds/werewolf intro.wav').start_effect() time.sleep(3) self.change_all_move_colors(80, 0, 0) time.sleep(2) self.change_all_move_colors(30, 0, 0) time.sleep(18) self.change_all_move_colors(20, 20, 20) time.sleep(2) self.start_timer = time.time() def game_loop(self): self.track_moves() if self.game_mode == common.Games.WereJoust.value: self.werewolf_intro() self.werewolf_reveal.value = 1 self.count_down() time.sleep(0.02) self.audio.start_audio_loop() time.sleep(0.8) while self.running: self.check_music_speed() self.check_end_game() self.werewolf_audio_cue() if self.game_end: self.end_game() self.stop_tracking_moves()
class Bubble(): def __init__(self, moves): self.move_serials = moves self.tracked_moves = {} self.dead_moves = {} self.scores = {} self.music_speed = Value('d', 1.5) self.running = True self.force_move_colors = {} self.teams = {} self.win_amount = int(math.ceil((len(moves) / 2.0) + 2)) self.team_num = 2 self.generate_random_teams(self.team_num) music = 'audio/Joust/music/' + random.choice( os.listdir('audio/Joust/music')) self.start_beep = Audio('audio/Joust/sounds/start.wav') self.start_game = Audio('audio/Joust/sounds/start3.wav') self.explosion = Audio('audio/Joust/sounds/Explosion34.wav') fast_resample = False if len(moves) >= 5: fast_resample = True self.audio = Audio(music, fast_resample) #self.change_time = self.get_change_time(speed_up = True) self.change_time = time.time() + 8 self.speed_up = True self.currently_changing = False self.game_end = False self.winning_moves = [] self.losing_moves = [] self.game_loop() def generate_random_teams(self, team_num): team_pick = range(team_num) for serial in self.move_serials: random_choice = random.choice(team_pick) self.teams[serial] = random_choice team_pick.remove(random_choice) if not team_pick: team_pick = range(team_num) def track_moves(self): for move_num, move_serial in enumerate(self.move_serials): dead_move = Value('i', 1) score = Value('i', 0) force_color = Array('i', [1] * 3) proc = Process(target=track_move, args=(move_serial, move_num, self.teams[move_serial], self.team_num, score, self.win_amount, dead_move, force_color, self.music_speed)) proc.start() self.scores[move_serial] = score self.tracked_moves[move_serial] = proc self.dead_moves[move_serial] = dead_move self.force_move_colors[move_serial] = force_color def change_all_move_colors(self, r, g, b): for color in self.force_move_colors.itervalues(): common.change_color(color, r, g, b) #need to do the count_down here def count_down(self): self.change_all_move_colors(70, 0, 0) self.start_beep.start_effect() time.sleep(0.75) self.change_all_move_colors(70, 100, 0) self.start_beep.start_effect() time.sleep(0.75) self.change_all_move_colors(0, 70, 0) self.start_beep.start_effect() time.sleep(0.75) self.change_all_move_colors(0, 0, 0) self.start_game.start_effect() def get_change_time(self, speed_up): if speed_up: added_time = random.uniform(MIN_MUSIC_FAST_TIME, MAX_MUSIC_FAST_TIME) else: added_time = random.uniform(MIN_MUSIC_SLOW_TIME, MAX_MUSIC_SLOW_TIME) return time.time() + added_time def change_music_speed(self, fast): change_percent = numpy.clip( (time.time() - self.change_time) / INTERVAL_CHANGE, 0, 1) if fast: self.music_speed.value = common.lerp(FAST_MUSIC_SPEED, SLOW_MUSIC_SPEED, change_percent) elif not fast: self.music_speed.value = common.lerp(SLOW_MUSIC_SPEED, FAST_MUSIC_SPEED, change_percent) self.audio.change_ratio(self.music_speed.value) def check_music_speed(self): if time.time() > self.change_time and time.time( ) < self.change_time + INTERVAL_CHANGE: self.change_music_speed(self.speed_up) self.currently_changing = True self.audio.change_chunk_size(True) elif time.time( ) >= self.change_time + INTERVAL_CHANGE and self.currently_changing: self.music_speed.value = SLOW_MUSIC_SPEED if self.speed_up else FAST_MUSIC_SPEED self.speed_up = not self.speed_up self.change_time = self.get_change_time(speed_up=self.speed_up) self.audio.change_ratio(self.music_speed.value) self.currently_changing = False self.audio.change_chunk_size(False) def get_real_team(self, team): if team < 0: return -1 else: return team def check_end_game(self): team_win = False for move_serial, score in self.scores.iteritems(): #if we are alive if score.value >= self.win_amount: winning_team = self.teams[move_serial] team_win = True if team_win: for move_serial in self.teams.iterkeys(): if self.teams[move_serial] == winning_team: self.winning_moves.append(move_serial) else: self.losing_moves.append(move_serial) self.game_end = True def check_for_points(self): for move_serial, score in self.scores.iteritems(): if score.value == -1: score.value = 0 self.explosion.start_effect() team_increase = self.teams[move_serial] for move_serial_increase, score_increase in self.scores.iteritems( ): if self.teams[move_serial_increase] != team_increase: score_increase.value += 1 def stop_tracking_moves(self): for proc in self.tracked_moves.itervalues(): proc.terminate() proc.join() def end_game(self): self.audio.stop_audio() end_time = time.time() + END_GAME_PAUSE h_value = 0 while (time.time() < end_time): time.sleep(0.01) win_color = common.hsv2rgb(h_value, 1, 1) for win_move in self.winning_moves: win_color_array = self.force_move_colors[win_move] common.change_color(win_color_array, *win_color) for lose_move in self.losing_moves: lose_color_array = self.force_move_colors[lose_move] common.change_color(lose_color_array, 1, 0, 0) h_value = (h_value + 0.01) if h_value >= 1: h_value = 0 self.running = False def game_loop(self): self.track_moves() self.count_down() self.audio.start_audio_loop() while self.running: self.check_music_speed() self.check_for_points() self.check_end_game() if self.game_end: self.end_game() self.stop_tracking_moves()