我正在使用 pygame 制作游戏,我将每个部分制作在一个单独的文件中,例如主页、说明页面、实际游戏等,但我不知道如何将它们放在一起。我考虑过使用这段代码
from graphics import*
w = GraphWin("Window", 600,400)
playing = True
while playing:
click = w.getMouse()
potato = click.getX()
carrot = click.getY()
if potato < 300 and carrot < 200:
newWin = GraphWin("New", 200, 200)
if potato > 300 and carrot > 200:
w.setBackground("blue")
if potato < 300 and carrot > 200:
playing = False
w.close()
n = GraphWin("Homepage", 500, 200)
n.getMouse()
n.close()
但我仍然不知道如何将它们放在一起。你能帮我看看如何把这两个文件放在一起吗?这个文件是主页:
from graphics import*
import pygame
import sys
import random
from time import sleep
padWidth = 500 #the width the of game
padHeight = 600 # the length of the game
white = (255,255,255)
black = (0,0,0)
red = (255,0,0)
def writeIns(text):
global gamePad
textfont = pygame.font.Font('Ranchers-Regular.ttf', 29) #textfont of the game message
text = textfont.render(text, True, red) #red text
textpos = (158,417)
gamePad.blit(text, textpos) #print the text
pygame.display.update()
def drawObject(obj, x, y):
global gamePad
gamePad.blit(obj, (int(x), int(y)))
def initGame():
global gamePad, clock, background
pygame.init()
gamePad = pygame.display.set_mode((padWidth, padHeight))
pygame.display.set_caption('Shooting game') #the title of the game
clock = pygame.time.Clock()
def runGame():
global gamePad, clock, background
onGame = False
while not onGame:
for event in pygame.event.get():
if event.type in [pygame.QUIT]:
pygame.quit()
sys.exit()
drawObject(background, 0, 0) #display the background
pygame.draw.rect(gamePad, black, (120,400,250,70))
writeIns('INSTRUCTIONS')
pygame.display.update()
clock.tick(60)
pygame.quit()
initGame()
runGame()
PIPIONE
相关分类