- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
这是游戏代码
https://inventwithpython.com/pygame/chapter3.html
我目前将显示速度设置为 1,但这是针对初始显示和玩游戏时的显示。无论如何,我是否能够将初始显示速度保持在 1,然后在播放时将显示速度更改为更快的速度?
为了做到这一点,我觉得我需要在第 12 行的 revealspeed 下添加一行代码,我只是不知道新行应该说什么。
FPS = 30 # frames per second, the general speed of the program
WINDOWWIDTH = 640 # size of window's width in pixels
WINDOWHEIGHT = 480 # size of windows' height in pixels
REVEALSPEED = 2 # speed boxes' sliding reveals and covers
BOXSIZE = 60 # size of box height & width in pixels
GAPSIZE = 10 # size of gap between boxes in pixels
BOARDWIDTH = 8 # number of columns of icons
BOARDHEIGHT = 7 # number of rows of icons
assert (BOARDWIDTH * BOARDHEIGHT) % 2 == 0, 'Board needs to have an even number of boxes for pairs of matches.'
XMARGIN = int((WINDOWWIDTH - (BOARDWIDTH * (BOXSIZE + GAPSIZE))) / 2)
YMARGIN = int((WINDOWHEIGHT - (BOARDHEIGHT * (BOXSIZE + GAPSIZE))) / 2)
最佳答案
所以我们想以两种不同的速度制作动画,所以让我们首先为此创建一个新的全局变量:
...
WINDOWHEIGHT = 480 # size of windows' height in pixels
# ADD THIS
INITIALREVEALSPEED = 1 # speed boxes' sliding reveals and covers AT THE START OF THE GAME
REVEALSPEED = 8 # speed boxes' sliding reveals and covers
BOXSIZE = 40 # size of box height & width in pixels
...
通过搜索 REVEALSPEED
,我们看到动画是在 revealBoxesAnimation
和 coverBoxesAnimation
函数中处理的。他们使用 REVEALSPEED
常量(不是真正的常量,但是嘿),但我们希望速度是动态的,所以让我们只传递我们想要用作参数的速度。将功能更改为:
def revealBoxesAnimation(board, boxesToReveal, speed=REVEALSPEED):
# Do the "box reveal" animation.
for coverage in range(BOXSIZE, (-speed) - 1, -speed):
drawBoxCovers(board, boxesToReveal, coverage)
def coverBoxesAnimation(board, boxesToCover, speed=REVEALSPEED):
# Do the "box cover" animation.
for coverage in range(0, BOXSIZE + speed, speed):
drawBoxCovers(board, boxesToCover, coverage)
我们仍然使用 REVEALSPEED
作为默认值,因此我们不必更改每个方法调用。
因为我们只想在游戏开始时放慢动画速度,所以我们只需更改开始时发生的方法调用。如果我们搜索使用 revealBoxesAnimation
的地方,我们会找到 startGameAnimation
函数。让我们将其更改为:
def startGameAnimation(board):
# Randomly reveal the boxes 8 at a time.
coveredBoxes = generateRevealedBoxesData(False)
boxes = []
for x in range(BOARDWIDTH):
for y in range(BOARDHEIGHT):
boxes.append( (x, y) )
random.shuffle(boxes)
boxGroups = splitIntoGroupsOf(8, boxes)
drawBoard(board, coveredBoxes)
for boxGroup in boxGroups:
revealBoxesAnimation(board, boxGroup, INITIALREVEALSPEED)
coverBoxesAnimation(board, boxGroup, INITIALREVEALSPEED)
就是这样。
关于python - 在pygame上的内存益智游戏中,我可以保持原来的显示速度很慢,然后在玩游戏时让它变快吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58115470/
我正在尝试创建一个数据库来处理我在 Play 中的任务!框架。 这是我所拥有的: 在build.sbt中: libraryDependencies ++= Seq( jdbc, cache,
在我的游戏中定义一个表单!当编译器吐出这个奇怪的错误时 Controller :重载方法值映射与替代:...[一堆废话]...Error occurred in an application invo
我的应用程序有问题,@Max约束注释。 我的 Controller 方法定义如下: public static void save(@Required @Max(255) String content
我想创建一个像这样的标签: #{some_tag entity:user, field:'name'} 并期望它通过使用如下表达式生成带有用户名的输出: ${_entity._field} 我知道这行
我创建了一些 Model 对象来代表一家拥有多个客户的公司,以及一个由公司和客户组合以及多个发票行组成的发票对象。我创建了以下模型对象: @Entity public class Company ex
Playframework 现在是 typesafe-stack 的一部分。 那么,如果我要使用像主要语言一样的 Scala ,我现在应该下载什么? TypsafeStack 还是 PlayFrame
在玩!如果你这样称呼: void method() { User u = User(); u.name = "bob"; u.save(); while(true){/* endless loop *
我正在 Play 中构建一个应用程序!包含大量我想跟踪更改的数据的框架。在企业解决方案中,我可能会使用数据库触发器将更改复制到历史表中以跟踪这些更改。我不熟悉 Play!/JPA 中的类似范例,但也许
我一直在学习JavaScript技能,但是遇到一个问题,当单击此处是我的代码时,音频没有被播放。 Your browser does no
我想实现在某些模型保存后在表中插入一行的行为。我当前的解决方案简而言之是:(这只是我的代码示例,因此请不要评论数据库或描述符模型的正确性)。 我有一个监听器,用于在更新/插入实体上插入行为行 Desc
如何使我的模型类字段独一无二?例如。如果已经登录,我想为用户显示正确的消息。我必须自己编写验证检查并使用它,或者可以使用 JPA @UniqueConstraint? 最佳答案 我是这样做的: @En
我使用的是 Play 1.2.1。我想对我的用户密码进行哈希处理。我认为 Crypto.passwordHash 会很好,但事实并非如此。 passwordHash 文档说它返回 MD5 密码哈希值。
我一直在研究戏剧!框架模块并希望扩展它,添加一些功能。我发现了一个从Enhancer(play.classloading.enhancers.Enhancer)扩展的类,但不明白为什么Play!采用了
我使用的是 Play Framework 1.2.5。我有几个与 NAme 和 Age 字段相关的验证。年龄验证无法正常工作。即使年龄大于 18 岁,我也会收到错误消息。 下面是action方法中的验
我使用的是 Play Framework 1.2.5。两者有什么区别: @{Application.render()} 和 @Application.render() 第一个最好用在表单 Action
我是新来的!我被一些总是有错误的表格所困扰。即使所有字段都已填写,我也无法弄清楚问题是什么。 路线 GET /products/ controllers.Pr
我显示可编辑的数据库表行的列表。我想允许用户编辑显示表中的数据并同时保存所有更新。我应该如何取回 Controller 的更新列表? 最佳答案 由于 Play 可以绑定(bind)到 POJO,也可以
那么,假设我从 Controller 异步启动一个作业,然后渲染一些模板。 MyJob job = new MyJob(); job.doJob(); render(); 我的工作看起来像: 导入 p
当前使用的 Play Framework 为 2.0.4。当我尝试使用此命令升级到 2.6.21 时: addSbtPlugin("com.typesafe.play"% "sbt-plugin"%
我目前正在与 Play 合作!框架和看来日志记录只适用于游戏!仅但对于具有 LOGGER 初始化的类不起作用。 这是 logback.xml ${application.hom
我是一名优秀的程序员,十分优秀!