Commit f52d9ebb authored by santiago duque's avatar santiago duque

added second button and logic to stop events as a test

parent b7ed47b8
...@@ -17,7 +17,7 @@ window = pygame.display.set_mode((winW, winH)) ...@@ -17,7 +17,7 @@ window = pygame.display.set_mode((winW, winH))
# window.fill((205,100,100)) # window.fill((205,100,100))
# pygame.display.update() # pygame.display.update()
clock = pygame.time.Clock() #clock = pygame.time.Clock()
def reset_sounds(): def reset_sounds():
...@@ -53,9 +53,6 @@ def play_sound(index): ...@@ -53,9 +53,6 @@ def play_sound(index):
global current_sound_index global current_sound_index
global channel global channel
global sound_array global sound_array
global btn_array
btn_array[index].when_pressed = None
if not cut_current_sound: if not cut_current_sound:
current_sound_index = index current_sound_index = index
...@@ -117,16 +114,23 @@ current_sound_index = -1 ...@@ -117,16 +114,23 @@ current_sound_index = -1
# run setup # run setup
setup_paths(False) setup_paths(False)
def btn_pressed(index):
global btn_array
btn_array[index].when_pressed = None
print('btn pressed')
play_sound(index)
def resetBtn(index): def resetBtn(index):
global btn_array global btn_array
btn_array[index].when_pressed = lambda: play_sound(index) btn_array[index].when_pressed = lambda: play_sound(index)
btn1 = Button(21) btn1 = Button(21)
btn1.when_pressed = lambda: play_sound(0) btn1.when_pressed = lambda: btn_pressed(0)
btn1.when_released = lambda: resetBtn(0) btn1.when_released = lambda: resetBtn(0)
btn2 = Button(13) btn2 = Button(13)
btn2.when_pressed = lambda: play_sound(1) btn2.when_pressed = lambda: btn_pressed(1)
btn2.when_released = lambda: resetBtn(1) btn2.when_released = lambda: resetBtn(1)
btn_array = [btn1, btn2] btn_array = [btn1, btn2]
...@@ -135,7 +139,7 @@ btn_array = [btn1, btn2] ...@@ -135,7 +139,7 @@ btn_array = [btn1, btn2]
run = True run = True
while run: while run:
clock.tick(25) #clock.tick(25)
for event in pygame.event.get(): for event in pygame.event.get():
if event.type == pygame.QUIT: if event.type == pygame.QUIT:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment