Something

This commit is contained in:
Bruno Rybársky 2021-10-30 19:38:33 +02:00
parent 84b930a628
commit b95a4d816a
3 changed files with 2 additions and 7 deletions

@ -29,8 +29,8 @@ class Bomb:
self.sprites.append(button)
def getevents(self):
for event in self.pygame.event.get(): # User did something
if event.type == self.pygame.QUIT: # If user clicked close
for event in self.pygame.event.get():
if event.type == self.pygame.QUIT:
return False
elif event.type == self.pygame.MOUSEBUTTONUP:
pos = self.pygame.mouse.get_pos()

@ -13,13 +13,10 @@ clock = pygame.time.Clock()
bomb = Bomb(pygame, screen)
while True:
bomb.drawstuff()
bomb.ticktimer += clock.tick(60)
bomb.beep()
if bomb.getevents() == False:
break
#Once we have exited the main program loop we can stop the game engine:
pygame.quit()

@ -5,14 +5,12 @@ class ToneGen():
def __init__(self, pygame, freq_l, freq_r, duration=1):
n_samples = int(round(duration*44100))
#setup our numpy array to handle 16 bit ints, which is what we set our mixer to expect with "bits" up above
buf = np.zeros((n_samples, 2), dtype = np.int16)
max_sample = 2**(16 - 1) - 1
for s in range(n_samples):
t = float(s)/44100 # time in seconds
#grab the x-coordinate of the sine wave at a given time, while constraining the sample to what our mixer is set to with "bits"
buf[s][0] = int(round(max_sample*sin(2*pi*freq_l*t))) # left
buf[s][1] = int(round(max_sample*0.5*sin(2*pi*freq_r*t))) # right
pygame.sndarray.make_sound(buf).play()