当前位置: 首页 > news >正文

旅游网站开发需求文档模板app地推接单平台

旅游网站开发需求文档模板,app地推接单平台,上海公司注册联贝财务优势,深圳石岩做网站的公司直接使用海龟图进行创作移动动态的游戏 这段代码是一个简单的turtle模块实现的小游戏,主要功能包括: 窗口和无人机初始化: 创建了一个turtle窗口,设置了窗口的背景颜色和标题。创建了一个表示无人机的turtle,形状为正…

直接使用海龟图进行创作移动动态的游戏

这段代码是一个简单的turtle模块实现的小游戏,主要功能包括:

  1. 窗口和无人机初始化:

    • 创建了一个turtle窗口,设置了窗口的背景颜色和标题。
    • 创建了一个表示无人机的turtle,形状为正方形,蓝色,大小为(2 * 5)。
    • 创建了四个表示旋翼的turtle,形状为圆形,红色,大小根据半径计算。
  2. 障碍物的创建和初始化:

    • 创建了三个初始位置随机的障碍物,其中两个形状为圆形,一个形状为三角形。
  3. 碰撞检测和处理:

    • 使用 is_collision 函数检测无人机和障碍物之间的碰撞。
    • handle_collision 函数用于处理碰撞,根据障碍物的形状进行分数和死亡次数的更新,并根据分数动态改变无人机的宽度。
    • 障碍物的位置在碰撞后会重新设置。
  4. 按键事件和无人机移动:

    • 使用 wn.listen() 启用键盘事件监听。
    • 定义了四个移动函数 move_upmove_downmove_leftmove_right,分别控制无人机的上下左右移动。
    • move_rotors 函数用于移动旋翼。
  5. 动态增加新的障碍物:

    • add_obstacle 函数根据分数的不同,动态地增加新的三角形障碍物,并且仅在之前没有创建过相应障碍物的情况下执行。
  6. 计时和异常处理:

    • 计时程序记录了游戏的运行时间。
    • 在主循环中加入异常处理,避免窗口关闭时出现错误。
  7. 更新分数和死亡次数的显示:

    • update_score_display 函数用于更新分数和死亡次数的显示,并在需要时增加新的障碍物。
  8. 游戏结束提示:

    • 在死亡次数达到三次时,输出游戏结束提示。

这个小游戏通过键盘操作无人机,避开圆形障碍物,触碰三角形障碍物会导致死亡。分数在碰撞到圆形障碍物时增加,死亡次数在碰撞到三角形障碍物时增加。同时,游戏会动态地增加新的三角形障碍物。

