2017-05-26 32 views
0

私は自分のソーシャルスタディクラスのためにPygameを作っています。私はこの既存のゲームに新しい要素を追加したいと思います。問題は、古いゲームを読み込んだときに大きな変更を加えることなくエラーが発生することです。私は見たことがあるが、スレッドの大部分は数年前からのものです。Pygame - ミキサーシステムが初期化されていない

Jordans-MacBook-Air:SS-Game Jordanxxi$ python ocean_cleaner.py 
2017-05-26 12:23:15.729 Python[61184:1392206] Warning once: This application, or a library it uses, is using NSQuickDrawView, which has been deprecated. Apps should cease use of QuickDraw and move to Quartz. 
May 26 12:23:15 Python[61184] <Error>: The function ‘SLSFlushWindow’ is obsolete and will be removed in an upcoming update. Unfortunately, this application, or a library it uses, is using this obsolete function, and is thereby contributing to an overall degradation of system performance. Please use `SLSFlushWindowContentRegion' instead. 
Traceback (most recent call last): 
    File "ocean_cleaner.py", line 30, in <module> 
    hit = pygame.mixer.Sound("resources/audio/pop.wav") 
pygame.error: mixer system not initialized 

私のコードを、今のところ、以下のとおりである:私のエラーは、次の通りである

#Import statements 
import pygame, sys 
import pygame.mixer 
import time 
from pygame.locals import * 

#Pygame function to load the game and screen size 
pygame.init() 
screen = pygame.display.set_mode((700,500)) 

#Images needed in game 
background = pygame.image.load("resources/images/background.png") 
slick = pygame.image.load("resources/images/slick.png") 
slick_med = pygame.image.load("resources/images/slick_med.png") 
slick_sml = pygame.image.load("resources/images/slick_sml.png") 
diver = pygame.image.load("resources/images/diver_gun.png") 
diver1 = pygame.image.load("resources/images/diver_gun1.png") 
spray_right = pygame.image.load("resources/images/spray_right.png") 
spray_left = pygame.image.load("resources/images/spray_left.png") 
win_screen = pygame.image.load("resources/images/win_screen.png") 
lose_screen = pygame.image.load("resources/images/lose_screen.png") 
red_bar = pygame.image.load("resources/images/red_bar.png") 
green_bar2 = pygame.image.load("resources/images/green_bar2.png") 
green_bar4 = pygame.image.load("resources/images/green_bar4.png") 
air_bar = pygame.image.load("resources/images/air_bar.png") 
spray_bar = pygame.image.load("resources/images/spray_bar.png") 

#Sounds 
hit = pygame.mixer.Sound("resources/audio/pop.wav") 
hit.set_volume(0.5) 
wash = pygame.mixer.Sound("resources/audio/spray.wav") 
wash.set_volume(0.4) 
pygame.mixer.music.load('resources/audio/tune_1.wav') 
pygame.mixer.music.play(-1, 0.0) 
pygame.mixer.music.set_volume(0.25) 

#The Variables 
player = diver 
spray = spray_right 
spray_off_set = 0 
pop=False 
pop_index=0 
player_x = 250 
player_y = 100 
background_x = 0 
background_y = 0 
move_x = 0 
move_y = 0 
keys=[False,False,False,False,False] 
slick_large=[[slick,300,250],[slick,1000,650],[slick,1400,1050]]  
slick_medium =[] 
slick_small = [] 
clean_up = 12 
life = True 
sprays = 30 

main_loop = 1 
while main_loop: 

    pygame.display.set_caption('Greek Mythology Quiz') 

    #How the charater moves when certain keys are clicked 
    #---------------------------------------------------# 
    #Move Right 
    if keys[0]==True and move_x <5: 
     move_x+= 1 
     player = diver1 
     spray = spray_left 
     spray_off_set = -200 
    #Move Left 
    if keys[1]==True and move_x >-1310: 
     move_x-= 1 
     player = diver 
     spray = spray_right 
     spray_off_set = 0 
    #Move Up 
    if keys[2]==True and move_y <10: 
     move_y+= 1 
    #Move Down 
    if keys[3]==True and move_y >-1010: 
     move_y-= 1 


    #Check for collisions 
    spray_rect=pygame.Rect(spray.get_rect()) 
    spray_rect.left=(350+spray_off_set) 
    spray_rect.top=100 

    player_rect=pygame.Rect(player.get_rect()) 
    player_rect.left= player_x 
    player_rect.top= player_y  

    for i in range(len(slick_large)): 
     slick_rect=pygame.Rect(slick.get_rect()) 
     slick_rect.left=((slick_large[i][1])+move_x) 
     slick_rect.top=(slick_large[i][2]+move_y) 
     if spray_rect.colliderect(slick_rect) and keys[4] == True: 
      pop=True 
      pop_index=i 
     if player_rect.colliderect(slick_rect): 
      life = False 
    #When pop sound is called, volume depends on object size 
    if pop==True: 
     hit.play() 
     slick_medium.append([slick_med,(slick_large[pop_index][1]+75),(slick_large[pop_index][2]-50)]) 
     slick_medium.append([slick_med,(slick_large[pop_index][1]+150),(slick_large[pop_index][2]+50)]) 
     slick_large.pop(pop_index) 
     pop=False 

    #Collision redirect physics 
    for i in range(len(slick_medium)): 
     slick_rect=pygame.Rect(slick_med.get_rect()) 
     slick_rect.left=((slick_medium[i][1])+move_x) 
     slick_rect.top=(slick_medium[i][2]+move_y) 
     if spray_rect.colliderect(slick_rect) and keys[4] == True: 
      pop=True 
      pop_index=i 
     if player_rect.colliderect(slick_rect): 
      life = False 
    if pop==True: 
     hit.play() 
     slick_small.append([slick_sml,(slick_medium[pop_index][1]-75),(slick_medium[pop_index][2]-75)]) 
     slick_small.append([slick_sml,(slick_medium[pop_index][1]-150),(slick_medium[pop_index][2]-50)]) 
     slick_medium.pop(pop_index) 
     pop=False 

    for i in range(len(slick_small)): 
     slick_rect=pygame.Rect(slick_sml.get_rect()) 
     slick_rect.left=((slick_small[i][1])+move_x) 
     slick_rect.top=(slick_small[i][2]+move_y) 
     if spray_rect.colliderect(slick_rect) and keys[4] == True: 
      pop=True 
      pop_index=i 
     if player_rect.colliderect(slick_rect): 
      life = False  
    if pop==True: 
     hit.play() 
     slick_small.pop(pop_index) 
     clean_up -=1 
     pop=False 


    #Background scrolling 
    screen.fill(0) 

    screen.blit(background,((background_x+move_x),(background_y+move_y))) 
    screen.blit(player,(player_x,player_y)) 

    if keys[4]==True: 
     wash.play() 
     screen.blit(spray,((350+spray_off_set),100)) 
    else: 
     wash.stop() 

    for i in range(len(slick_large)):  
     screen.blit(slick_large[i][0],((slick_large[i][1]+move_x),(slick_large[i][2]+move_y))) 

    for i in range(len(slick_medium)):  
     screen.blit(slick_medium[i][0],((slick_medium[i][1]+move_x),(slick_medium[i][2]+move_y))) 

    for i in range(len(slick_small)):  
     screen.blit(slick_small[i][0],((slick_small[i][1]+move_x),(slick_small[i][2]+move_y))) 

    time_remaining = int((60-(pygame.time.get_ticks()/1000))) 
    screen.blit(air_bar,(8,8)) 
    screen.blit(red_bar,(10,10)) 
    for i in range(time_remaining): 
     screen.blit(green_bar2,(10+(i*2),10)) 


    screen.blit(spray_bar,(570,8)) 
    screen.blit(red_bar,(572,10)) 
    for i in range(sprays): 
     screen.blit(green_bar4,(572+(i*4),10)) 


    if clean_up == 0: 
     screen.blit(win_screen,(0,0)) 
     main_loop = 0 
    if life == False or sprays == 0 or time_remaining == 0: 
     screen.blit(lose_screen,(0,0)) 
     main_loop = 0 

    pygame.display.flip() 


    for event in pygame.event.get(): 
     if event.type==pygame.QUIT: 
      pygame.quit() 
      exit(0) 
     #Event checkers - Check to see if certain keys are pressed 
     if event.type == pygame.KEYDOWN: 
      if event.key==K_LEFT: 
       keys[0]=True 
      elif event.key==K_RIGHT: 
       keys[1]=True 
      elif event.key==K_UP: 
       keys[2]=True 
      elif event.key==K_DOWN: 
       keys[3]=True 
      elif event.key==K_SPACE: 
       keys[4]=True 
     #Check to see when certain keys are released 
     if event.type == pygame.KEYUP: 
      if event.key==K_LEFT: 
       keys[0]=False 
      elif event.key==K_RIGHT: 
       keys[1]=False 
      elif event.key==K_UP: 
       keys[2]=False 
      elif event.key==K_DOWN: 
       keys[3]=False 
      elif event.key==K_SPACE: 
       keys[4]=False 
       sprays -= 1 

end = 1 
while end: 
    #Exit function 
    for event in pygame.event.get(): 
     if event.type==pygame.QUIT: 
      pygame.quit() 
      exit(0) 

任意のヘルプ?前もって感謝します。

更新 - Idleの代わりに端末でゲームを実行していました。私はまだエラーが発生しますが、それは少し異なります。誰でもこれを修正する方法を知っていますか?

Traceback (most recent call last): 
    File "/Users/Jordanxxi/Desktop/Game/ocean_cleaner.py", line 29, in <module> 
    hit = pygame.mixer.Sound("resources/audio/pop.wav") 
error: mixer system not initialized 

答えて

0

私はあなたがしなければならないと信じて:

pygame.mixer.init() 

(これは常にあなたが問題を抱えているとき、最初に行うのは良いアイデアです!)ミキサーのためのマニュアルを参照してください:http://www.pygame.org/docs/ref/mixer.html

関連する問題