Exemple #1
0
 def end_game(self):
     if self.play_audio:
         try:
             self.audio.stop_audio()
         except:
             print('no audio loaded to stop')
     end_time = time.time() + END_GAME_PAUSE
     h_value = 0
     self.update_status('ending',self.winning_team)
     if self.play_audio:
         self.end_game_sound(self.winning_team)
     while (time.time() < end_time):
         time.sleep(0.01)
         win_color = colors.hsv2rgb(h_value, 1, 1)
         for win_move in self.move_serials:
             if win_move != self.last_move:
                 win_color_array = self.force_move_colors[win_move]
                 colors.change_color(win_color_array, *win_color)
             else:
                 win_color_array = self.force_move_colors[win_move]
                 colors.change_color(win_color_array, 1,1,1)
         h_value = (h_value + 0.01)
         if h_value >= 1:
             h_value = 0
     self.running = False
Exemple #2
0
    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
Exemple #3
0
    def end_game(self):
        try:
            self.audio.stop_audio()
        except:
            print('no audio loaded to stop')
        end_time = time.time() + END_GAME_PAUSE
        h_value = 0

        while (time.time() < end_time):
            time.sleep(0.01)
            win_color = 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
Exemple #4
0
    def end_game(self):
        self.audio.stop_audio()
        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)
            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
Exemple #5
0
    def end_game(self):
        if self.play_audio:
            try:
                self.audio.stop_audio()
            except:
                print('no audio loaded to stop')
        end_time = time.time() + END_GAME_PAUSE

        self.update_status('ending')

        h_value = 0

        while (time.time() < end_time):
            time.sleep(0.01)
            win_color = colors.hsv2rgb(h_value, 1, 1)
            if len(self.alive_moves) > 0:
                win_move = self.alive_moves[0]
                win_color_array = self.force_move_colors[win_move]
                colors.change_color(win_color_array, *win_color)
                h_value = (h_value + 0.01)
                if h_value >= 1:
                    h_value = 0
        self.running = False
Exemple #6
0
 def fillHSV(self, hsv, start=0, end=-1):
     """Fill the entire strip with HSV color tuple"""
     self.fill(colors.hsv2rgb(hsv), start, end)
Exemple #7
0
 def setHSV(self, pixel, hsv):
     """Set single pixel to HSV tuple"""
     color = colors.hsv2rgb(hsv)
     self._set_base(pixel, color)
Exemple #8
0
    def Start(self):
        running = True
        moves = []
        for move_num in range(len(self.controllers_alive)):
            moves.append(
                common.get_move(self.controllers_alive[move_num], move_num))

        serials = self.controllers_alive
        processes = []

        for num_try, serial in enumerate(serials):
            starting_bullets = 0
            #starting_bullets = random.choice([0, 1])
            opts = Array('i', [0, 0, 0, 1, starting_bullets, 1, 1])
            p = Process(target=track_controller, args=(serial, num_try, opts))
            p.start()
            processes.append(p)
            self.controller_opts[serial] = opts
            self.humans.append(serial)

        if self.play_audio:
            human_victory = Audio(
                'audio/Zombie/sound_effects/human_victory.wav')
            zombie_victory = Audio(
                'audio/Zombie/sound_effects/zombie_victory.wav')
            death = Audio('audio/Zombie/sound_effects/zombie_death.wav')
            pistol = Audio('audio/Zombie/sound_effects/pistol.wav')
            shotgun = Audio('audio/Zombie/sound_effects/shotgun.wav')
            molotov = Audio('audio/Zombie/sound_effects/molotov.wav')
            try:
                self.music.start_audio_loop()
