找回密码
 立即注册
搜索
查看: 12|回复: 0

基于PyGame的乒乓球和滑雪游戏开发指南与昝道广的公众号运营经验分享

[复制链接]

2万

主题

0

回帖

6万

积分

管理员

积分
65129
发表于 2025-3-18 18:09:45 | 显示全部楼层 |阅读模式
基于的乒乓球和滑雪游戏

[]

概述前言

阿广确实有些调皮了。近期公众号上商业互吹以及广告的比例比较高,之后会留意广告篇幅和文章质量,希望大家多多谅解。前天我竞选了我们学校的十大优秀学生,所以利用公众号进行了拉票。在这期间,有个别粉丝给我发消息,说“取关取关!”当我想要挽留一下的时候,出现了红色叹号,这让我久久难以忘怀。他一定是这样想的:作为一个分享知识、传播知识的平台,应当秉持着利他的基本原则,每天都发布知识干货。

说实话,我没办法做到每天都发干货。因为我要生存,要生活。不过我会以“分享知识、传播正能量”为主要方向,把其他作为辅助方向。也就是说,一个不接广告的知识平台是难以长久的,因为广告以及你们的阅读和支持才是我们继续办下去的动力。可以说,写一篇原创需要前期进行大量的阅读学习,还需要进行代码调试和实现。用幽默的语言讲出来的话,至少也需要几个小时的时间。希望大家能理解每个人的处境。今天我需要大家帮忙,大家就帮我一下;明天你们若有急需解决的问题,也可以向阿广寻求帮助,我定会毫无保留地帮助你们。对于我而言,十大优秀学生称号并无实际性意义。可以说,这是为了我们济南校区的荣誉而拼搏,所以我会竭尽全力。在此,我非常感激为我拉票和点赞的朋友们,也非常感谢你们一直以来的支持与关注!

乒乓球小游戏很好玩,滑雪小游戏也很好玩,希望大家能通过此代码理解库的使用,从而为开发其他游戏打好基础。

乒乓球游戏规则乒乓球游戏图形界面

游戏界面

游戏结束界面

乒乓球部分代码



