From 46fdaffe5eda5443782931d6e52087193bda584e Mon Sep 17 00:00:00 2001 From: Robotopera Date: Thu, 2 Nov 2017 15:55:44 -0400 Subject: [PATCH 01/13] Rename commander.py to games/commander.py --- commander.py => games/commander.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename commander.py => games/commander.py (100%) diff --git a/commander.py b/games/commander.py similarity index 100% rename from commander.py rename to games/commander.py From 1651a5b09045c8719662ed58e8b0cb0a3a106e03 Mon Sep 17 00:00:00 2001 From: Robotopera Date: Thu, 2 Nov 2017 15:56:21 -0400 Subject: [PATCH 02/13] Rename speed_bomb.py to games/speed_bomb.py --- speed_bomb.py => games/speed_bomb.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename speed_bomb.py => games/speed_bomb.py (100%) diff --git a/speed_bomb.py b/games/speed_bomb.py similarity index 100% rename from speed_bomb.py rename to games/speed_bomb.py From f1235f7a1e40d23601bc7d7ccb0d1a8cb270f9e4 Mon Sep 17 00:00:00 2001 From: Robotopera Date: Thu, 2 Nov 2017 15:57:01 -0400 Subject: [PATCH 03/13] Rename zombie.py to games/zombie.py --- zombie.py => games/zombie.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename zombie.py => games/zombie.py (100%) diff --git a/zombie.py b/games/zombie.py similarity index 100% rename from zombie.py rename to games/zombie.py From 736e81b34dd2ec8725acbe6f3fca6361ce465d36 Mon Sep 17 00:00:00 2001 From: Robotopera Date: Thu, 2 Nov 2017 15:57:36 -0400 Subject: [PATCH 04/13] Rename tournament.py to games/tournament.py --- tournament.py => games/tournament.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tournament.py => games/tournament.py (100%) diff --git a/tournament.py b/games/tournament.py similarity index 100% rename from tournament.py rename to games/tournament.py From a89714fcf769220a0c1418b1a2ea4184bd44e7e5 Mon Sep 17 00:00:00 2001 From: Robotopera Date: Thu, 2 Nov 2017 15:58:22 -0400 Subject: [PATCH 05/13] Rename swapper.py to games/swapper.py --- swapper.py => games/swapper.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename swapper.py => games/swapper.py (100%) diff --git a/swapper.py b/games/swapper.py similarity index 100% rename from swapper.py rename to games/swapper.py From 213fa4f4728235d16c21151d1aff0a6479cbded8 Mon Sep 17 00:00:00 2001 From: Robotopera Date: Thu, 2 Nov 2017 15:58:57 -0400 Subject: [PATCH 06/13] Update piparty.py --- piparty.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/piparty.py b/piparty.py index 2ccb19c2..5b3aaf79 100644 --- a/piparty.py +++ b/piparty.py @@ -1,12 +1,11 @@ import psmove, pair import common, colors, joust, webui import yaml -import zombie, commander, swapper, tournament, speed_bomb import time, random, json, os, os.path, sys, glob from piaudio import Music, DummyMusic, Audio, InitAudio from enum import Enum from multiprocessing import Process, Value, Array, Queue, Manager -from games import ffa +from games import ffa, zombie, commander, swapper, tournament, speed_bomb import jm_dbus From 12c49747d83ed994ffc6f2b52a23f3971c0b58c6 Mon Sep 17 00:00:00 2001 From: Robby Date: Sat, 4 Nov 2017 19:56:57 -0400 Subject: [PATCH 07/13] Create fight_club --- games/fight_club | 1 + 1 file changed, 1 insertion(+) create mode 100644 games/fight_club diff --git a/games/fight_club b/games/fight_club new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/games/fight_club @@ -0,0 +1 @@ + From ff6d49bec4df8932c5875185027ce089c4e5742d Mon Sep 17 00:00:00 2001 From: Robby Date: Sat, 4 Nov 2017 19:57:43 -0400 Subject: [PATCH 08/13] Update fight_club --- games/fight_club | 513 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 513 insertions(+) diff --git a/games/fight_club b/games/fight_club index 8b137891..4b38b1ca 100644 --- a/games/fight_club +++ b/games/fight_club @@ -1 +1,514 @@ +import common, colors +import psmove +import time +import psutil, os +import random +import numpy +import math +import json +from piaudio import Audio +from enum import Enum +from multiprocessing import Process, Value, Array + +# How fast/slow the music can go +SLOW_MUSIC_SPEED = 0.5 +#this was 0.5 +FAST_MUSIC_SPEED = 2.0 + +# The min and max timeframe in seconds for +# the speed change to trigger, randomly selected +MIN_MUSIC_FAST_TIME = 4 +MAX_MUSIC_FAST_TIME = 8 +MIN_MUSIC_SLOW_TIME = 10 +MAX_MUSIC_SLOW_TIME = 23 + +END_MIN_MUSIC_FAST_TIME = 6 +END_MAX_MUSIC_FAST_TIME = 10 +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 + +#How long the winning moves shall sparkle +END_GAME_PAUSE = 6 +KILL_GAME_PAUSE = 4 + + +def track_move(move_serial, move_num, team, num_teams, dead_move, force_color, music_speed, show_team_colors, invincibility): + #proc = psutil.Process(os.getpid()) + #proc.nice(3) + #explosion = Audio('audio/Joust/sounds/Explosion34.wav') + #explosion.start_effect() + 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) + vibrate = False + vibration_time = time.time() + 1 + flash_lights = True + flash_lights_timer = 0 + start_inv = False + change_arr = [0,0,0] + + #keep on looping while move is not dead + while True: + if show_team_colors.value == 1: + if team.value != -1: + move.set_leds(*team_colors[team.value]) + else: + move.set_leds(100,100,100) + move.update_leds() + elif sum(force_color) != 0: + no_rumble_time = time.time() + 5 + time.sleep(0.01) + move.set_leds(*force_color) + if sum(force_color) == 30: + move.set_leds(0, 0, 0) + move.set_rumble(0) + move.update_leds() + no_rumble = time.time() + 0.5 + 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 + + + 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 + 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) + + + + move_last_value = total + move.update_leds() + else: + if dead_move.value < 1: + move.set_leds(0,0,0) + elif team.value == -1: + move.set_leds(100,100,100) + move.update_leds() + + time.sleep(0.5) + move.set_rumble(0) + + +class Tournament(): + def __init__(self, moves, command_queue, ns, music): + + self.command_queue = command_queue + self.ns = ns + + 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 = {} + self.dead_moves = {} + self.music_speed = Value('d', 1.5) + self.running = True + self.force_move_colors = {} + self.invince_moves = {} + + + self.start_timer = time.time() + self.audio_cue = 0 + self.num_dead = 0 + self.show_team_colors = Value('i', 0) + self.teams = {} + self.update_time = 0 + + #self.num_teams = math.ceil(len(moves)/2) + self.num_teams = len(moves) + + + self.generate_random_teams(self.num_teams) + + self.tourney_list = self.generate_tourney_list(len(moves)) + fast_resample = False + if self.play_audio: + print("tourney list is " + str(self.tourney_list)) + +## 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') + + end = False + self.audio = music + #self.change_time = self.get_change_time(speed_up = True) + + self.speed_up = True + self.currently_changing = False + self.game_end = False + self.winning_moves = [] + self.game_loop() + + def generate_tourney_list(self, player_num): + def divide(arr, depth, m): + if len(complements) <= depth: + complements.append(2 ** (depth + 2) + 1) + complement = complements[depth] + for i in range(2): + if complement - arr[i] <= m: + arr[i] = [arr[i], complement - arr[i]] + divide(arr[i], depth + 1, m) + + m = player_num + + arr = [1, 2] + complements = [] + + divide(arr, 0, m) + dup_serials = self.move_serials[:] + + def insert_move(arr): + for i in range(2): + if type(arr[i]) is list: + insert_move(arr[i]) + else: + arr[i] = random.choice(dup_serials) + dup_serials.remove(arr[i]) + insert_move(arr) + print(arr) + return arr + + + def generate_random_teams(self, num_teams): + team_pick = list(range(num_teams)) + for serial in self.move_serials: + random_choice = Value('i', random.choice(team_pick) ) + self.teams[serial] = random_choice + team_pick.remove(random_choice.value) + if not team_pick: + team_pick = list(range(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) + invincibility = Value('i', 0) + 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.show_team_colors, + invincibility)) + proc.start() + self.invince_moves[move_serial] = invincibility + 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(): + colors.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) + if self.play_audio: + self.start_beep.start_effect() + time.sleep(0.75) + self.change_all_move_colors(70, 100, 0) + if self.play_audio: + self.start_beep.start_effect() + time.sleep(0.75) + self.change_all_move_colors(0, 70, 0) + if self.play_audio: + self.start_beep.start_effect() + time.sleep(0.75) + self.change_all_move_colors(0, 0, 0) + if self.play_audio: + 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 + 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 + + + def check_matches(self): + #do this only when a controller dies, or at the beginning + def check_moves(arr): + if (type(arr[0]) is not list and type(arr[1]) is not list): + if self.teams[arr[1]].value != -1: + self.teams[arr[0]].value = self.teams[arr[1]].value + else: + self.teams[arr[1]].value = self.teams[arr[0]].value + elif(type(arr[0]) is not list and type(arr[1]) is list): + self.teams[arr[0]].value = -1 + check_moves(arr[1]) + elif(type(arr[1]) is not list and type(arr[0]) is list): + self.teams[arr[1]].value = -1 + check_moves(arr[0]) + elif(type(arr[0]) is list and type(arr[1]) is list): + check_moves(arr[0]) + check_moves(arr[1]) + check_moves(self.tourney_list) + + def remove_dead_player(self, dead_serial): + def remove_dead(arr): + if type(arr) is list and dead_serial in arr: + arr.remove(dead_serial) + else: + if type(arr[0]) is list: + remove_dead(arr[0]) + if type(arr[1]) is list: + remove_dead(arr[1]) + remove_dead(self.tourney_list) + + + def move_up(arr): + if type(arr) is list and len(arr) == 1: + return arr[0] + else: + if type(arr[0]) is list and move_up(arr[0]): + arr[0] = move_up(arr[0]) + if type(arr[1]) is not list: + self.teams[arr[1]].value = self.teams[arr[0]].value + self.invince_moves[arr[1]].value = 1 + self.invince_moves[arr[0]].value = 1 + else: + self.teams[arr[0]].value = -1 + elif type(arr[1]) is list and move_up(arr[1]): + arr[1] = move_up(arr[1]) + + if type(arr[0]) is not list: + self.teams[arr[0]].value = self.teams[arr[1]].value + self.invince_moves[arr[1]].value = 1 + self.invince_moves[arr[0]].value = 1 + else: + self.teams[arr[1]].value = -1 + move_up(self.tourney_list) + + + + def check_end_game(self): + self.winning_moves = [] + for move_serial, dead in self.dead_moves.items(): + #if we are alive + if dead.value == 1: + self.winning_moves.append(move_serial) + if dead.value == 0: + self.remove_dead_player(move_serial) + #This is to play the sound effect + self.num_dead += 1 + dead.value = -1 + if self.play_audio: + self.explosion.start_effect() + if len(self.winning_moves) <= 1: + 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() + self.update_status('ending') + end_time = time.time() + END_GAME_PAUSE + h_value = 0 + + while (time.time() < end_time): + time.sleep(0.01) + win_color = colors.hsv2rgb(h_value, 1, 1) + for win_move in self.winning_moves: + win_color_array = self.force_move_colors[win_move] + colors.change_color(win_color_array, *win_color) + h_value = (h_value + 0.01) + if h_value >= 1: + h_value = 0 + self.running = False + + + + def game_loop(self): + self.track_moves() + self.show_team_colors.value = 0 + self.count_down() + self.change_time = time.time() + 6 + time.sleep(0.02) + if self.play_audio: + self.audio.start_audio_loop() + else: + #when no audio is playing set the music speed to middle speed + self.music_speed.value = (FAST_MUSIC_SPEED + SLOW_MUSIC_SPEED) / 2 + time.sleep(0.8) + self.check_matches() + + while self.running: + #I think the loop is so fast that this causes + #a crash if done every loop + if time.time() - 0.1 > self.update_time: + self.update_time = time.time() + self.check_command_queue() + self.update_status('in_game') + if self.play_audio: + self.check_music_speed() + self.check_end_game() + if self.game_end: + self.end_game() + + self.stop_tracking_moves() + + def check_command_queue(self): + package = None + while not(self.command_queue.empty()): + package = self.command_queue.get() + command = package['command'] + if not(package == None): + if command == 'killgame': + self.kill_game() + + def kill_game(self): + if self.play_audio: + 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 + + bright = 255 + while (time.time() < end_time): + time.sleep(0.01) + color = (bright,0,0) + for move in all_moves: + color_array = self.force_move_colors[move] + colors.change_color(color_array, *color) + bright = bright - 1 + if bright < 10: + bright = 10 + self.running = False + + def update_status(self,game_status,winning_team=-1): + data ={'game_status' : game_status, + 'game_mode' : 'Tournament', + 'winning_team' : winning_team} + self.ns.status = data + + + + + + + + + + From 8248ed2f593c8031b2ce9a79f61eaa714979c4a1 Mon Sep 17 00:00:00 2001 From: Aaron Angert Date: Tue, 2 Jan 2018 05:46:25 +0000 Subject: [PATCH 09/13] added fightclub WIP --- audio/Joust/sounds/beep_loud.wav | Bin 0 -> 7706 bytes common.py | 7 +- games/{fight_club => fight_club.py} | 274 ++++++++++++++-------------- joust.py | 2 +- piparty.py | 12 +- 5 files changed, 154 insertions(+), 141 deletions(-) create mode 100644 audio/Joust/sounds/beep_loud.wav rename games/{fight_club => fight_club.py} (70%) diff --git a/audio/Joust/sounds/beep_loud.wav b/audio/Joust/sounds/beep_loud.wav new file mode 100644 index 0000000000000000000000000000000000000000..cae4ef8739f2c92f07d1b05cd1f98394cb48612e GIT binary patch literal 7706 zcmX|_1$R|vu!iGG+}+)eyIY_Hhae4*o7%yioR_BYMJ{u7r{2MH*m%|m$*T^mpn3G#a}IG z5^NXF2v3OY#5crll82H&=_6@~?3pY?{zx96xTo+`URPSG&Zve|yVdpTwHmz!uYIo# z)m_!i>UQXB^&gRM7(tASbPIYmt(p2GwSbaNk&y9ZHYt_#iI_xuPlzXcz^CHB;E*^z zmVs4cmSHN;o6tR|V<;Qc9b^RZ3xbTOfNzG+z%IceU>xWoXba>d#2fN4ZGKu-nEvb5 z+}Yfl>{O1BlgVx39^_f`Z}Fo9?*&+)TDVYDDasPJinmGzB)g=8(rnqFY`45e{+ps% zu~Av6%v7mW3^hlcqIs%u*Iv|)YPaahbyPh^A7Z#-m@w?@`kAF?VwrCkfs9M^8Co{2 zk-8fE1A`(XqsX}=2^o8r^LShQ z4V)Y9E;bPR0+Wd0qVZ@wYBj16xd&;Eyn%>7e1g;AWw0GEbJ#s-5>yLW2l-3&H#>zR z(ERf#r$%5RtSO0uP6(mk?a*?xJie6ONK@r$xnxk6Q_ zqO198h~^)SzxJGVPWy|lR>%Ba`5T52!!Jg?5o_9!-oT==c+6nt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$OM#aPYQ_}IMh_;Jd3=J=lRi{sD6+2f_-&EsYh9ur9u#ECT%zfPQ* zxI6K7LNZZ0(K0bR;XD~JiJY82nKk+AV(w}t1K&~6~QXj$~5CV88?ZaTt4~BI=y@P{PeZyC)1y%1=Ggq z%ITKrv1#)ex0%41xS0(WR#p?1O_uqVQp*pP_bsnj9<|(Vxz3VhiL{Kj46t;voVMt; z_-2uBA+umxJhQlOalzu4#ZHU$7OO0n7C4JUi!cix3tI~_i+=Mq^Gb7*xyGDl{=xjY z`2+JS<`>ONW}0S(XQpS|X8mU4XOXkC+2ylYv)g75&7PUPIs16_o(rFgnM2KC=9qJf=Q8Iu&TXIDKX+{I?A(>PoViDH|INLd vibration_time: + #print("vibrate to false") vibrate = False start_inv = False - invincibility.value = 0 + invincibility.value = False else: - if team.value != -1: - move.set_leds(*team_colors[team.value]) - else: - move.set_leds(100,100,100) + #if team.value != -1: + # move.set_leds(*team_colors[team.value]) + #else: + move.set_leds(100,200,100) - if invincibility.value == 0: + if not invincibility.value: if change > threshold: + #print("over threshold") if time.time() > no_rumble: + print("kill em") move.set_leds(0,0,0) move.set_rumble(90) - dead_move.value = 0 + dead_move.value = -1 elif change > warning and not vibrate: if time.time() > no_rumble: + print("setting vibrate to true") vibrate = True vibration_time = time.time() + 0.5 move.set_leds(20,50,100) @@ -144,15 +150,16 @@ def track_move(move_serial, move_num, team, num_teams, dead_move, force_color, m else: if dead_move.value < 1: move.set_leds(0,0,0) - elif team.value == -1: - move.set_leds(100,100,100) + #elif team.value == -1: + # move.set_leds(100,100,100) + invincibility.value = 1 move.update_leds() - + start_inv = False time.sleep(0.5) move.set_rumble(0) -class Tournament(): +class Fight_club(): def __init__(self, moves, command_queue, ns, music): self.command_queue = command_queue @@ -189,18 +196,26 @@ def __init__(self, moves, command_queue, ns, music): self.teams = {} self.update_time = 0 - #self.num_teams = math.ceil(len(moves)/2) - self.num_teams = len(moves) + self.fighter_list = [] + self.create_fighter_list() + self.chosen_defender = self.fighter_list.pop() + self.chosen_fighter = self.fighter_list.pop() + + self.round_num = len(self.move_serials)*3 + self.round_counter = 0 + + self.round_time = time.time() + self.round_limit = 16 + self.score = {} + self.timer_beep = 4 - self.generate_random_teams(self.num_teams) - self.tourney_list = self.generate_tourney_list(len(moves)) + fast_resample = False if self.play_audio: - print("tourney list is " + str(self.tourney_list)) - ## music = 'audio/Joust/music/' + random.choice(os.listdir('audio/Joust/music')) + self.loud_beep = Audio('audio/Joust/sounds/loud_beep.wav') 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') @@ -214,58 +229,23 @@ def __init__(self, moves, command_queue, ns, music): self.game_end = False self.winning_moves = [] self.game_loop() - - def generate_tourney_list(self, player_num): - def divide(arr, depth, m): - if len(complements) <= depth: - complements.append(2 ** (depth + 2) + 1) - complement = complements[depth] - for i in range(2): - if complement - arr[i] <= m: - arr[i] = [arr[i], complement - arr[i]] - divide(arr[i], depth + 1, m) - - m = player_num - - arr = [1, 2] - complements = [] - - divide(arr, 0, m) - dup_serials = self.move_serials[:] - def insert_move(arr): - for i in range(2): - if type(arr[i]) is list: - insert_move(arr[i]) - else: - arr[i] = random.choice(dup_serials) - dup_serials.remove(arr[i]) - insert_move(arr) - print(arr) - return arr - - - def generate_random_teams(self, num_teams): - team_pick = list(range(num_teams)) - for serial in self.move_serials: - random_choice = Value('i', random.choice(team_pick) ) - self.teams[serial] = random_choice - team_pick.remove(random_choice.value) - if not team_pick: - team_pick = list(range(num_teams)) + def create_fighter_list(self): + self.fighter_list = self.move_serials[:] + shuffle(self.fighter_list) + + def track_moves(self): for move_num, move_serial in enumerate(self.move_serials): - time.sleep(0.02) - dead_move = Value('i', 1) + time.sleep(0.1) + dead_move = Value('i', 0) force_color = Array('i', [1] * 3) - invincibility = Value('i', 0) + invincibility = Value('b', True) proc = Process(target=track_move, args=(move_serial, move_num, - self.teams[move_serial], - self.num_teams, dead_move, force_color, self.music_speed, @@ -338,77 +318,48 @@ def check_music_speed(self): self.currently_changing = False - def check_matches(self): - #do this only when a controller dies, or at the beginning - def check_moves(arr): - if (type(arr[0]) is not list and type(arr[1]) is not list): - if self.teams[arr[1]].value != -1: - self.teams[arr[0]].value = self.teams[arr[1]].value - else: - self.teams[arr[1]].value = self.teams[arr[0]].value - elif(type(arr[0]) is not list and type(arr[1]) is list): - self.teams[arr[0]].value = -1 - check_moves(arr[1]) - elif(type(arr[1]) is not list and type(arr[0]) is list): - self.teams[arr[1]].value = -1 - check_moves(arr[0]) - elif(type(arr[0]) is list and type(arr[1]) is list): - check_moves(arr[0]) - check_moves(arr[1]) - check_moves(self.tourney_list) - - def remove_dead_player(self, dead_serial): - def remove_dead(arr): - if type(arr) is list and dead_serial in arr: - arr.remove(dead_serial) - else: - if type(arr[0]) is list: - remove_dead(arr[0]) - if type(arr[1]) is list: - remove_dead(arr[1]) - remove_dead(self.tourney_list) - - - def move_up(arr): - if type(arr) is list and len(arr) == 1: - return arr[0] - else: - if type(arr[0]) is list and move_up(arr[0]): - arr[0] = move_up(arr[0]) - if type(arr[1]) is not list: - self.teams[arr[1]].value = self.teams[arr[0]].value - self.invince_moves[arr[1]].value = 1 - self.invince_moves[arr[0]].value = 1 - else: - self.teams[arr[0]].value = -1 - elif type(arr[1]) is list and move_up(arr[1]): - arr[1] = move_up(arr[1]) - - if type(arr[0]) is not list: - self.teams[arr[0]].value = self.teams[arr[1]].value - self.invince_moves[arr[1]].value = 1 - self.invince_moves[arr[0]].value = 1 - else: - self.teams[arr[1]].value = -1 - move_up(self.tourney_list) - - - + def check_end_round(self): + if self.play_audio: + if time.time() > self.round_time - (2.5 * (self.timer_beep/4)): + self.loud_beep.start_effect() + self.timer_beep -= 1 + + + if time.time() > self.round_time: + self.dead_moves[self.chosen_fighter].value = 0 + self.dead_moves[self.chosen_defender].value = 0 + self.fighter_list.insert(0,self.chosen_defender) + self.fighter_list.insert(0,self.chosen_fighter) + if self.play_audio: + self.explosion.start_effect() + self.chosen_defender = self.fighter_list.pop() + self.chosen_fighter = self.fighter_list.pop() + self.invince_moves[self.chosen_fighter].value = True + self.invince_moves[self.chosen_defender].value = True + self.revive_fighters() + self.reset_round_timer() + self.timer_beep = 4 + def check_end_game(self): + + + self.winning_moves = [] for move_serial, dead in self.dead_moves.items(): #if we are alive if dead.value == 1: - self.winning_moves.append(move_serial) + #self.winning_moves.append(move_serial) + pass if dead.value == 0: - self.remove_dead_player(move_serial) + pass #This is to play the sound effect - self.num_dead += 1 - dead.value = -1 - if self.play_audio: - self.explosion.start_effect() + #self.num_dead += 1 + #dead.value = -1 + #if self.play_audio: + # self.explosion.start_effect() if len(self.winning_moves) <= 1: - self.game_end = True + #self.game_end = True + pass @@ -435,6 +386,53 @@ def end_game(self): h_value = 0 self.running = False + def check_next_fighter(self): + #dead_moves: 0 dead waiting to be a fighter + #dead_moves: 1 alive fighting + #dead_moves: -1 just died as a fighter, go to the back of the line + + + if self.dead_moves[self.chosen_defender].value == -1: + self.invince_moves[self.chosen_fighter].value = True + if self.play_audio: + self.explosion.start_effect() + self.add_score(self.chosen_fighter) + self.fighter_list.insert(0,self.chosen_defender) + self.dead_moves[self.chosen_defender].value = 0 + self.chosen_defender = self.chosen_fighter + self.chosen_fighter = self.fighter_list.pop() + self.revive_fighters() + self.reset_round_timer() + + #move to the back of the line + elif self.dead_moves[self.chosen_fighter].value == -1: + self.invince_moves[self.chosen_defender].value = True + if self.play_audio: + self.explosion.start_effect() + self.add_score(self.chosen_defender) + self.fighter_list.insert(0,self.chosen_fighter) + self.dead_moves[self.chosen_fighter].value = 0 + self.chosen_fighter = self.fighter_list.pop() + self.revive_fighters() + self.reset_round_timer() + + #move to the back of the line + + def revive_fighters(self): + if self.dead_moves[self.chosen_defender].value == 0: + self.dead_moves[self.chosen_defender].value = 1 + if self.dead_moves[self.chosen_fighter].value == 0: + self.dead_moves[self.chosen_fighter].value = 1 + + + def add_score(self, serial): + if serial not in self.score: + self.score[serial] = 1 + else: + self.score[serial] += 1 + + def reset_round_timer(self): + self.round_time = time.time() + self.round_limit def game_loop(self): @@ -449,8 +447,9 @@ def game_loop(self): #when no audio is playing set the music speed to middle speed self.music_speed.value = (FAST_MUSIC_SPEED + SLOW_MUSIC_SPEED) / 2 time.sleep(0.8) - self.check_matches() + self.reset_round_timer() + self.revive_fighters() while self.running: #I think the loop is so fast that this causes #a crash if done every loop @@ -458,10 +457,13 @@ def game_loop(self): self.update_time = time.time() self.check_command_queue() self.update_status('in_game') - if self.play_audio: - self.check_music_speed() + #if self.play_audio: + #self.check_music_speed() + self.check_next_fighter() + self.check_end_round() self.check_end_game() if self.game_end: + print("end game") self.end_game() self.stop_tracking_moves() @@ -499,7 +501,7 @@ def kill_game(self): def update_status(self,game_status,winning_team=-1): data ={'game_status' : game_status, - 'game_mode' : 'Tournament', + 'game_mode' : 'Fight Club', 'winning_team' : winning_team} self.ns.status = data diff --git a/joust.py b/joust.py index 5171172b..d731db16 100644 --- a/joust.py +++ b/joust.py @@ -322,7 +322,7 @@ def generate_random_teams(self, num_teams): def track_moves(self): for move_num, move_serial in enumerate(self.move_serials): self.alive_moves.append(move_serial) - time.sleep(0.02) + time.sleep(0.1) dead_move = Value('i', 1) force_color = Array('i', [1] * 3) proc = Process(target=track_move, args=(move_serial, diff --git a/piparty.py b/piparty.py index 3fce1eaf..4922be7c 100644 --- a/piparty.py +++ b/piparty.py @@ -5,7 +5,7 @@ from piaudio import Music, DummyMusic, Audio, InitAudio from enum import Enum from multiprocessing import Process, Value, Array, Queue, Manager -from games import ffa, zombie, commander, swapper, tournament, speed_bomb +from games import ffa, zombie, commander, swapper, tournament, speed_bomb, fight_club import jm_dbus @@ -150,6 +150,9 @@ def track_move(serial, move_num, move_opts, force_color, battery, dead_count): else: move.set_leds(*colors.Colors.Green.value) + + elif game_mode == common.Games.FightClub: + move.set_leds(*colors.Colors.Magenta.value) elif game_mode == common.Games.Tournament: if move_num <= 0: @@ -704,6 +707,13 @@ def start_game(self, random_mode=False): elif self.game_mode == common.Games.Swapper: swapper.Swapper(game_moves, self.command_queue, self.ns, self.joust_music) self.tracked_moves = {} + elif self.game_mode == common.Games.FightClub: + if random.randint(0,1)==1: + fight_music = self.commander_music + else: + fight_music = self.joust_music + fight_club.Fight_club(game_moves, self.command_queue, self.ns, fight_music) + self.tracked_moves = {} elif self.game_mode == common.Games.Tournament: tournament.Tournament(game_moves, self.command_queue, self.ns, self.joust_music) self.tracked_moves = {} From e125f455b8b8cec3de948a0d6b2c582c6c2460dc Mon Sep 17 00:00:00 2001 From: Aaron Angert Date: Tue, 2 Jan 2018 06:02:22 +0000 Subject: [PATCH 10/13] fixed timer/sound bug --- games/fight_club.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/games/fight_club.py b/games/fight_club.py index 812b5bca..0a2d57b9 100644 --- a/games/fight_club.py +++ b/games/fight_club.py @@ -215,7 +215,7 @@ def __init__(self, moves, command_queue, ns, music): fast_resample = False if self.play_audio: ## music = 'audio/Joust/music/' + random.choice(os.listdir('audio/Joust/music')) - self.loud_beep = Audio('audio/Joust/sounds/loud_beep.wav') + self.loud_beep = Audio('audio/Joust/sounds/beep_loud.wav') 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') @@ -320,7 +320,8 @@ def check_music_speed(self): def check_end_round(self): if self.play_audio: - if time.time() > self.round_time - (2.5 * (self.timer_beep/4)): + if time.time() > self.round_time - (2.3 * (self.timer_beep/4)): + print("wowow") self.loud_beep.start_effect() self.timer_beep -= 1 @@ -338,7 +339,7 @@ def check_end_round(self): self.invince_moves[self.chosen_defender].value = True self.revive_fighters() self.reset_round_timer() - self.timer_beep = 4 + def check_end_game(self): @@ -433,6 +434,7 @@ def add_score(self, serial): def reset_round_timer(self): self.round_time = time.time() + self.round_limit + self.timer_beep = 4 def game_loop(self): From 400720b3450b2d6fd0c127cd9f7f4e29e2ddee01 Mon Sep 17 00:00:00 2001 From: Aaron Angert Date: Tue, 2 Jan 2018 06:11:19 +0000 Subject: [PATCH 11/13] added wip changes --- games/fight_club.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/games/fight_club.py b/games/fight_club.py index 0a2d57b9..73f4cbb7 100644 --- a/games/fight_club.py +++ b/games/fight_club.py @@ -340,9 +340,17 @@ def check_end_round(self): self.revive_fighters() self.reset_round_timer() - + + #check to see if there is a winner, + #if there is a tie, have them face off, no time limit + #set winning moves + def check_winner(self): + pass + def check_end_game(self): - + if self.round_counter >= self.round_num: + self.check_winner() + self.winning_moves = [] @@ -433,8 +441,10 @@ def add_score(self, serial): self.score[serial] += 1 def reset_round_timer(self): + self.round_counter += 1 self.round_time = time.time() + self.round_limit self.timer_beep = 4 + self.check_end_game() def game_loop(self): @@ -463,7 +473,6 @@ def game_loop(self): #self.check_music_speed() self.check_next_fighter() self.check_end_round() - self.check_end_game() if self.game_end: print("end game") self.end_game() From 9399ca87b3e67ef00b86059d3c83ba11a8810a46 Mon Sep 17 00:00:00 2001 From: Aaron Angert Date: Tue, 2 Jan 2018 23:03:33 +0000 Subject: [PATCH 12/13] added faceoff for fight_club --- games/fight_club.py | 69 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 56 insertions(+), 13 deletions(-) diff --git a/games/fight_club.py b/games/fight_club.py index 73f4cbb7..2cf460a7 100644 --- a/games/fight_club.py +++ b/games/fight_club.py @@ -131,14 +131,12 @@ def track_move(move_serial, move_num, dead_move, force_color, music_speed, show_ if change > threshold: #print("over threshold") if time.time() > no_rumble: - print("kill em") move.set_leds(0,0,0) move.set_rumble(90) dead_move.value = -1 elif change > warning and not vibrate: if time.time() > no_rumble: - print("setting vibrate to true") vibrate = True vibration_time = time.time() + 0.5 move.set_leds(20,50,100) @@ -202,12 +200,13 @@ def __init__(self, moves, command_queue, ns, music): self.chosen_defender = self.fighter_list.pop() self.chosen_fighter = self.fighter_list.pop() - self.round_num = len(self.move_serials)*3 + self.round_num = len(self.move_serials)*1 self.round_counter = 0 self.round_time = time.time() self.round_limit = 16 self.score = {} + self.add_initial_score() self.timer_beep = 4 @@ -233,6 +232,10 @@ def __init__(self, moves, command_queue, ns, music): def create_fighter_list(self): self.fighter_list = self.move_serials[:] shuffle(self.fighter_list) + + def add_initial_score(self): + for move in self.move_serials: + self.score[move] = 0 @@ -321,7 +324,6 @@ def check_music_speed(self): def check_end_round(self): if self.play_audio: if time.time() > self.round_time - (2.3 * (self.timer_beep/4)): - print("wowow") self.loud_beep.start_effect() self.timer_beep -= 1 @@ -340,12 +342,53 @@ def check_end_round(self): self.revive_fighters() self.reset_round_timer() + + def alive_move_count(self): + count =0 + for move, lives in self.dead_moves.items(): + if lives.value == 1: + count += 1 + return count + + #more than one tied winner, have them face off + def face_off(self): + for move in self.winning_moves: + self.dead_moves[move].value = 1 + count_explode = self.alive_move_count() + while count_explode > 1: + if count_explode > self.alive_move_count(): + count_explode = self.alive_move_count() + if self.play_audio: + self.explosion.start_effect() + self.winning_moves = [] + for move, lives in self.dead_moves.items(): + if lives.value == 1: + self.winning_moves.append(move) + self.game_end = True + + #check to see if there is a winner, #if there is a tie, have them face off, no time limit #set winning moves def check_winner(self): - pass + self.winning_moves = [] + self.winning_score = 0 + print(self.score.items()) + for move, score in self.score.items(): + if score == self.winning_score: + self.winning_moves.append(move) + if score > self.winning_score: + self.winning_moves = [] + self.winning_moves.append(move) + self.winning_score = score + if len(self.winning_moves) > 1: + self.face_off() + else: + self.game_end = True + + + def check_end_game(self): if self.round_counter >= self.round_num: @@ -353,22 +396,22 @@ def check_end_game(self): - self.winning_moves = [] - for move_serial, dead in self.dead_moves.items(): + #self.winning_moves = [] + #for move_serial, dead in self.dead_moves.items(): #if we are alive - if dead.value == 1: + # if dead.value == 1: #self.winning_moves.append(move_serial) - pass - if dead.value == 0: - pass + # pass + # if dead.value == 0: + # pass #This is to play the sound effect #self.num_dead += 1 #dead.value = -1 #if self.play_audio: # self.explosion.start_effect() - if len(self.winning_moves) <= 1: + # if len(self.winning_moves) <= 1: #self.game_end = True - pass + # pass From 8e042d4779cb57e8b05be0a7192886c5c0189a56 Mon Sep 17 00:00:00 2001 From: Aaron Angert Date: Thu, 4 Jan 2018 02:04:45 +0000 Subject: [PATCH 13/13] added more bug fixes for fight club --- games/fight_club.py | 136 +++++++++++++++++++++++++++++++------------- piparty.py | 6 +- setup.sh | 2 +- 3 files changed, 102 insertions(+), 42 deletions(-) diff --git a/games/fight_club.py b/games/fight_club.py index 2cf460a7..ffc0beaf 100644 --- a/games/fight_club.py +++ b/games/fight_club.py @@ -42,11 +42,11 @@ INTERVAL_CHANGE = 1.5 #How long the winning moves shall sparkle -END_GAME_PAUSE = 6 +END_GAME_PAUSE = 12 KILL_GAME_PAUSE = 4 -def track_move(move_serial, move_num, dead_move, force_color, music_speed, show_team_colors, invincibility): +def track_move(move_serial, move_num, dead_move, force_color, music_speed, color, invincibility): #proc = psutil.Process(os.getpid()) #proc.nice(3) #explosion = Audio('audio/Joust/sounds/Explosion34.wav') @@ -65,13 +65,13 @@ def track_move(move_serial, move_num, dead_move, force_color, music_speed, show_ #keep on looping while move is not dead while True: - if show_team_colors.value == 1: - if team.value != -1: - move.set_leds(*team_colors[team.value]) - else: - move.set_leds(100,100,100) - move.update_leds() - elif sum(force_color) != 0: + #if show_team_colors.value == 1: + # if team.value != -1: + # move.set_leds(*team_colors[team.value]) + # else: + # move.set_leds(100,100,100) + # move.update_leds() + if sum(force_color) != 0: no_rumble_time = time.time() + 5 time.sleep(0.01) move.set_leds(*force_color) @@ -106,7 +106,13 @@ def track_move(move_serial, move_num, dead_move, force_color, music_speed, show_ flash_lights_timer = 0 flash_lights = not flash_lights if flash_lights: - move.set_leds(100,100,100) + #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]) @@ -122,16 +128,19 @@ def track_move(move_serial, move_num, dead_move, force_color, music_speed, show_ start_inv = False invincibility.value = False else: - #if team.value != -1: - # move.set_leds(*team_colors[team.value]) - #else: - move.set_leds(100,200,100) + #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) if not invincibility.value: if change > threshold: #print("over threshold") if time.time() > no_rumble: - move.set_leds(0,0,0) + move.set_leds(*colors.Colors.Red.value) move.set_rumble(90) dead_move.value = -1 @@ -147,7 +156,10 @@ def track_move(move_serial, move_num, dead_move, force_color, music_speed, show_ move.update_leds() else: if dead_move.value < 1: - move.set_leds(0,0,0) + if color.value == 3: + move.set_leds(*colors.Colors.Green80.value) + else: + move.set_leds(20,20,20) #elif team.value == -1: # move.set_leds(100,100,100) invincibility.value = 1 @@ -200,7 +212,7 @@ def __init__(self, moves, command_queue, ns, music): self.chosen_defender = self.fighter_list.pop() self.chosen_fighter = self.fighter_list.pop() - self.round_num = len(self.move_serials)*1 + self.round_num = len(self.move_serials)*3 self.round_counter = 0 self.round_time = time.time() @@ -208,6 +220,10 @@ def __init__(self, moves, command_queue, ns, music): self.score = {} self.add_initial_score() self.timer_beep = 4 + self.high_score = 1 + self.current_winner = "" + + self.colors = {} @@ -247,14 +263,16 @@ def track_moves(self): force_color = Array('i', [1] * 3) invincibility = Value('b', True) + color = Value('i', 0) proc = Process(target=track_move, args=(move_serial, move_num, dead_move, force_color, self.music_speed, - self.show_team_colors, + color, invincibility)) proc.start() + self.colors[move_serial] = color self.invince_moves[move_serial] = invincibility self.tracked_moves[move_serial] = proc self.dead_moves[move_serial] = dead_move @@ -331,12 +349,15 @@ def check_end_round(self): if time.time() > self.round_time: self.dead_moves[self.chosen_fighter].value = 0 self.dead_moves[self.chosen_defender].value = 0 + self.colors[self.chosen_defender].value = 0 + self.colors[self.chosen_fighter].value = 0 self.fighter_list.insert(0,self.chosen_defender) self.fighter_list.insert(0,self.chosen_fighter) if self.play_audio: self.explosion.start_effect() self.chosen_defender = self.fighter_list.pop() self.chosen_fighter = self.fighter_list.pop() + self.invince_moves[self.chosen_fighter].value = True self.invince_moves[self.chosen_defender].value = True self.revive_fighters() @@ -350,10 +371,17 @@ def alive_move_count(self): count += 1 return count + + #more than one tied winner, have them face off def face_off(self): + #print(self.winning_moves) + os.popen('espeak -ven -p 70 -a 200 "Tie game..... Face off"') + for move in self.move_serials: + self.dead_moves[move].value = 0 for move in self.winning_moves: self.dead_moves[move].value = 1 + self.colors[move].value = 4 count_explode = self.alive_move_count() while count_explode > 1: if count_explode > self.alive_move_count(): @@ -393,28 +421,12 @@ def check_winner(self): def check_end_game(self): if self.round_counter >= self.round_num: self.check_winner() + if self.round_counter == self.round_num - 5: + os.popen('espeak -ven -p 70 -a 200 "5 rounds remain"') + if self.round_counter == self.round_num - 1: + os.popen('espeak -ven -p 70 -a 200 "last round"') - - - #self.winning_moves = [] - #for move_serial, dead in self.dead_moves.items(): - #if we are alive - # if dead.value == 1: - #self.winning_moves.append(move_serial) - # pass - # if dead.value == 0: - # pass - #This is to play the sound effect - #self.num_dead += 1 - #dead.value = -1 - #if self.play_audio: - # self.explosion.start_effect() - # if len(self.winning_moves) <= 1: - #self.game_end = True - # pass - - - + def stop_tracking_moves(self): for proc in self.tracked_moves.values(): proc.terminate() @@ -426,6 +438,9 @@ def end_game(self): self.update_status('ending') end_time = time.time() + END_GAME_PAUSE h_value = 0 + for move in self.move_serials: + self.dead_moves[move].value = 0 + os.popen('espeak -ven -p 70 -a 200 "winner"') while (time.time() < end_time): time.sleep(0.01) @@ -451,8 +466,11 @@ def check_next_fighter(self): self.add_score(self.chosen_fighter) self.fighter_list.insert(0,self.chosen_defender) self.dead_moves[self.chosen_defender].value = 0 + self.colors[self.chosen_defender].value = 0 self.chosen_defender = self.chosen_fighter + #self.colors[self.chosen_defender].value = 1 self.chosen_fighter = self.fighter_list.pop() + #self.colors[self.chosen_fighter].value = 2 self.revive_fighters() self.reset_round_timer() @@ -463,8 +481,10 @@ def check_next_fighter(self): self.explosion.start_effect() self.add_score(self.chosen_defender) self.fighter_list.insert(0,self.chosen_fighter) + self.colors[self.chosen_fighter].value = 0 self.dead_moves[self.chosen_fighter].value = 0 self.chosen_fighter = self.fighter_list.pop() + #self.colors[self.chosen_fighter].value = 2 self.revive_fighters() self.reset_round_timer() @@ -483,10 +503,45 @@ def add_score(self, serial): else: self.score[serial] += 1 + def get_highest_score(self): + max_score = 1 + for move, score in self.score.items(): + if score > max_score: + max_score = score + return max_score + + + def set_highest_score_color(self): + max_score = self.get_highest_score() + for move,score in self.score.items(): + if score == max_score: + if self.colors[move].value == 0: + self.colors[move].value = 3 + elif self.colors[move].value == 3: + self.colors[move].value = 0 + + def reset_round_timer(self): self.round_counter += 1 self.round_time = time.time() + self.round_limit self.timer_beep = 4 + self.colors[self.chosen_defender].value = 1 + self.colors[self.chosen_fighter].value = 2 + print(self.score.items()) + self.set_highest_score_color() + print(self.get_highest_score()) + print(self.high_score) + if self.get_highest_score() > self.high_score : + self.high_score = self.get_highest_score() + if self.current_winner != self.chosen_defender: + self.current_winner = self.chosen_defender + saying = random.randint(0,2) + if saying == 0: + os.popen('espeak -ven -p 70 -a 200 "Defender has taken the lead"') + elif saying == 1: + os.popen('espeak -ven -p 70 -a 200 "Defender is now winning"') + elif saying == 2: + os.popen('espeak -ven -p 70 -a 200 "Defender has the high score"') self.check_end_game() @@ -503,8 +558,9 @@ def game_loop(self): self.music_speed.value = (FAST_MUSIC_SPEED + SLOW_MUSIC_SPEED) / 2 time.sleep(0.8) - self.reset_round_timer() + self.revive_fighters() + self.reset_round_timer() while self.running: #I think the loop is so fast that this causes #a crash if done every loop diff --git a/piparty.py b/piparty.py index 4922be7c..f1e34510 100644 --- a/piparty.py +++ b/piparty.py @@ -361,6 +361,8 @@ def game_mode_announcement(self): Audio('audio/Menu/menu ninjabomb.wav').start_effect() if self.game_mode == common.Games.Random: Audio('audio/Menu/menu Random.wav').start_effect() + if self.game_mode == common.Games.FightClub: + os.popen('espeak -ven -p 70 -a 200 "Fight Club"') def check_change_mode(self): change_mode = False @@ -652,7 +654,9 @@ def play_random_instructions(self): Audio('audio/Menu/Swapper-instructions.wav').start_effect_and_wait() if self.game_mode == common.Games.Tournament: Audio('audio/Menu/Tournament-instructions.wav').start_effect_and_wait() - + if self.game_mode == common.Games.FightClub: + os.popen('espeak -ven -p 70 -a 200 "Two players fight, the winner must defend thier title, the player with the highest score wins') + time.sleep(5) def start_game(self, random_mode=False): self.enable_bt_scanning(False) diff --git a/setup.sh b/setup.sh index 5be8f606..81776982 100755 --- a/setup.sh +++ b/setup.sh @@ -24,7 +24,7 @@ setup() { bluez bluez-tools rfkill supervisor cmake ffmpeg \ libudev-dev swig libbluetooth-dev \ alsa-utils alsa-tools libasound2-dev \ - python-dbus-dev libdbus-glib-1-dev || exit -1 + python-dbus-dev libdbus-glib-1-dev espeak || exit -1 #install components for psmoveapi sudo apt-get install -y \