图形应该从上到下随机放置。当图形从屏幕上落下并“消失”时,它应该在从上到下的任意位置再次落下。我总是收到以下错误消息:“randrange()的空范围(0,-799,-799)”。 在图形出现在游戏窗口之前,它必须有一个负的y坐标?那么,我怎样才能制造坠物呢
from random import randint
import pygame
WIDTH = 800
HEIGHT = 800
apple = Actor("apple")
apple.pos = randint(0, 800), randint(0, -800)
score = 0
def draw():
screen.clear()
apple.draw()
screen.draw.text("Punkte: " + str(score), (700, 5), color = "white")
def update():
if apple.y < 800:
apple.y = apple.y + 4
else:
apple.x = randint(0, 800)
apple.y = randint(0, -800)
使用^{} 时,
a
必须小于或等于b
:apple.y = randint(0, -800)
注意,
randint
返回一个随机整数N
,这样a <= N <= b
注意,如果要在屏幕顶部启动
apple
,则必须将y坐标设置为0(或苹果的-radius):实际上,您要做的是将
apple
设置在屏幕上方的一个随机位置相关问题 更多 >
编程相关推荐