diff --git a/common.py b/common.py index 929cfedc..d5f53a3f 100644 --- a/common.py +++ b/common.py @@ -10,23 +10,31 @@ SETTINGSFILE = 'joustsettings.yaml' #Human speeds[slow, mid, fast] -SLOW_WARNING = [0.1, 0.15, 0.28] -SLOW_MAX = [0.25, 0.8, 1] -FAST_WARNING = [0.5, 0.6, 0.8] -FAST_MAX = [1, 1.4, 1.8] - #SLOW_WARNING = [0.1, 0.15, 0.28] -#SLOW_MAX = [0.5, 0.8, 1] +#SLOW_MAX = [0.25, 0.8, 1] #FAST_WARNING = [0.5, 0.6, 0.8] #FAST_MAX = [1, 1.4, 1.8] -WERE_SLOW_WARNING = [0.2, 0.3, 0.4] -WERE_SLOW_MAX = [0.7, 0.9, 1.1] -WERE_FAST_WARNING = [0.6, 0.7, 0.9] -WERE_FAST_MAX = [1.1, 1.5, 2.0] +SLOW_WARNING = [1.0, 1.3, 1.6, 2.0, 2.5] +SLOW_MAX = [1.1, 1.5, 1.8, 2.5, 3.2] +FAST_WARNING = [1.3, 1.6, 1.9, 2.7, 2.8] +FAST_MAX = [1.5, 1.8, 2.8, 3.2, 3.5] + +#WERE_SLOW_WARNING = [0.2, 0.3, 0.4] +#WERE_SLOW_MAX = [0.7, 0.9, 1.1] +#WERE_FAST_WARNING = [0.6, 0.7, 0.9] +#WERE_FAST_MAX = [1.1, 1.5, 2.0] + +WERE_SLOW_WARNING = [1.1, 1.4, 1.7, 2.1, 2.9] +WERE_SLOW_MAX = [1.2, 1.6, 1.9, 2.6, 3.9] +WERE_FAST_WARNING = [1.4, 1.7, 2.0, 2.8, 3.5] +WERE_FAST_MAX = [1.6, 1.9, 2.9, 3.3, 4.9] + +#ZOMBIE_WARNING = [0.5, 0.6, 0.8] +#ZOMBIE_MAX = [0.8, 1, 1.4] -ZOMBIE_WARNING = [0.5, 0.6, 0.8] -ZOMBIE_MAX = [0.8, 1, 1.4] +ZOMBIE_WARNING = [1.2, 1.5, 1.8, 2.6, 2.7] +ZOMBIE_MAX = [1.4, 1.7, 2.7, 3.1, 3.4] def get_move(serial, move_num): diff --git a/controller_process.py b/controller_process.py index 6e45457b..994f8f63 100644 --- a/controller_process.py +++ b/controller_process.py @@ -2,7 +2,7 @@ import common, colors, joust, webui, piparty #this should all be refactored to use the same options per game def main_track_move(menu, restart, move_serial, move_num, move_opts, force_color, battery, dead_count, game_mode, \ - team, team_color_enum, dead_move, music_speed, werewolf_reveal, show_team_colors, red_on_kill, zombie_opt,\ + team, team_color_enum, controller_sensitivity, dead_move, music_speed, werewolf_reveal, show_team_colors, red_on_kill, zombie_opt,\ commander_intro, commander_move_opt, commander_powers, commander_overdrive,five_controller_opt, swapper_team_colors,\ invincibility, fight_club_color, num_teams,bomb_color,game_start,false_color, faked, rumble, kill_proc): print("starting Controller Process") @@ -15,20 +15,20 @@ def main_track_move(menu, restart, move_serial, move_num, move_opts, force_color elif (menu.value == 1): piparty.track_move(move_serial, move_num, move, move_opts, force_color, battery, dead_count, restart, menu, kill_proc) elif(game_mode.value == common.Games.Zombies.value): - zombie.track_controller(move, zombie_opt, restart, menu) + zombie.track_controller(move, zombie_opt, restart, menu, controller_sensitivity) elif(game_mode.value == common.Games.Commander.value): commander.track_move(move, team.value, dead_move, force_color, music_speed, commander_intro, \ - commander_move_opt, commander_powers, commander_overdrive, restart, menu) + commander_move_opt, commander_powers, commander_overdrive, restart, menu, controller_sensitivity) elif(game_mode.value == common.Games.Swapper.value): swapper.track_move(move, team, 2, swapper_team_colors, \ - dead_move, force_color, music_speed, five_controller_opt, restart, menu) + dead_move, force_color, music_speed, five_controller_opt, restart, menu, controller_sensitivity) elif(game_mode.value == common.Games.FightClub.value): - fight_club.track_move(move, dead_move, force_color, music_speed, fight_club_color, invincibility, menu, restart) + fight_club.track_move(move, dead_move, force_color, music_speed, fight_club_color, invincibility, menu, restart, controller_sensitivity) elif(game_mode.value == common.Games.Tournament.value): - tournament.track_move(move, team, num_teams.value, dead_move, force_color, music_speed, show_team_colors, invincibility, menu, restart) + tournament.track_move(move, team, num_teams.value, dead_move, force_color, music_speed, show_team_colors, invincibility, menu, restart, controller_sensitivity) elif(game_mode.value == common.Games.Ninja.value): speed_bomb.track_move(move, dead_move, force_color,bomb_color, five_controller_opt, game_start, false_color, faked, rumble, menu, restart) else: joust.track_move(move, game_mode.value, team.value, team_color_enum, dead_move, force_color, \ - music_speed, werewolf_reveal, show_team_colors, red_on_kill, restart, menu) + music_speed, werewolf_reveal, show_team_colors, red_on_kill, restart, menu, controller_sensitivity) diff --git a/games/commander.py b/games/commander.py index c212d8c1..c829aef8 100644 --- a/games/commander.py +++ b/games/commander.py @@ -23,15 +23,7 @@ MIN_MUSIC_SLOW_TIME = 10 MAX_MUSIC_SLOW_TIME = 23 -#Sensitivity of the contollers -#changes by the values in common #TODO: make commander should be harder to kill -SLOW_MAX = 1.3 -SLOW_WARNING = 0.28 -FAST_MAX = 2.5 -FAST_WARNING = 1.3 - - #How long the speed change takes INTERVAL_CHANGE = 1.5 @@ -81,7 +73,7 @@ def calculate_flash_time(r,g,b, score): new_b = int(common.lerp(255, b, flash_percent)) return (new_r, new_g, new_b) -def track_move(move, team, dead_move, force_color, music_speed, commander_intro, move_opts, commander_powers, commander_overdrive, restart, menu): +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] @@ -102,7 +94,13 @@ def track_move(move, team, dead_move, force_color, music_speed, commander_intro, vibration_time = time.time() + 1 flash_lights = True flash_lights_timer = 0 - change_arr = [0,0,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() @@ -145,66 +143,60 @@ def track_move(move, team, dead_move, force_color, music_speed, commander_intro, 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 + 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 + 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() + 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 + 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: + if move_opts[Opts.is_commander.value] == Bool.no.value: + if overdrive.value == 0: + move.set_leds(*Commander_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) + 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 + 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 + #move_last_value = total if vibrate: flash_lights_timer += 1 if flash_lights_timer > 7: @@ -241,16 +233,6 @@ def __init__(self, moves, command_queue, ns, music, dead_moves, commander_intro, self.sensitivity = self.ns.settings['sensitivity'] self.random_teams = self.ns.settings['random_teams'] - global SLOW_MAX - global SLOW_WARNING - global FAST_MAX - global FAST_WARNING - - SLOW_MAX = common.SLOW_MAX[self.sensitivity] - SLOW_WARNING = common.SLOW_WARNING[self.sensitivity] - FAST_MAX = common.FAST_MAX[self.sensitivity] - FAST_WARNING = common.FAST_WARNING[self.sensitivity] - self.update_time = 0 self.move_serials = moves diff --git a/games/fight_club.py b/games/fight_club.py index ebfe75fb..a64549de 100644 --- a/games/fight_club.py +++ b/games/fight_club.py @@ -30,14 +30,6 @@ END_MIN_MUSIC_SLOW_TIME = 8 END_MAX_MUSIC_SLOW_TIME = 12 -#Default Sensitivity of the contollers -#These are changed from the options in common -SLOW_MAX = 1 -SLOW_WARNING = 0.28 -FAST_MAX = 1.8 -FAST_WARNING = 0.8 - - #How long the speed change takes INTERVAL_CHANGE = 1.5 @@ -46,7 +38,7 @@ KILL_GAME_PAUSE = 4 -def track_move(move, dead_move, force_color, music_speed, color, invincibility, menu, restart): +def track_move(move, dead_move, force_color, music_speed, color, invincibility, menu, restart, controller_sensitivity): start = False no_rumble = time.time() + 1 move_last_value = None @@ -55,7 +47,12 @@ def track_move(move, dead_move, force_color, music_speed, color, invincibility, flash_lights = True flash_lights_timer = 0 start_inv = False - change_arr = [0,0,0] + change = 0 + + SLOW_MAX = controller_sensitivity[0] + SLOW_WARNING = controller_sensitivity[1] + FAST_MAX = controller_sensitivity[2] + FAST_WARNING = controller_sensitivity[3] #keep on looping while move is not dead while True: @@ -73,75 +70,66 @@ def track_move(move, dead_move, force_color, music_speed, color, invincibility, elif dead_move.value == 1: #and not invincibility.value: 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 - speed_percent = (music_speed.value - SLOW_MUSIC_SPEED)/(FAST_MUSIC_SPEED - SLOW_MUSIC_SPEED) - warning = common.lerp(SLOW_WARNING, FAST_WARNING, speed_percent) - threshold = common.lerp(SLOW_MAX, FAST_MAX, speed_percent) - if not start_inv and invincibility.value: - start_inv = True - vibrate = True - vibration_time = time.time() + 4 - - - 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 color.value == 1: - move.set_leds(*colors.Colors.Orange.value) - if color.value == 2: - move.set_leds(*colors.Colors.Blue.value) - if color.value == 4: - move.set_leds(*colors.Colors.Green.value) - else: - #if team.value != -1: - # move.set_leds(*team_colors[team.value]) - #else: - move.set_leds(10,10,10) - if time.time() < vibration_time - 0.22: - move.set_rumble(110) - else: - move.set_rumble(0) - if time.time() > vibration_time: - #print("vibrate to false") - vibrate = False - start_inv = False - invincibility.value = False - else: - #move.set_leds(100,200,100) + change = (change * 4 + total)/5 + + speed_percent = (music_speed.value - SLOW_MUSIC_SPEED)/(FAST_MUSIC_SPEED - SLOW_MUSIC_SPEED) + warning = common.lerp(SLOW_WARNING, FAST_WARNING, speed_percent) + threshold = common.lerp(SLOW_MAX, FAST_MAX, speed_percent) + if not start_inv and invincibility.value: + start_inv = True + vibrate = True + vibration_time = time.time() + 4 + + 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 color.value == 1: move.set_leds(*colors.Colors.Orange.value) if color.value == 2: move.set_leds(*colors.Colors.Blue.value) if color.value == 4: move.set_leds(*colors.Colors.Green.value) - - if not invincibility.value: - if change > threshold: - if time.time() > no_rumble: - move.set_leds(*colors.Colors.Red.value) - move.set_rumble(90) - dead_move.value = -1 - - elif change > warning and not vibrate: - if time.time() > no_rumble: - vibrate = True - vibration_time = time.time() + 0.5 - move.set_leds(20,50,100) - - + else: + #if team.value != -1: + # move.set_leds(*team_colors[team.value]) + #else: + move.set_leds(10,10,10) + if time.time() < vibration_time - 0.22: + move.set_rumble(110) + else: + move.set_rumble(0) + if time.time() > vibration_time: + #print("vibrate to false") + vibrate = False + start_inv = False + invincibility.value = False + else: + #move.set_leds(100,200,100) + if color.value == 1: + move.set_leds(*colors.Colors.Orange.value) + if color.value == 2: + move.set_leds(*colors.Colors.Blue.value) + if color.value == 4: + move.set_leds(*colors.Colors.Green.value) - move_last_value = total + if not invincibility.value: + if change > threshold: + if time.time() > no_rumble: + move.set_leds(*colors.Colors.Red.value) + move.set_rumble(90) + dead_move.value = -1 + + elif change > warning and not vibrate: + if time.time() > no_rumble: + vibrate = True + vibration_time = time.time() + 0.5 + move.set_leds(20,50,100) + move.update_leds() else: if dead_move.value < 1: @@ -167,17 +155,6 @@ def __init__(self, moves, command_queue, ns, music, show_team_colors, music_spee self.sensitivity = self.ns.settings['sensitivity'] self.play_audio = self.ns.settings['play_audio'] - print("speed is {}".format(self.sensitivity)) - global SLOW_MAX - global SLOW_WARNING - global FAST_MAX - global FAST_WARNING - - SLOW_MAX = common.SLOW_MAX[self.sensitivity] - SLOW_WARNING = common.SLOW_WARNING[self.sensitivity] - FAST_MAX = common.FAST_MAX[self.sensitivity] - FAST_WARNING = common.FAST_WARNING[self.sensitivity] - self.move_serials = moves self.tracked_moves = {} diff --git a/games/swapper.py b/games/swapper.py index 2614efef..42c2a5f9 100644 --- a/games/swapper.py +++ b/games/swapper.py @@ -23,15 +23,6 @@ MIN_MUSIC_SLOW_TIME = 10 MAX_MUSIC_SLOW_TIME = 23 -#Sensitivity of the contollers -#changes by the values in common -#TODO: make commander should be harder to kill -SLOW_MAX = 1.3 -SLOW_WARNING = 0.28 -FAST_MAX = 2.5 -FAST_WARNING = 1.3 - - #How long the speed change takes INTERVAL_CHANGE = 1.5 @@ -79,7 +70,7 @@ def calculate_flash_time(r,g,b, score): new_b = int(common.lerp(255, b, flash_percent)) return (new_r, new_g, new_b) -def track_move(move, team, num_teams, team_colors, dead_move, force_color, music_speed, move_opts, restart, menu): +def track_move(move, team, num_teams, team_colors, dead_move, force_color, music_speed, move_opts, restart, menu, controller_sensitivity): start = False no_rumble = time.time() + 1 move_last_value = None @@ -92,7 +83,12 @@ def track_move(move, team, num_teams, team_colors, dead_move, force_color, music vibration_time = time.time() + 1 flash_lights = True flash_lights_timer = 0 - change_arr = [0,0,0] + change = 0 + + SLOW_MAX = controller_sensitivity[0] + SLOW_WARNING = controller_sensitivity[1] + FAST_MAX = controller_sensitivity[2] + FAST_WARNING = controller_sensitivity[3] death_time = 2 time_of_death = time.time() @@ -114,66 +110,58 @@ def track_move(move, team, num_teams, team_colors, dead_move, force_color, music 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 - - warning = SLOW_WARNING - threshold = SLOW_MAX - - - 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(*colors.Colors.White60.value) - else: - if(team.value == 0): - - move.set_leds(team_colors[0],team_colors[1],team_colors[2]) - else: - move.set_leds(team_colors[3],team_colors[4],team_colors[5]) - if time.time() < vibration_time - 0.22: - move.set_rumble(110) - else: - move.set_rumble(0) - if time.time() > vibration_time: - vibrate = False + change = (change * 4 + total)/5 + + warning = SLOW_WARNING + threshold = SLOW_MAX + + + 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(*colors.Colors.White60.value) else: if(team.value == 0): move.set_leds(team_colors[0],team_colors[1],team_colors[2]) else: move.set_leds(team_colors[3],team_colors[4],team_colors[5]) - - - if change > threshold: - if time.time() > no_rumble: - #vibrate = False - move.set_leds(*colors.Colors.Black.value) - move.set_rumble(90) - dead_move.value = 0 - time_of_death = time.time() - - elif change > warning and not vibrate: - if time.time() > no_rumble: - vibrate = True - vibration_time = time.time() + 0.5 - move.set_leds(20,50,100) - #else: - # move.set_rumble(0) + if time.time() < vibration_time - 0.22: + move.set_rumble(110) + else: + move.set_rumble(0) + if time.time() > vibration_time: + vibrate = False + else: + if(team.value == 0): + + move.set_leds(team_colors[0],team_colors[1],team_colors[2]) + else: + move.set_leds(team_colors[3],team_colors[4],team_colors[5]) + + + if change > threshold: + if time.time() > no_rumble: + #vibrate = False + move.set_leds(*colors.Colors.Black.value) + move.set_rumble(90) + dead_move.value = 0 + time_of_death = time.time() + + elif change > warning and not vibrate: + if time.time() > no_rumble: + vibrate = True + vibration_time = time.time() + 0.5 + move.set_leds(20,50,100) + #else: + # move.set_rumble(0) - - move_last_value = total move.update_leds() #if we are dead elif dead_move.value <= 0: @@ -200,16 +188,6 @@ def __init__(self, moves, command_queue, ns, music, controller_colors, dead_move self.color_lock = self.ns.settings['color_lock'] self.color_lock_choices = self.ns.settings['color_lock_choices'] self.random_teams = self.ns.settings['random_teams'] - - global SLOW_MAX - global SLOW_WARNING - global FAST_MAX - global FAST_WARNING - - SLOW_MAX = common.SLOW_MAX[self.sensitivity] - SLOW_WARNING = common.SLOW_WARNING[self.sensitivity] - FAST_MAX = common.FAST_MAX[self.sensitivity] - FAST_WARNING = common.FAST_WARNING[self.sensitivity] self.move_serials = moves self.tracked_moves = {} diff --git a/games/tournament.py b/games/tournament.py index 24b1d81d..2ed632d5 100644 --- a/games/tournament.py +++ b/games/tournament.py @@ -29,14 +29,6 @@ END_MIN_MUSIC_SLOW_TIME = 8 END_MAX_MUSIC_SLOW_TIME = 12 -#Default Sensitivity of the contollers -#These are changed from the options in common -SLOW_MAX = 1 -SLOW_WARNING = 0.28 -FAST_MAX = 1.8 -FAST_WARNING = 0.8 - - #How long the speed change takes INTERVAL_CHANGE = 1.5 @@ -45,7 +37,7 @@ KILL_GAME_PAUSE = 4 -def track_move(move, team, num_teams, dead_move, force_color, music_speed, show_team_colors, invincibility, menu, restart): +def track_move(move, team, num_teams, dead_move, force_color, music_speed, show_team_colors, invincibility, menu, restart, controller_sensitivity): start = False no_rumble = time.time() + 1 move_last_value = None @@ -56,6 +48,12 @@ def track_move(move, team, num_teams, dead_move, force_color, music_speed, show_ flash_lights_timer = 0 start_inv = False change_arr = [0,0,0] + change = 0 + + SLOW_MAX = controller_sensitivity[0] + SLOW_WARNING = controller_sensitivity[1] + FAST_MAX = controller_sensitivity[2] + FAST_WARNING = controller_sensitivity[3] #keep on looping while move is not dead while True: @@ -79,65 +77,57 @@ def track_move(move, team, num_teams, dead_move, force_color, music_speed, show_ elif dead_move.value == 1 and team.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 - speed_percent = (music_speed.value - SLOW_MUSIC_SPEED)/(FAST_MUSIC_SPEED - SLOW_MUSIC_SPEED) - warning = common.lerp(SLOW_WARNING, FAST_WARNING, speed_percent) - threshold = common.lerp(SLOW_MAX, FAST_MAX, speed_percent) - if not start_inv and invincibility.value == 1: - start_inv = True - vibrate = True - vibration_time = time.time() + 3 - + change = (change * 4 + total)/5 + + speed_percent = (music_speed.value - SLOW_MUSIC_SPEED)/(FAST_MUSIC_SPEED - SLOW_MUSIC_SPEED) + warning = common.lerp(SLOW_WARNING, FAST_WARNING, speed_percent) + threshold = common.lerp(SLOW_MAX, FAST_MAX, speed_percent) + if not start_inv and invincibility.value == 1: + start_inv = True + vibrate = True + vibration_time = time.time() + 3 + - 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) - else: - if team.value != -1: - move.set_leds(*team_colors[team.value]) - else: - 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 - start_inv = False - invincibility.value = 0 + 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) else: if team.value != -1: move.set_leds(*team_colors[team.value]) else: move.set_leds(100,100,100) - - if invincibility.value == 0: - if change > threshold: - if time.time() > no_rumble: - move.set_leds(0,0,0) - move.set_rumble(90) - dead_move.value = 0 - - elif change > warning and not vibrate: - if time.time() > no_rumble: - vibrate = True - vibration_time = time.time() + 0.5 - move.set_leds(20,50,100) - - + if time.time() < vibration_time - 0.22: + move.set_rumble(110) + else: + move.set_rumble(0) + if time.time() > vibration_time: + vibrate = False + start_inv = False + invincibility.value = 0 + else: + if team.value != -1: + move.set_leds(*team_colors[team.value]) + else: + move.set_leds(100,100,100) - move_last_value = total + if invincibility.value == 0: + if change > threshold: + if time.time() > no_rumble: + move.set_leds(0,0,0) + move.set_rumble(90) + dead_move.value = 0 + + elif change > warning and not vibrate: + if time.time() > no_rumble: + vibrate = True + vibration_time = time.time() + 0.5 + move.set_leds(20,50,100) + move.update_leds() else: if dead_move.value < 1: @@ -159,17 +149,6 @@ def __init__(self, moves, command_queue, ns, music, show_team_colors, music_spee self.sensitivity = self.ns.settings['sensitivity'] self.play_audio = self.ns.settings['play_audio'] - print("speed is {}".format(self.sensitivity)) - global SLOW_MAX - global SLOW_WARNING - global FAST_MAX - global FAST_WARNING - - SLOW_MAX = common.SLOW_MAX[self.sensitivity] - SLOW_WARNING = common.SLOW_WARNING[self.sensitivity] - FAST_MAX = common.FAST_MAX[self.sensitivity] - FAST_WARNING = common.FAST_WARNING[self.sensitivity] - self.move_serials = moves self.tracked_moves = {} diff --git a/games/zombie.py b/games/zombie.py index df7c376b..f5834159 100644 --- a/games/zombie.py +++ b/games/zombie.py @@ -9,11 +9,11 @@ from math import sqrt -human_warning = 1 -human_max = 1.8 +#human_warning = 1 +#human_max = 1.8 -zombie_warning = 0.6 -zombie_max = 1.0 +#zombie_warning = 0.6 +#zombie_max = 1.0 zombie_spawn_invincibility = 2 zombie_max_respawn_time = 30 @@ -68,7 +68,7 @@ -def track_controller(move, opts, restart, menu): +def track_controller(move, opts, restart, menu, controller_sensitivity): time.sleep(0.01) move.set_leds(200,200,200) move.update_leds() @@ -78,45 +78,43 @@ def track_controller(move, opts, restart, menu): vibration_time = time.time() + 1 flash_lights = True flash_lights_timer = 0 - change_arr=[0,0,0] + #change_arr=[0,0,0] + change = 0 + + human_warning = controller_sensitivity[3] + human_max = controller_sensitivity[2] + zombie_warning = controller_sensitivity[9] + zombie_max = controller_sensitivity[8] while True: if(restart.value == 1 or menu.value == 1): break 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 - # Dead - - #TODO: should probably only change this - # when the state changes (i.e. human death) - if opts[0] == 0: - warning = human_warning - threshold = human_max - if opts[0] == 1: - warning = zombie_warning - threshold = zombie_max - + change = (change * 4 + total)/5 + # Dead + #TODO: should probably only change this + # when the state changes (i.e. human death) + if opts[0] == 0: + warning = human_warning + threshold = human_max + if opts[0] == 1: + warning = zombie_warning + threshold = zombie_max - if change > threshold: - move.set_leds(255,0,0) - move.set_rumble(100) - opts[3] = 0 - - # Warn - elif change > warning and not vibrate: - move.set_leds(20,50,100) - vibrate = True - vibration_time = time.time() + 0.5 - move.update_leds() + if change > threshold: + move.set_leds(255,0,0) + move.set_rumble(100) + opts[3] = 0 + + # Warn + elif change > warning and not vibrate: + move.set_leds(20,50,100) + vibrate = True + vibration_time = time.time() + 0.5 + move.update_leds() #if we are dead if opts[3] == 0: @@ -190,7 +188,7 @@ def track_controller(move, opts, restart, menu): #else: # move.set_leds(*team_colors[team.value]) move.update_leds() - move_last_value = total + #move_last_value = total #we should try one process per controller, @@ -207,16 +205,6 @@ def __init__(self, cont_alive, command_queue, ns, music,restart, zombie_opts): self.music = music self.restart = restart - - global human_warning - global human_max - global zombie_warning - global zombie_max - - human_warning = common.FAST_WARNING[self.sensitivity] - human_max = common.FAST_MAX[self.sensitivity] - zombie_warning = common.ZOMBIE_WARNING[self.sensitivity] - zombie_max = common.ZOMBIE_MAX[self.sensitivity] self.update_time = 0 self.humans = [] diff --git a/joust.py b/joust.py index ed6a0bbb..3f181bca 100644 --- a/joust.py +++ b/joust.py @@ -9,6 +9,7 @@ from enum import Enum from multiprocessing import Process, Value, Array, Queue from math import sqrt +import statistics # How fast/slow the music can go @@ -30,16 +31,16 @@ #Default Sensitivity of the contollers #These are changed from the options in common -SLOW_MAX = 1 -SLOW_WARNING = 0.28 -FAST_MAX = 1.8 -FAST_WARNING = 0.8 +#SLOW_MAX = 1 +#SLOW_WARNING = 0.28 +#FAST_MAX = 1.8 +#FAST_WARNING = 0.8 #Sensitivity of the werewolf contollers -WERE_SLOW_MAX = 1.4 -WERE_SLOW_WARNING = 0.5 -WERE_FAST_MAX = 2.3 -WERE_FAST_WARNING = 1.2 +#WERE_SLOW_MAX = 1.4 +#WERE_SLOW_WARNING = 0.5 +#WERE_FAST_MAX = 2.3 +#WERE_FAST_WARNING = 1.2 #How long the speed change takes INTERVAL_CHANGE = 1.5 @@ -49,17 +50,31 @@ KILL_GAME_PAUSE = 4 -def track_move(move, game_mode, team, team_color_enum, dead_move, force_color, music_speed, werewolf_reveal, show_team_colors, red_on_kill, restart, menu): +def track_move(move, game_mode, team, team_color_enum, dead_move, force_color, \ + music_speed, werewolf_reveal, show_team_colors, red_on_kill, restart, menu, controller_sensitivity): + + SLOW_MAX = controller_sensitivity[0] + SLOW_WARNING = controller_sensitivity[1] + FAST_MAX = controller_sensitivity[2] + FAST_WARNING = controller_sensitivity[3] + + WERE_SLOW_MAX = controller_sensitivity[4] + WERE_SLOW_WARNING = controller_sensitivity[5] + WERE_FAST_MAX = controller_sensitivity[6] + WERE_FAST_WARNING = controller_sensitivity[7] + start = False - no_rumble = time.time() + 1 + no_rumble = time.time() + 2 move_last_value = None my_team_colors = team_color_enum werewolf = False vibrate = False - change_arr = [0,0,0] + change_arr = [0]*8 vibration_time = time.time() + 1 flash_lights = True flash_lights_timer = 0 + previous_average = 0 + change = 0 if team < 0: team = (team + 1) * -1 werewolf = True @@ -92,48 +107,27 @@ def track_move(move, game_mode, team, team_color_enum, dead_move, force_color, m if move.poll(): ax, ay, az = move.get_accelerometer_frame(psmove.Frame_SecondHalf) total = sqrt(sum([ax**2, ay**2, az**2])) - #total = sum([ax, ay, az]) - 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 - speed_percent = (music_speed.value - SLOW_MUSIC_SPEED)/(FAST_MUSIC_SPEED - SLOW_MUSIC_SPEED) - if werewolf: - warning = common.lerp(WERE_SLOW_WARNING, WERE_FAST_WARNING, speed_percent) - threshold = common.lerp(WERE_SLOW_MAX, WERE_FAST_MAX, speed_percent) - else: - warning = common.lerp(SLOW_WARNING, FAST_WARNING, speed_percent) - threshold = common.lerp(SLOW_MAX, FAST_MAX, speed_percent) + change = (change * 4 + total)/5 + speed_percent = (music_speed.value - SLOW_MUSIC_SPEED)/(FAST_MUSIC_SPEED - SLOW_MUSIC_SPEED) + if werewolf: + warning = common.lerp(WERE_SLOW_WARNING, WERE_FAST_WARNING, speed_percent) + threshold = common.lerp(WERE_SLOW_MAX, WERE_FAST_MAX, speed_percent) + else: + warning = common.lerp(SLOW_WARNING, FAST_WARNING, speed_percent) + threshold = common.lerp(SLOW_MAX, FAST_MAX, speed_percent) - if vibrate: - flash_lights_timer += 1 - if flash_lights_timer > 7: - flash_lights_timer = 0 - flash_lights = not flash_lights - if flash_lights: - if game_mode == common.Games.WereJoust.value: - move.set_leds(*colors.Colors.Black.value) - else: - move.set_leds(*colors.Colors.White40.value) - else: - if game_mode == common.Games.WereJoust.value: - if werewolf_reveal.value == 2 and werewolf: - move.set_leds(*colors.Colors.Blue40.value) - else: - move.set_leds(*colors.Colors.White40.value) - else: - move.set_leds(*my_team_colors) - if time.time() < vibration_time - 0.22: - move.set_rumble(110) + if vibrate: + flash_lights_timer += 1 + if flash_lights_timer > 7: + flash_lights_timer = 0 + flash_lights = not flash_lights + if flash_lights: + if game_mode == common.Games.WereJoust.value: + move.set_leds(*colors.Colors.Black.value) else: - move.set_rumble(0) - if time.time() > vibration_time: - vibrate = False - + move.set_leds(*colors.Colors.White40.value) else: if game_mode == common.Games.WereJoust.value: if werewolf_reveal.value == 2 and werewolf: @@ -142,25 +136,40 @@ def track_move(move, game_mode, team, team_color_enum, dead_move, force_color, m move.set_leds(*colors.Colors.White40.value) else: move.set_leds(*my_team_colors) - #move.set_rumble(0) + if time.time() < vibration_time-0.25: + move.set_rumble(90) + else: + move.set_rumble(0) + if time.time() > vibration_time: + vibrate = False + else: + if game_mode == common.Games.WereJoust.value: + if werewolf_reveal.value == 2 and werewolf: + move.set_leds(*colors.Colors.Blue40.value) + else: + move.set_leds(*colors.Colors.White40.value) + else: + move.set_leds(*my_team_colors) + #move.set_rumble(0) - if change > threshold: - if time.time() > no_rumble: - if red_on_kill: - move.set_leds(*colors.Colors.Red.value) - else: - move.set_leds(*colors.Colors.Black.value) - move.set_rumble(90) - dead_move.value = 0 - elif change > warning and not vibrate: - if time.time() > no_rumble: - vibrate = True - vibration_time = time.time() + 0.5 - #move.set_leds(20,50,100) + if change > threshold: + if time.time() > no_rumble: + if red_on_kill: + move.set_leds(*colors.Colors.Red.value) + else: + move.set_leds(*colors.Colors.Black.value) + move.set_rumble(90) + dead_move.value = 0 - move_last_value = total + elif change > warning and not vibrate: + if time.time() > no_rumble: + vibrate = True + vibration_time = time.time() + 0.5 + #move.set_leds(20,50,100) + + #move_last_value = total move.update_leds() elif dead_move.value < 1: @@ -222,25 +231,6 @@ def __init__(self, moves, command_queue, ns, music, teams, game_mode,controller_ self.alive_moves = [] #self.update_status('starting') - - print("speed is {}".format(self.sensitivity)) - global SLOW_MAX - global SLOW_WARNING - global FAST_MAX - global FAST_WARNING - - SLOW_MAX = common.SLOW_MAX[self.sensitivity] - SLOW_WARNING = common.SLOW_WARNING[self.sensitivity] - FAST_MAX = common.FAST_MAX[self.sensitivity] - FAST_WARNING = common.FAST_WARNING[self.sensitivity] - - print("SLOWMAX IS {}".format(SLOW_MAX)) - - #Sensitivity of the werewolf contollers - WERE_SLOW_MAX = common.WERE_SLOW_MAX[self.sensitivity] - WERE_SLOW_WARNING = common.WERE_SLOW_WARNING[self.sensitivity] - WERE_FAST_MAX = common.WERE_FAST_MAX[self.sensitivity] - WERE_FAST_WARNING = common.WERE_FAST_WARNING[self.sensitivity] self.werewolf_reveal = werewolf_reveal self.werewolf_reveal.value = 2 diff --git a/piparty.py b/piparty.py index ead1324d..9c77e732 100644 --- a/piparty.py +++ b/piparty.py @@ -15,7 +15,7 @@ #TEAM_COLORS = colors.generate_colors(TEAM_NUM) -SENSITIVITY_MODES = 3 +SENSITIVITY_MODES = 5 class Opts(Enum): alive = 0 @@ -38,15 +38,18 @@ class Selections(Enum): change_instructions = 5 show_battery = 6 update = 7 + admin = 8 class Holding(Enum): not_holding = 0 holding = 1 class Sensitivity(Enum): - slow = 0 - mid = 1 - fast = 2 + ultra_slow = 0 + slow = 1 + mid = 2 + fast = 3 + ultra_fast = 4 def track_move(serial, move_num, move, move_opts, force_color, battery, dead_count, restart, menu, kill_proc): move.set_leds(0,0,0) @@ -67,14 +70,10 @@ def track_move(serial, move_num, move, move_opts, force_color, battery, dead_cou dead_count.value = dead_count.value - 1 time.sleep(0.1) else: - #remove this function for now, doesn't work - #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 + if move_button == common.Button.SHAPES: + move_opts[Opts.selection.value] = Selections.admin.value + move_opts[Opts.holding.value] = Holding.holding.value + if move_button == common.Button.UPDATE: move_opts[Opts.selection.value] = Selections.update.value move_opts[Opts.holding.value] = Holding.holding.value @@ -296,6 +295,7 @@ def __init__(self): self.was_faked = {} self.rumble = {} self.kill_controller_proc = {} + self.controller_sensitivity = Array('d', [0] *10) self.i = 0 #load audio now so it converts before the game begins @@ -394,7 +394,7 @@ def pair_move(self, move, move_num): proc = Process(target= controller_process.main_track_move, args=(self.menu, self.restart, move_serial, move_num, opts, color, self.show_battery, \ - self.dead_count, self.controller_game_mode, team, team_color_enum, dead_move, \ + self.dead_count, self.controller_game_mode, team, team_color_enum, self.controller_sensitivity, dead_move, \ self.music_speed, self.werewolf_reveal, self.show_team_colors, self.red_on_kill,zombie_opt,\ self.commander_intro, commander_move_opt, self.commander_powers, self.commander_overdrive,\ five_controller_opt, self.swapper_team_colors, invincibility, fight_club_color, self.num_teams,\ @@ -480,11 +480,11 @@ def check_change_mode(self): if move_opt[Opts.selection.value] == Selections.change_mode.value: #remove previous admin, and set new one if self.ns.settings['move_can_be_admin']: - if self.admin_move: - self.force_color[self.admin_move][0] = 0 - self.force_color[self.admin_move][1] = 0 - self.force_color[self.admin_move][2] = 0 - self.admin_move = move + #if self.admin_move: + #self.force_color[self.admin_move][0] = 0 + #self.force_color[self.admin_move][1] = 0 + #self.force_color[self.admin_move][2] = 0 + #self.admin_move = move change_mode = True move_opt[Opts.selection.value] = Selections.nothing.value @@ -506,6 +506,20 @@ def check_change_mode(self): if self.ns.settings['play_audio']: self.game_mode_announcement() + def check_new_admin(self): + for move, move_opt in self.move_opts.items(): + if move_opt[Opts.selection.value] == Selections.admin.value: + #remove previous admin, and set new one + if self.ns.settings['move_can_be_admin']: + #set the old admin_move to have no colors + if self.admin_move: + self.force_color[self.admin_move][0] = 0 + self.force_color[self.admin_move][1] = 0 + self.force_color[self.admin_move][2] = 0 + self.admin_move = move + move_opt[Opts.selection.value] = Selections.nothing.value + + #all controllers need to opt-in again in order fo the game to start def reset_controller_game_state(self): for move_opt in self.move_opts.values(): @@ -560,6 +574,7 @@ def game_loop(self): self.check_for_new_moves() if len(self.tracked_moves) > 0: + self.check_new_admin() self.check_change_mode() self.check_admin_controls() self.check_start_game() @@ -604,12 +619,16 @@ def check_admin_controls(self): self.update_setting('sensitivity', (self.ns.settings['sensitivity'] + 1) % SENSITIVITY_MODES) if self.ns.settings['play_audio']: - if self.ns.settings['sensitivity'] == Sensitivity.slow.value: - Audio('audio/Menu/slow_sensitivity.wav').start_effect() + if self.ns.settings['sensitivity'] == Sensitivity.ultra_slow.value: + Audio('audio/Menu/ultra_high.wav').start_effect() + elif self.ns.settings['sensitivity'] == Sensitivity.slow.value: + Audio('audio/Menu/high.wav').start_effect() elif self.ns.settings['sensitivity'] == Sensitivity.mid.value: - Audio('audio/Menu/mid_sensitivity.wav').start_effect() + Audio('audio/Menu/medium.wav').start_effect() elif self.ns.settings['sensitivity'] == Sensitivity.fast.value: - Audio('audio/Menu/fast_sensitivity.wav').start_effect() + Audio('audio/Menu/low.wav').start_effect() + elif self.ns.settings['sensitivity'] == Sensitivity.ultra_fast.value: + Audio('audio/Menu/ultra_low.wav').start_effect() #no admin colors in con custom teams mode if self.game_mode == common.Games.JoustTeams or self.game_mode == common.Games.Random: @@ -818,6 +837,20 @@ def start_game(self, random_mode=False): self.menu.value = 0 self.restart.value =1 self.update_status('starting') + + self.sensitivity = self.ns.settings['sensitivity'] + self.controller_sensitivity[0] = common.SLOW_MAX[self.sensitivity] + self.controller_sensitivity[1] = common.SLOW_WARNING[self.sensitivity] + self.controller_sensitivity[2] = common.FAST_MAX[self.sensitivity] + self.controller_sensitivity[3] = common.FAST_WARNING[self.sensitivity] + + self.controller_sensitivity[4] = common.WERE_SLOW_MAX[self.sensitivity] + self.controller_sensitivity[5] = common.WERE_SLOW_WARNING[self.sensitivity] + self.controller_sensitivity[6] = common.WERE_FAST_MAX[self.sensitivity] + self.controller_sensitivity[7] = common.WERE_FAST_WARNING[self.sensitivity] + + self.controller_sensitivity[8] = common.ZOMBIE_MAX[self.sensitivity] + self.controller_sensitivity[9] = common.ZOMBIE_WARNING[self.sensitivity] if random_mode: good_random_modes = [game for game in common.Games if game.name in self.ns.settings['random_modes']]