bif="bg.jpg"
mif="star.png"
a=["flag1.png","flag2.png","flag3.png","flag4.png"]
import pygame,sys
from pygame.locals import *
pygame.init()
pygame.display.set_caption('GAME')
screen=pygame.display.set_mode((800,600),0,32)
background=pygame.image.load(bif).convert()
mouse_c=pygame.image.load(mif).convert_alpha()
mouse_d0=pygame.image.load(a[0]).convert_alpha()
mouse_d1=pygame.image.load(a[1]).convert_alpha()
mouse_d2=pygame.image.load(a[2]).convert_alpha()
mouse_d3=pygame.image.load(a[3]).convert_alpha()
clock=pygame.time.Clock()
score=0
x,y=0,480
movex,movey=0,0
a,b=800,600
movea,moveb=0,0
speed=170
speeda=150
speedb=170
zicolor=(255,255,255)#########
fontobj=pygame.font.Font('freesansbold.ttf',32)###########
textsurfaceobj=fontobj.render(score,False,zicolor)#########################
textrectobj=textsurfaceobj.get_rect()#########
textrectobj.center=(200,150)########
while True:
milli=clock.tick()
seconds=milli/1000.
dm=seconds*speed
dma=seconds*speeda
dmb=seconds*speedb
for event in pygame.event.get():
if event.type==QUIT:
pygame.quit()
sys.exit()
if event.type==KEYDOWN:
if event.key==K_LEFT:
movex=-1
elif event.key==K_RIGHT:
movex=+1
elif event.key==K_UP:
movey-=2
elif event.key==K_DOWN:
movey=dm
if event.type==KEYUP:
if event.key==K_LEFT:
movex=0
elif event.key==K_RIGHT:
movex=0
elif event.key==K_UP:
movey=dm
elif event.key==K_DOWN:
movey=dm
a-=dma
b-=dmb
x+=movex
y+=movey
if x>700:
x=700
if y>500:
y=500
if x<1:
x=1
if y<8:
y=8
if a<0:
a=800
score+=1
if b<0:
b=600
if (a-x)<128 and(a-x)>0:
if(b-y)<128 and(b-y)>0:
score-=1
elif (y-b)>0 and(y-b)<48:
score-=1
screen.blit(background,(0,0))
screen.blit(mouse_c,(x,y))
screen.blit(mouse_d0,(a,b))
screen.blit(textsurfaceobj,textrectobj)##########
pygame.display.update()
这是我编的小游戏,代码后加注了“######”的是显示变量相关的代码,在“#####################”(最长的#所标注的代码行)上,写上score这个变量就出错,只能写'hello'这类的静态str,如果我想把分数动态的显示出来需要怎么做呢?谢谢了~~实在木有办法了再这儿求助。。。中秋在代码中度过了。。。祝大家中秋+国庆愉快~~