##                music = Audio('audio/Zombie/music/' + random.choice(os.listdir('audio/Zombie/music/')))
##                music.start_effect_music()
            except:
                print('no music in audio/Zombie/music/')

        start_kill = time.time() + 5
        while time.time() < start_kill:
            pass

        #kill first humans
        for random_human in random.sample(set(self.humans), 2):
            #random_human = random.choice(self.humans)
            self.controller_opts[random_human][3] = 0

        while running:
            if self.play_audio:
                self.audio_cue()
            if time.time() - 0.1 > self.update_time:
                self.update_time = time.time()
                self.check_command_queue()
                self.update_status('in_game')

            #human update, loop through the different human controllers
            for serial in self.humans:
                #human is dead and now a zombie
                if self.controller_opts[serial][3] == 0:
                    self.controller_opts[serial][0] = 1
                    self.dead_zombies[serial] = time.time(
                    ) + self.get_kill_time()

                #pistol fired(1 bullet 1 random alive zombie)
                elif self.controller_opts[serial][1] == 2:
                    if self.play_audio:
                        pistol.start_effect()
                    self.kill_zombies(1, [0, 0, 0, 0, 1, 1, 1])
                    self.controller_opts[serial][1] = 0

                #molotov fired(5 bullets all alive zombies)
                elif self.controller_opts[serial][1] == 4:
                    if self.play_audio:
                        molotov.start_effect()
                    self.kill_zombies(50, [0, 0, 1, 1, 2, 3])
                    self.controller_opts[serial][1] = 0

            for serial, spawn_time in self.dead_zombies.items():
                if serial in self.humans:
                    self.humans.remove(serial)
                if spawn_time < time.time():
                    #set zombie to alive
                    self.controller_opts[serial][3] = 1
                    self.alive_zombies.append(serial)

            #loop through dead zombies
            for serial in self.alive_zombies:
                if serial in self.dead_zombies:
                    del self.dead_zombies[serial]

                #melee
                if self.controller_opts[serial][3] == 0:
                    self.controller_opts[serial][0] = 1
                    self.dead_zombies[serial] = time.time(
                    ) + self.get_kill_time()
                    self.alive_zombies.remove(serial)
                    self.reward([0, 0, 1, 1, 2])
                    death.start_effect()

            #win scenario
            if len(self.humans) <= 0 or (time.time() - self.start_time
                                         ) > self.win_time or self.kill_game:
                for proc in processes:
                    proc.terminate()
                    proc.join()
                pause_time = time.time() + 3
                HSV = [(x * 1.0 / (50 * len(self.controllers_alive)), 0.9, 1)
                       for x in range(50 * len(self.controllers_alive))]
                colour_range = [[int(x) for x in colors.hsv2rgb(*colour)]
                                for colour in HSV]
                win_controllers = []
                if len(self.humans) <= 0:
                    if self.play_audio:
                        zombie_victory.start_effect()
                    self.alive_zombies.extend(self.dead_zombies.keys())
                    self.update_status('ending', 1)
                    win_controllers = self.alive_zombies
                if (time.time() - self.start_time) > self.win_time:
                    if self.play_audio:
                        human_victory.start_effect()
                    win_controllers = self.humans
                    self.update_status('ending', 0)
                if self.kill_game:
                    self.alive_zombies.extend(self.dead_zombies.keys())
                    win_controllers = self.humans + self.alive_zombies
                    self.update_status('killed')
                #This needs to go in it's own function
                while time.time() < pause_time:
                    for win_move in moves:
                        if win_move.get_serial() in win_controllers:
                            win_move.set_leds(*colour_range[0])
                            colour_range.append(colour_range.pop(0))
                            win_move.update_leds()
                        else:
                            win_move.set_rumble(100)
                            win_move.poll()
                            win_move.set_leds(0, 0, 0)
                            win_move.update_leds()
                    time.sleep(0.01)
                running = False
                if self.play_audio:
                    try:
                        self.music.stop_audio()
                    except:
                        print('no audio loaded')
Exemple #9
0
def track_move(serial, move_num, move_opts, force_color, battery, dead_count):
    move = common.get_move(serial, move_num)
    move.set_leds(0, 0, 0)
    move.update_leds()
    random_color = random.random()

    while True:
        time.sleep(0.01)
        if move.poll():
            game_mode = common.Games(move_opts[Opts.game_mode.value])
            move_button = common.Button(move.get_buttons())
            if move_opts[Opts.alive.value] == Alive.off.value:
                if move_button == common.Button.SYNC:
                    move_opts[Opts.alive.value] = Alive.on.value
                    dead_count.value = dead_count.value - 1
                time.sleep(0.1)
            else:
                if move_button == common.Button.SHAPES:
                    move_opts[Opts.alive.value] = Alive.off.value
                    dead_count.value = dead_count.value + 1
                    move.set_leds(0, 0, 0)
                    move.set_rumble(0)
                    move.update_leds()
                    continue

                #show battery level
                if battery.value == 1:
                    battery_level = move.get_battery()
                    #granted a charging move should be dead
                    #so it won't light up anyway
                    if battery_level == psmove.Batt_CHARGING:
                        move.set_leds(*colors.Colors.White20.value)

                    elif battery_level == psmove.Batt_CHARGING_DONE:
                        move.set_leds(*colors.Colors.White.value)

                    elif battery_level == psmove.Batt_MAX:
                        move.set_leds(*colors.Colors.Green.value)

                    elif battery_level == psmove.Batt_80Percent:
                        move.set_leds(*colors.Colors.Turquoise.value)

                    elif battery_level == psmove.Batt_60Percent:
                        move.set_leds(*colors.Colors.Blue.value)

                    elif battery_level == psmove.Batt_40Percent:
                        move.set_leds(*colors.Colors.Yellow.value)

                    else:  # under 40% - you should charge it!
                        move.set_leds(*colors.Colors.Red.value)

                #custom team mode is the only game mode that
                #can't be added to con mode
                elif game_mode == common.Games.JoustTeams:
                    if move_opts[Opts.team.value] >= TEAM_NUM:
                        move_opts[Opts.team.value] = 3
                    move.set_leds(*colors.team_color_list[move_opts[
                        Opts.team.value]].value)
                    if move_button == common.Button.MIDDLE:
                        #allow players to increase their own team
                        if move_opts[Opts.holding.
                                     value] == Holding.not_holding.value:
                            move_opts[Opts.team.value] = (
                                move_opts[Opts.team.value] + 1) % TEAM_NUM
                            move_opts[
                                Opts.holding.value] = Holding.holding.value

                #set leds to forced color
                elif sum(force_color) != 0:
                    move.set_leds(*force_color)

                elif game_mode == common.Games.JoustFFA:
                    move.set_leds(*colors.Colors.Orange.value)

                elif game_mode == common.Games.JoustRandomTeams:
                    color = time.time() / 10 % 1
                    color = colors.hsv2rgb(color, 1, 1)
                    move.set_leds(*color)

                elif game_mode == common.Games.Traitor:
                    if move_num % 4 == 2 and time.time() / 3 % 1 < .15:
                        move.set_leds(*colors.Colors.Red80.value)
                    else:
                        color = 1 - time.time() / 10 % 1
                        color = colors.hsv2rgb(color, 1, 1)
                        move.set_leds(*color)

                elif game_mode == common.Games.WereJoust:
                    if move_num <= 0:
                        move.set_leds(*colors.Colors.Blue40.value)
                    else:
                        move.set_leds(*colors.Colors.Yellow.value)

                elif game_mode == common.Games.Zombies:
                    move.set_leds(*colors.Colors.Zombie.value)

                elif game_mode == common.Games.Commander:
                    if move_num % 2 == 0:
                        move.set_leds(*colors.Colors.Orange.value)
                    else:
                        move.set_leds(*colors.Colors.Blue.value)

                elif game_mode == common.Games.Swapper:
                    if (time.time() / 5 + random_color) % 1 > 0.5:
                        move.set_leds(*colors.Colors.Magenta.value)
                    else:

                        move.set_leds(*colors.Colors.Green.value)

                elif game_mode == common.Games.FightClub:
                    move.set_leds(*colors.Colors.Green80.value)

                elif game_mode == common.Games.NonStop:
                    move.set_leds(*colors.Colors.Turquoise.value)

                elif game_mode == common.Games.Tournament:
                    if move_num <= 0:
                        color = time.time() / 10 % 1
                        color = colors.hsv2rgb(color, 1, 1)
                        move.set_leds(*color)
                    else:
                        move.set_leds(*colors.Colors.Blue40.value)

                elif game_mode == common.Games.Ninja:
                    if move_num <= 0:
                        move.set_leds(random.randrange(100, 200), 0, 0)
                    else:
                        move.set_leds(*colors.Colors.Red60.value)

                elif game_mode == common.Games.Random:

                    move.set_leds(0, 0, 255)
                if move.get_trigger() > 100:
                    move_opts[Opts.random_start.value] = Alive.off.value
                if move_opts[Opts.random_start.value] == Alive.off.value:
                    move.set_leds(255, 255, 255)

                if move_opts[Opts.holding.value] == Holding.not_holding.value:
                    #Change game mode and become admin controller
                    if move_button == common.Button.SELECT:
                        move_opts[Opts.selection.
                                  value] = Selections.change_mode.value
                        move_opts[Opts.holding.value] = Holding.holding.value

                    #start the game
                    if move_button == common.Button.START:
                        move_opts[
                            Opts.selection.value] = Selections.start_game.value
                        move_opts[Opts.holding.value] = Holding.holding.value

                    #as an admin controller add or remove game from convention mode
                    if move_button == common.Button.CROSS:
                        move_opts[
                            Opts.selection.value] = Selections.add_game.value
                        move_opts[Opts.holding.value] = Holding.holding.value

                    #as an admin controller change sensitivity of controllers
                    if move_button == common.Button.CIRCLE:
                        move_opts[Opts.selection.
                                  value] = Selections.change_sensitivity.value
                        move_opts[Opts.holding.value] = Holding.holding.value

                    #as an admin controller change if instructions play
                    if move_button == common.Button.SQUARE:
                        move_opts[Opts.selection.
                                  value] = Selections.change_instructions.value
                        move_opts[Opts.holding.value] = Holding.holding.value

                    #as an admin show battery level of controllers
                    if move_button == common.Button.TRIANGLE:
                        move_opts[Opts.selection.
                                  value] = Selections.show_battery.value
                        move_opts[Opts.holding.value] = Holding.holding.value

                if move_button == common.Button.NONE:
                    move_opts[Opts.holding.value] = Holding.not_holding.value

        move.update_leds()
Exemple #10
0
 def setHSV(self, x, y, hsv):
     color = colors.hsv2rgb(hsv)
     self._set(x, y, color)
Exemple #11
0
 def setHSV(self, pixel, hsv):
     """Set single pixel to HSV tuple"""
     color = colors.hsv2rgb(hsv)
     self.set(pixel, color)
Exemple #12
0
 def fillHSV(self, hsv, start=0, end=-1):
     """Fill the entire strip with HSV color tuple"""
     self.fill(colors.hsv2rgb(hsv), start, end)
Exemple #13
0
 def setHSV(self, x, y, hsv):
     color = colors.hsv2rgb(hsv)
     self._set(x,y,color)