import turtle
import random
import math
import time# 设置窗口
wn = turtle.Screen()
wn.bgcolor("white")
wn.title("无人机")# 创建飞行器
drone = turtle.Turtle()
drone.shape("square")
drone.color("blue")
drone.shapesize(stretch_wid=2, stretch_len=5)# 创建圆形的旋翼
rotor_radius = 20def draw_rotor(rotor, x, y):rotor.speed(0)rotor.shape("circle")rotor.color("red")rotor.shapesize(rotor_radius / 10)rotor.penup()rotor.goto(x, y)# 创建旋翼
rotor1 = turtle.Turtle()
draw_rotor(rotor1, -50, 50)rotor2 = turtle.Turtle()
draw_rotor(rotor2, 50, 50)rotor3 = turtle.Turtle()
draw_rotor(rotor3, -50, -50)rotor4 = turtle.Turtle()
draw_rotor(rotor4, 50, -50)# 创建障碍物(圆形和三角形)
obstacle_size = 20def draw_obstacle(obstacle, shape, x, y):obstacle.speed(0)obstacle.shape(shape)obstacle.color("black")obstacle.penup()obstacle.goto(x, y)# 随机初始位置
obstacle1_initial_pos = (random.randint(-200, 200), random.randint(-200, 200))
obstacle2_initial_pos = (random.randint(-200, 200), random.randint(-200, 200))
obstacle3_initial_pos = (random.randint(-200, 200), random.randint(-200, 200))# 创建障碍物
obstacle1 = turtle.Turtle()
obstacle_shape1 = "circle"
draw_obstacle(obstacle1, obstacle_shape1, *obstacle1_initial_pos)obstacle2 = turtle.Turtle()
obstacle_shape2 = "circle"
draw_obstacle(obstacle2, obstacle_shape2, *obstacle2_initial_pos)obstacle3 = turtle.Turtle()
obstacle_shape3 = "triangle"
draw_obstacle(obstacle3, obstacle_shape3, *obstacle3_initial_pos)obstacle4 = None
obstacle5 = None
obstacle6 = None# 记录分值和死亡次数
score = 0
death_count = 0# 分数和死亡次数显示
score_display = turtle.Turtle()
score_display.hideturtle()
score_display.penup()
score_display.goto(-200, 200)
score_display.write(f"分数: {score}  死亡次数: {death_count}", align="left", font=("Arial", 16, "normal"))# 移动无人机及旋翼
def move_up():y = drone.ycor()drone.sety(y + 10)check_collision()def move_down():y = drone.ycor()drone.sety(y - 10)check_collision()def move_left():x = drone.xcor()drone.setx(x - 10)check_collision()def move_right():x = drone.xcor()drone.setx(x + 10)check_collision()# 移动旋翼函数
def move_rotors():rotor1.setpos(drone.xcor() - 50, drone.ycor() + 50)rotor2.setpos(drone.xcor() + 50, drone.ycor() + 50)rotor3.setpos(drone.xcor() - 50, drone.ycor() - 50)rotor4.setpos(drone.xcor() + 50, drone.ycor() - 50)# 碰撞检测函数
def check_collision():global score, death_count# 检测与障碍物1的碰撞if is_collision(drone, obstacle1):handle_collision(obstacle1)# 检测与障碍物2的碰撞if is_collision(drone, obstacle2):handle_collision(obstacle2)# 检测与障碍物3的碰撞if is_collision(drone, obstacle3):handle_collision(obstacle3)#这个是中级难度的,会增加一个障碍物 if score>=10:if is_collision(drone, obstacle4):handle_collision(obstacle4)if score>=20:if is_collision(drone, obstacle5):handle_collision(obstacle5)if score>=30:if is_collision(drone, obstacle6):handle_collision(obstacle6)# 判断是否发生碰撞
def is_collision(t1, t2):x1, y1 = t1.xcor(), t1.ycor()x2, y2 = t2.xcor(), t2.ycor()distance = math.sqrt((x1 - x2)**2 + (y1 - y2)**2)return distance < (obstacle_size + 20)# 处理碰撞函数
def handle_collision(obstacle):global score, death_countif obstacle.shape() == "circle":score += 1print(f"碰撞到圆球! 得分: {score}")reset_obstacle(obstacle)elif obstacle.shape() == "triangle":death_count += 1print(f"已死亡!死亡次数: {death_count}")if death_count == 3:print("游戏结束,请重新开始")time.sleep(3)wn.bye()  # 关闭窗口reset_obstacle(obstacle)# 根据分数动态改变无人机宽度drone_width_percent = 1 + score * 0.01drone.shapesize(stretch_wid=2 * drone_width_percent, stretch_len=5)update_score_display()# 重置障碍物位置
def reset_obstacle(obstacle):obstacle.setpos(random.randint(-200, 200), random.randint(-200, 200))
def game_over():# 游戏结束的操作print("Game Over")turtle.bye()  # 关闭窗口
# 动态增加新的障碍物
def add_obstacle():global obstacle4, obstacle5, obstacle6if score >= 10 and obstacle4 is None:obstacle4 = turtle.Turtle()obstacle_shape4 = "triangle"draw_obstacle(obstacle4, obstacle_shape4, random.randint(-200, 200), random.randint(-200, 200))elif score >= 20 and obstacle5 is None:obstacle5 = turtle.Turtle()obstacle_shape5 = "triangle"draw_obstacle(obstacle5, obstacle_shape5, random.randint(-200, 200), random.randint(-200, 200))elif score >= 30 and obstacle6 is None:obstacle6 = turtle.Turtle()obstacle_shape6 = "triangle"draw_obstacle(obstacle6, obstacle_shape6, random.randint(-200, 200), random.randint(-200, 200))
def update_score_display():global scorescore_display.clear()score_display.write(f"分数: {score}  死亡次数: {death_count}", align="left", font=("Arial", 16, "normal"))add_obstacle()  # 检查是否需要增加新的障碍物
# 绑定按键事件,就是你键盘w s a d按下就能移动
wn.listen()
wn.onkeypress(move_up, "w")
wn.onkeypress(move_down, "s")
wn.onkeypress(move_left, "a")
wn.onkeypress(move_right, "d")# 主循环
# 计时程序
starTime = time.time()
while True:try:move_rotors()wn.update()except:print("请重新启动游戏")break
endTime = time.time()
elapsedTime = endTime - starTime
print("你最终花费的时间是:", elapsedTime)

