我用www.example.com做了一个replit.com弓箭的小游戏,它运行得很好,但是,当我用python 3.9.6把代码导入VSC时,我得到了一些replit没有的错误。
我的代码是:
import math
import turtle
import time
wn = turtle.Screen()
wn.title("Tiro al blanco")
wn.bgcolor("black")
wn.setup(width = 800, height = 600)
wn.tracer(0)
#parametros optimos: vi = 14.5, th = 45
vi = 14.5
th = 45
segs = 0
score = 0
#dibujar target
target = turtle.Turtle()
target.speed(0) #Velocidad de animacion, no de movimiento
target.shape("circle")
target.color("white")
target.shapesize(stretch_wid = 3, stretch_len = 3)
target.penup() ##Para que no trace línea de movimiento
target.goto(350,0) ##posición inicial
target2 = turtle.Turtle()
target2.speed(0) #Velocidad de animacion, no de movimiento
target2.shape("circle")
target2.color("red")
target2.shapesize(stretch_wid = 2, stretch_len = 2)
target2.penup() ##Para que no trace línea de movimiento
target2.goto(350,0) ##posición inicial
target3 = turtle.Turtle()
target3.speed(0) #Velocidad de animacion, no de movimiento
target3.shape("circle")
target3.color("white")
target3.shapesize(stretch_wid = 1, stretch_len = 1)
target3.penup() ##Para que no trace línea de movimiento
target3.goto(350,0) ##posición inicial
target4 = turtle.Turtle()
target4.speed(0) #Velocidad de animacion, no de movimiento
target4.shape("circle")
target4.color("red")
target4.shapesize(stretch_wid = 0.5, stretch_len = 0.5)
target4.penup() ##Para que no trace línea de movimiento
target4.goto(350,0) ##posición inicial
#dibujar arco
bow = turtle.Turtle()
bow.speed(0) #Velocidad de animacion, no de movimiento
bow.shape(turtle.circle(20,180))
bow.color("brown")
bow.shapesize(stretch_wid = 5, stretch_len = 1)
bow.penup() ##Para que no trace línea de movimiento
bow.goto(-350,0) ##posición inicial
#dibujar flecha
arrow = turtle.Turtle()
arrow.speed(0) #Velocidad de animacion, no de movimiento
arrow.shape("arrow")
arrow.color("cyan")
arrow.penup() ##Para que no trace línea de movimiento
arrow.goto(-350,0) ##posición inicial
arrow.velx = vi*math.cos(math.radians(th))
arrow.vely = vi*math.sin(math.radians(th))
#scoreboard
pen = turtle.Turtle()
pen.speed(0)
pen.color("white")
pen.penup()
pen.hideturtle()
pen.goto(0, 260)
pen.write("Score: 0", align = "center", font=("Courier", 24, "normal"))
#parametros
pen = turtle.Turtle()
pen.speed(0)
pen.color("white")
pen.penup()
pen.hideturtle()
pen.goto(0, -260)
pen.write("Velocidad:{}, Inclinacion: {} ".format(vi, th), align = "center", font=("Courier", 24, "normal"))
while True:
wn.update()
segs +=1
arrow.vely = vi*math.sin(math.radians(th)) - 0.3*(segs)
if arrow.ycor() < -100:
arrow.vely = 0
arrow.velx = 0
if arrow.ycor() > 275:
arrow.vely = 0
arrow.velx = 0
if arrow.xcor() > 335:
arrow.vely = 0
arrow.velx = 0
if arrow.xcor() >= 330:
if arrow.xcor() <= 350:
if arrow.ycor() >= -30:
if arrow.ycor() <= 30:
arrow.vely = 0
arrow.velx = 0
score +=1
pen.clear()
time.sleep(3)
arrow.goto(-350,0)
arrow.setx(arrow.xcor() + arrow.velx)
arrow.sety(arrow.ycor() + arrow.vely)
我收到错误消息:
DEPRECATION WARNING: The system version of Tk is deprecated and may be removed in a future release. Please don't rely on it. Set TK_SILENCE_DEPRECATION=1 to suppress this warning.
Traceback (most recent call last):
File "/Users/nicolasderbez/Desktop/tiroalblanco.py", line 21, in <module>
target = turtle.Turtle()
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/turtle.py", line 3814, in __init__
RawTurtle.__init__(self, Turtle._screen,
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/turtle.py", line 2558, in __init__
self._update()
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/turtle.py", line 2661, in _update
self._update_data()
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/turtle.py", line 2647, in _update_data
self.screen._incrementudc()
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/turtle.py", line 1293, in _incrementudc
raise Terminator
turtle.Terminator
如前所述,我在replit上没有收到任何错误消息。是否可能是版本不同,我必须重新编写代码?
1条答案
按热度按时间zvokhttg1#
更新到较新的Python版本后,代码运行起来没有问题。
还可以尝试:
并添加time.sleep()使箭头路径在快速机器上也可见。