-
个人简介
我药听梦回还😭😭😭
=================== 分割线 ==================
复制以下代码为坠落的人类命名🤓👇™
import turtle import time
#初始化屏幕 screen = turtle.Screen() screen.title("传说之下") screen.bgcolor("black") screen.setup(width=900, height=600) screen.tracer(0) # 关闭自动刷新,手动控制刷新
#创建小球 ball = turtle.Turtle() ball.shape("circle") ball.color("red") ball.penup() ball.speed(0)
#初始位置 x = 0 y = 0 x_speed = 0 # 水平速度 y_speed = 0 # 垂直速度 gravity = -0.09 # 重力加速度
#手动刷新屏幕 字幕和小球同时显示 screen.update()
#键盘控制函数 def up(): global y_speed y_speed = 7 # 向上移动
def left(): global x_speed x_speed = -7 # 向左移动
def right(): global x_speed x_speed = 7 # 向右移动
def down(): global y_speed y_speed = -7 # 向下移动
def left_stop(): global x_speed x_speed = 0 # 松开左键时停止移动
def right_stop(): global x_speed x_speed = 0 # 松开右键时停止移动
def up_stop(): global y_speed y_speed = 0 # 松开上键时停止移动
def down_stop(): global y_speed y_speed = 0 # 松开下键时停止移动
#绑定键盘事件 screen.listen()
screen.onkeypress(up, "w") # 按下上键触发up()
screen.onkeyrelease(up_stop,"w") #松开上键触发up_stop()
screen.onkeypress(down,"s") # 按下下键触发up()
screen.onkeyrelease(down_stop,"s") #松开下键触发down_stop()
screen.onkeypress(left, "a") # 按下左键触发left()
screen.onkeyrelease(left_stop, "a") # 松开左键触发left_stop()
screen.onkeypress(right, "d") # 按下右键触发right()
screen.onkeyrelease(right_stop, "d") # 松开右键触发right_stop()
#创建字幕海龟 title = turtle.Turtle() title.hideturtle() title.penup() title.color("white") title.speed(0)
#多行文本(包含\n) text = '''WASD移动,你懂的 \n当然,先等我说完了你再动 \n*好了,开始探索吧''' lines = text.split('\n') # 拆分成行列表
#初始显示位置 x, y = -440, 260
#逐行显示(含逐字效果) for line in lines: current_line = "" # 当前行已显示的字符 title.goto(x, y) # 设置当前行位置 for char in line: # 遍历每个字符 current_line += char # 添加新字符 title.clear() # 清除旧内容 title.write(current_line, align="left", font=("Arial", 22, "normal")) screen.update() # 手动刷新 time.sleep(0.08) # 字符间隔 time.sleep(0.5)
while True: screen.update() # 手动刷新屏幕 #更新Y方向运动 ball.sety(ball.ycor() + y_speed) # 速度改变位置 #地面碰撞检测 if ball.ycor() <= -282: # 触碰地面 ball.sety(-282) # 防止下穿 y_speed = 0 # 停止 if ball.ycor() >= 288: # 触碰天花板 ball.sety(288) # 防止上穿 y_speed = 0 # 停止 # X方向运动 ball.setx(ball.xcor() + x_speed) # 防止小球移出屏幕左右边界 if ball.xcor() > 432: ball.setx(432) elif ball.xcor() < -440: ball.setx(-440) time.sleep(0.016) # 控制帧率
-
最近活动
This person is lazy and didn't join any contests or homework.