0
私はあなたがリンゴをクリックしなければならないゲームを作ろうとしています。そして、それはランダムポジションになります。今のところ5秒あります。リンゴイメージを何回もクリックしなければなりません。ゲームは動作しますが、私は2つの問題があります:
1)ゲーム終了後、プログラムは応答しません。
2)時間は自分自身を更新し続けます(それはちらつきを続けます)。私はそれを望んでいません。 これらの2つのバグを修正するにはどうすればよいですか?pygameで時間の自動更新を修正するには?
import pygame
import time
import random
pygame.init()
foodimg=pygame.image.load("food.png")
foodrect=foodimg.get_rect()
#Colours
white = (255,255,255)
black = (0,0,0)
red = (255,0,0)
#Game Display
display_width = 1080
display_height = 720
gameDisplay = pygame.display.set_mode((display_width,display_height))
pygame.display.set_caption('Click It! ~ Snapnel Productions')
gameDisplay.fill((white))
font=pygame.font.SysFont("Arial",30)
a=6
running=True
while running:
gameDisplay.fill((white))
time=pygame.time.get_ticks()/1000
if a==time:
print "Game over"
break
for event in pygame.event.get():
if event.type==pygame.QUIT:
running=False
pygame.quit()
quit()
if event.type == pygame.MOUSEBUTTONDOWN:
# Set the x, y postions of the mouse click
x, y = event.pos
if foodrect.collidepoint(x, y):
foodrect.center=(random.randint(5,1060),random.randint(5,700))
print "New Position: ",foodrect.center
continue
gameDisplay.blit(foodimg,foodrect)
pygame.display.flip()
showtime=font.render("Time: "+str(time),0,(0,0,0))
gameDisplay.blit(showtime,(950,10))
pygame.display.flip()
Hereは私の食料画像です:
は、ここに私のコードです。
私にとっては、プログラムは正常に終了します –