<p><pre style="margin: 0px;padding: 0px;background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: initial;">    <code style="border-radius: 4px;font-size: 0.85em;margin: 0px 0.15em;background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgb(40, 44, 52);color: rgb(171, 178, 191);display: block;padding: 5.95px;overflow-x: auto;white-space: nowrap;" class="hljs-default">import pygame,sys,random<br  />from pygame.locals import *<br  /><span class="hljs-default-class" style="color: rgb(171, 178, 191);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 262px;text-decoration: none solid rgb(171, 178, 191);font-weight: 400;font-style: normal;"><span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 33px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">class</span> <span class="hljs-default-title" style="color: rgb(230, 192, 123);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 72px;text-decoration: none solid rgb(230, 192, 123);font-weight: 400;font-style: normal;">MyBallClass</span>(<span class="hljs-default-title" style="color: rgb(230, 192, 123);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 39px;text-decoration: none solid rgb(230, 192, 123);font-weight: 400;font-style: normal;">pygame</span>.<span class="hljs-default-title" style="color: rgb(230, 192, 123);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 39px;text-decoration: none solid rgb(230, 192, 123);font-weight: 400;font-style: normal;">sprite</span>.<span class="hljs-default-title" style="color: rgb(230, 192, 123);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 39px;text-decoration: none solid rgb(230, 192, 123);font-weight: 400;font-style: normal;">Sprite</span>):</span><br  />    <span class="hljs-default-function" style="color: rgb(171, 178, 191);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 288px;text-decoration: none solid rgb(171, 178, 191);font-weight: 400;font-style: normal;"><span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 20px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">def</span> <span class="hljs-default-title" style="color: rgb(97, 174, 238);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 52px;text-decoration: none solid rgb(97, 174, 238);font-weight: 400;font-style: normal;">__init__</span><span class="hljs-default-params" style="color: rgb(171, 178, 191);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 210px;text-decoration: none solid rgb(171, 178, 191);font-weight: 400;font-style: normal;">(<span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 26px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">[id_2007211369]</span>,image_file,location,speed)</span></span>:<br  />pygame 的 sprite 模块中的 Sprite 类的初始化方法 __init__ 。<span class="hljs-default-number" style="color: rgb(209, 154, 102);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 6px;text-decoration: none solid rgb(209, 154, 102);font-weight: 400;font-style: normal;">_</span>(<span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 26px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">self</span>)<br  />        <span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 26px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">self</span>pygame 加载了指定的图像文件,加载后的图像被赋值给了变量 image ,即 image = pygame.image.load(image_file) 。<br  />        <span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 26px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">self</span>.rect = <span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 26px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">self</span>.image.get_rect()<br  />        <span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 26px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">self</span>.rect.left,<span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 26px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">self</span>.rect.top = location<br  />        <span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 26px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">self</span>.speed = speed<br  />    <span class="hljs-default-function" style="color: rgb(171, 178, 191);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 92px;text-decoration: none solid rgb(171, 178, 191);font-weight: 400;font-style: normal;"><span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 20px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">def</span> <span class="hljs-default-title" style="color: rgb(97, 174, 238);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 26px;text-decoration: none solid rgb(97, 174, 238);font-weight: 400;font-style: normal;">move</span><span class="hljs-default-params" style="color: rgb(171, 178, 191);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 39px;text-decoration: none solid rgb(171, 178, 191);font-weight: 400;font-style: normal;">(<span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 26px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">self</span>)</span></span>:<br  />全球积分、得分文本<br  />        <span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 26px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">self</span>.rect = <span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 26px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">self</span>.rect.move(<span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 26px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">self</span>.speed)<br  />        <span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 13px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">if</span> <span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 26px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">self</span>.rect.left < <span class="hljs-default-number" style="color: rgb(209, 154, 102);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 6px;text-decoration: none solid rgb(209, 154, 102);font-weight: 400;font-style: normal;">0</span> <span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 13px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">or</span> <span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 26px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">self</span>屏幕的宽度小于矩形的右侧边界。<br  />            <span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 26px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">self</span>.speed[<span class="hljs-default-number" style="color: rgb(209, 154, 102);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 6px;text-decoration: none solid rgb(209, 154, 102);font-weight: 400;font-style: normal;">0</span>] = - <span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 26px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">self</span>.speed[<span class="hljs-default-number" style="color: rgb(209, 154, 102);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 6px;text-decoration: none solid rgb(209, 154, 102);font-weight: 400;font-style: normal;">0</span>]<br  />            hit_wall.play()<br  />        <span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 13px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">if</span> <span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 26px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">self</span>.rect.top <= <span class="hljs-default-number" style="color: rgb(209, 154, 102);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 6px;text-decoration: none solid rgb(209, 154, 102);font-weight: 400;font-style: normal;">0</span>:<br  />            points = points + <span class="hljs-default-number" style="color: rgb(209, 154, 102);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 6px;text-decoration: none solid rgb(209, 154, 102);font-weight: 400;font-style: normal;">1</span><br  />            <span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 13px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">if</span> <span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 26px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">self</span>.speed[<span class="hljs-default-number" style="color: rgb(209, 154, 102);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 6px;text-decoration: none solid rgb(209, 154, 102);font-weight: 400;font-style: normal;">1</span>] < <span class="hljs-default-number" style="color: rgb(209, 154, 102);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 6px;text-decoration: none solid rgb(209, 154, 102);font-weight: 400;font-style: normal;">0</span>:<br  />                <span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 26px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">self</span>.speed[<span class="hljs-default-number" style="color: rgb(209, 154, 102);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 7px;text-decoration: none solid rgb(209, 154, 102);font-weight: 400;font-style: normal;">1</span>] = random.randint(<span class="hljs-default-number" style="color: rgb(209, 154, 102);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 6px;text-decoration: none solid rgb(209, 154, 102);font-weight: 400;font-style: normal;">5</span>,<span class="hljs-default-number" style="color: rgb(209, 154, 102);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 14px;text-decoration: none solid rgb(209, 154, 102);font-weight: 400;font-style: normal;">10</span>)<br  />            <span class="hljs-default-symbol" style="color: rgb(97, 174, 238);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 33px;text-decoration: none solid rgb(97, 174, 238);font-weight: 400;font-style: normal;">else:</span><br  />                <span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 26px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">self</span>.speed[<span class="hljs-default-number" style="color: rgb(209, 154, 102);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 7px;text-decoration: none solid rgb(209, 154, 102);font-weight: 400;font-style: normal;">1</span>] = random.randint(-<span class="hljs-default-number" style="color: rgb(209, 154, 102);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 13px;text-decoration: none solid rgb(209, 154, 102);font-weight: 400;font-style: normal;">10</span>,-<span class="hljs-default-number" style="color: rgb(209, 154, 102);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 6px;text-decoration: none solid rgb(209, 154, 102);font-weight: 400;font-style: normal;">5</span>)<br  /><br  />font 渲染出了表示 points 的字符串,即 font 把 points 渲染成了字符串形式并输出。<span class="hljs-default-number" style="color: rgb(209, 154, 102);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 6px;text-decoration: none solid rgb(209, 154, 102);font-weight: 400;font-style: normal;">1</span>,(<span class="hljs-default-number" style="color: rgb(209, 154, 102);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 6px;text-decoration: none solid rgb(209, 154, 102);font-weight: 400;font-style: normal;">0</span>,<span class="hljs-default-number" style="color: rgb(209, 154, 102);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 20px;text-decoration: none solid rgb(209, 154, 102);font-weight: 400;font-style: normal;">200</span>,<span class="hljs-default-number" style="color: rgb(209, 154, 102);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 6px;text-decoration: none solid rgb(209, 154, 102);font-weight: 400;font-style: normal;">0</span>))<br  />            get_point.play()<br  />        <span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 13px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">if</span> <span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 26px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">self</span>矩形的顶部位置大于屏幕的矩形区域。<span class="hljs-default-symbol" style="color: rgb(97, 174, 238);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 46px;text-decoration: none solid rgb(97, 174, 238);font-weight: 400;font-style: normal;">bottom:</span><br  />            hit_wall.stop()<br  /><br  /><br  /><span class="hljs-default-class" style="color: rgb(171, 178, 191);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 274px;text-decoration: none solid rgb(171, 178, 191);font-weight: 400;font-style: normal;"><span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 33px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">class</span> <span class="hljs-default-title" style="color: rgb(230, 192, 123);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 85px;text-decoration: none solid rgb(230, 192, 123);font-weight: 400;font-style: normal;">MyPaddleClass</span>(<span class="hljs-default-title" style="color: rgb(230, 192, 123);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 39px;text-decoration: none solid rgb(230, 192, 123);font-weight: 400;font-style: normal;">pygame</span>.<span class="hljs-default-title" style="color: rgb(230, 192, 123);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 39px;text-decoration: none solid rgb(230, 192, 123);font-weight: 400;font-style: normal;">sprite</span>.<span class="hljs-default-title" style="color: rgb(230, 192, 123);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 39px;text-decoration: none solid rgb(230, 192, 123);font-weight: 400;font-style: normal;">Sprite</span>):</span><br  />    <span class="hljs-default-function" style="color: rgb(171, 178, 191);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 229px;text-decoration: none solid rgb(171, 178, 191);font-weight: 400;font-style: normal;"><span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 20px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">def</span> <span class="hljs-default-title" style="color: rgb(97, 174, 238);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 52px;text-decoration: none solid rgb(97, 174, 238);font-weight: 400;font-style: normal;">__init__</span><span class="hljs-default-params" style="color: rgb(171, 178, 191);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 150px;text-decoration: none solid rgb(171, 178, 191);font-weight: 400;font-style: normal;">(<span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 26px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">self</span>,location = [<span class="hljs-default-number" style="color: rgb(209, 154, 102);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 6px;text-decoration: none solid rgb(209, 154, 102);font-weight: 400;font-style: normal;">0</span>,<span class="hljs-default-number" style="color: rgb(209, 154, 102);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 6px;text-decoration: none solid rgb(209, 154, 102);font-weight: 400;font-style: normal;">0</span>])</span></span>:<br  />        pygame.sprite.Sprite.__init_<span class="hljs-default-number" style="color: rgb(209, 154, 102);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 6px;text-decoration: none solid rgb(209, 154, 102);font-weight: 400;font-style: normal;">_</span>(<span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 26px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">self</span>)<br  />image_surface 等于 pygame 的 surface 创建了一个表面,其尺寸为 [<span class="hljs-default-number" style="color: rgb(209, 154, 102);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 20px;text-decoration: none solid rgb(209, 154, 102);font-weight: 400;font-style: normal;">100</span>,<span class="hljs-default-number" style="color: rgb(209, 154, 102);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 13px;text-decoration: none solid rgb(209, 154, 102);font-weight: 400;font-style: normal;">20</span>])<br  />        image_surface.fill([<span class="hljs-default-number" style="color: rgb(209, 154, 102);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 6px;text-decoration: none solid rgb(209, 154, 102);font-weight: 400;font-style: normal;">0</span>,<span class="hljs-default-number" style="color: rgb(209, 154, 102);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 6px;text-decoration: none solid rgb(209, 154, 102);font-weight: 400;font-style: normal;">0</span>,<span class="hljs-default-number" style="color: rgb(209, 154, 102);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 6px;text-decoration: none solid rgb(209, 154, 102);font-weight: 400;font-style: normal;">0</span>])<br  />        <span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 26px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">self</span>图像被转换成了图像表面。<br  />        <span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 26px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">self</span>.rect = <span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 26px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">self</span>.image.get_rect()<br  />        <span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 26px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">self</span>.rect.left,<span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 26px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">self</span>.rect.top = location<br  /></code></pre></p>
<p><pre style="margin-top: 0px;margin-bottom: 0px;padding: 0px;background-color: initial;">    <pre style="background-color: rgb(255, 255, 255);font-family: 宋体;font-size: 7.2pt;"><br  /></pre></p>
滑雪小游戏规则滑雪小游戏图形界面

滑雪小游戏部分代码

<p><pre style="margin: 0px;padding: 0px;background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: initial;">    <code style="border-radius: 4px;font-size: 0.85em;margin: 0px 0.15em;background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgb(40, 44, 52);color: rgb(171, 178, 191);display: block;padding: 5.95px;overflow-x: auto;white-space: nowrap;" class="hljs-default">import pygame, sys, random<br  /><br  />skier_images = [<span class="hljs-default-string" style="color: rgb(152, 195, 121);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 164px;text-decoration: none solid rgb(152, 195, 121);font-weight: 400;font-style: normal;">"./bg_img/skier_down.png"</span>, <span class="hljs-default-string" style="color: rgb(152, 195, 121);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 177px;text-decoration: none solid rgb(152, 195, 121);font-weight: 400;font-style: normal;">"./bg_img/skier_right1.png"</span>, <span class="hljs-default-string" style="color: rgb(152, 195, 121);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 177px;text-decoration: none solid rgb(152, 195, 121);font-weight: 400;font-style: normal;">"./bg_img/skier_right2.png"</span>,<br  />                 <span class="hljs-default-string" style="color: rgb(152, 195, 121);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 170px;text-decoration: none solid rgb(152, 195, 121);font-weight: 400;font-style: normal;">"./bg_img/skier_left2.png"</span>, <span class="hljs-default-string" style="color: rgb(152, 195, 121);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 170px;text-decoration: none solid rgb(152, 195, 121);font-weight: 400;font-style: normal;">"./bg_img/skier_left1.png"</span>]<br  /><br  /><span class="hljs-default-class" style="color: rgb(171, 178, 191);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 254px;text-decoration: none solid rgb(171, 178, 191);font-weight: 400;font-style: normal;"><span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 33px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">class</span> <span class="hljs-default-title" style="color: rgb(230, 192, 123);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 65px;text-decoration: none solid rgb(230, 192, 123);font-weight: 400;font-style: normal;">SkierClass</span>(<span class="hljs-default-title" style="color: rgb(230, 192, 123);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 39px;text-decoration: none solid rgb(230, 192, 123);font-weight: 400;font-style: normal;">pygame</span>.<span class="hljs-default-title" style="color: rgb(230, 192, 123);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 39px;text-decoration: none solid rgb(230, 192, 123);font-weight: 400;font-style: normal;">sprite</span>.<span class="hljs-default-title" style="color: rgb(230, 192, 123);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 39px;text-decoration: none solid rgb(230, 192, 123);font-weight: 400;font-style: normal;">Sprite</span>):</span><br  />    <span class="hljs-default-function" style="color: rgb(171, 178, 191);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 118px;text-decoration: none solid rgb(171, 178, 191);font-weight: 400;font-style: normal;"><span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 20px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">def</span> <span class="hljs-default-title" style="color: rgb(97, 174, 238);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 52px;text-decoration: none solid rgb(97, 174, 238);font-weight: 400;font-style: normal;">__init__</span><span class="hljs-default-params" style="color: rgb(171, 178, 191);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 39px;text-decoration: none solid rgb(171, 178, 191);font-weight: 400;font-style: normal;">(<span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 26px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">self</span>)</span></span>:<br  />        pygame.sprite.Sprite.__init_<span class="hljs-default-number" style="color: rgb(209, 154, 102);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 6px;text-decoration: none solid rgb(209, 154, 102);font-weight: 400;font-style: normal;">_</span>(<span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 26px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">self</span>)<br  />        <span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 26px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">self</span>.image = pygame.image.load(<span class="hljs-default-string" style="color: rgb(152, 195, 121);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 164px;text-decoration: none solid rgb(152, 195, 121);font-weight: 400;font-style: normal;">"./bg_img/skier_down.png"</span>)<br  />        <span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 26px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">self</span>.rect = <span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 26px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">self</span>.image.get_rect()<br  />        <span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 26px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">self</span>.rect.center = [<span class="hljs-default-number" style="color: rgb(209, 154, 102);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 19px;text-decoration: none solid rgb(209, 154, 102);font-weight: 400;font-style: normal;">320</span>, <span class="hljs-default-number" style="color: rgb(209, 154, 102);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 20px;text-decoration: none solid rgb(209, 154, 102);font-weight: 400;font-style: normal;">100</span>]<br  />        <span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 26px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">self</span>.angle = <span class="hljs-default-number" style="color: rgb(209, 154, 102);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 6px;text-decoration: none solid rgb(209, 154, 102);font-weight: 400;font-style: normal;">0</span><br  /><br  />    <span class="hljs-default-function" style="color: rgb(171, 178, 191);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 164px;text-decoration: none solid rgb(171, 178, 191);font-weight: 400;font-style: normal;"><span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 20px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">def</span> <span class="hljs-default-title" style="color: rgb(97, 174, 238);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 26px;text-decoration: none solid rgb(97, 174, 238);font-weight: 400;font-style: normal;">turn</span><span class="hljs-default-params" style="color: rgb(171, 178, 191);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 111px;text-decoration: none solid rgb(171, 178, 191);font-weight: 400;font-style: normal;">(<span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 26px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">self</span>, direction)</span></span>:<br  />        <span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 26px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">self</span>.angle = <span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 26px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">self</span>.angle + direction<br  />        <span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 13px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">if</span> <span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 26px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">self</span>.angle < -<span class="hljs-default-number" style="color: rgb(209, 154, 102);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 6px;text-decoration: none solid rgb(209, 154, 102);font-weight: 400;font-style: normal;">2</span>:  <span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 26px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">self</span>.angle = -<span class="hljs-default-number" style="color: rgb(209, 154, 102);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 6px;text-decoration: none solid rgb(209, 154, 102);font-weight: 400;font-style: normal;">2</span><br  />        <span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 13px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">if</span> <span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 26px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">self</span>.angle >  <span class="hljs-default-number" style="color: rgb(209, 154, 102);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 6px;text-decoration: none solid rgb(209, 154, 102);font-weight: 400;font-style: normal;">2</span>:  <span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 26px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">self</span>.angle =  <span class="hljs-default-number" style="color: rgb(209, 154, 102);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 6px;text-decoration: none solid rgb(209, 154, 102);font-weight: 400;font-style: normal;">2</span><br  />        center = <span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 26px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">self</span>.rect.center<br  />        <span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 26px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">self</span>“语言风格需保持原文风格,需去掉最前面的序号,并且要把长句拆分成多个小分句,同时要让分句尽可能地短。”<span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 26px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">self</span>.angle])<br  />        <span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 26px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">self</span>.rect = <span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 26px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">self</span>.image.get_rect()<br  />        <span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 26px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">self</span>.rect.center = center<br  />        speed = [<span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 26px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">self</span>.angle, <span class="hljs-default-number" style="color: rgb(209, 154, 102);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 6px;text-decoration: none solid rgb(209, 154, 102);font-weight: 400;font-style: normal;">6</span> - abs(<span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 26px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">self</span>.angle) * <span class="hljs-default-number" style="color: rgb(209, 154, 102);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 6px;text-decoration: none solid rgb(209, 154, 102);font-weight: 400;font-style: normal;">2</span>]<br  />        <span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 39px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">return</span> speed<br  /><br  />    <span class="hljs-default-function" style="color: rgb(171, 178, 191);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 138px;text-decoration: none solid rgb(171, 178, 191);font-weight: 400;font-style: normal;"><span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 20px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">def</span> <span class="hljs-default-title" style="color: rgb(97, 174, 238);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 26px;text-decoration: none solid rgb(97, 174, 238);font-weight: 400;font-style: normal;">move</span><span class="hljs-default-params" style="color: rgb(171, 178, 191);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 85px;text-decoration: none solid rgb(171, 178, 191);font-weight: 400;font-style: normal;">(<span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 26px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">self</span>, speed)</span></span>:<br  />        <span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 26px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">self</span>.rect.centerx = <span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 26px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">self</span>.rect.centerx + speed[<span class="hljs-default-number" style="color: rgb(209, 154, 102);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 6px;text-decoration: none solid rgb(209, 154, 102);font-weight: 400;font-style: normal;">0</span>]<br  />        <span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 13px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">if</span> <span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 26px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">self</span>.rect.centerx < <span class="hljs-default-number" style="color: rgb(209, 154, 102);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 13px;text-decoration: none solid rgb(209, 154, 102);font-weight: 400;font-style: normal;">20</span>:  <span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 26px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">self</span>.rect.centerx = <span class="hljs-default-number" style="color: rgb(209, 154, 102);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 14px;text-decoration: none solid rgb(209, 154, 102);font-weight: 400;font-style: normal;">20</span><br  />        <span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 13px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">if</span> <span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 26px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">self</span>.rect.centerx > <span class="hljs-default-number" style="color: rgb(209, 154, 102);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 20px;text-decoration: none solid rgb(209, 154, 102);font-weight: 400;font-style: normal;">620</span>: <span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 26px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">self</span>.rect.centerx = <span class="hljs-default-number" style="color: rgb(209, 154, 102);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 20px;text-decoration: none solid rgb(209, 154, 102);font-weight: 400;font-style: normal;">620</span><br  /><br  /><span class="hljs-default-class" style="color: rgb(171, 178, 191);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 274px;text-decoration: none solid rgb(171, 178, 191);font-weight: 400;font-style: normal;"><span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 33px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">class</span> <span class="hljs-default-title" style="color: rgb(230, 192, 123);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 85px;text-decoration: none solid rgb(230, 192, 123);font-weight: 400;font-style: normal;">ObstacleClass</span>(<span class="hljs-default-title" style="color: rgb(230, 192, 123);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 39px;text-decoration: none solid rgb(230, 192, 123);font-weight: 400;font-style: normal;">pygame</span>.<span class="hljs-default-title" style="color: rgb(230, 192, 123);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 39px;text-decoration: none solid rgb(230, 192, 123);font-weight: 400;font-style: normal;">sprite</span>.<span class="hljs-default-title" style="color: rgb(230, 192, 123);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 39px;text-decoration: none solid rgb(230, 192, 123);font-weight: 400;font-style: normal;">Sprite</span>):</span><br  />    <span class="hljs-default-function" style="color: rgb(171, 178, 191);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 301px;text-decoration: none solid rgb(171, 178, 191);font-weight: 400;font-style: normal;"><span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 20px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">def</span> <span class="hljs-default-title" style="color: rgb(97, 174, 238);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 52px;text-decoration: none solid rgb(97, 174, 238);font-weight: 400;font-style: normal;">__init__</span><span class="hljs-default-params" style="color: rgb(171, 178, 191);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 222px;text-decoration: none solid rgb(171, 178, 191);font-weight: 400;font-style: normal;">(<span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 26px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">self</span>, image_file, location, type)</span></span>:<br  />        pygame.sprite.Sprite.__init_<span class="hljs-default-number" style="color: rgb(209, 154, 102);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 6px;text-decoration: none solid rgb(209, 154, 102);font-weight: 400;font-style: normal;">_</span>(<span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 26px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">self</span>)<br  />        <span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 26px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">self</span>.image_file = image_file<br  />        <span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 26px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">self</span>.image = pygame.image.load(image_file)<br  />        <span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 26px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">self</span>.location = location<br  />        <span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 26px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">self</span>.rect = <span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 26px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">self</span>.image.get_rect()<br  />        <span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 26px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">self</span>.rect.center = location<br  />        <span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 26px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">self</span>.type = type<br  />        <span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 26px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">self</span>.passed = False<br  /><br  />    <span class="hljs-default-function" style="color: rgb(171, 178, 191);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 183px;text-decoration: none solid rgb(171, 178, 191);font-weight: 400;font-style: normal;"><span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 20px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">def</span> <span class="hljs-default-title" style="color: rgb(97, 174, 238);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 39px;text-decoration: none solid rgb(97, 174, 238);font-weight: 400;font-style: normal;">scroll</span><span class="hljs-default-params" style="color: rgb(171, 178, 191);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 118px;text-decoration: none solid rgb(171, 178, 191);font-weight: 400;font-style: normal;">(<span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 26px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">self</span>, terrainPos)</span></span>:<br  />        <span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 26px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">self</span>.rect.centery = <span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 26px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">self</span>.location[<span class="hljs-default-number" style="color: rgb(209, 154, 102);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 6px;text-decoration: none solid rgb(209, 154, 102);font-weight: 400;font-style: normal;">1</span>] - terrainPos<br  /><br  /><span class="hljs-default-function" style="color: rgb(171, 178, 191);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 170px;text-decoration: none solid rgb(171, 178, 191);font-weight: 400;font-style: normal;"><span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 19px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">def</span> <span class="hljs-default-title" style="color: rgb(97, 174, 238);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 66px;text-decoration: none solid rgb(97, 174, 238);font-weight: 400;font-style: normal;">create_map</span><span class="hljs-default-params" style="color: rgb(171, 178, 191);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 78px;text-decoration: none solid rgb(171, 178, 191);font-weight: 400;font-style: normal;">(start, <span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 20px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">end</span>)</span></span>:<br  />障碍物被创建为一个 pygame.sprite.Group() 。<br  />    locations = []<br  />gates 等于 pygame 中的精灵组(pygame.sprite.Group())<br  />    <span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 20px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">for</span> i <span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 14px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">in</span> range(<span class="hljs-default-number" style="color: rgb(209, 154, 102);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 13px;text-decoration: none solid rgb(209, 154, 102);font-weight: 400;font-style: normal;">10</span>):<br  />row 被赋值为 random.randint(start, end) 所生成的随机整数。<span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 19px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">end</span>)<br  />        col = random.randint(<span class="hljs-default-number" style="color: rgb(209, 154, 102);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 6px;text-decoration: none solid rgb(209, 154, 102);font-weight: 400;font-style: normal;">0</span>, <span class="hljs-default-number" style="color: rgb(209, 154, 102);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 6px;text-decoration: none solid rgb(209, 154, 102);font-weight: 400;font-style: normal;">9</span>)<br  />        location  = [col * <span class="hljs-default-number" style="color: rgb(209, 154, 102);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 14px;text-decoration: none solid rgb(209, 154, 102);font-weight: 400;font-style: normal;">64</span> + <span class="hljs-default-number" style="color: rgb(209, 154, 102);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 14px;text-decoration: none solid rgb(209, 154, 102);font-weight: 400;font-style: normal;">20</span>, row * <span class="hljs-default-number" style="color: rgb(209, 154, 102);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 13px;text-decoration: none solid rgb(209, 154, 102);font-weight: 400;font-style: normal;">64</span> + <span class="hljs-default-number" style="color: rgb(209, 154, 102);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 13px;text-decoration: none solid rgb(209, 154, 102);font-weight: 400;font-style: normal;">20</span>]<br  />        <span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 13px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">if</span> <span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 19px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">not</span> (location <span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 13px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">in</span> locations):<br  />将 location 添加到 locations 列表中。<br  />以下是改写后的内容:语言风格需保持原文风格,要去掉最前面的序号,并且把长句拆分成多个小分句,分句要尽可能短,以达到差异最大化的效果,同时要保留原意,禁止修改专有名词,也禁止穿插英文单词,只需给出改写结果,无需复述原句,无需换行,无需任何解释。<span class="hljs-default-string" style="color: rgb(152, 195, 121);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 39px;text-decoration: none solid rgb(152, 195, 121);font-weight: 400;font-style: normal;">"tree"</span>, <span class="hljs-default-string" style="color: rgb(152, 195, 121);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 39px;text-decoration: none solid rgb(152, 195, 121);font-weight: 400;font-style: normal;">"flag"</span>])<br  />            <span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 13px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">if</span> type == <span class="hljs-default-string" style="color: rgb(152, 195, 121);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 39px;text-decoration: none solid rgb(152, 195, 121);font-weight: 400;font-style: normal;">"tree"</span>: img = <span class="hljs-default-string" style="color: rgb(152, 195, 121);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 163px;text-decoration: none solid rgb(152, 195, 121);font-weight: 400;font-style: normal;">"./bg_img/skier_tree.png"</span><br  />            elif type == <span class="hljs-default-string" style="color: rgb(152, 195, 121);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 39px;text-decoration: none solid rgb(152, 195, 121);font-weight: 400;font-style: normal;">"flag"</span>:  img = <span class="hljs-default-string" style="color: rgb(152, 195, 121);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 163px;text-decoration: none solid rgb(152, 195, 121);font-weight: 400;font-style: normal;">"./bg_img/skier_flag.png"</span><br  />创建一个 ObstacleClass 的实例,传入图像 img、位置 location 和类型 type,这个实例被赋值给 obstacle 变量。<br  />将 obstacle 添加到 obstacles 中。<br  />    <span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 39px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">return</span> obstacles<br  /><br  /><span class="hljs-default-function" style="color: rgb(171, 178, 191);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 85px;text-decoration: none solid rgb(171, 178, 191);font-weight: 400;font-style: normal;"><span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 19px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">def</span> <span class="hljs-default-title" style="color: rgb(97, 174, 238);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 46px;text-decoration: none solid rgb(97, 174, 238);font-weight: 400;font-style: normal;">animate</span><span class="hljs-default-params" style="color: rgb(171, 178, 191);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 13px;text-decoration: none solid rgb(171, 178, 191);font-weight: 400;font-style: normal;">()</span></span>:<br  />    screen.fill([<span class="hljs-default-number" style="color: rgb(209, 154, 102);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 19px;text-decoration: none solid rgb(209, 154, 102);font-weight: 400;font-style: normal;">255</span>, <span class="hljs-default-number" style="color: rgb(209, 154, 102);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 19px;text-decoration: none solid rgb(209, 154, 102);font-weight: 400;font-style: normal;">255</span>, <span class="hljs-default-number" style="color: rgb(209, 154, 102);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 20px;text-decoration: none solid rgb(209, 154, 102);font-weight: 400;font-style: normal;">255</span>])<br  />使用 obstacles 的 draw 方法在屏幕 screen 上绘制后,更新 pygame 的显示 pygame.display.update<br  />将滑雪者的图像绘制到屏幕上,使用滑雪者的矩形区域进行定位。<br  />    screen.blit(score_text, [<span class="hljs-default-number" style="color: rgb(209, 154, 102);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 13px;text-decoration: none solid rgb(209, 154, 102);font-weight: 400;font-style: normal;">10</span>, <span class="hljs-default-number" style="color: rgb(209, 154, 102);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 14px;text-decoration: none solid rgb(209, 154, 102);font-weight: 400;font-style: normal;">10</span>])<br  />    pygame.display.flip()<br  /><br  /><span class="hljs-default-function" style="color: rgb(171, 178, 191);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 229px;text-decoration: none solid rgb(171, 178, 191);font-weight: 400;font-style: normal;"><span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 19px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">def</span> <span class="hljs-default-title" style="color: rgb(97, 174, 238);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 125px;text-decoration: none solid rgb(97, 174, 238);font-weight: 400;font-style: normal;">updateObstacleGroup</span><span class="hljs-default-params" style="color: rgb(171, 178, 191);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 78px;text-decoration: none solid rgb(171, 178, 191);font-weight: 400;font-style: normal;">(map<span class="hljs-default-number" style="color: rgb(209, 154, 102);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 7px;text-decoration: none solid rgb(209, 154, 102);font-weight: 400;font-style: normal;">0</span>, map1)</span></span>:<br  />    obstacles = pygame.sprite.Group()<br  />    <span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 20px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">for</span> ob <span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 13px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">in</span> <span class="hljs-default-symbol" style="color: rgb(97, 174, 238);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 33px;text-decoration: none solid rgb(97, 174, 238);font-weight: 400;font-style: normal;">map0:</span>  obstacles.add(ob)<br  />    <span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 20px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">for</span> ob <span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 13px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">in</span> <span class="hljs-default-symbol" style="color: rgb(97, 174, 238);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 33px;text-decoration: none solid rgb(97, 174, 238);font-weight: 400;font-style: normal;">map1:</span>  obstacles.add(ob)<br  />    <span class="hljs-default-keyword" style="color: rgb(198, 120, 221);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: rgba(0, 0, 0, 0);display: inline;width: 39px;text-decoration: none solid rgb(198, 120, 221);font-weight: 400;font-style: normal;">return</span> obstacles<br  /></code></pre></p>
因为篇幅有所限制,两款游戏仅展示了部分代码。若想了解详情,可自行查看源码,也可以点击文末的阅读原文来获取源码。

