我正在尝试制作Python游戏,当我跳上方块时,它将游戏软锁定

时间:2019-05-30 22:18:15

标签: python turtle-graphics

当我跳上方块时,游戏将软锁定游戏。游戏使用乌龟作为角色。

Here's a link to the game if you want to try out what I have

我尝试更改变量,但是没有用。

    import turtle, random, math 
    canvas_width = 700
    canvas_height = 300
    w = "n"
    q = "n"

    screen = turtle.Screen()

    screen.setup(canvas_width, canvas_height, startx = None, starty = None)
    myPen = turtle.Turtle()
    myPen.pencolor("rgb(0, 255, 235)")
    myPen.hideturtle()

    def hit(g) :
      if turtle.distance(bad) < 15:
        j = myPen.xcor()
        myPen.setx(j + g)

    def r():
      global w
      if w == "n":
        w = "y"
        j = myPen.xcor()
        myPen.setx(j + 10)
        w = "n"
    def l():
      global w
      if w == "n":
        w = "y"
        j = myPen.xcor()
        myPen.setx(j - 10)
        w = "n"
    """part i need help at"""
    def u(): 
      global q
      if q == "n": # stops people from doing lots of jumps
        q = "y"
        j = myPen.ycor()
        for i in range(20):
          j = j + 1
          myPen.sety(j)
          j = myPen.ycor()
        while j != 0: #makes player fall down to y0
          if myPen.distance(bad) > 15: #makes player stop falling on block
            j = j - 1
            myPen.sety(j)
          q = "n"
    screen.onkey(r, "Right")
    screen.onkey(l, "Left")
    screen.onkey(u, "Up")
    screen.listen()
    #myPen.hideturtle()
    myPen.goto(0, 0)
    myPen.speed(1)
    #myPen.penup()
    #and so on

它在控制台中未显示任何错误

0 个答案:

没有答案