def kill_game(self): try: self.audio.stop_audio() except: print('no audio loaded to stop') self.update_status('killed') all_moves = [x for x in self.dead_moves.keys()] end_time = time.time() + KILL_GAME_PAUSE h_value = 0 while (time.time() < end_time): time.sleep(0.01) color = common.hsv2rgb(h_value, 1, 1) for move in all_moves: color_array = self.force_move_colors[move] common.change_color(color_array, *color) h_value = (h_value + 0.01) if h_value >= 1: h_value = 0 # bright = 255 # while (time.time() < end_time): # time.sleep(0.01) # color = (bright,bright,bright) # for move in all_moves: # color_array = self.force_move_colors[move] # common.change_color(color_array, *color) # bright = bright - 1 # if bright < 10: # bright = 10 self.running = False
def end_game(self): if self.audio_toggle: try: self.audio.stop_audio() except: print('no audio loaded to stop') end_time = time.time() + END_GAME_PAUSE h_value = 0 self.update_status('ending',self.winning_team) if self.audio_toggle: self.end_game_sound(self.winning_team) while (time.time() < end_time): time.sleep(0.01) win_color = common.hsv2rgb(h_value, 1, 1) for win_move in self.move_serials: if win_move != self.last_move: win_color_array = self.force_move_colors[win_move] common.change_color(win_color_array, *win_color) else: win_color_array = self.force_move_colors[win_move] common.change_color(win_color_array, 1,1,1) h_value = (h_value + 0.01) if h_value >= 1: h_value = 0 self.running = False
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(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(self): try: self.audio.stop_audio() except: print('no audio loaded to stop') 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) if len(self.alive_moves) > 0: win_move = self.alive_moves[0] 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 Start(self): running = True moves = [] for move_num in range(len(self.controllers_alive)): moves.append(common.get_move(self.controllers_alive[move_num], move_num)) serials = self.controllers_alive processes = [] for num_try, serial in enumerate(serials): starting_bullets = 0 #starting_bullets = random.choice([0, 1]) opts = Array('i', [0, 0, 0, 1, starting_bullets, 1, 1]) p = Process(target=track_controller, args=(serial, num_try, opts)) p.start() processes.append(p) self.controller_opts[serial] = opts self.humans.append(serial) human_victory = Audio('audio/Zombie/sound_effects/human_victory.wav') zombie_victory = Audio('audio/Zombie/sound_effects/zombie_victory.wav') death = Audio('audio/Zombie/sound_effects/zombie_death.wav') pistol = Audio('audio/Zombie/sound_effects/pistol.wav') shotgun = Audio('audio/Zombie/sound_effects/shotgun.wav') molotov = Audio('audio/Zombie/sound_effects/molotov.wav') try: music = Audio('audio/Zombie/music/' + random.choice(os.listdir('audio/Zombie/music/'))) music.start_effect_music() except: print('no music in audio/Zombie/music/') start_kill = time.time() + 5 while time.time() < start_kill: pass #kill first humans for i in range(2): random_human = random.choice(self.humans) self.controller_opts[random_human][3] = 0 while running: self.audio_cue() #human update, loop through the different human controllers for serial in self.humans: #human is dead and now a zombie if self.controller_opts[serial][3] == 0: self.controller_opts[serial][0] = 1 self.dead_zombies[serial] = time.time() + self.get_kill_time() #pistol fired(1 bullet 1 random alive zombie) elif self.controller_opts[serial][1] == 2: pistol.start_effect() self.kill_zombies(1, [0, 0, 0, 0, 1, 1, 1]) self.controller_opts[serial][1] = 0 #shotgun fired(2 bullets 3 random alive zombies) #elif self.controller_opts[serial][1] == 3: # shotgun.start_effect() # self.kill_zombies(3, [ 0, 0, 1, 1, 2]) # self.controller_opts[serial][1] = 0 #molotov fired(5 bullets all alive zombies) elif self.controller_opts[serial][1] == 4: molotov.start_effect() self.kill_zombies(20, [0, 0, 1, 1, 2, 3]) self.controller_opts[serial][1] = 0 for serial, spawn_time in self.dead_zombies.items(): if serial in self.humans: self.humans.remove(serial) if spawn_time < time.time(): #set zombie to alive self.controller_opts[serial][3] = 1 self.alive_zombies.append(serial) #loop through dead zombies for serial in self.alive_zombies: if serial in self.dead_zombies: del self.dead_zombies[serial] #melee if self.controller_opts[serial][3] == 0: self.controller_opts[serial][0] = 1 self.dead_zombies[serial] = time.time() + self.get_kill_time() self.alive_zombies.remove(serial) self.reward([0, 0, 1, 1, 2]) death.start_effect() #win scenario if len(self.humans) <= 0 or (time.time() - self.start_time) > self.win_time: for proc in processes: proc.terminate() proc.join() pause_time = time.time() + 3 HSV = [(x*1.0/(50*len(self.controllers_alive)), 0.9, 1) for x in range(50*len(self.controllers_alive))] colour_range = [[int(x) for x in common.hsv2rgb(*colour)] for colour in HSV] win_controllers = [] if len(self.humans) <= 0: zombie_victory.start_effect() self.alive_zombies.extend(self.dead_zombies.keys()) win_controllers = self.alive_zombies if (time.time() - self.start_time) > self.win_time: human_victory.start_effect() win_controllers = self.humans #This needs to go in it's own function while time.time() < pause_time: for win_move in moves: if win_move.get_serial() in win_controllers: win_move.set_leds(*colour_range[0]) colour_range.append(colour_range.pop(0)) win_move.update_leds() else: win_move.set_rumble(100) win_move.poll() win_move.set_leds(0, 0, 0) win_move.update_leds() time.sleep(0.01) running = False try: music.stop_effect_music() except: print('no audio loaded')
def track_move(serial, move_num, move_opts): move = common.get_move(serial, move_num) move.set_leds(0,0,0) move.update_leds() #move.set_leds(255,255,255) #move.update_leds() random_color = 0 while True: time.sleep(0.01) if move.poll(): game_mode = move_opts[Opts.game_mode.value] move_button = move.get_buttons() if move_opts[Opts.alive.value] == Alive.off.value: if move_button == Buttons.sync.value: move_opts[Opts.alive.value] = Alive.on.value time.sleep(0.1) else: if move_button == Buttons.all_buttons.value: move_opts[Opts.alive.value] = Alive.off.value move.set_leds(0,0,0) move.set_rumble(0) move.update_leds() continue if game_mode == common.Games.JoustFFA.value: move.set_leds(255,255,255) elif game_mode == common.Games.JoustTeams.value: if move_opts[Opts.team.value] >= TEAM_NUM: move_opts[Opts.team.value] = 0 move.set_leds(*TEAM_COLORS[move_opts[Opts.team.value]]) if move_button == Buttons.middle.value: #allow players to increase their own team if move_opts[Opts.holding.value] == Holding.not_holding.value: move_opts[Opts.team.value] = (move_opts[Opts.team.value] + 1) % TEAM_NUM move_opts[Opts.holding.value] = Holding.holding.value elif game_mode == common.Games.JoustRandomTeams.value: color = common.hsv2rgb(random_color, 1, 1) move.set_leds(*color) random_color += 0.001 if random_color >= 1: random_color = 0 elif game_mode == common.Games.WereJoust.value: if move_num <= 0: move.set_leds(150,0,0) else: move.set_leds(200,200,200) elif game_mode == common.Games.Zombies.value: move.set_leds(50,150,50) elif game_mode == common.Games.Commander.value: if move_num % 2 == 0: move.set_leds(150,0,0) else: move.set_leds(0,0,150) elif game_mode == common.Games.Random.value: if move_button == Buttons.middle.value: move_opts[Opts.random_start.value] = Alive.off.value if move_opts[Opts.random_start.value] == Alive.on.value: move.set_leds(0,0,255) else: move.set_leds(255,255,0) if move_opts[Opts.holding.value] == Holding.not_holding.value: if move_button == Buttons.select.value: move_opts[Opts.selection.value] = Selections.change_mode.value move_opts[Opts.holding.value] = Holding.holding.value if move_button == Buttons.start.value: print ('start') move_opts[Opts.selection.value] = Selections.start_game.value move_opts[Opts.holding.value] = Holding.holding.value if move_button == Buttons.nothing.value: move_opts[Opts.holding.value] = Holding.not_holding.value move.update_leds()
def track_move(serial, move_num, move_opts, force_color, battery): move = common.get_move(serial, move_num) move.set_leds(0,0,0) move.update_leds() random_color = 0 while True: time.sleep(0.01) if move.poll(): game_mode = move_opts[Opts.game_mode.value] move_button = move.get_buttons() if move_opts[Opts.alive.value] == Alive.off.value: if move_button == Buttons.sync.value: move_opts[Opts.alive.value] = Alive.on.value time.sleep(0.1) else: if move_button == Buttons.all_buttons.value: move_opts[Opts.alive.value] = Alive.off.value move.set_leds(0,0,0) move.set_rumble(0) move.update_leds() continue #show battery level if battery.value == 1: battery_level = move.get_battery() if battery_level == 5: # 100% - green move.set_leds(0, 255, 0) elif battery_level == 4: # 80% - green-ish move.set_leds(128, 200, 0) elif battery_level == 3: # 60% - yellow move.set_leds(255, 255, 0) else: # <= 40% - red move.set_leds(255, 0, 0) #custom team mode is the only game mode that #can't be added to con mode elif game_mode == common.Games.JoustTeams.value: if move_opts[Opts.team.value] >= TEAM_NUM: move_opts[Opts.team.value] = 0 move.set_leds(*TEAM_COLORS[move_opts[Opts.team.value]]) if move_button == Buttons.middle.value: #allow players to increase their own team if move_opts[Opts.holding.value] == Holding.not_holding.value: move_opts[Opts.team.value] = (move_opts[Opts.team.value] + 1) % TEAM_NUM move_opts[Opts.holding.value] = Holding.holding.value #set leds to forced color elif sum(force_color) != 0: move.set_leds(*force_color) elif game_mode == common.Games.JoustFFA.value: move.set_leds(255,255,255) elif game_mode == common.Games.JoustRandomTeams.value: color = common.hsv2rgb(random_color, 1, 1) move.set_leds(*color) random_color += 0.001 if random_color >= 1: random_color = 0 elif game_mode == common.Games.WereJoust.value: if move_num <= 0: move.set_leds(150,0,0) else: move.set_leds(200,200,200) elif game_mode == common.Games.Zombies.value: move.set_leds(50,150,50) elif game_mode == common.Games.Commander.value: if move_num % 2 == 0: move.set_leds(150,0,0) else: move.set_leds(0,0,150) elif game_mode == common.Games.Swapper.value: if random_color > 0.5: move.set_leds(150,0,0) else: move.set_leds(0,0,150) random_color += 0.002 if random_color >= 1: random_color = 0 elif game_mode == common.Games.Ninja.value: if move_num <= 0: move.set_leds(random.randrange(100, 200),0,0) else: move.set_leds(200,200,200) elif game_mode == common.Games.KingoftheHill.value: if random_color > 0.5: move.set_leds(150,0,0) else: move.set_leds(0,0,150) random_color += 0.002 if random_color >= 1: random_color = 0 elif game_mode == common.Games.Random.value: if move_button == Buttons.middle.value: move_opts[Opts.random_start.value] = Alive.off.value if move_opts[Opts.random_start.value] == Alive.on.value: move.set_leds(0,0,255) else: move.set_leds(255,255,0) if move_opts[Opts.holding.value] == Holding.not_holding.value: #Change game mode and become admin controller if move_button == Buttons.select.value: move_opts[Opts.selection.value] = Selections.change_mode.value move_opts[Opts.holding.value] = Holding.holding.value #start the game if move_button == Buttons.start.value: move_opts[Opts.selection.value] = Selections.start_game.value move_opts[Opts.holding.value] = Holding.holding.value #as an admin controller add or remove game from convention mode if move_button == Buttons.cross.value: move_opts[Opts.selection.value] = Selections.add_game.value move_opts[Opts.holding.value] = Holding.holding.value #as an admin controller change sensitivity of controllers if move_button == Buttons.circle.value: move_opts[Opts.selection.value] = Selections.change_sensitivity.value move_opts[Opts.holding.value] = Holding.holding.value #as an admin controller change if instructions play if move_button == Buttons.square.value: move_opts[Opts.selection.value] = Selections.change_instructions.value move_opts[Opts.holding.value] = Holding.holding.value #as an admin show battery level of controllers if move_button == Buttons.triangle.value: move_opts[Opts.selection.value] = Selections.show_battery.value move_opts[Opts.holding.value] = Holding.holding.value if move_button == Buttons.nothing.value: move_opts[Opts.holding.value] = Holding.not_holding.value move.update_leds()
def track_move(serial, move_num, move_opts): move = common.get_move(serial, move_num) move.set_leds(0, 0, 0) move.update_leds() #move.set_leds(255,255,255) #move.update_leds() random_color = 0 while True: time.sleep(0.01) if move.poll(): game_mode = move_opts[Opts.game_mode.value] move_button = move.get_buttons() if move_opts[Opts.alive.value] == Alive.off.value: if move_button == Buttons.sync.value: move_opts[Opts.alive.value] = Alive.on.value time.sleep(0.1) else: if move_button == Buttons.all_buttons.value: move_opts[Opts.alive.value] = Alive.off.value move.set_leds(0, 0, 0) move.set_rumble(0) move.update_leds() continue if game_mode == common.Games.JoustFFA.value: move.set_leds(255, 255, 255) elif game_mode == common.Games.JoustTeams.value: if move_opts[Opts.team.value] >= TEAM_NUM: move_opts[Opts.team.value] = 0 move.set_leds(*TEAM_COLORS[move_opts[Opts.team.value]]) if move_button == Buttons.middle.value: #allow players to increase their own team if move_opts[Opts.holding. value] == Holding.not_holding.value: move_opts[Opts.team.value] = ( move_opts[Opts.team.value] + 1) % TEAM_NUM move_opts[ Opts.holding.value] = Holding.holding.value elif game_mode == common.Games.JoustRandomTeams.value: color = common.hsv2rgb(random_color, 1, 1) move.set_leds(*color) random_color += 0.001 if random_color >= 1: random_color = 0 elif game_mode == common.Games.WereJoust.value: if move_num <= 0: move.set_leds(150, 0, 0) else: move.set_leds(200, 200, 200) elif game_mode == common.Games.Zombies.value: move.set_leds(50, 150, 50) elif game_mode == common.Games.Commander.value: if move_num % 2 == 0: move.set_leds(150, 0, 0) else: move.set_leds(0, 0, 150) elif game_mode == common.Games.Random.value: if move_button == Buttons.middle.value: move_opts[Opts.random_start.value] = Alive.off.value if move_opts[Opts.random_start.value] == Alive.on.value: move.set_leds(0, 0, 255) else: move.set_leds(255, 255, 0) if move_opts[Opts.holding.value] == Holding.not_holding.value: if move_button == Buttons.select.value: move_opts[Opts.selection. value] = Selections.change_mode.value move_opts[Opts.holding.value] = Holding.holding.value if move_button == Buttons.start.value: print('start') move_opts[ Opts.selection.value] = Selections.start_game.value move_opts[Opts.holding.value] = Holding.holding.value if move_button == Buttons.nothing.value: move_opts[Opts.holding.value] = Holding.not_holding.value move.update_leds()
def track_move(serial, move_num, move_opts, force_color, battery, dead_count): move = common.get_move(serial, move_num) move.set_leds(0, 0, 0) move.update_leds() random_color = random.random() while True: time.sleep(0.01) if move.poll(): game_mode = move_opts[Opts.game_mode.value] move_button = move.get_buttons() if move_opts[Opts.alive.value] == Alive.off.value: if move_button == Buttons.sync.value: move_opts[Opts.alive.value] = Alive.on.value dead_count.value = dead_count.value - 1 time.sleep(0.1) else: if move_button == Buttons.all_buttons.value: move_opts[Opts.alive.value] = Alive.off.value dead_count.value = dead_count.value + 1 move.set_leds(0, 0, 0) move.set_rumble(0) move.update_leds() continue #show battery level if battery.value == 1: battery_level = move.get_battery() #granted a charging move should be dead #so it won't light up anyway if battery_level == 238: # charging - dim move.set_leds(10, 10, 10) elif battery_level == 239: # fully charged - white move.set_leds(255, 255, 255) elif battery_level == 5: # full - blue move.set_leds(0, 0, 255) elif battery_level == 4: # 80% - cyan move.set_leds(0, 255, 255) elif battery_level == 5: # 60% - green move.set_leds(0, 255, 0) elif battery_level == 2: # 40% - lime green move.set_leds(191, 255, 0) elif battery_level == 1: # 20% - yellow move.set_leds(255, 255, 0) else: # under 20% - red move.set_leds(255, 0, 0) #custom team mode is the only game mode that #can't be added to con mode elif game_mode == common.Games.JoustTeams.value: if move_opts[Opts.team.value] >= TEAM_NUM: move_opts[Opts.team.value] = 0 move.set_leds(*TEAM_COLORS[move_opts[Opts.team.value]]) if move_button == Buttons.middle.value: #allow players to increase their own team if move_opts[Opts.holding. value] == Holding.not_holding.value: move_opts[Opts.team.value] = ( move_opts[Opts.team.value] + 1) % TEAM_NUM move_opts[ Opts.holding.value] = Holding.holding.value #set leds to forced color elif sum(force_color) != 0: move.set_leds(*force_color) elif game_mode == common.Games.JoustFFA.value: move.set_leds(255, 255, 255) elif game_mode == common.Games.JoustRandomTeams.value: color = time.time() / 10 % 1 color = common.hsv2rgb(color, 1, 1) move.set_leds(*color) elif game_mode == common.Games.Traitor.value: if move_num % 4 == 2 and time.time() / 3 % 1 < .15: move.set_leds(200, 0, 0) else: color = 1 - time.time() / 10 % 1 color = common.hsv2rgb(color, 1, 1) move.set_leds(*color) elif game_mode == common.Games.WereJoust.value: if move_num <= 0: move.set_leds(150, 0, 0) else: move.set_leds(200, 200, 200) elif game_mode == common.Games.Zombies.value: move.set_leds(50, 150, 50) elif game_mode == common.Games.Commander.value: if move_num % 2 == 0: move.set_leds(150, 0, 0) else: move.set_leds(0, 0, 150) elif game_mode == common.Games.Swapper.value: if (time.time() / 5 + random_color) % 1 > 0.5: move.set_leds(150, 0, 0) else: move.set_leds(0, 0, 150) elif game_mode == common.Games.Tournament.value: if move_num <= 0: color = time.time() / 10 % 1 color = common.hsv2rgb(color, 1, 1) move.set_leds(*color) else: move.set_leds(200, 200, 200) elif game_mode == common.Games.Ninja.value: if move_num <= 0: move.set_leds(random.randrange(100, 200), 0, 0) else: move.set_leds(200, 200, 200) elif game_mode == common.Games.Random.value: if move_button == Buttons.middle.value: move_opts[Opts.random_start.value] = Alive.off.value if move_opts[Opts.random_start.value] == Alive.on.value: move.set_leds(0, 0, 255) else: move.set_leds(255, 255, 0) if move_opts[Opts.holding.value] == Holding.not_holding.value: #Change game mode and become admin controller if move_button == Buttons.select.value: move_opts[Opts.selection. value] = Selections.change_mode.value move_opts[Opts.holding.value] = Holding.holding.value #start the game if move_button == Buttons.start.value: move_opts[ Opts.selection.value] = Selections.start_game.value move_opts[Opts.holding.value] = Holding.holding.value #as an admin controller add or remove game from convention mode if move_button == Buttons.cross.value: move_opts[ Opts.selection.value] = Selections.add_game.value move_opts[Opts.holding.value] = Holding.holding.value #as an admin controller change sensitivity of controllers if move_button == Buttons.circle.value: move_opts[Opts.selection. value] = Selections.change_sensitivity.value move_opts[Opts.holding.value] = Holding.holding.value #as an admin controller change if instructions play if move_button == Buttons.square.value: move_opts[Opts.selection. value] = Selections.change_instructions.value move_opts[Opts.holding.value] = Holding.holding.value #as an admin show battery level of controllers if move_button == Buttons.triangle.value: move_opts[Opts.selection. value] = Selections.show_battery.value move_opts[Opts.holding.value] = Holding.holding.value if move_button == Buttons.nothing.value: move_opts[Opts.holding.value] = Holding.not_holding.value move.update_leds()