如何将对象的速度提高到游戏中的水平?
在我的代码(用于游戏的代码)中,我想每次达到一定量的点击和级别时都会提高随机移动对象的速度(我称之为squidward)。但是,我的功能不起作用。我认为功能本身是有道理的,也许我忘了添加一些东西,但是,我几次都看了一下,但是在这一点上,我不知道为了解决它,我还能做些什么。
这是我的代码:
import turtle
from tkinter import*
from random import randint
# set up
win = turtle.Screen()
win.title("Squid-game")
win.bgcolor("black")
win.register_shape("squid_big.gif")
# variabelen
clicks = -1
level = 1
Speed = 1
# dem Turtle-objekt in Thadäus formen
squidward = turtle.Turtle()
squidward.shape("squid_big.gif")
squidward.penup()
squidward.speed(Speed)
def Speed():
global Speed, level, clicks
if level == 1 and clicks == 5:
level += 1
Speed += 1
if level == 2 and clicks == 10:
level += 1
Speed += 5
if level == 3 and clicks == 15:
level += 1
Speed += 2
squidward.speed(Speed)
squidward.onclick(Speed())
# zeigt an wie viele Clicks man hat
pen = turtle.Turtle()
pen.hideturtle()
pen.color("white")
pen.penup
pen.goto(0, 400)
pen.write (f"Clicks: {clicks}", align="center", font=("Courier New", 32, "normal"))
# Funtion für das Clicken und den random Bewegung
def clicked (x,y):
global clicks
clicks += 1
pen.clear()
pen.write (f"Clicks: {clicks}", align="center", font=("Courier New", 32, "normal"))
while TRUE: squidward.goto(randint(-1200, 1200), randint(-1200, 1200))
# die Geschwindigkeit muss ich ab einer bestimmten Aazahl bis 10 steigen// Level-up
squidward.onclick(clicked)
win.mainloop()
in my code, which is for a game, I want to increase the speed of my randomly moving object ( here I call it squidward ) every time a certain amount of clicks and level is reached. However, my function is not working. I think the function itself makes sense and maybe I forgot to add something, however, I looked over it several times, but at this point I don't know what else I could possibly do in order to fix it.
Here is my code:
import turtle
from tkinter import*
from random import randint
# set up
win = turtle.Screen()
win.title("Squid-game")
win.bgcolor("black")
win.register_shape("squid_big.gif")
# variabelen
clicks = -1
level = 1
Speed = 1
# dem Turtle-objekt in Thadäus formen
squidward = turtle.Turtle()
squidward.shape("squid_big.gif")
squidward.penup()
squidward.speed(Speed)
def Speed():
global Speed, level, clicks
if level == 1 and clicks == 5:
level += 1
Speed += 1
if level == 2 and clicks == 10:
level += 1
Speed += 5
if level == 3 and clicks == 15:
level += 1
Speed += 2
squidward.speed(Speed)
squidward.onclick(Speed())
# zeigt an wie viele Clicks man hat
pen = turtle.Turtle()
pen.hideturtle()
pen.color("white")
pen.penup
pen.goto(0, 400)
pen.write (f"Clicks: {clicks}", align="center", font=("Courier New", 32, "normal"))
# Funtion für das Clicken und den random Bewegung
def clicked (x,y):
global clicks
clicks += 1
pen.clear()
pen.write (f"Clicks: {clicks}", align="center", font=("Courier New", 32, "normal"))
while TRUE: squidward.goto(randint(-1200, 1200), randint(-1200, 1200))
# die Geschwindigkeit muss ich ab einer bestimmten Aazahl bis 10 steigen// Level-up
squidward.onclick(clicked)
win.mainloop()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的问题是您只定义了一次乌龟的速度。相反,您应该像这样重置每个级别;
此外,随着它进入无限循环,clicked()函数永远不会结束
Your problem comes in that you only define the speed of the turtle once. Instead you should reset the speed every level like so;
In addition, the clicked() function is never ended as it goes into an infinite loop