如何解决我怎样才能使汽车在道路上方而不是下方使用乌龟
我正在开发我的第一款原创可玩游戏,但我遇到了这个问题。基本上,当汽车在路上行驶时,它会从下面而不是从上面行驶。在绘制道路时,我需要使用一个功能正常的系统,因为我希望游戏能够轻松地拥有多个关卡,而它不能成为背景,因为我需要其他汽车通过检测它的位置来绕着这条轨道行驶。
我知道乌龟先画底部的东西,但我已经这样做了。在我添加汽车图形之前,它工作得很好,但现在不行了。提前致谢,对于语法问题很抱歉,因为英语不是我的母语。
'''` # 关卡绘制 def draw_level(): insert_road(0,90) insert_turn(60,0) insert_road(60,-50,180)
# window
wn = turtle.Screen()
wn.setup(800,600)
wn.clear()
wn.bgcolor("grey")
wn.tracer(0)
wn.title("Millwoods Version - 1.0")
draw_level()
# graphics file code,not included because I don't think it is relevant to the problem
# Car
car = turtle.Turtle()
car.speed(0)
car.penup()
car.shape(car90)
car.goto(100,100)
car.state = 1
car.dx = 0
car.shift = 'Park'
car.inertia = 0
car.rt(90)
# writes the speed of the car in the corner of the screen (not important so removed)
pause = turtle.Turtle()
pause.speed(0)
pause.shape("square")
pause.color("white")
pause.penup()
pause.goto(260,240)
pause.hideturtle()
pause.pendown()
pause.forward(60)
pause.lt(90)
pause.forward(30)
pause.lt(90)
pause.forward(60)
pause.lt(90)
pause.forward(30)
pause.penup()
pause.goto(292,245)
def toggle_stat_mode_on():
statistics.goto(300,270)
def toggle_stat_mode_off():
statistics.goto(700,700)
def toggle_control_up():
car.state += 1
if car.state > 3:
car.state = 3
if car.state == 1:
car.shift = 'Park'
elif car.state == 2:
car.shift = 'Reverse'
elif car.state == 3:
car.shift = 'Drive'
else:
car.shift = 'ERROR'
def toggle_control_down():
car.state -= 1
if car.state < 1:
car.state = 1
if car.state == 1:
car.shift = 'Park'
elif car.state == 2:
car.shift = 'Reverse'
elif car.state == 3:
car.shift = 'Drive'
else:
car.shift = 'ERROR'
def gas():
if car.state == 3:
car.dx += 0.1
if car.dx > 3:
car.dx = 3
elif car.state == 2:
car.dx -= 0.1
if car.dx < -1:
car.dx = -1
elif car.state == 0:
pass
def brake():
if car.dx > 0:
car.dx -= 0.2
if car.dx < 0:
car.dx = 0
elif car.dx < 0:
car.dx += 0.2
if car.dx > 0:
car.dx = 0
def lturn():
x = 0
if car.dx != 0:
x = (car.dx*5)
if x > 5:
x = 5
car.lt(x)
def rturn():
x = 0
if car.dx != 0:
x = (car.dx*5)
if x > 5:
x = 5
car.rt(x)
def inertia():
if car.dx > 0:
car.inertia = 0.005
car.dx -= car.inertia
elif car.dx < 0:
car.inertia = -0.005
car.dx -= car.inertia
def button_click(x,y):
if x > 260 and x < 320 and y > 240 and y < 270:
print("'PAUSE' has been clicked")
pause_screen_level2()
wn.listen()
wn.onkeypress(gas,"w")
wn.onkeypress(brake,"s")
wn.onkeypress(lturn,"a")
wn.onkeypress(rturn,"d")
wn.onkeypress(toggle_control_up,"Up")
wn.onkeypress(toggle_control_down,"Down")
wn.onscreenclick(button_click,1)
while True:
float(car.heading())
if car.heading() >= 90 and car.heading() <= 94:
car.shape(car180)
elif car.heading() >= 95 and car.heading() <= 99:
car.shape(car185)
elif car.heading() >= 100 and car.heading() <= 104:
car.shape(car190)
elif car.heading() >= 105 and car.heading() <= 109:
car.shape(car195)
elif car.heading() >= 110 and car.heading() <= 114:
car.shape(car200)
elif car.heading() >= 115 and car.heading() <= 119:
car.shape(car205)
elif car.heading() >= 120 and car.heading() <= 124:
car.shape(car210)
elif car.heading() >= 125 and car.heading() <= 129:
car.shape(car215)
elif car.heading() >= 130 and car.heading() <= 134:
car.shape(car220)
elif car.heading() >= 135 and car.heading() <= 139:
car.shape(car225)
elif car.heading() >= 140 and car.heading() <= 144:
car.shape(car230)
elif car.heading() >= 145 and car.heading() <= 149:
car.shape(car235)
elif car.heading() >= 150 and car.heading() <= 154:
car.shape(car240)
elif car.heading() >= 155 and car.heading() <= 159:
car.shape(car245)
elif car.heading() >= 160 and car.heading() <= 164:
car.shape(car250)
elif car.heading() >= 165 and car.heading() <= 169:
car.shape(car255)
elif car.heading() >= 170 and car.heading() <= 174:
car.shape(car260)
elif car.heading() >= 175 and car.heading() <= 179:
car.shape(car265)
elif car.heading() >= 180 and car.heading() <= 184:
car.shape(car270)
elif car.heading() >= 185 and car.heading() <= 189:
car.shape(car275)
elif car.heading() >= 190 and car.heading() <= 194:
car.shape(car280)
elif car.heading() >= 195 and car.heading() <= 199:
car.shape(car285)
elif car.heading() >= 200 and car.heading() <= 204:
car.shape(car290)
elif car.heading() >= 205 and car.heading() <= 209:
car.shape(car295)
elif car.heading() >= 210 and car.heading() <= 214:
car.shape(car300)
elif car.heading() >= 215 and car.heading() <= 219:
car.shape(car305)
elif car.heading() >= 220 and car.heading() <= 224:
car.shape(car310)
elif car.heading() >= 225 and car.heading() <= 229:
car.shape(car315)
elif car.heading() >= 230 and car.heading() <= 234:
car.shape(car320)
elif car.heading() >= 235 and car.heading() <= 239:
car.shape(car325)
elif car.heading() >= 240 and car.heading() <= 244:
car.shape(car330)
elif car.heading() >= 245 and car.heading() <= 249:
car.shape(car335)
elif car.heading() >= 250 and car.heading() <= 254:
car.shape(car340)
elif car.heading() >= 255 and car.heading() <= 259:
car.shape(car245)
elif car.heading() >= 260 and car.heading() <= 264:
car.shape(car350)
elif car.heading() >= 265 and car.heading() <= 269:
car.shape(car355)
elif car.heading() >= 270 and car.heading() <= 274:
car.shape(car360)
elif car.heading() >= 275 and car.heading() <= 279:
car.shape(car5)
elif car.heading() >= 280 and car.heading() <= 284:
car.shape(car10)
elif car.heading() >= 285 and car.heading() <= 289:
car.shape(car15)
elif car.heading() >= 290 and car.heading() <= 294:
car.shape(car20)
elif car.heading() >= 295 and car.heading() <= 299:
car.shape(car25)
elif car.heading() >= 300 and car.heading() <= 304:
car.shape(car30)
elif car.heading() >= 305 and car.heading() <= 309:
car.shape(car35)
elif car.heading() >= 310 and car.heading() <= 314:
car.shape(car40)
elif car.heading() >= 315 and car.heading() <= 319:
car.shape(car45)
elif car.heading() >= 320 and car.heading() <= 324:
car.shape(car50)
elif car.heading() >= 325 and car.heading() <= 329:
car.shape(car55)
elif car.heading() >= 330 and car.heading() <= 334:
car.shape(car60)
elif car.heading() >= 335 and car.heading() <= 339:
car.shape(car65)
elif car.heading() >= 340 and car.heading() <= 344:
car.shape(car70)
elif car.heading() >= 345 and car.heading() <= 349:
car.shape(car75)
elif car.heading() >= 350 and car.heading() <= 354:
car.shape(car80)
elif car.heading() >= 355 and car.heading() <= 359:
car.shape(car85)
elif car.heading() >= 0 and car.heading() <= 4:
car.shape(car90)
elif car.heading() >= 5 and car.heading() <= 9:
car.shape(car95)
elif car.heading() >= 10 and car.heading() <= 14:
car.shape(car100)
elif car.heading() >= 15 and car.heading() <= 19:
car.shape(car105)
elif car.heading() >= 20 and car.heading() <= 24:
car.shape(car110)
elif car.heading() >= 25 and car.heading() <= 29:
car.shape(car115)
elif car.heading() >= 30 and car.heading() <= 34:
car.shape(car120)
elif car.heading() >= 35 and car.heading() <= 39:
car.shape(car125)
elif car.heading() >= 40 and car.heading() <= 44:
car.shape(car130)
elif car.heading() >= 45 and car.heading() <= 49:
car.shape(car135)
elif car.heading() >= 50 and car.heading() <= 54:
car.shape(car140)
elif car.heading() >= 55 and car.heading() <= 59:
car.shape(car145)
elif car.heading() >= 60 and car.heading() <= 64:
car.shape(car150)
elif car.heading() >= 65 and car.heading() <= 69:
car.shape(car155)
elif car.heading() >= 70 and car.heading() <= 74:
car.shape(car160)
elif car.heading() >= 75 and car.heading() <= 79:
car.shape(car165)
elif car.heading() >= 80 and car.heading() <= 84:
car.shape(car170)
elif car.heading() >= 85 and car.heading() <= 89:
car.shape(car175)
else:
pass
statistics.clear()
state.clear()
speed.clear()
inertia()
car.forward(car.dx - car.inertia)
pause.write("PAUSE",move=False,align='center',font=('Arial',10,'normal'))
speed.write("speed: " + str(car.dx),align='left',8,'normal'))
state.write("gear shift: " + str(car.shift),'normal'))
wn.update()`'''
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。