Created
September 30, 2017 14:49
-
-
Save fgolemo/8e7f50e746efa4ef0e4532c724f8ec5a to your computer and use it in GitHub Desktop.
pygame play sample on keypress
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import time | |
import pygame | |
pygame.init() | |
pygame.mixer.init() | |
pygame.display.set_mode() | |
kick = pygame.mixer.Sound("../../Bass-Drum-1.wav") | |
snare = pygame.mixer.Sound("../../Ensoniq-ESQ-1-Snare.wav") | |
while True: | |
for event in pygame.event.get(): | |
if event.type == pygame.QUIT: | |
pygame.quit(); #sys.exit() if sys is imported | |
if event.type == pygame.KEYDOWN: | |
if event.key == pygame.K_m: | |
kick.play() | |
if event.key == pygame.K_x: | |
snare.play() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment