pygame只能编写游戏_Pygame游戏循环槽

新手在使用Pygame编写游戏时遇到游戏循环只能运行一次的问题。游戏主菜单可以正常启动,但点击'播放'后无法重新启动游戏循环。代码中展示了菜单和游戏循环的实现,但当尝试再次导入游戏主程序时,游戏无法重新开始。开发者寻求解决Python导入循环问题的方法。
摘要由CSDN通过智能技术生成

我是一个使用Pygame用Python语言编写游戏的新手。我的游戏循环有问题。我只能运行我的游戏一次,然后我不能再让我的游戏循环。我将在这里发布我的代码:

这是我的鼠标菜单(菜单.py)在import pygame, os, sys

from pygame.locals import *

pygame.init()

def play_music(name, volume=0.7, loop=-1):

fullname = os.path.join('data', name)

try:

pygame.mixer.music.load(fullname)

pygame.mixer.music.set_volume(volume)

pygame.mixer.music.play(loop)

except:

raise SystemExit, "Can't load: " + fullname

def load_sound(name, volume=0.05):

fullname = os.path.join('data', name)

try:

sound = pygame.mixer.Sound(fullname)

sound.set_volume(volume)

except:

raise SystemExit, "Can't load: " + fullname

return sound

def run_game():

import Grab

def reset_highscore():

open("data/highscore.sav", "w").write(str(0))

print "Grab High score reset to 0"

class GrabMenu():

os.environ["SDL_VIDEO_CENTERED"] = "1"

pygame.mouse.set_visible(0) #make the mouse cursor invisible

pygame.display.set_caption("Grab") #name the game

pygame.display.set_icon(pygame.image.load("data/Icon.png")) #set an icon for the game

screen = pygame.display.set_mode((800, 800)) #screen resolution width and height

background = pygame.Surface(screen.get_size()) #make

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值