Permalink
Browse files

major stability update

  • Loading branch information...
adangert committed Jan 14, 2019
1 parent 42634ce commit b4ebc6fb2a3f8ea2fcf3da944aa7e82c3922df45
Showing with 437 additions and 488 deletions.
  1. +1 −0 common.py
  2. +34 −0 controller_process.py
  3. +39 −51 games/commander.py
  4. +21 −56 games/fight_club.py
  5. +31 −104 games/speed_bomb.py
  6. +39 −42 games/swapper.py
  7. +22 −41 games/tournament.py
  8. +18 −22 games/zombie.py
  9. +34 −47 joust.py
  10. +92 −84 piaudio.py
  11. +106 −41 piparty.py
@@ -37,6 +37,7 @@ def get_move(serial, move_num):
for move_num in range(psmove.count_connected()):
move = psmove.PSMove(move_num)
if move.get_serial() == serial:
print("returning " +str(move.get_serial()))
return move
return None
else:
@@ -0,0 +1,34 @@
from games import ffa, zombie, commander, swapper, tournament, speed_bomb, fight_club
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,\
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):
print("starting Controller Process")

move = common.get_move(move_serial, move_num)
while(True):
move.set_rumble(0)
if(restart.value == 1):
pass
elif (menu.value == 1):
piparty.track_move(move_serial, move_num, move, move_opts, force_color, battery, dead_count, restart, menu)
elif(game_mode.value == common.Games.Zombies.value):
zombie.track_controller(move, zombie_opt, restart, menu)
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)
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)
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)
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)
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)

@@ -81,16 +81,18 @@ 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_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)


def track_move(move, team, dead_move, force_color, music_speed, commander_intro, move_opts, commander_powers, commander_overdrive, restart, menu):
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
move = common.get_move(move_serial, move_num)
team_colors = colors.generate_colors(num_teams)
team_colors = colors.generate_colors(2)
#keep on looping while move is not dead
ready = False
move.set_leds(0,0,0)
@@ -130,6 +132,8 @@ def track_move(move_serial, move_num, team, num_teams, dead_move, force_color, m
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)
@@ -228,7 +232,8 @@ def track_move(move_serial, move_num, team, num_teams, dead_move, force_color, m


class Commander():
def __init__(self, moves, command_queue, ns, music):
def __init__(self, moves, command_queue, ns, music, dead_moves, commander_intro, commander_move_opt,\
commander_powers, commander_overdrive, music_speed,force_color, restart, controller_teams):

self.command_queue = command_queue
self.ns = ns
@@ -250,42 +255,45 @@ def __init__(self, moves, command_queue, ns, music):

self.move_serials = moves
self.tracked_moves = {}
self.dead_moves = {}
self.dead_moves = dead_moves
self.teams = {}
self.music_speed = Value('d', 1)
self.music_speed = music_speed
self.music_speed.value = 1
self.running = True
self.force_move_colors = {}
self.force_move_colors = force_color
self.num_teams = 2
self.werewolf_timer = 35
self.start_timer = time.time()
self.audio_cue = 0

self.move_opts = {}
self.move_opts = commander_move_opt
self.current_commander = ["",""]

self.time_to_power = [20,20]
self.activated_time = [time.time(), time.time()]

self.activated_overdrive = [time.time(), time.time()]
self.controller_teams = controller_teams


self.powers = [Value('d', 0.0), Value('d', 0.0)]
self.powers = commander_powers
self.powers[0].value = 0.0
self.powers[1].value = 0.0
self.restart = restart

self.alpha_overdrive = Value('i', 0)
self.bravo_overdrive = Value('i', 0)
self.alpha_overdrive = commander_overdrive[0]
self.alpha_overdrive.value = 0
self.bravo_overdrive = commander_overdrive[1]
self.alpha_overdrive.value = 1


self.generate_random_teams(self.num_teams)
self.commander_intro = Value('i', 1)
self.commander_intro = commander_intro
self.commander_intro.value = 1

self.powers_active = [False, False]



## try:
## music = 'audio/Commander/music/' + random.choice(os.listdir('audio/Commander/music'))
## except:
## print('no music in audio/Commander/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')
@@ -322,32 +330,14 @@ def generate_random_teams(self, num_teams):

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)
opts = Array('i', [0] * 5)
power = self.powers[self.teams[move_serial]]

if self.teams[move_serial] == Team.alpha.value:
overdrive = self.alpha_overdrive
else:
overdrive = self.bravo_overdrive
proc = Process(target=track_move, args=(move_serial,
move_num,
self.teams[move_serial],
self.num_teams,
dead_move,
force_color,
self.music_speed,
self.commander_intro,
opts,
power,
overdrive))
proc.start()
self.tracked_moves[move_serial] = proc
self.dead_moves[move_serial] = dead_move
self.force_move_colors[move_serial] = force_color
self.move_opts[move_serial] = opts
self.controller_teams[move_serial].value = self.teams[move_serial]
self.dead_moves[move_serial].value = 1
self.force_move_colors[move_serial][0] = 1
self.force_move_colors[move_serial][1] = 1
self.force_move_colors[move_serial][2] = 1
for i in range(5):
self.move_opts[move_serial][i] = 0


def change_all_move_colors(self, r, g, b):
for color in self.force_move_colors.values():
@@ -408,10 +398,7 @@ def check_end_game(self):


def stop_tracking_moves(self):
for proc in self.tracked_moves.values():
proc.terminate()
proc.join()
time.sleep(0.02)
self.restart.value = 1

def end_game(self):
try:
@@ -563,6 +550,7 @@ def commander_intro_audio(self):

def game_loop(self):
self.track_moves()
self.restart.value = 0
self.commander_intro_audio()

self.count_down()
Oops, something went wrong.

0 comments on commit b4ebc6f

Please sign in to comment.