编码《Jetpac》火箭组装动作 | 《Wireframe》第40期
拾取飞船部件、加注燃料,然后升空——马克·范斯通(Mark Vanstone)使用 Python 与 Pygame Zero 对 ZX Spectrum 经典游戏的复刻实现

原版《Jetpac》,尽显 8 位 ZX Spectrum 风采
对 ZX Spectrum 用户而言,等待游戏从磁带加载的过程别具魅力:计算机旁的磁带机嘶嘶作响,播放着代表 0 和 1 的尖锐音调。当加载画面——一幅宇航员图像及 Ultimate Play the Game 公司标志——浮现于屏幕时,你便知道这段等待终将值得。这款由克里斯·斯坦珀(Chris Stamper)与蒂姆·斯坦珀(Tim Stamper)兄弟于 1983 年开发的游戏,是他们创立的工作室 Ultimate Play the Game 推出的首批热门作品之一。游戏中,倒霉的宇航员“喷气人”(Jetman)必须收集散落在屏幕各处的火箭部件并为其加注燃料,同时躲避或射击成群袭来的致命外星生物。
本期代码片段将实现“喷气人”收集火箭部件与燃料、最终令飞船升空的核心机制。我们可以利用 Pygame Zero 内置的 Actor 对象来表示所有屏幕元素,并借助 Actor 的碰撞检测机制处理重力效果与物品拾取逻辑。首先,我们需要初始化各个 Actor:包括“喷气人”、地面、若干平台、火箭的三个部件、火箭发动机火焰以及一个燃料容器。每个 Actor 的行为均由一组列表控制:我们设有受重力影响的对象列表、每帧需绘制的对象列表、平台列表、碰撞检测对象列表,以及可拾取物品列表。

“喷气人”跃入火箭,一飞冲天!万岁!
我们的draw() function is straightforward as it loops through the list of items in the draw list and then has a couple of conditional elements being drawn after. The update() function is where all the action happens: we check for keyboard input to move Jetman around, apply gravity to all the items on the gravity list, check for collisions with the platform list, pick up the next item if Jetman is touching it, apply any thrust to Jetman, and move any items that Jetman is holding to move with him. When that’s all done, we can check if refuelling levels have reached the point where Jetman can enter the rocket and blast off.
若查看辅助函数checkCollisions() and checkTouching(), you’ll see that they use different methods of collision detection, the first being checking for a collision with a specified point so we can detect collisions with the top or bottom of an actor, and the touching collision is a rectangle or bounding box collision, so that if the bounding box of two Actors intersect, a collision is registered. The other helper function applyGravity() makes everything on the gravity list fall downward until the base of the Actor hits something on the collide list.
如此便大功告成:组装火箭、注入燃料、点火升空。唯一尚待添加的是大量烦人的外星生物,以及一把能用激光枪消灭它们的机制。

这是马克的《Jetpac》完整代码。要在您的系统上运行它,您需要安装 Pygame Zero。并且要下载全部代码与资源文件,请点击此处。
获取《Wireframe》第40期纸质版
你可以在本期杂志中阅读更多类似内容《Wireframe》第40期,现可通过 Raspberry Pi Press 官方渠道直接订购——支持全球配送。[19] 免费下载第40期电子版
如果你想要一份方便的电子版杂志,也可以免费下载第40期的PDF格式版本。

3条评论
JonM
因此,当我点击“下载完整代码和资源,请前往此处”链接时,跳转到的页面显示:
“正在更新您的电子游戏杂志,
请稍候……”
该网站是否已宕机?
Simon – SnapShooter 备份服务
我们也遇到了相同的问题 :/
TimS
我也遇到了同样的问题,但通过“修改”上个月代码的 URL 成功绕过了该问题。请尝试以下链接:
https://github.com/Wireframe-Magazine/Wireframe-40
评论已关闭