所以基本上,我不能移动我的乌龟,即使有它的功能。而且,当我可以的时候,当它到达边界时,它就会继续前进。我试过移动函数的位置,但不起作用。我已经为它设置了所有的功能,它们在过去工作过,我不知道是什么让它们停止工作。另外,海龟和边境的接触也没什么用
import turtle, os, math
#setting up the dimensions of the screen + color
wn = turtle.Screen()
wn.screensize(500,500)
wn.title("Mario vs the turtles")
wn.bgcolor("white")
border_pen = turtle.Turtle()
border_pen.speed(0)
border_pen.color("black")
border_pen.penup()
border_pen.setposition(-350,-350)
border_pen.pendown()
border_pen.pensize(3)
for side in range (4):
border_pen.fd(600)
border_pen.lt(90)
border_pen.hideturtle()
score_mario=0
hearts_mario=3
#score
score = turtle.Turtle()
score.speed(0)
score.color("black")
score.penup()
score.hideturtle()
score.goto(50,300)
score.pendown()
score.write("Score: 0 Hearts: 3", align="center", font=("Courier", 24, "normal"))
#Main game loop
#color of the turtle, speed, two variables for the position
mario=turtle.Turtle()
mario.shape("turtle")
colors = ['red', 'blue', 'green', 'purple', 'yellow', 'orange', 'black']
mario.penup()
mario.hideturtle()
mario.goto(-320,-320)
mario.showturtle()
simon=turtle.Turtle()
simon.shape("turtle")
simon.color("black")
simon.penup()
simon.hideturtle()
simon.setposition(-270,-320)
simon.showturtle()
while hearts_mario>0:
mario.ycor==simon.ycor
x,y=mario.position()
x,y=simon.position()
while simon.xcor<500 and simon.xcor>-500:
simon.setheading(180)
mario.forward(100)
mario.speed(0)
mario.shapesize(stretch_wid=1, stretch_len=1)
def jump():
cor1=mario.ycor()
cor1+=10
mario.delay=2
mario.setposition(x,cor1)
cor1-=10
mario.setposition(x,cor1)
def left():
mario.setheading(180)
mario.forward(100)
def right():
mario.setheading(0)
mario.forward(100)
def escape():
wn.bye()
def reset():
mario.reset()
if mario.xcor==simon.xcor and mario.ycor==simon.ycor:
hearts_mario=2
#all these functions are for movement/boundaries
#boundaries
if mario.xcor<=border_pen.xcor and mario.ycor<=border_pen.ycor:
mario.setposition(250,250)
if mario.setheading(180) and mario.forward (100):
turtle.register_shape("marioleft.gif")
mario.shape("marioleft.gif")
turtle.onkey(left, "Left")
turtle.onkey(right, "Right")
turtle.onkey(escape, "Escape")
turtle.onkey(reset, "r")
turtle.onkey(jump, "space")
turtle.listen()
turtle.mainloop()
我很难相信这个代码曾经有效。这似乎是一个弗兰肯帕斯的位从其他程序,等待一个好的闪电风暴。例如:
mario.xcor()
和.ycor()
是方法,mario.xcor
和.ycor
什么都不做。此外:mario.setheading(180)
和mario.forward(100)
总是返回None
,所以这永远不会发生。有很多设置逻辑,但没有真正的运行时循环。我已经尽可能地将代码重新编写成一个可玩的游戏,尽管它可能不是您想要的游戏:相关问题 更多 >
编程相关推荐