def start(self): self.assign_cards() cur_shot = Shot() cur_player = random.randint(0, 5) big_player = cur_player num_pass = self.reset_num_pass() while not self.is_finish(): # print(f"cur_shot={cur_shot}, cur={cur_player}, big={big_player}, finish={self.finish_players}") if num_pass == 0: cur_shot = Shot() self.show_all_cards() num_pass = self.reset_num_pass() shot = self.players[cur_player].next_shot(cur_shot) if shot.type != 0: cur_shot = shot big_player = cur_player num_pass = self.reset_num_pass() else: num_pass -= 1 print(f"Player{cur_player}: {str(shot)}, num_pass={num_pass}") if self.players[cur_player].is_finish(): print(f"Player{cur_player} finishes") self.finish_players.append(cur_player) big_player = self.next_player(big_player) cur_player = self.next_player(cur_player)
def shoot(self): player = variables.player now = variables.time if (self.last_shot != None and now - self.last_shot < self.shot_interval): return self.last_shot = variables.time center = self.get_center() center = (center[1], center[0]) shot = Shot(True) shot.sender = self shot.harm_player = True shot.x, shot.y = center[0], center[1] #Make shot follow player shot.speed = 250 player_center = player.get_center() player_center = (player_center[1], player_center[0]) diffx = (player_center[0] - center[0]) diffy = (player_center[1] - center[1]) shot.rotation = math.degrees(math.atan(diffx / diffy)) if (diffy < 0): shot.rotation += 180 shot.rotation += 180 shot.move() variables.entities_to_add.add(shot)
def new_round_shot(self): # type 5 cards_5 = self.form_5() if len(cards_5[0]) == 5: cards = cards_5[0] self.remove_cards(cards) return Shot(cards=cards_5[0], type=5, team=self.team) # type 1, 2, 3 for card_type, v in self.split_cards.items(): for cards in v: self.remove_cards(cards) return Shot(cards=cards, type=card_type, team=self.team)
def __create_shot(self, sound): """ Since the player generally fires more than one shot at a time, it would be unneccessary to play sounds for all of them, hence the sound argument which is boolean. """ pos, shipdir = self.get_position(), self.get_direction() if sound: return Shot(self.common, Shot.playershot, pos, shipdir, SHOTSPEED, Shot.mediumdamage, Shot.playersound) else: return Shot(self.common, Shot.playershot, pos, shipdir, SHOTSPEED, Shot.mediumdamage, None)
def FromDir(self, dir: str): shots = ThreeShots() files = os.listdir(dir) shots.shot1 = Shot.FromFile(None, os.path.join(dir, files[0])) shots.shot2 = Shot.FromFile(None, os.path.join(dir, files[1])) shots.shot3 = Shot.FromFile(None, os.path.join(dir, files[2])) shots.delta12 = ShotDelta(shots.shot1, shots.shot2) shots.delta23 = ShotDelta(shots.shot2, shots.shot3) shots.delta31 = ShotDelta(shots.shot3, shots.shot1) return shots
def shot_by_type(self, cur_shot): if cur_shot.type == 5: for cards in self.form_5(): if len(cards) != 5: break if cur_shot.check_big(cards): self.remove_cards(cards) return Shot(cards=cards, type=5, team=self.team) return Shot(team=self.team) # type 1, 2, 3 for card_type, v in self.split_cards.items(): for iter_cards in v: if len(iter_cards) < cur_shot.type: break cards = iter_cards[:cur_shot.type] # print(f"check card_type={card_type}, iter_cards={iter_cards}, cards={cards}") if cur_shot.check_big(cards): self.remove_cards(cards) return Shot(cards=cards, type=len(cards), team=self.team) return Shot(team=self.team)
def create_shot(self, direction_key): """ Create a Shot object and return it. Parameters ---------- direction_key: str String that describes the direction: 'UP', 'DOWN', 'RIGHT', 'LEFT'. """ return Shot(self.position, direction_key)
def update(cam): env = Environment env.clear_visible_objects() env.getScreen().fill((0, 0, 0)) env.clear_edges() if not env.player.inatmosphere: cam.top = False Stars.update(cam) Asteroid.updateTempAsteroids(cam) else: cam.top = True #Objects.Update(cam) env.sun.update2(cam) Emitter.update(cam) Shot.update(cam) env.player.update(cam) Mind.update(cam) Ship.updateUnOccupied(cam) DrawINFO.update(cam) env.draw()
def shot_by_input(self, cur_shot): print('Current cards: ', end='') self.show_cards() print(f"Please type your next shot, friend={cur_shot.is_friend(self.team)}:") cards_str = input().strip(' \n') if cards_str.lower() == 'pass': return Shot(team=self.team) cards_list = sorted([CARDS.index(char) for char in cards_str]) if (cur_shot.type == 0 or len(cards_list) == cur_shot.type) \ and self.check_cards_valid(cards_list): if len(cards_list) == 5: if cur_shot.type == 0 or cur_shot.check_big(cards_list): self.remove_cards(cards_list) return Shot(cards=cards_str, type=5, team=self.team) else: # print(f"cards_str={cards_str}, cards_list={cards_list}, big={big}") if cur_shot.type == 0 or cur_shot.check_big(cards_list): self.remove_cards(cards_list) return Shot(cards=cards_str, type=len(cards_str), team=self.team) print('Oops, wrong card!') return self.shot_by_input(cur_shot)
def fire(self): now = time.time() if (self.last_shot != None and now - self.last_shot < self.shot_interval): return self.last_shot = now shot = Shot() shot.sender = self #shot.sound.play() center = self.get_center() shot.y = center[0] shot.x = center[1] shot.rotation = self.rotation shot.move() variables.all_entities.add(shot)
def handle_player_input(player, shots, shoot_sound): keystate = pygame.key.get_pressed() direction = keystate[K_RIGHT] - keystate[K_LEFT] player.move(direction) firing = keystate[K_SPACE] if not player.reloading and firing and len(shots) < MAX_SHOTS: Shot(player.get_gun_position()) shoot_sound.play() player.reloading = firing
def take_shot(self, shot_location): hit_battleship = None is_hit = False for b in self.battleships: # Wir müssen nicht nur wissen, ob das Schiff getroffen wurde, sondern auch wo, damit Schuss für die nächsten Spielzüge "gespeichert" werden kann index = b.body_index(shot_location) if index is not None: is_hit = True b.hits[index] = True hit_battleship = b # Breakt raus, weil wir wissen, welches Schiff getroffen wurde und nur eins zur Zeit getroffen werden kann break self.shots.append(Shot(shot_location, is_hit)) return hit_battleship
def next_shot(self, cur_shot): self.split_cards = Card.split_cards(self.cards) if self.type == 'USER': while True: try: return self.shot_by_input(cur_shot) except: print('Oops, wrong card!') if cur_shot.type == 0: return self.new_round_shot() elif self.check_friend_shot(cur_shot): return Shot(team=self.team) else: return self.shot_by_type(cur_shot)
def tick(self, player_obj): if time.time() >= self.time_start + self.fuse: angle = 0 for i in range(0, 8, 1): angle += 360 / 8 new_shot = Shot(angle=math.radians(angle), px=self.cord_x, py=self.cord_y, speed=3.25, size=player_obj.shot_size, distance=75, shot_list=player_obj.shots) player_obj.shots.append(new_shot) player_obj.bombs.remove(self)
def getVacuum(shot): if shot.shot['plasma'] < 0.5: raise AttributeError( 'Cannot find vacuum shot for another vacuum shot (' + str(int(shot.shot['shotno'])) + ')') # shots = [] for i in range( int(shot.shot['shotno']) - 1, int(shot.shot['shotno']) - vacuumHistory, -1): vacuum = Shot(i) if vacuum['plasma'] < 0.5: if ((vacuum['ub'] == shot.shot['ub']) & (vacuum['ucd'] == shot.shot['ucd'])): return vacuum raise AttributeError('Cannot find vacuum shot for shot (' + str(int(shot.shot['shotno'])) + ')')
def run_game(file_path): music_file_name = file_path songs_file = '' lame_path = 'lame.exe' screen_w = display_width screen_h = display_height percentage_displayed_f = 0.007 #Percentage of frequencies to show (Removes higher frequencies) Range = [0, 1] max_height_percentile = 80 fftlength = 2048 entertainment = False while True: #While no valid file if music_file_name[len(music_file_name) - 4:] == '.mp3' and Path( lame_path).is_file(): #if mp3, convert if possible print('Attempting to convert mp3 file into wav') call([ "lame", "--decode", music_file_name, music_file_name[:len(music_file_name) - 4] + '.wav' ], shell=True) music_file_name = music_file_name[:len(music_file_name) - 4] + '.wav' elif music_file_name[len(music_file_name) - 4:] != '.wav': music_file_name += '.wav' if songs_file != '': music_file_name = songs_file + "//" + music_file_name sr, original_signal = scipy.io.wavfile.read(music_file_name) break print("Found File!") print("Stereo to Mono Conversion") music = scipy.mean( original_signal, axis=1) #Combining both ears (computationally intensive) print('Fourier Transform') #f, t are axis, Sxx is 2d array f, t, Sxx = scipy.signal.spectrogram( music, sr, nperseg=fftlength) #Sxx[frequency][time] no_of_displayed_f = int(len(f) * percentage_displayed_f + 0.5) Sxx = Sxx[:no_of_displayed_f - 2].transpose( ) #Sxx[time][frequency] Last Frequency at 10163.671875 f = f[:no_of_displayed_f - 2] print("Playing...") pygame.init() screen = pygame.display.set_mode( (screen_w, screen_h)) #creates main screen surface rect_scale_factor = screen_h / scipy.percentile(Sxx, max_height_percentile) done = False dt = t[1] - t[0] #Printing clock and title on bottom right pygame.font.init() myfont = pygame.font.SysFont('Verdana', 20) title = myfont.render(music_file_name, False, (0, 255, 255)) #Initialising colour array for rectangles colours = [] colour_f = 0.05 #Colour Frequency for i in range(no_of_displayed_f): colours.append((225, 0, 0)) #Initialising timer and music start_time = time.time() song = pygame.mixer.Sound(file_path) pygame.mixer.music.load(music_file_name) #Load and play music pygame.mixer.music.play(1) #Precalulations to make animation smoother Sxx_len = len(Sxx) rect_width = screen_w / no_of_displayed_f done = False #Animation Loop game = True lines = [ display_width // 2 - 108 - 12, display_width // 2 - 54 - 12, display_width // 2 - 12, display_width // 2 + 54 - 12, display_width // 2 + 108 - 12 ] shots0 = [] shots1 = [] shots2 = [] shots3 = [] shots4 = [] #boss = Boss(display_width // 2, 30, 20, 30) player = Player(display_width // 2 - 7, display_height - 40, 14, 15) firstLineNodeNumber = 100 secondLineNodeNumber = 100 thirdLineNodeNumber = 100 foursLineNodeNumber = 100 fivesLineNodeNumber = 100 while game: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() quit() if event.type == pygame.KEYDOWN: if event.key == pygame.K_LEFT: player.moveLeft() if event.key == pygame.K_RIGHT: player.moveRight() if (not pygame.mixer.music.get_busy()): return player.hp display.fill((0, 0, 0)) #pygame.draw.rect(display, (255, 255, 255), (boss.x, boss.y, boss.width, boss.height)) pygame.draw.rect(display, (0, 0, 255), (player.x, player.y, player.width, player.height)) for shot in shots0: if not (shot.isRunAway()): shot.draw(random.randint(3, 5)) if shot.isShotTouchPoint(player.x, player.y): player.hp -= 5 shots0.remove(shot) if player.hp == 0: return 0 else: shots0.remove(shot) for shot in shots1: if not (shot.isRunAway()): shot.draw(random.randint(3, 6)) if shot.isShotTouchPoint(player.x, player.y): player.hp -= 5 shots1.remove(shot) if player.hp == 0: return 0 else: shots1.remove(shot) for shot in shots2: if not (shot.isRunAway()): shot.draw(random.randint(3, 6)) if shot.isShotTouchPoint(player.x, player.y): player.hp -= 5 shots2.remove(shot) if player.hp == 0: return 0 else: shots2.remove(shot) for shot in shots3: if not (shot.isRunAway()): shot.draw(random.randint(3, 4)) if shot.isShotTouchPoint(player.x, player.y): player.hp -= 5 shots3.remove(shot) if player.hp == 0: return 0 else: shots3.remove(shot) for shot in shots4: if not (shot.isRunAway()): shot.draw(random.randint(3, 5)) if shot.isShotTouchPoint(player.x, player.y): player.hp -= 5 shots4.remove(shot) if player.hp == 0: return 0 else: shots4.remove(shot) draw_hp_bar(display, 10, 10, player.hp) pygame.display.update() clock.tick(100) cur_time = time.time() - start_time timer = myfont.render(str(int(cur_time)) + "s", False, (0, 255, 255)) #Timer #Puts timer on screen #Puts sound file name on screen main_time_index = int(cur_time // dt) if int(cur_time) != int(song.get_length()): for index, frequency in enumerate(Sxx[(main_time_index)]): proportion_of_tleft = main_time_index - (main_time_index) height = max( proportion_of_tleft * frequency + (1 - proportion_of_tleft) * Sxx[(main_time_index) + 1][index], 2 / rect_scale_factor) #Draws rectangles where height combines 2 nearest time bins by proportion for each frequency (height of 2px if no amplitude) if (index == 0): if (height * rect_scale_factor > firstLineNodeNumber): if (checkCollision(shots0, 0, lines)): shots0.append(Shot((255, 0, 0), 24, lines[0], 0)) firstLineNodeNumber += 150 else: if (firstLineNodeNumber > 600): firstLineNodeNumber -= 5 firstLineNodeNumber -= 0.8 if (index == 1): if (height * rect_scale_factor > secondLineNodeNumber): if (checkCollision(shots1, 1, lines)): shots1.append(Shot((255, 0, 0), 24, lines[1], 0)) secondLineNodeNumber += 200 else: if (secondLineNodeNumber > 1000): secondLineNodeNumber -= 7 secondLineNodeNumber -= 1 if (index == 2): if (height * rect_scale_factor > thirdLineNodeNumber): if (checkCollision(shots2, 2, lines)): shots2.append(Shot((255, 0, 0), 24, lines[2], 0)) thirdLineNodeNumber += 300 else: if (thirdLineNodeNumber > 700): thirdLineNodeNumber -= 5 thirdLineNodeNumber -= 0.7 if (index == 3): if (height * rect_scale_factor > foursLineNodeNumber): if (checkCollision(shots3, 3, lines)): shots3.append(Shot((255, 0, 0), 24, lines[3], 0)) foursLineNodeNumber += 200 else: if (foursLineNodeNumber > 1300): foursLineNodeNumber -= 6 foursLineNodeNumber -= 0.7 if (index == 4): if (height * rect_scale_factor > fivesLineNodeNumber): if (checkCollision(shots4, 4, lines)): shots4.append(Shot((255, 0, 0), 24, lines[4], 0)) fivesLineNodeNumber += 100 else: if (fivesLineNodeNumber > 800): fivesLineNodeNumber -= 4 fivesLineNodeNumber -= 0.3
def init_shot(speed, rect, maprects): global shots shots.append(Shot(speed, rect, maprects))
from SigMod import * from Shot import Shot import numpy as np import matplotlib.pyplot as plot # obtain vacuum shot a nd plasma shot shot = Shot(26793) # plasma shot shotv = Shot(26790) # vacuum shot # obtain data from mirnov coils (already integrated) time, mc5_p = shot['mirnov_5'] time, mc5_v = shotv['mirnov_5'] time, mc13_p = shot['mirnov_13'] time, mc13_v = shotv['mirnov_13'] # remove offset mc5_p -= np.average(mc5_p[time < 0.004]) mc5_v -= np.average(mc5_v[time < 0.004]) mc13_p -= np.average(mc13_p[time < 0.004]) mc13_v -= np.average(mc13_v[time < 0.004]) mc5_p = movingAverage(mc5_p, 10) mc5_v = movingAverage(mc5_v, 10) mc13_p = movingAverage(mc13_p, 10) mc13_v = movingAverage(mc13_v, 10) # clear signal mc5 = mc5_p - mc5_v mc13 = mc13_p - mc13_v # only for diplay original data and clear signal # plot.plot(time, mc5_p, label='mc5_plasma')
def Shoot(self, pos, rot, ant): #def __ ( pos=[0, 0, 0], rot= , scale, angle_rad=0, speed=1, damage=0, shape=0, color=[255, 0, 0]): if self.updateTimer() and self.updateTemp(): Shot(ant, [pos.X(), pos.Y(), 0], self.getRotation(), self.getScale(), rot, self.getSpeed(), self.totalDamage(), self.getShape(), self.getColor(), self.getOffset(), self.dst)