Re: Audio wrapper for Python
Hmm, I see. If thats the goal then you'd probably need to track when a button is held with a variable and run it in the main loop. Something like this:
import pygame
from pygame import mixer
import sys
class Player:
def __init__(self):
self.x = 0
self.y = 0
self.z = 0
self.left = False
self.right = False
pygame.init() mixer.init() window = pygame.display.set_mode((800,600)) pygame.display.set_caption("Test Game") sound = mixer.Sound("Sounds\step.wav") clock = pygame.time.Clock() counter = 0 p = Player() while True: for event in pygame.event.get(): if event.type == pygame.KEYDOWN: if event.key == pygame.K_LEFT: if p.x > 0: p.left = True p.right = False p.x -= 1 sound.play() if event.key == pygame.K_RIGHT: if p.right <= 50: p.left = False p.right = True p.x += 1 sound.play() if event.key == pygame.K_ESCAPE: pygame.quit() sys.exit(0) if event.type == pygame.KEYUP: if event.key == pygame.K_LEFT: p.left = False if event.key == pygame.K_RIGHT: p.right = False if p.left == True or p.right == True: counter += clock.tick()/1000.0 if p.left == True and p.x > 0: if counter >= 1.0: counter = 0 p.x -= 1 sound.play() if p.right == True and p.x <= 50: if counter >= 1.0: counter = 0 p.x += 1 sound.play() pygame.display.update()
-- Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector