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 splitn(axis, n, rands, box): axis = axis.normalized() shapes = [ Shape(HOU.Vector3(box.center), HOU.Vector3(box.size)) for x in range(n) ] # get the min/max, keeping only components specified by `axis` min = common.compMul3(axis, box.center - box.size / 2) + common.compMul3( HOU.Vector3(1, 1, 1) - axis, box.center) max = common.compMul3(axis, box.center + box.size / 2) + common.compMul3( HOU.Vector3(1, 1, 1) - axis, box.center) binsize = float(1) / (n - 1) splits = [min] for x in range(n - 1): u = (x + rands[x]) * binsize # u = random.uniform((x + 0.3) * binsize, (x+0.7) * binsize) # get random parametrization along axis offset = min + common.compMul3(box.size, axis * u) splits.append(offset) splits.append(max) for x in range(n): nsize = HOU.Vector3() diff = splits[x + 1] - splits[x] for i in range(3): # copy size, but set components specified by axis to the difference between adjacent splits nsize[i] = common.lerp(box.size[i], diff[i], axis[i]) shapes[x] = Shape(center=common.lerp(splits[x], splits[x + 1], 0.5), size=nsize) return shapes
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 track_move(move_serial, move_num, team, team_num, score, win_amount, dead_move, force_color, music_speed): #proc = psutil.Process(os.getpid()) #proc.nice(3) #explosion = Audio('audio/Joust/sounds/Explosion34.wav') #explosion.start_effect() move_last_value = None move = common.get_move(move_serial, move_num) team_colors = common.generate_colors(team_num) werewolf = False flash_time = time.time() #keep on looping while move is not dead while True: if sum(force_color) != 0: time.sleep(0.01) move.set_leds(*force_color) move.update_leds() if werewolf: move.set_rumble(80) elif dead_move.value == 1: if move.poll(): ax, ay, az = move.get_accelerometer_frame(psmove.Frame_SecondHalf) total = sum([ax, ay, az]) if move_last_value is not None: change = abs(move_last_value - total) 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 change > threshold: move.set_leds(0,0,0) move.set_rumble(90) score.value = -1 dead_move.value = 0 elif change > warning: move.set_leds(20,50,100) move.set_rumble(110) else: if score.value >= 1: if time.time() > flash_time: vall = calculate_flash_time(team_colors[team][0],team_colors[team][1],team_colors[team][2],score.value, win_amount) #print vall move.set_leds(*vall) #flash_time = time.time() + calculate_flash_time(score.value, win_amount) else: move.set_leds(*team_colors[team]) move.set_rumble(0) move_last_value = total move.update_leds() elif dead_move.value == 0: if move.poll(): move_button = move.get_buttons() if score.value >= 0 and move_button == common.Buttons.middle: dead_move.value = 1 move_last_value = None
def calculate_flash_time(r, g, b, score): flash_percent = max(min(float(score) + 0.2, 1.0), 0.0) # val_percent = (val-(flash_speed/2))/(flash_speed/2) new_r = int(common.lerp(255, r, flash_percent)) new_g = int(common.lerp(255, g, flash_percent)) new_b = int(common.lerp(255, b, flash_percent)) return (new_r, new_g, new_b)
def calculate_flash_time(r,g,b, score): flash_percent = max(min(float(score)+0.2,1.0),0.0) #val_percent = (val-(flash_speed/2))/(flash_speed/2) new_r = int(common.lerp(255, r, flash_percent)) new_g = int(common.lerp(255, g, flash_percent)) new_b = int(common.lerp(255, b, flash_percent)) return (new_r, new_g, new_b)
def calculate_flash_time(r, g, b, score, win_amount): flash_percent = float(score) / (win_amount - 1.0) flash_speed = common.lerp(MIN_FLASH, MAX_FLASH, flash_percent) val = (time.time() % float(flash_speed)) if val < flash_speed / 2: return (r, g, b) else: val_percent = (val - (flash_speed / 2)) / (flash_speed / 2) new_r = int(common.lerp(r, 255, val_percent)) new_g = int(common.lerp(g, 255, val_percent)) new_b = int(common.lerp(b, 255, val_percent)) return (new_r, new_g, new_b)
def calculate_flash_time(r,g,b, score, win_amount): flash_percent = float(score)/(win_amount-1.0) flash_speed = common.lerp(MIN_FLASH, MAX_FLASH, flash_percent) val = (time.time() % float(flash_speed)) if val < flash_speed/2: return (r,g,b) else: val_percent = (val-(flash_speed/2))/(flash_speed/2) new_r = int(common.lerp(r, 255, val_percent)) new_g = int(common.lerp(g, 255, val_percent)) new_b = int(common.lerp(b, 255, val_percent)) return (new_r, new_g, new_b)
def update(self): request = self.maxThrust*self.limit delta = request-self.thrust if delta > 0: if self.acceleration > 0: self.thrust = lerp(self.thrust, request, self.acceleration * dt) else: self.thrust = request elif delta < 0: if self.deceleration > 0: self.thrust = lerp(self.thrust, request, self.deceleration * dt) else: self.thrust = request self.torque = self.thrust*self.lever
def cut_and_paste_strip(src_img, dest_srf, p_rect, tint, shadow_color=(0, 0, 0)): size = dest_srf.get_size() rect = pygame.Rect(lerp(0, size[0], p_rect[0]), lerp(0, size[1], p_rect[1]), lerp(0, size[0], p_rect[2]), lerp(0, size[1], p_rect[3])) srf = pygame.Surface(rect.size, SRCALPHA) srf.fill((255, 255, 255, 0)) srf.blit(src_img, (-rect.left, -rect.top)) srf.fill(tint, None, special_flags=BLEND_RGB_MULT) pygame.draw.rect(srf, (255, 255, 255), (0, 0, rect.width, rect.height), 7) srf = apply_shadow(srf, 18, 96, shadow_color) offset = 2 p1 = (rect.left + lerp(-offset, offset, random.random()), rect.top + lerp(-offset, offset, random.random())) p2 = (rect.right + lerp(-offset, offset, random.random()), rect.bottom + lerp(-offset, offset, random.random())) center = ((p1[0] + p2[0]) / 2.0, (p1[1] + p2[1]) / 2.0) angle = math.degrees( math.atan2(rect.height, rect.width) - math.atan2(p2[1] - p1[1], p2[0] - p1[0])) new_srf = pygame.transform.rotozoom(srf, angle, 1.0) #new_srf = srf #center = rect.center #new_srf = srf new_rect = new_srf.get_rect(center=center) #rect.center) dest_srf.blit(new_srf, new_rect)
def correlated_colour_temp(X, Y, Z): if X < 1.0e-20 or Y < 1.0e-20 or Z < 1.0e-20: raise ValueError("Bad XYZ value, would cause divide-by-zero") us = 4 * X / (X + 15 * Y + 3 * Z) vs = 6 * Y / (X + 15 * Y + 3 * Z) dm = 0.0 for i in range(31): di = (vs - uvt[i].v) - uvt[i].t * (us - uvt[i].u) if i > 0 and (di < 0.0) and (dm > 0.0) or (di >= 0.0) and (dm < 0.0): break # Found lines bounding (us, vs), i-1 and i dm = di else: raise ValueError( "Bad XYZ value, colour temperature would be under 1666.7, or too far towards blue" ) di = di / math.sqrt(1.0 + uvt[i].t * uvt[i].t) dm = dm / math.sqrt(1.0 + uvt[i - 1].t * uvt[i - 1].t) p = dm / (dm - di) # interoplation param p = 1.0 / lerp(rt[i - 1], rt[i], p) return p
def phys_loop(self, on_frame=lambda: None): i = 1 while self.dX >= 0 and (self.T[-1] < self.t1 or i < self.N): self.T.append(self.T[-1] + dt) self.update_upAF() on_frame() # VSF self.K.append(self.vK) # thrust rthrust = self.thrust * self.K[-1] speed = self.AS if rthrust > self.cthrust else self.DS self.cthrust = lerp(self.cthrust, rthrust, speed * dt) if speed > 0 else rthrust # dynamics self.upA = (self.add_thrust + self.cthrust - self.M * 9.81) / self.M self.upV += self.upA * dt self.upX += self.upV * dt self.dX = self.upX - (self.Ter[i] if self.N > 0 else 0) self.dV = EWA(self.dV, (self.dX - self.rX[-1]) / dt, 0.1) # logging self.F.append(self.cthrust * dt) self.A.append(self.upA) self.V.append(self.upV) self.rV.append(self.dV) self.X.append(self.upX) self.rX.append(self.dX) i += 1
def update(self): request = self.maxThrust * self.limit delta = request - self.thrust if delta > 0: if self.acceleration > 0: self.thrust = lerp(self.thrust, request, self.acceleration * dt) else: self.thrust = request elif delta < 0: if self.deceleration > 0: self.thrust = lerp(self.thrust, request, self.deceleration * dt) else: self.thrust = request self.torque = self.thrust * self.lever
def xform(p): p -= center d = p.mag() / 500 p = common.lerp(common.smoothstep(min(1.0, 1.3 * math.pow(t, d))), p * 5, p) p += center return p
async def do_transition(): num_steps = 20 old_ratio = self.ratio.value for i in range(num_steps): t = (i + 1) / 20 ratio = common.lerp(old_ratio, new_ratio, t) ratio = old_ratio * (1 - t) + new_ratio * t self.change_ratio(ratio) await asyncio.sleep(transition_duration / num_steps)
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 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 update(self): if self.on_update is not None: self.on_update(self) else: self.PID.update(abs(self.error)) self.angle = lerp(self.angle, np.arctan2(self.PID.action*np.sign(self.error), 1), self.turn_speed*dt) self.engine.limit = clamp01(self.base_limit/abs(np.cos(self.angle))) self.engine.update() self.accel = self.engine.thrust*np.sin(self.angle)/self.mass + (np.random.rand()-0.5)*1e-3 self.error -= self.accel*dt
def update(self): if self.on_update is not None: self.on_update(self) else: self.PID.update(abs(self.error)) self.angle = lerp(self.angle, np.arctan2(self.PID.action * np.sign(self.error), 1), self.turn_speed * dt) self.engine.limit = clamp01(self.base_limit / abs(np.cos(self.angle))) self.engine.update() self.accel = self.engine.thrust * np.sin( self.angle) / self.mass + (np.random.rand() - 0.5) * 1e-3 self.error -= self.accel * dt
def correlated_colour_temp(X, Y, Z): if X < 1.0e-20 or Y < 1.0e-20 or Z < 1.0e-20: raise ValueError("Bad XYZ value, would cause divide-by-zero") us = 4*X / (X + 15*Y + 3*Z) vs = 6*Y / (X + 15*Y + 3*Z) dm = 0.0 for i in range(31): di = (vs - uvt[i].v) - uvt[i].t * (us - uvt[i].u) if i > 0 and (di < 0.0) and (dm > 0.0) or (di >= 0.0) and (dm < 0.0): break # Found lines bounding (us, vs), i-1 and i dm = di else: raise ValueError("Bad XYZ value, colour temperature would be under 1666.7, or too far towards blue") di = di / math.sqrt(1.0 + uvt[i].t * uvt[i].t) dm = dm / math.sqrt(1.0 + uvt[i-1].t * uvt[i-1].t) p = dm / (dm - di) # interoplation param p = 1.0 / lerp(rt[i - 1], rt[i], p) return p
def render(self): s = pygame.Surface(self.main.screen_size,SRCALPHA) p = min(max((self.fade-self.pre_delay)/float(self.fade_length),0.0),1.0) color = (255,255,255,lerp(0,255,p)) s.fill(color) self.main.screen.blit(s,(0,0))
def track_move(move_serial, move_num, game_mode, team, team_num, dead_move, force_color, music_speed, werewolf_reveal): #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 = common.generate_colors(team_num) werewolf = False if team < 0: team = (team + 1) * -1 werewolf = True #keep on looping while move is not dead while True: if sum(force_color) != 0: no_rumble_time = time.time() + 5 time.sleep(0.01) move.set_leds(*force_color) if sum(force_color) > 75: if werewolf: move.set_rumble(80) else: if sum(force_color) == 30: if werewolf: move.set_leds(255, 0, 0) else: 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 werewolf_reveal.value > 0: if move.poll(): ax, ay, az = move.get_accelerometer_frame(psmove.Frame_SecondHalf) total = sum([ax, ay, az]) if move_last_value is not None: change = abs(move_last_value - total) 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 change > threshold: if time.time() > no_rumble: move.set_leds(0,0,0) move.set_rumble(90) dead_move.value = 0 elif change > warning: if time.time() > no_rumble: move.set_leds(20,50,100) move.set_rumble(110) else: if game_mode == common.Games.WereJoust.value: if werewolf_reveal.value == 2 and werewolf: move.set_leds(255,0,0) else: move.set_leds(100,100,100) else: move.set_leds(*team_colors[team]) move.set_rumble(0) move_last_value = total move.update_leds()
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)
def track_move(move_serial, move_num, dead_move, force_color, bomb_color, move_opts, game_start, false_color, faked, rumble): #proc = psutil.Process(os.getpid()) #proc.nice(3) start = False no_rumble = time.time() + 1 move_last_value = None move = common.get_move(move_serial, move_num) #keep on looping while move is not dead ready = False move.set_leds(0, 0, 0) move.update_leds() time.sleep(1) super_dead = False no_bomb_color = [0, 0, 200] fake_bomb_color = [0, 255, 0] no_fake_bomb_color = [0, 0, 200] death_time = 8 time_of_death = time.time() can_fake = True faking = False move_opts[Opts.holding.value] = Holding.not_holding.value move_opts[Opts.selection.value] = Selections.nothing.value while not super_dead: if sum(force_color) != 0 and game_start.value == 1: no_rumble_time = time.time() + 5 time.sleep(0.01) move.set_leds(*force_color) move.update_leds() move.set_rumble(rumble.value) no_rumble = time.time() + 0.5 #if we are not dead elif dead_move.value > 0: move.set_rumble(rumble.value) if dead_move.value == 2: no_bomb_color = [150, 150, 150] no_fake_bomb_color = [120, 255, 120] else: no_bomb_color = [30, 30, 30] no_fake_bomb_color = [100, 100, 100] if move.poll(): button = move.get_buttons() if move_opts[Opts.has_bomb.value] == Bool.yes.value: if (move.get_trigger() > 50 and can_fake): faking = True #move_opts[Opts.holding.value] = Holding.holding.value move_opts[Opts.selection. value] = Selections.false_trigger.value if (move.get_trigger() <= 127): col1 = int( common.lerp(fake_bomb_color[0], no_fake_bomb_color[0], (move.get_trigger() - 50) / 77)) col2 = int( common.lerp(fake_bomb_color[1], no_fake_bomb_color[1], (move.get_trigger() - 50) / 77)) col3 = int( common.lerp(fake_bomb_color[2], no_fake_bomb_color[2], (move.get_trigger() - 50) / 77)) move.set_leds(col1, col2, col3) #if (move.get_trigger() > 127 and move.get_trigger() <= 140): # move.set_leds(*no_fake_bomb_color) if (move.get_trigger() > 127): col1 = int( common.lerp(no_fake_bomb_color[0], fake_bomb_color[0], (move.get_trigger() - 127) / 128)) col2 = int( common.lerp(no_fake_bomb_color[1], fake_bomb_color[1], (move.get_trigger() - 127) / 128)) col3 = int( common.lerp(no_fake_bomb_color[2], fake_bomb_color[2], (move.get_trigger() - 127) / 128)) move.set_leds(col1, col2, col3) #move.set_leds(0,200,0) else: move.set_leds(*bomb_color) if game_start.value == 0: move.set_leds(*force_color) move.update_leds() #move_opts[Opts.holding.value] == Holding.not_holding.value if faking: #move_opts[Opts.selection.value] = Selections.not_holding.value if game_start.value == 1: can_fake = False faking = False #non bomb holder else: can_fake = True faking = False if false_color.value == 1: move.set_leds(150, 20, 20) else: move.set_leds(*no_bomb_color) if move_opts[Opts.holding. value] == Holding.not_holding.value and ( move.get_trigger() > 50 or button == Buttons.middle.value): if move_opts[Opts.has_bomb.value] == Bool.no.value: move_opts[ Opts.holding.value] = Holding.holding.value if game_start.value == 1 and false_color.value == 1: print("JUST DIED TO BEING FAKED!!!") faked.value = 1 #dead_move.value -= 1 move.set_rumble(0) if move_opts[ Opts.holding.value] == Holding.not_holding.value and ( button == Buttons.triangle.value or button == Buttons.circle.value or button == Buttons.cross.value or button == Buttons.square.value): move_opts[Opts.selection.value] = Selections.counter.value move_opts[Opts.holding.value] = Holding.holding.value if button == Buttons.middle.value and move_opts[ Opts.holding.value] == Holding.not_holding.value: move_opts[Opts.selection.value] = Selections.a_button.value move_opts[Opts.holding.value] = Holding.holding.value elif move_opts[ Opts.holding. value] == Holding.holding.value and button == Buttons.nothing.value and move.get_trigger( ) <= 50: move_opts[Opts.selection.value] = Selections.nothing.value move_opts[Opts.holding.value] = Holding.not_holding.value else: if super_dead == False: #for i in range(100): # time.sleep(0.01) # move.set_leds(0,random.randrange(100, 200),0) # move.set_rumble(200) # move.update_leds() super_dead = True move.set_rumble(0) move.set_leds(0, 0, 0) move.update_leds()
def game_loop(self): self.track_moves() self.rotate_colors() self.bomb_serial = self.move_serials[random.choice( range(len(self.move_serials)))] self.next_rand_holder = self.bomb_serial self.bomb_generator = self.get_next_bomb_holder() self.bomb_serial = next(self.bomb_generator) self.move_opts[self.bomb_serial][Opts.has_bomb.value] = Bool.yes.value self.holding = True self.game_start.value = 1 self.count_down() time.sleep(0.02) if self.audio_toggle: try: self.audio.start_audio_loop() except: print('no audio loaded to start') time.sleep(0.8) self.bomb_time = time.time() + self.get_bomb_length() self.bomb_start_time = time.time() while self.running: if time.time() - 0.1 > self.update_time: self.update_time = time.time() self.check_command_queue() self.update_status('in_game') percentage = 1 - ((self.bomb_time - time.time()) / (self.bomb_time - self.bomb_start_time)) if (percentage > 0.8): self.bomb_color[0] = random.randrange( int(100 + 55 * percentage), int(200 + 55 * percentage)) else: self.bomb_color[0] = int(common.lerp(90, 255, percentage)) self.bomb_color[1] = int(common.lerp(30, 0, percentage)) self.bomb_color[2] = int(common.lerp(30, 0, percentage)) if self.move_opts[self.bomb_serial][ Opts.selection.value] == Selections.nothing.value: self.holding = False if self.move_opts[self.bomb_serial][ Opts.selection. value] == Selections.a_button.value and self.holding == False: self.reset_bomb_time() self.move_bomb() if self.audio_toggle: self.start_beep.start_effect() self.holding = True if time.time() > self.bomb_time: if self.audio_toggle: self.explosiondeath.start_effect() self.explosion.start_effect() self.pause_for_player_death(self.bomb_serial) self.dead_moves[self.bomb_serial].value -= 1 self.reset_bomb_length() self.reset_bomb_time() #if player is dead move bomb if not self.dead_moves[self.bomb_serial].value > 0: self.move_bomb() print("TIME BOMB") self.check_dead_moves() self.check_faked_out() if self.game_end: self.end_game() self.stop_tracking_moves()
def track_move(move_serial, move_num, game_mode, team, team_color_enum, dead_move, force_color, music_speed, werewolf_reveal, show_team_colors, red_on_kill): #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) my_team_colors = team_color_enum.value werewolf = False vibrate = False change_arr = [0, 0, 0] vibration_time = time.time() + 1 flash_lights = True flash_lights_timer = 0 if team < 0: team = (team + 1) * -1 werewolf = True #keep on looping while move is not dead while True: if show_team_colors.value == 1: move.set_leds(*my_team_colors) 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) > 75: if werewolf: move.set_rumble(80) else: if sum(force_color) == 30: if werewolf: move.set_leds(*colors.Colors.Blue40.value) else: move.set_leds(*colors.Colors.Black.value) move.set_rumble(0) move.update_leds() no_rumble = time.time() + 0.5 elif dead_move.value == 1 and werewolf_reveal.value > 0: 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) 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: move.set_leds(*colors.Colors.Black.value) else: move.set_leds(*colors.Colors.White40.value) else: if game_mode == common.Games.WereJoust: 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) else: move.set_rumble(0) if time.time() > vibration_time: vibrate = False else: if game_mode == common.Games.WereJoust: 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) move_last_value = total move.update_leds() elif dead_move.value < 1: time.sleep(0.5) if dead_move.value == -1 and game_mode == common.Games.NonStop: time.sleep(2) move_last_value = 0 change_arr = [0, 0, 0] no_rumble = time.time() + 1 vibration_time = time.time() + 1 dead_move.value = 2
def track_move(move_serial, move_num, team, team_num, score, win_amount, dead_move, force_color, music_speed): #proc = psutil.Process(os.getpid()) #proc.nice(3) #explosion = Audio('audio/Joust/sounds/Explosion34.wav') #explosion.start_effect() move_last_value = None move = common.get_move(move_serial, move_num) team_colors = common.generate_colors(team_num) werewolf = False flash_time = time.time() #keep on looping while move is not dead while True: if sum(force_color) != 0: time.sleep(0.01) move.set_leds(*force_color) move.update_leds() if werewolf: move.set_rumble(80) elif dead_move.value == 1: if move.poll(): ax, ay, az = move.get_accelerometer_frame( psmove.Frame_SecondHalf) total = sum([ax, ay, az]) if move_last_value is not None: change = abs(move_last_value - total) 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 change > threshold: move.set_leds(0, 0, 0) move.set_rumble(90) score.value = -1 dead_move.value = 0 elif change > warning: move.set_leds(20, 50, 100) move.set_rumble(110) else: if score.value >= 1: if time.time() > flash_time: vall = calculate_flash_time( team_colors[team][0], team_colors[team][1], team_colors[team][2], score.value, win_amount) #print vall move.set_leds(*vall) #flash_time = time.time() + calculate_flash_time(score.value, win_amount) else: move.set_leds(*team_colors[team]) move.set_rumble(0) move_last_value = total move.update_leds() elif dead_move.value == 0: if move.poll(): move_button = move.get_buttons() if score.value >= 0 and move_button == common.Buttons.middle: dead_move.value = 1 move_last_value = None
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, dead_invince): 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] dead_invince.value = False start = False no_rumble = time.time() + 2 move_last_value = None my_team_colors = team_color_enum werewolf = False vibrate = False 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 #keep on looping while move is not dead while True: if (restart.value == 1 or menu.value == 1): return if show_team_colors.value == 1: move.set_leds(*my_team_colors) 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) > 75: if werewolf: move.set_rumble(80) else: if sum(force_color) == 30: if werewolf: move.set_leds(*colors.Colors.Blue40.value) else: move.set_leds(*colors.Colors.Black.value) move.set_rumble(0) move.update_leds() no_rumble = time.time() + 0.5 elif dead_move.value == 1 and werewolf_reveal.value > 0: if move.poll(): ax, ay, az = move.get_accelerometer_frame( psmove.Frame_SecondHalf) total = sqrt(sum([ax**2, ay**2, az**2])) change = (change * 4 + total) / 5 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.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 and not dead_invince.value: if time.time() > no_rumble: dead_invince.value = True 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.update_leds() time.sleep(0.5) dead_invince.value = False 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: time.sleep(0.5) if dead_move.value == -1 and game_mode == common.Games.NonStop.value: time.sleep(2) move_last_value = 0 change_arr = [0, 0, 0] no_rumble = time.time() + 1 vibration_time = time.time() + 1 dead_move.value = 2
def track_move(move, dead_move, force_color, bomb_color, move_opts, game_start, false_color, faked, rumble, menu, restart): start = False no_rumble = time.time() + 1 move_last_value = None #keep on looping while move is not dead ready = False move.set_leds(0, 0, 0) move.update_leds() time.sleep(1) super_dead = False no_bomb_color = [0, 0, 200] fake_bomb_color = [0, 255, 0] no_fake_bomb_color = [0, 0, 200] death_time = 8 time_of_death = time.time() can_fake = True faking = False move_opts[Opts.holding.value] = Holding.not_holding.value move_opts[Opts.selection.value] = Selections.nothing.value while True: if (menu.value == 1 or restart.value == 1): return if sum(force_color) != 0 and game_start.value == 1: no_rumble_time = time.time() + 5 time.sleep(0.01) move.set_leds(*force_color) move.update_leds() move.set_rumble(rumble.value) no_rumble = time.time() + 0.5 #if we are not dead elif dead_move.value > 0: move.set_rumble(rumble.value) if dead_move.value == 2: no_bomb_color = [150, 150, 150] no_fake_bomb_color = [120, 255, 120] else: no_bomb_color = [30, 30, 30] no_fake_bomb_color = [100, 100, 100] if move.poll(): button = common.Button(move.get_buttons()) if move_opts[Opts.has_bomb.value] == Bool.yes.value: if (move.get_trigger() > 50 and can_fake): faking = True move_opts[Opts.selection. value] = Selections.false_trigger.value if (move.get_trigger() <= 127): col1 = int( common.lerp(fake_bomb_color[0], no_fake_bomb_color[0], (move.get_trigger() - 50) / 77)) col2 = int( common.lerp(fake_bomb_color[1], no_fake_bomb_color[1], (move.get_trigger() - 50) / 77)) col3 = int( common.lerp(fake_bomb_color[2], no_fake_bomb_color[2], (move.get_trigger() - 50) / 77)) move.set_leds(col1, col2, col3) if (move.get_trigger() > 127): col1 = int( common.lerp(no_fake_bomb_color[0], fake_bomb_color[0], (move.get_trigger() - 127) / 128)) col2 = int( common.lerp(no_fake_bomb_color[1], fake_bomb_color[1], (move.get_trigger() - 127) / 128)) col3 = int( common.lerp(no_fake_bomb_color[2], fake_bomb_color[2], (move.get_trigger() - 127) / 128)) move.set_leds(col1, col2, col3) else: move.set_leds(*bomb_color) if game_start.value == 0: move.set_leds(*force_color) move.update_leds() if faking: if game_start.value == 1: can_fake = False faking = False #non bomb holder else: can_fake = True faking = False if false_color.value == 1: move.set_leds(150, 20, 20) else: move.set_leds(*no_bomb_color) if move_opts[Opts.holding. value] == Holding.not_holding.value and ( move.get_trigger() > 50 or button == common.Button.MIDDLE): if move_opts[Opts.has_bomb.value] == Bool.no.value: move_opts[ Opts.holding.value] = Holding.holding.value if game_start.value == 1 and false_color.value == 1: print("JUST DIED TO BEING FAKED!!!") faked.value = 1 move.set_rumble(0) if move_opts[ Opts.holding.value] == Holding.not_holding.value and ( button in common.all_shapes): move_opts[Opts.selection.value] = Selections.counter.value move_opts[Opts.holding.value] = Holding.holding.value if button == common.Button.MIDDLE and move_opts[ Opts.holding.value] == Holding.not_holding.value: move_opts[Opts.selection.value] = Selections.a_button.value move_opts[Opts.holding.value] = Holding.holding.value elif move_opts[ Opts.holding. value] == Holding.holding.value and button == common.Button.NONE and move.get_trigger( ) <= 50: move_opts[Opts.selection.value] = Selections.nothing.value move_opts[Opts.holding.value] = Holding.not_holding.value else: if super_dead == False: super_dead = True move.set_rumble(0) move.set_leds(0, 0, 0) time.sleep(2) move.update_leds()
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 vibrate = False vibration_time = time.time() + 1 flash_lights = True flash_lights_timer = 0 start_inv = False 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: if (menu.value == 1 or restart.value == 1): return if 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 not invincibility.value: if move.poll(): ax, ay, az = move.get_accelerometer_frame( psmove.Frame_SecondHalf) total = sqrt(sum([ax**2, ay**2, az**2])) change = (change * 4 + total) / 5 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) 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) move.update_leds() else: if dead_move.value < 1: 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 move.update_leds() start_inv = False time.sleep(0.5) move.set_rumble(0)
def draw(self): gd = self.gd y0 = 720 - 640 t = time.time() # + 180 * 24 * 3600 t = time.time() + self.t * 600 (sun_lat, sun_lon) = subsolar_point(t) print(self.t, sun_lat, sun_lon) x = 640 + 640 * sun_lon / 180 y = y0 + 320 - 320 * sun_lat / 90 lim = light(sun_lat, sun_lon) ld = common.Loader(gd) ld.a = (1 << 20) - (256 * 128) gd.BitmapHandle(2) ld.L8(lim) gd.BitmapSize(gd3.BILINEAR, gd3.REPEAT, gd3.BORDER, 0, 0) gd.VertexFormat(2) # Match the color of the arctic br = lim.load()[128, 0] / 255 r = int(common.lerp(br, 27, 255)) g = int(common.lerp(br, 27, 255)) b = int(common.lerp(br, 55, 255)) gd.ClearColorRGB(r, g, b) gd.Clear() gd.Begin(gd3.BITMAPS) gd.SaveContext() gd.BitmapHandle(1) i = 180 gd.ColorRGB(i, i, i) gd.Vertex2f(0, y0) gd.RestoreContext() gd.SaveContext() sf = 1280 / 256 gd.cmd_scale(sf, sf) gd.cmd_setmatrix() gd.BitmapHandle(2) gd.ColorMask(0, 0, 0, 1) gd.BlendFunc(1, 0) gd.Vertex2f(0, y0) gd.RestoreContext() gd.SaveContext() gd.BlendFunc(gd3.DST_ALPHA, gd3.ONE_MINUS_DST_ALPHA) gd.BitmapHandle(0) gd.Vertex2f(0, y0) gd.RestoreContext() gd.SaveContext() gd.Begin(gd3.POINTS) gd.ColorRGB(80, 70, 30) gd.BlendFunc(gd3.SRC_ALPHA, gd3.ONE) for i in range(50, 250, 50): gd.PointSize(i) gd.Vertex2f(x, y) gd.RestoreContext() dt = datetime.datetime.fromtimestamp(t, timezone.utc) if 0: gd.SaveContext() gd.ColorRGB(0, 0, 0) gd.cmd_text(640, 3, 31, gd3.OPT_CENTERX, dt.ctime()) gd.RestoreContext() if 0: for i in range(25): hr = (dt.hour - 12 + i) % 12 gd.cmd_clock(1280 * i // 24, 30, 20, gd3.OPT_FLAT | gd3.OPT_NOSECS, hr, dt.minute, 0, 0) self.t += 1 # gd.screenshot_im().save("out.png"); sys.exit(0); # time.sleep(10) assert self.t < 180
def track_move(move_serial, move_num, game_mode, team, team_num, dead_move, force_color, music_speed, werewolf_reveal): # 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 = common.generate_colors(team_num) werewolf = False if team < 0: team = (team + 1) * -1 werewolf = True # keep on looping while move is not dead while True: if sum(force_color) != 0: no_rumble_time = time.time() + 5 time.sleep(0.01) move.set_leds(*force_color) if sum(force_color) > 75: if werewolf: move.set_rumble(80) else: if sum(force_color) == 30: if werewolf: move.set_leds(255, 0, 0) else: 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 werewolf_reveal.value > 0: if move.poll(): ax, ay, az = move.get_accelerometer_frame(psmove.Frame_SecondHalf) total = sum([ax, ay, az]) if move_last_value is not None: change = abs(move_last_value - total) 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 change > threshold: if time.time() > no_rumble: move.set_leds(0, 0, 0) move.set_rumble(90) dead_move.value = 0 elif change > warning: if time.time() > no_rumble: move.set_leds(20, 50, 100) move.set_rumble(110) else: if game_mode == common.Games.WereJoust.value: if werewolf_reveal.value == 2 and werewolf: move.set_leds(255, 0, 0) else: move.set_leds(100, 100, 100) else: move.set_leds(*team_colors[team]) move.set_rumble(0) move_last_value = total move.update_leds()
def nominal_current_torque(self, K): return (self.torque * (lerp(self.min_thrust, self.max_thrust, K) if not self.manual else self.max_thrust))