Something
This commit is contained in:
parent
84b930a628
commit
b95a4d816a
4
bomb.py
4
bomb.py
@ -29,8 +29,8 @@ class Bomb:
|
|||||||
self.sprites.append(button)
|
self.sprites.append(button)
|
||||||
|
|
||||||
def getevents(self):
|
def getevents(self):
|
||||||
for event in self.pygame.event.get(): # User did something
|
for event in self.pygame.event.get():
|
||||||
if event.type == self.pygame.QUIT: # If user clicked close
|
if event.type == self.pygame.QUIT:
|
||||||
return False
|
return False
|
||||||
elif event.type == self.pygame.MOUSEBUTTONUP:
|
elif event.type == self.pygame.MOUSEBUTTONUP:
|
||||||
pos = self.pygame.mouse.get_pos()
|
pos = self.pygame.mouse.get_pos()
|
||||||
|
3
main.py
3
main.py
@ -13,13 +13,10 @@ clock = pygame.time.Clock()
|
|||||||
bomb = Bomb(pygame, screen)
|
bomb = Bomb(pygame, screen)
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
|
|
||||||
bomb.drawstuff()
|
bomb.drawstuff()
|
||||||
|
|
||||||
bomb.ticktimer += clock.tick(60)
|
bomb.ticktimer += clock.tick(60)
|
||||||
bomb.beep()
|
bomb.beep()
|
||||||
if bomb.getevents() == False:
|
if bomb.getevents() == False:
|
||||||
break
|
break
|
||||||
|
|
||||||
#Once we have exited the main program loop we can stop the game engine:
|
|
||||||
pygame.quit()
|
pygame.quit()
|
@ -5,14 +5,12 @@ class ToneGen():
|
|||||||
def __init__(self, pygame, freq_l, freq_r, duration=1):
|
def __init__(self, pygame, freq_l, freq_r, duration=1):
|
||||||
|
|
||||||
n_samples = int(round(duration*44100))
|
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)
|
buf = np.zeros((n_samples, 2), dtype = np.int16)
|
||||||
max_sample = 2**(16 - 1) - 1
|
max_sample = 2**(16 - 1) - 1
|
||||||
|
|
||||||
for s in range(n_samples):
|
for s in range(n_samples):
|
||||||
t = float(s)/44100 # time in seconds
|
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][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
|
buf[s][1] = int(round(max_sample*0.5*sin(2*pi*freq_r*t))) # right
|
||||||
pygame.sndarray.make_sound(buf).play()
|
pygame.sndarray.make_sound(buf).play()
|
||||||
|
Loading…
Reference in New Issue
Block a user