技术分析

后记

鸟长大了,能飞入各种林子。今天遇到了一个黑粉,我对此进行了吐槽。为了提升微信群的内容质量,我在微信群名字前面加上了【禁非合作推文】,然而……



结果退群之后还祝我新年快乐...What!?

视学算法的读者发表了他们的意见,在此,我们要感谢各位合作伙伴以及读者给予的支持。

大家可以对今天带来的小游戏进行进一步思考。从小时候会抱着手机电脑打游戏,到现在能够开发出简单的小游戏,这是一种进步,同时也是一种责任。从牙牙学语时的天真无邪,到走向社会后懂得我无尔诈、尔无我虞,这不仅仅是后知后觉的成长,更是矢志不渝的考量。每一行所写的代码,代表着自己的执着,这种执着是不求回报的;代表着一种大无畏精神,就如同咬定青山不放松;还代表着有着成为人上人的壮志凌云。

现在大部分人都处于“道理我都懂,可是我做不到”的世界中。然而,我期望在若干年后,我们能够怀着“初听不识曲中意,再听已是曲中人”的心境,郑重地向朋友讲述自己当年所做的那些事,讲解属于自己的故事。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|【宏智网络】 ( 京ICP备20013102号 )

GMT+8, 2025-5-15 04:51 , Processed in 0.114837 second(s), 20 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表