Skip to content

Instantly share code, notes, and snippets.

@codetricity
Created March 2, 2014 17:21
Show Gist options
  • Save codetricity/9309998 to your computer and use it in GitHub Desktop.
Save codetricity/9309998 to your computer and use it in GitHub Desktop.
Example of Python, Pygame, PGS4A Sound
import pygame, sys
pygame.init()
try:
import android
except ImportError:
android = None
if android:
android.init()
android.map_key(android.KEYCODE_BACK, pygame.K_ESCAPE)
try:
import pygame.mixer as mixer
except ImportError:
import android.mixer as mixer
screen = pygame.display.set_mode((480, 320))
# load the sound file
# suggest using .wav format, especially for the first test
mixer.music.load("boom.wav")
# load fonts
font_a = pygame.font.Font("font_a.ttf", 32)
button_boom = font_a.render("Press Here for Boom", True, (200, 0,0), (0, 200, 0) )
boom_box = button_boom.get_rect(centerx = 100, centery= 120)
while True:
for event in pygame.event.get():
if (event.type == pygame.QUIT) or event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
pygame.quit()
sys.exit()
elif event.type == pygame.MOUSEBUTTONDOWN:
mixer.music.play()
screen.blit(button_boom, boom_box)
pygame.display.update()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment