簡體   English   中英

彈跳球代碼的問題在哪里

[英]Where is the problem on that bouncing ball code

當我運行該代碼時,它只是顯示一個帶有標題和背景的空白窗口,然后它停止響應對我的英語感到抱歉

我使用原始的python,Visual Studio代碼,在線python編輯器

import turtle

wn = turtle.Screen()
wn.title("bouncing pysics")
wn.bgcolor("orange")
wn.setup(width=800, height=600)
wn.tracer(0)

ball = turtle.Turtle()
ball.speed(0)
ball.shape("circle")
ball.color("green")
ball.penup()
ball.goto(0,-1)
ball.dy = -1
ball.dy_2 = 1
first_location = ball.ycor()
while True:
    while first_location < -280:
        while ball.ycor() < 290:
            ball.sety(ball.ycor() - ball.dy_2)
        wn.update()
        last_location = ball.ycor()
        first_location = (last_location + first_location) / 2
        while ball.ycor() > first_location:
            ball.sety(ball.ycor() - ball.dy)
        wn.update()

我無法為您的彈跳邏輯做任何事情,但這就是為什么您的代碼不執行任何操作的原因:

ball.goto(0,-1)
# ...
first_location = ball.ycor()
while True:
    while first_location < -280:

進入外部while循環,將first_location設置為-1(球的初始Y位置。)由於不滿足內部while循環的條件(-1 大於 -280),內部循環永遠不會運行,因此我們重復執行一遍又一遍。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM