簡體   English   中英

如何像游戲中的關卡一樣提高對象的速度?

[英]How can I increase the speed of my object like with levels in a game?

在我的游戲代碼中,我想在每次達到一定數量的點擊和關卡時提高隨機移動對象(這里我稱之為 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() 

您的問題在於您只定義了一次烏龜的速度。 相反,您應該像這樣重置每個級別的速度;

    def Speed():
         global Speed, level, clicks, squidward 
         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)

此外,clicked() 函數永遠不會結束,因為它會進入無限循環

暫無
暫無

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

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