我正在创建一个视频游戏,我希望当汽车向前移动时背景重复,因此屏幕的左侧随着汽车的末端移动。我相信它与循环以及img1和img2变量有关。这是我到目前为止的代码:
currX = 0
dX = 1
images = []
def setup():
global img1
global img2
background(255)
size(400,400)
img1 = loadImage("road.jpg")
img2 = loadImage("road.jpg")
def draw():
global img1
global img2
image(img1,0,0,width,height)
global currX, dX
drawCar(currX,200)
currX += dX
if currX > width - 110 or currX < 0:
dX = +dX
if currX > 1:
images.append(img2)
def drawCar(x,y):
pushMatrix()
translate(x,y)
fill(255,0,0)
rect(0,0,100,50)
fill(0)
for wheelX in [5,15,65,75,87,102]:
ellipse(wheelX,55,15,15)
stroke(255,0,0)
fill(255,0,0)
rect(100,15,50,30)
fill(0)
rect(115,15,20,20)
popMatrix()
请帮忙或提供一些建议!我真的很感激!