我在用乌龟的图案做游戏。这是密码
import turtle
import time
width = -462
height = 387
cellHeight = 387
turtle.title('Tutorial Game')
##TurtleImage
turtle.addshape('cell1.gif')
turtle.addshape('platformTile.gif')
##Render
def renderScreen():
#Background
turtle.bgcolor('green')
##Roof
for i in range(3):
roof()
global cellHeight
cellHeight -= 32
##Floor
cellHeight = -387
for i in range(2):
floor()
global cellHeight
cellHeight += 32
char()
def roof():
turtle.shape('platformTile.gif')
turtle.goto(width, cellHeight)
for i in range(30):
turtle.stamp()
turtle.forward(32)
def floor():
turtle.shape('platformTile.gif')
turtle.goto(width, cellHeight)
for i in range(30):
turtle.stamp()
turtle.forward(32)
def char():
turtle.shape('cell1.gif')
turtle.showturtle()
turtle.goto(0, 0)
turtle.onkey(forward, 'd')
turtle.onkey(backward, 'a')
turtle.onkey(up, 'space')
turtle.listen()
##Movement
def forward():
turtle.forward(32)
def backward():
turtle.backward(32)
def jump():
turtle.setheading(90)
turtle.forward(32)
time.sleep(0.5)
turtle.forward(32)
time.sleep(0.5)
turtle.setheading(270)
turtle.forward(32)
time.sleep(0.5)
turtle.forward(32)
turtle.setheading(0)
def up():
turtle.setheading(90)
turtle.forward(32)
turtle.setheading(0)
turtle.penup()
turtle.hideturtle()
turtle.speed(0)
renderScreen()
turtle.done()
我想让它这样,当角色没有接触到黄色的瓷砖时,它会漂浮下来,直到它接触到黄色的瓷砖。我在想,也许,如果它没有接触到暗黄色
有什么帮助吗?在
您可以检查字符是否低于y轴的特定度数(例如10);如果它高于该值,它的y轴将减小;如果达到该限制(10),它将停止(在该循环中使用break/if语句)
下面是我对您的代码的重新编写,它试图简化它,添加向下运动,并让它测试楼层边界:
希望您可以在解决方案中使用这些逻辑。
您需要修改您的}。
up()
逻辑,将移动限制在阶段顶部。对于侧面,同上forward()
和{相关问题 更多 >
编程相关推荐