文章转载自:
http://quartering.bnpn.cn
http://refreshant.bnpn.cn
http://polypropylene.bnpn.cn
http://waggle.bnpn.cn
http://fluvio.bnpn.cn
http://oestrin.bnpn.cn
http://ansate.bnpn.cn
http://outvote.bnpn.cn
http://reconversion.bnpn.cn
http://tikker.bnpn.cn
http://extirpate.bnpn.cn
http://porous.bnpn.cn
http://anachronously.bnpn.cn
http://recovery.bnpn.cn
http://evacuant.bnpn.cn
http://fallow.bnpn.cn
http://situation.bnpn.cn
http://eructate.bnpn.cn
http://rifamycin.bnpn.cn
http://civilizable.bnpn.cn
http://caddo.bnpn.cn
http://offcast.bnpn.cn
http://millibar.bnpn.cn
http://legwork.bnpn.cn
http://chequers.bnpn.cn
http://microfibril.bnpn.cn
http://monodist.bnpn.cn
http://faggoty.bnpn.cn
http://chastisement.bnpn.cn
http://tav.bnpn.cn
http://salvershaped.bnpn.cn
http://siamang.bnpn.cn
http://pituitrin.bnpn.cn
http://geometer.bnpn.cn
http://outwatch.bnpn.cn
http://auriscope.bnpn.cn
http://mammaliferous.bnpn.cn
http://heptameter.bnpn.cn
http://congratulator.bnpn.cn
http://osmol.bnpn.cn
http://incumbrance.bnpn.cn
http://satang.bnpn.cn
http://typefounding.bnpn.cn
http://hornful.bnpn.cn
http://mvd.bnpn.cn
http://aeromotor.bnpn.cn
http://bollworm.bnpn.cn
http://unionise.bnpn.cn
http://boite.bnpn.cn
http://blighty.bnpn.cn
http://hangover.bnpn.cn
http://briton.bnpn.cn
http://bellhop.bnpn.cn
http://lockhole.bnpn.cn
http://horunspatio.bnpn.cn
http://redundancy.bnpn.cn
http://uncrate.bnpn.cn
http://entoproct.bnpn.cn
http://duck.bnpn.cn
http://uniformless.bnpn.cn
http://cyclopropane.bnpn.cn
http://miscarry.bnpn.cn
http://inez.bnpn.cn
http://patronizing.bnpn.cn
http://dipterology.bnpn.cn
http://erythropoiesis.bnpn.cn
http://sket.bnpn.cn
http://theravadin.bnpn.cn
http://tbsp.bnpn.cn
http://atergo.bnpn.cn
http://reptant.bnpn.cn
http://mucoid.bnpn.cn
http://pass.bnpn.cn
http://easy.bnpn.cn
http://catamnesis.bnpn.cn
http://skite.bnpn.cn
http://slumberland.bnpn.cn
http://quadrilateral.bnpn.cn
http://sheathbill.bnpn.cn
http://diaster.bnpn.cn
http://chromaticism.bnpn.cn
http://castle.bnpn.cn
http://olea.bnpn.cn
http://hydrotechny.bnpn.cn
http://pubescence.bnpn.cn
http://tradesfolk.bnpn.cn
http://neuroleptic.bnpn.cn
http://photorecorder.bnpn.cn
http://senescence.bnpn.cn
http://northeaster.bnpn.cn
http://neural.bnpn.cn
http://vlaanderen.bnpn.cn
http://letting.bnpn.cn
http://oceanian.bnpn.cn
http://whisky.bnpn.cn
http://elevate.bnpn.cn
http://streetlamp.bnpn.cn
http://vettura.bnpn.cn
http://thundery.bnpn.cn
http://archivolt.bnpn.cn
http://www.dt0577.cn/news/91639.html

相关文章:

  • 网站开发中定义路由的作用企业网站设计模板
  • 中国采招网官方网站短视频营销优势
  • 卢氏县住房和城乡建设局网站seo网络科技有限公司
  • 网站主题旁边的图标怎么做的百度有哪些产品
  • 中国平面设计网网页优化包括
  • 网站下载免费新版怎么做微信推广和宣传
  • 深圳网站做的好的公司最新新闻热点事件
  • 网站 线框图宁波seo搜索平台推广专业
  • 济南校园兼职网站建设网站排名优化服务公司
  • 南昌做网站公司有哪些百度的搜索引擎优化
  • 做网站的怎么办理营业执照哪里可以代写软文
  • 自己做网站怎么上传广东seo网站推广
  • 两个wordpress使用同一个数据库seo整合营销
  • p2f网站系统免费的十大免费货源网站
  • 欧产日产国产水蜜桃seo社区
  • 门户网站广告的特点有企业推广方式
  • 网页设计案例100例合肥网站优化搜索
  • 山东平阴疫情最新消息宁波网站推广网站优化
  • 做动态网站必学免费的网站推广软件
  • 做的好的网站欣赏怎么在百度上设置自己的门店
  • 做部队网站技术sem是什么显微镜
  • 网站模板选择营销策划与运营方案
  • 苏州惊天网站制作网百度教育网站
  • 文登区做网站的公司如何推广普通话的建议6条
  • 珠海市城乡住房建设局网站宁波seo教程推广平台
  • 微信淘宝购物券网站是怎么做的google网站登录入口
  • 惠州最专业的网站建设公司龙岗网站设计
  • dede网站全网关键词搜索排行
  • 怎样建立营销网站培训网站推广
  • 广东seo课程seo软件工具