我们使用一些必要的Cookie来确保网站正常运行。

我们使用可选的 Cookie,具体详情请参阅我们的Cookie政策,用于记住您的设置并了解您如何使用我们的网站。

制作一款《猴岛小英雄》风格的冒险游戏 | 线框图 #69

使用脚本系统重现卢卡斯艺术公司经典的点击式冒险游戏《猴岛小英雄》。马克·范斯顿在本期《线框图》杂志中提供了代码,《线框图》杂志,现已上市。

1990年,卢卡斯艺术推出了一个点击式冒险游戏,凭借其幽默感、叙事风格和巧妙的谜题立刻吸引了观众。事实上,《猴岛小英雄的秘密》——最初发布于阿米加、雅达利ST、MS-DOS和麦金塔平台——深受喜爱,至今仍在持续更新;最新作品《重返猴岛》于2022年推出,系列创始人罗恩·吉尔伯特再次担任导演。

A screen from the original Secret of Monkey Island, published in 1990. Hero Guybrush Threepwood is on his way to the Scumm bar.
在卢卡斯艺术公司的海盗与点击经典之作《猴岛小英雄的秘密》中,盖布里什抵达了“斯卡姆酒吧”。

原版游戏讲述了年轻盖布里什·三木伍德立志成为海盗,以及他与幽灵反派勒查克相遇的故事。与卢卡斯艺术同期的其他冒险游戏一样,《猴岛》将角色之间的脚本化互动、动画效果和可操作物品结合在每个场景中。在本示例中,我们将重现游戏的开场:盖布里什遇见瞭望员,并询问如何成为一名海盗。我们将编写一个脚本系统,能够处理角色互动并响应玩家所面对的选择。

我们的脚本系统概念简单,但足够灵活,可以随着开发进程逐步添加更多选项。脚本保存在一个文本文件 data.txt 中。其中包含如 Background:clifftop 这类命令,我们将其解释为“将场景背景设置为名为 clifftop 的图像”。每行一个命令,命令与其动作之间用冒号分隔。根据命令内容,格式可能需要调整。

为了开始我们的场景,我们加载数据文件,将默认背景图像设为标题画面,然后开始读取脚本列表中的行。我们的processScriptLine() function breaks up each line of the script into commands and action data. For example, our first line of script is Pause:8 – Pause is a command and 8 is the data. This sets a countdown lasting eight seconds before the next line of script is read. Then we can set the background image with a Background command, and in this scene, we’ve set a foreground image of a wall so that our characters can move behind it.

Our Python homage to The Secret of Monkey Island.
我们对《猴岛小英雄》的Python致敬。也许你可以让盖布里什的冒险走向全新的方向?

为了设置角色,我们有一个角色列表(Actors),而脚本命令将决定使用该列表中的哪个槽位来表示该角色。对于盖布里什,我们将使用第0个槽位,并在脚本中写入Character:0:guybrush1,460,220. This translates to, ‘Set character 0 to the image guybrush1 and position it at x=460, y=220’. We can set up a character for the lookout man in the same way and make Guybrush walk towards him by alternating between two walking frames and pausing in between each. We then start the dialogue between the two characters. We define a Speech command and have the text defined in this script line appear over the character’s head. While this speech is being displayed, we can alternate between two animation frames to make it look like the character’s talking.

这样,我们就搭建起了场景脚本系统的基础。在进入下一场景之前,会有一段对话。在此示例中,我们可以为玩家设置一些可点击的文字选项。当玩家点击“前往斯卡姆酒吧”的选项时,我们会查找脚本中是否存在Scene command for ‘Scumm Bar’ and start reading the script from there.

我们在这里只制作了《猴岛小英雄的秘密》冒险游戏的一小部分。要继续推进剧情,我们需要向脚本系统添加更多命令,以允许盖布里什在屏幕上移动并与物品互动,但我们的代码片段应能为你创建自己的点击式冒险游戏提供良好基础。

An image of the Python and Pygame Zero code listing from this month's edition of Wireframe magazine.
这是马克为一款《猴岛小英雄》风格的冒险游戏场景提供的代码。要在你的系统上运行它,你首先需要安装 Pygame Zero。完整说明请访问wfmag.cc/pgzero。完整的代码清单和资源可在此处找到.

获取你的《线框图》#69 版本

你可以在更多类似文章中阅读《线框图》第69期的内容,可直接从树莓派出版社购买——我们支持全球配送。

The cover of Wireframe issue 69, featuring a landscape image from the upcoming adventure game, Planet of Lana.
光彩夺目的《Wireframe》全新版本,内含一张免费海报!

如果您更喜欢数字版杂志,还可以下载《Wireframe》第69期的免费PDF!

1条评论

Jamie Biggs avatar

这让我瞬间回到90年代,我稍后会好好研究一下!谢谢。

评论已关闭