Pygame 2初学者级别开始画面

时间:2014-01-04 13:43:11

标签: python pygame

我是刚开始使用pygame的基础程序员。我现在正在制作RPG游戏而且我被卡住了。我已经制作了开始屏幕,但之后我想点击鼠标运行一些开始游戏的代码。目前,我点击后循环继续。有人能帮帮我吗?

     import pygame,sys
import time

from pygame.locals import * 

pygame.init()

FPS=40
fpsclock=pygame.time.Clock()
startgame=False
DISPLAYSURF=pygame.display.set_mode((800,800))
pygame.display.set_caption('Currently, Clicking will only freeze program.')

WHITE=(255,255,255)
GREEN=(0,255,25)
BLUE=(0,0,255)

startbuttonImg=pygame.image.load('startbutton.png')
startbuttonx=150
startbuttony=445
titlesword1Img=pygame.image.load('titlesword1.png')
titlesword2Img=pygame.image.load('titlesword2.png')
titlesword1x=10
titlesword1y=10
titlesword1direction='r1'
titlesword2x=700
titlesword2y=550
titlesword2direction='l2'

mouseClicked=False

ourMenu= (startbuttonImg)
while startgame==False:
    fontObj1=pygame.font.Font('freesansbold.ttf', 60)
    textSurfaceObj1=fontObj1.render('Insert Awesome Title Here',True,GREEN,BLUE)
    textRectObj1=textSurfaceObj1.get_rect()
    textRectObj1.center=(400,400)

    fontObj2=pygame.font.Font('freesansbold.ttf', 40)
    textSurfaceObj2=fontObj2.render('By Peter Feng',True,BLUE,GREEN)
    textRectObj2=textSurfaceObj2.get_rect()
    textRectObj2.center=(400,465)

    fontObj3=pygame.font.Font('freesansbold.ttf',65)
    textSurfaceObj3=fontObj3.render('   The Legend of.....',True, BLUE,WHITE)
    textRectObj3=textSurfaceObj1.get_rect()
    textRectObj3.center=(400,300)





    mousex=0
    mousey=0

    DISPLAYSURF.fill(WHITE)
    DISPLAYSURF.blit(textSurfaceObj1,textRectObj1)
    DISPLAYSURF.blit(textSurfaceObj2,textRectObj2)
    DISPLAYSURF.blit(textSurfaceObj3,textRectObj3)



    if titlesword2direction=='l2':
        titlesword2x-=5
        if titlesword2x==10:
            titlesword2direction='r2'

    if titlesword2direction=='r2':
        titlesword2x+=5
        if titlesword2x==700:
            titlesword2direction='l2'

    if titlesword1direction =='r1':
        titlesword1x+=5
        if titlesword1x == 700:
            titlesword1direction='l1'

    if titlesword1direction =='l1':
        titlesword1x-=5
        if titlesword1x == 10:
            titlesword1direction='r1'

    DISPLAYSURF.blit(titlesword1Img,(titlesword1x, titlesword1y))
    DISPLAYSURF.blit(titlesword2Img,(titlesword2x, titlesword2y))
    DISPLAYSURF.blit(startbuttonImg,(startbuttonx,startbuttony))



    for event in pygame.event.get():
        if event.type==QUIT:
            pygame.quit()
            sys.exit()
        if event.type==pygame.MOUSEBUTTONDOWN:

            startgame==True






    pygame.display.update()


    fpsclock.tick()

1 个答案:

答案 0 :(得分:1)

startgame==True代替startgame = True

:)