所以我试图在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)
我不知道哪里出了问题,因为“篮子”出现得很好。在
试试看
在你画圆之前检查你的值。看起来你的y值是负的,我相信你需要正坐标才能在画布上绘制。在
编辑:确认了,我把y=-7改成y=300,你的代码开始工作了,屏幕上出现了一个蓝色的小球。另外,这可能是无关的,但我不得不编辑字体行:
^{pr2}$但我认为这与我的python和pygame版本有关。在
在第12行,您只有y=-7,也许您还想在它前面包含x=rand(50,50-w)行,这样您就有了一个
x
和一个y
位置,而不仅仅是y
位置。在x = rand(50, 50-w)
y = -7
相关问题 更多 >
编程相关推荐