def __init__(self, move): self.buttons = common.Button(move.get_buttons()) self.trigger = move.get_trigger() self.acceleration = tuple( move.get_accelerometer_frame(psmove.Frame_SecondHalf)) self.gyroscope = tuple( move.get_gyroscope_frame(psmove.Frame_SecondHalf)) self.ts = time.time()
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 = common.Games(move_opts[Opts.game_mode.value]) move_button = common.Button(move.get_buttons()) if move_opts[Opts.alive.value] == Alive.off.value: if move_button == common.Button.SYNC: move_opts[Opts.alive.value] = Alive.on.value dead_count.value = dead_count.value - 1 time.sleep(0.1) else: if move_button == common.Button.SHAPES: 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 == psmove.Batt_CHARGING: move.set_leds(*colors.Colors.White20.value) elif battery_level == psmove.Batt_CHARGING_DONE: move.set_leds(*colors.Colors.White.value) elif battery_level == psmove.Batt_MAX: move.set_leds(*colors.Colors.Green.value) elif battery_level == psmove.Batt_80Percent: move.set_leds(*colors.Colors.Turquoise.value) elif battery_level == psmove.Batt_60Percent: move.set_leds(*colors.Colors.Blue.value) elif battery_level == psmove.Batt_40Percent: move.set_leds(*colors.Colors.Yellow.value) else: # under 40% - you should charge it! move.set_leds(*colors.Colors.Red.value) #custom team mode is the only game mode that #can't be added to con mode elif game_mode == common.Games.JoustTeams: if move_opts[Opts.team.value] >= TEAM_NUM: move_opts[Opts.team.value] = 3 move.set_leds(*colors.team_color_list[move_opts[ Opts.team.value]].value) if move_button == common.Button.MIDDLE: #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: move.set_leds(*colors.Colors.Orange.value) elif game_mode == common.Games.JoustRandomTeams: color = time.time() / 10 % 1 color = colors.hsv2rgb(color, 1, 1) move.set_leds(*color) elif game_mode == common.Games.Traitor: if move_num % 4 == 2 and time.time() / 3 % 1 < .15: move.set_leds(*colors.Colors.Red80.value) else: color = 1 - time.time() / 10 % 1 color = colors.hsv2rgb(color, 1, 1) move.set_leds(*color) elif game_mode == common.Games.WereJoust: if move_num <= 0: move.set_leds(*colors.Colors.Blue40.value) else: move.set_leds(*colors.Colors.Yellow.value) elif game_mode == common.Games.Zombies: move.set_leds(*colors.Colors.Zombie.value) elif game_mode == common.Games.Commander: if move_num % 2 == 0: move.set_leds(*colors.Colors.Orange.value) else: move.set_leds(*colors.Colors.Blue.value) elif game_mode == common.Games.Swapper: if (time.time() / 5 + random_color) % 1 > 0.5: move.set_leds(*colors.Colors.Magenta.value) else: move.set_leds(*colors.Colors.Green.value) elif game_mode == common.Games.FightClub: move.set_leds(*colors.Colors.Green80.value) elif game_mode == common.Games.NonStop: move.set_leds(*colors.Colors.Turquoise.value) elif game_mode == common.Games.Tournament: if move_num <= 0: color = time.time() / 10 % 1 color = colors.hsv2rgb(color, 1, 1) move.set_leds(*color) else: move.set_leds(*colors.Colors.Blue40.value) elif game_mode == common.Games.Ninja: if move_num <= 0: move.set_leds(random.randrange(100, 200), 0, 0) else: move.set_leds(*colors.Colors.Red60.value) elif game_mode == common.Games.Random: move.set_leds(0, 0, 255) if move.get_trigger() > 100: move_opts[Opts.random_start.value] = Alive.off.value if move_opts[Opts.random_start.value] == Alive.off.value: move.set_leds(255, 255, 255) if move_opts[Opts.holding.value] == Holding.not_holding.value: #Change game mode and become admin controller if move_button == common.Button.SELECT: move_opts[Opts.selection. value] = Selections.change_mode.value move_opts[Opts.holding.value] = Holding.holding.value #start the game if move_button == common.Button.START: 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 == common.Button.CROSS: 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 == common.Button.CIRCLE: 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 == common.Button.SQUARE: 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 == common.Button.TRIANGLE: move_opts[Opts.selection. value] = Selections.show_battery.value move_opts[Opts.holding.value] = Holding.holding.value if move_button == common.Button.NONE: move_opts[Opts.holding.value] = Holding.not_holding.value move.update_leds()
def track_move(move_serial, move_num, team, num_teams, dead_move, force_color, music_speed, commander_intro, move_opts, power, overdrive): #proc = psutil.Process(os.getpid()) #proc.nice(3) start = False no_rumble = time.time() + 1 move_last_value = None move = common.get_move(move_serial, move_num) team_colors = colors.generate_colors(num_teams) #keep on looping while move is not dead ready = False move.set_leds(0, 0, 0) move.update_leds() time.sleep(1) vibrate = False vibration_time = time.time() + 1 flash_lights = True flash_lights_timer = 0 change_arr = [0, 0, 0] death_time = 8 time_of_death = time.time() while commander_intro.value == 1: if move.poll(): button = common.Button(move.get_buttons()) if button == common.Button.MIDDLE and move_opts[ Opts.holding.value] == Holding.not_holding.value: move_opts[Opts.selection.value] = Selections.a_button.value move_opts[Opts.holding.value] = Holding.holding.value elif button == common.Button.TRIANGLE and move_opts[ Opts.holding.value] == Holding.not_holding.value: move_opts[Opts.selection.value] = Selections.triangle.value move_opts[Opts.holding.value] = Holding.holding.value elif move_opts[ Opts.is_commander.value] == Bool.no.value and move_opts[ Opts.holding.value] == Holding.holding.value: move.set_leds(200, 200, 200) elif move_opts[ Opts.is_commander.value] == Bool.yes.value and move_opts[ Opts.holding.value] == Holding.holding.value: move.set_leds(*Current_commander_colors[team]) else: move.set_leds(*Commander_colors[team]) move.update_leds() move_opts[Opts.holding.value] = Holding.not_holding.value move_opts[Opts.selection.value] = Selections.nothing.value while True: if sum(force_color) != 0: no_rumble_time = time.time() + 5 time.sleep(0.01) move.set_leds(*force_color) move.update_leds() move.set_rumble(0) no_rumble = time.time() + 0.5 #if we are not dead elif dead_move.value == 1: if move.poll(): ax, ay, az = move.get_accelerometer_frame( psmove.Frame_SecondHalf) #total = sum([ax, ay, az]) total = sqrt(sum([ax**2, ay**2, az**2])) if move_last_value is not None: change_real = abs(move_last_value - total) change_arr[0] = change_arr[1] change_arr[1] = change_arr[2] change_arr[2] = change_real change = (change_arr[0] + change_arr[1] + change_arr[2]) / 3 if move_opts[Opts.is_commander.value] == Bool.no.value: if overdrive.value == 0: warning = SLOW_WARNING threshold = SLOW_MAX else: warning = FAST_WARNING threshold = FAST_MAX else: #if affected by overdrive, this could make the power better warning = SLOW_WARNING threshold = SLOW_MAX if change > threshold: if time.time() > no_rumble: move.set_leds(0, 0, 0) move.set_rumble(90) dead_move.value = 0 time_of_death = time.time() elif change > warning and not vibrate: if time.time() > no_rumble: move.set_leds(20, 50, 100) vibrate = True vibration_time = time.time() + 0.5 else: if move_opts[Opts.is_commander.value] == Bool.no.value: if overdrive.value == 0: move.set_leds(*Commander_colors[team]) else: move.set_leds(*Overdrive_colors[team]) else: move.set_leds(*calculate_flash_time( Current_commander_colors[team][0], Current_commander_colors[team][1], Current_commander_colors[team][2], power.value)) move.set_rumble(0) if move_opts[Opts.is_commander.value] == Bool.yes.value: if (move.get_buttons() == 0 and move.get_trigger() < 10): move_opts[ Opts.holding.value] = Holding.not_holding.value button = move.get_buttons() #print str(power.value) if power.value >= 1.0: #press trigger for overdrive if (move_opts[Opts.holding.value] == Holding.not_holding.value and move.get_trigger() > 100): move_opts[Opts.selection. value] = Selections.trigger.value move_opts[ Opts.holding.value] = Holding.holding.value move_last_value = total if vibrate: flash_lights_timer += 1 if flash_lights_timer > 7: flash_lights_timer = 0 flash_lights = not flash_lights if flash_lights: move.set_leds(100, 100, 100) if time.time() < vibration_time - 0.22: move.set_rumble(110) else: move.set_rumble(0) if time.time() > vibration_time: vibrate = False move.update_leds() #if we are dead elif dead_move.value <= 0: if time.time() - time_of_death >= death_time: dead_move.value = 3 elif dead_move.value == 3: move_last_value = None dead_move.value = 1 no_rumble = time.time() + 2 if death_time < 25: death_time += 2
def track_move(move, team, dead_move, force_color, music_speed, commander_intro, move_opts, commander_powers, commander_overdrive, restart, menu, controller_sensitivity): if team == Team.alpha.value: overdrive = commander_overdrive[0] power = commander_powers[0] else: overdrive = commander_overdrive[1] power = commander_powers[1] start = False no_rumble = time.time() + 1 move_last_value = None team_colors = colors.generate_colors(2) #keep on looping while move is not dead ready = False move.set_leds(0, 0, 0) move.update_leds() time.sleep(1) vibrate = False vibration_time = time.time() + 1 flash_lights = True flash_lights_timer = 0 change = 0 #change_arr = [0,0,0] SLOW_MAX = controller_sensitivity[0] SLOW_WARNING = controller_sensitivity[1] FAST_MAX = controller_sensitivity[2] FAST_WARNING = controller_sensitivity[3] death_time = 8 time_of_death = time.time() while commander_intro.value == 1: if move.poll(): button = common.Button(move.get_buttons()) if button == common.Button.MIDDLE and move_opts[ Opts.holding.value] == Holding.not_holding.value: move_opts[Opts.selection.value] = Selections.a_button.value move_opts[Opts.holding.value] = Holding.holding.value elif button == common.Button.TRIANGLE and move_opts[ Opts.holding.value] == Holding.not_holding.value: move_opts[Opts.selection.value] = Selections.triangle.value move_opts[Opts.holding.value] = Holding.holding.value elif move_opts[ Opts.is_commander.value] == Bool.no.value and move_opts[ Opts.holding.value] == Holding.holding.value: move.set_leds(200, 200, 200) elif move_opts[ Opts.is_commander.value] == Bool.yes.value and move_opts[ Opts.holding.value] == Holding.holding.value: move.set_leds(*Current_commander_colors[team]) else: move.set_leds(*Commander_colors[team]) move.update_leds() move_opts[Opts.holding.value] = Holding.not_holding.value move_opts[Opts.selection.value] = Selections.nothing.value while True: if (restart.value == 1 or menu.value == 1): return if sum(force_color) != 0: no_rumble_time = time.time() + 5 time.sleep(0.01) move.set_leds(*force_color) move.update_leds() move.set_rumble(0) no_rumble = time.time() + 0.5 #if we are not dead elif dead_move.value == 1: if move.poll(): ax, ay, az = move.get_accelerometer_frame( psmove.Frame_SecondHalf) total = sqrt(sum([ax**2, ay**2, az**2])) change = (change * 4 + total) / 5 if move_opts[Opts.is_commander.value] == Bool.no.value: if overdrive.value == 0: warning = SLOW_WARNING threshold = SLOW_MAX else: warning = FAST_WARNING threshold = FAST_MAX else: #if affected by overdrive, this could make the power better warning = SLOW_WARNING threshold = SLOW_MAX if change > threshold: if time.time() > no_rumble: move.set_leds(0, 0, 0) move.set_rumble(90) dead_move.value = 0 time_of_death = time.time() elif change > warning and not vibrate: if time.time() > no_rumble: move.set_leds(20, 50, 100) vibrate = True vibration_time = time.time() + 0.5 else: if move_opts[Opts.is_commander.value] == Bool.no.value: if overdrive.value == 0: move.set_leds(*Commander_colors[team]) else: move.set_leds(*Overdrive_colors[team]) else: move.set_leds(*calculate_flash_time( Current_commander_colors[team][0], Current_commander_colors[team][1], Current_commander_colors[team][2], power.value)) move.set_rumble(0) if move_opts[Opts.is_commander.value] == Bool.yes.value: if (move.get_buttons() == 0 and move.get_trigger() < 10): move_opts[ Opts.holding.value] = Holding.not_holding.value button = move.get_buttons() #print str(power.value) if power.value >= 1.0: #press trigger for overdrive if (move_opts[Opts.holding.value] == Holding.not_holding.value and move.get_trigger() > 100): move_opts[Opts.selection. value] = Selections.trigger.value move_opts[ Opts.holding.value] = Holding.holding.value #move_last_value = total if vibrate: flash_lights_timer += 1 if flash_lights_timer > 7: flash_lights_timer = 0 flash_lights = not flash_lights if flash_lights: move.set_leds(100, 100, 100) if time.time() < vibration_time - 0.22: move.set_rumble(110) else: move.set_rumble(0) if time.time() > vibration_time: vibrate = False move.update_leds() #if we are dead elif dead_move.value <= 0: if time.time() - time_of_death >= death_time: dead_move.value = 3 elif dead_move.value == 3: move_last_value = None dead_move.value = 1 no_rumble = time.time() + 2 if death_time < 25: death_time += 2
def track_move(move, dead_move, force_color, bomb_color, move_opts, game_start, false_color, faked, rumble, menu, restart): start = False no_rumble = time.time() + 1 move_last_value = None #keep on looping while move is not dead ready = False move.set_leds(0, 0, 0) move.update_leds() time.sleep(1) super_dead = False no_bomb_color = [0, 0, 200] fake_bomb_color = [0, 255, 0] no_fake_bomb_color = [0, 0, 200] death_time = 8 time_of_death = time.time() can_fake = True faking = False move_opts[Opts.holding.value] = Holding.not_holding.value move_opts[Opts.selection.value] = Selections.nothing.value while True: if (menu.value == 1 or restart.value == 1): return if sum(force_color) != 0 and game_start.value == 1: no_rumble_time = time.time() + 5 time.sleep(0.01) move.set_leds(*force_color) move.update_leds() move.set_rumble(rumble.value) no_rumble = time.time() + 0.5 #if we are not dead elif dead_move.value > 0: move.set_rumble(rumble.value) if dead_move.value == 2: no_bomb_color = [150, 150, 150] no_fake_bomb_color = [120, 255, 120] else: no_bomb_color = [30, 30, 30] no_fake_bomb_color = [100, 100, 100] if move.poll(): button = common.Button(move.get_buttons()) if move_opts[Opts.has_bomb.value] == Bool.yes.value: if (move.get_trigger() > 50 and can_fake): faking = True move_opts[Opts.selection. value] = Selections.false_trigger.value if (move.get_trigger() <= 127): col1 = int( common.lerp(fake_bomb_color[0], no_fake_bomb_color[0], (move.get_trigger() - 50) / 77)) col2 = int( common.lerp(fake_bomb_color[1], no_fake_bomb_color[1], (move.get_trigger() - 50) / 77)) col3 = int( common.lerp(fake_bomb_color[2], no_fake_bomb_color[2], (move.get_trigger() - 50) / 77)) move.set_leds(col1, col2, col3) if (move.get_trigger() > 127): col1 = int( common.lerp(no_fake_bomb_color[0], fake_bomb_color[0], (move.get_trigger() - 127) / 128)) col2 = int( common.lerp(no_fake_bomb_color[1], fake_bomb_color[1], (move.get_trigger() - 127) / 128)) col3 = int( common.lerp(no_fake_bomb_color[2], fake_bomb_color[2], (move.get_trigger() - 127) / 128)) move.set_leds(col1, col2, col3) else: move.set_leds(*bomb_color) if game_start.value == 0: move.set_leds(*force_color) move.update_leds() if faking: if game_start.value == 1: can_fake = False faking = False #non bomb holder else: can_fake = True faking = False if false_color.value == 1: move.set_leds(150, 20, 20) else: move.set_leds(*no_bomb_color) if move_opts[Opts.holding. value] == Holding.not_holding.value and ( move.get_trigger() > 50 or button == common.Button.MIDDLE): if move_opts[Opts.has_bomb.value] == Bool.no.value: move_opts[ Opts.holding.value] = Holding.holding.value if game_start.value == 1 and false_color.value == 1: print("JUST DIED TO BEING FAKED!!!") faked.value = 1 move.set_rumble(0) if move_opts[ Opts.holding.value] == Holding.not_holding.value and ( button in common.all_shapes): move_opts[Opts.selection.value] = Selections.counter.value move_opts[Opts.holding.value] = Holding.holding.value if button == common.Button.MIDDLE and move_opts[ Opts.holding.value] == Holding.not_holding.value: move_opts[Opts.selection.value] = Selections.a_button.value move_opts[Opts.holding.value] = Holding.holding.value elif move_opts[ Opts.holding. value] == Holding.holding.value and button == common.Button.NONE and move.get_trigger( ) <= 50: move_opts[Opts.selection.value] = Selections.nothing.value move_opts[Opts.holding.value] = Holding.not_holding.value else: if super_dead == False: super_dead = True move.set_rumble(0) move.set_leds(0, 0, 0) time.sleep(2) move.update_leds()