让一个圆消失,同时让另一个圆出现
我正在尝试为iOS重新制作一个叫做Flappy Fall的游戏,但我在让一个圆圈消失而另一个出现时遇到了问题。目前我有这个作为主循环。
while True:
if newBall==True:
x=rand(50,w-50)
y=-7
newBall=False
if x in range(xBasket-length,xBasket+length) and y in range(yBasket-int(length/2),yBasket+int(length/2)): #If the circle hit's the basket
newBall=True #Creates a new ball
score+=1
elif x in range(0,w) and y in range(700,751): #If it hits the ground
break
if newBall==False: #If there is no new ball yet
y-=7
win.fill(BLACK)
font=pygame.font.Font(None,48)
show=font.render(str(score),1,RED,None)
win.blit(show,(200,150))
pygame.draw.rect(win,RED,(0,700,w,h),0) #ground
for event in pygame.event.get():
if event.type==QUIT:
pygame.quit()
sys.exit()
if event.type==KEYDOWN:
if event.key==K_LEFT and xBasket-length!=0:
xBasket-=5
if event.key==K_RIGHT and xBasket+length!=w:
xBasket+=5
pygame.draw.circle(win,BLUE,(x,y),7) #ball that falls
pygame.draw.polygon(win,WHITE,((xBasket-length,yBasket-int(length/2)),(xBasket+length,yBasket-int(length/2)),(xBasket+length,yBasket+int(length/2)),(xBasket-length,yBasket+int(length/2)),0)) #basket
pygame.display.update()
time.delay(5)
s(0.001)
我不知道哪里出错了,因为“篮子”显示得很好。
2 个回答
0
试试在你画圆圈之前检查一下你的数值。
print x,y
看起来你的y值是负数,而我觉得你需要正数的坐标才能在画布上画东西。
补充:我确认了,我把y=-7改成y=300后,你的代码就能正常工作了,一个小蓝球就往上移动了。此外,这可能没什么关系,但我还得把字体那一行改成:
show=font.render(str(score),1,RED)#,None)
不过我觉得这跟我使用的python和pygame版本关系更大。
0
在第12行,你现在只有y = -7,可能你还想在它之前加上x = rand(50, 50-w)这一行,这样你就有了x和y两个位置,而不仅仅是y的位置。
x = rand(50, 50-w)
y = -7