from Tkinter import *
window = Tk()
canvas = Canvas(window, width=500, height=500, background="green")
canvas.pack()
x0 = 225
y0 = 225
x1 = 275
y1 = 275
speed_x = 2
speed_y = 3
ball = canvas.create_oval(x0,y0,x1,y1,fill="blue", tag='ball')
while True:
canvas.move('ball', speed_x, speed_y)
canvas.after(30)
canvas.update()
if x1 >= 500:
speed_x = -2
if x0 <= 500:
speed_y = -3
if y1 >= 0:
speed_y = 2
if y0 <= 0:
speed_x = 3
x0 += speed_x
x1 += speed_x
y0 += speed_y
y1 += speed_y
mainloop()
我的目标是让球永远在屏幕上弹跳。现在球从右边的墙上弹开,然后消失在底部的墙上。在
你的问题是一个非常简单的逻辑问题
这是你写的:
我们想说的是,如果我们在任何边界条件之外,沿着适当的分量反转我们的速度。在
也许你会立刻怀疑你从来没有对照高度来检查y位置,或者你怀疑你是在根据x位置来调整y速度。不管怎样,都要怀疑
这是你写的东西,按顺序排列
与此逻辑相比:
^{pr2}$相关问题 更多 >
编程相关推荐