|
Post by account_disabled on Jan 27, 2024 3:37:24 GMT
以下是我们的新书《HTML5 游戏:忍者新手》的简短摘录,作者为 Earle Castledine。SitePoint Premium 会员资格包含对这本书的访问权限,或者您也可以在世界各地的商店购买一本。您可以在此处查看第一章的免费样本。 我们现在拥有所有可以使用的工具来创造极其详细的世界来探索和居住。不幸的是,我们的邻居还没有证明自己是非常有价值的对手。他们很愚蠢:他们没有表现出任何情感,没有思想,没有阿尼玛。我们可以通过图形、动画,尤其是人工智能(AI)来灌输这些特征。 人工智能是一个巨大且极其复杂的领域。幸运的是,即使人工智能比智能多得多,我们也可以获得令人印象深刻的结果。一些简单的规则(与我们的老朋友相结合Math.random)可以给出一种还算可以的意图和思想幻觉。 它不必过于现实,只要它支持我们的游戏机制并且有趣即可。 与碰撞检测一样,人工智能通 WhatsApp 号码数据 常在效果不太好时才是最好的。计算机对手是超人。他们拥有全知的天赋,能够了解世界每个时间点的整个状况。可怜的老人类玩家只能看到屏幕上可见的内容。它们通常无法与计算机相比。 但我们不会让他们知道!他们会感觉很糟糕,质疑人类的未来,并且不想玩我们的游戏。作为游戏设计师,我们的工作是平衡和决定游戏的流程,以便游戏始终公平、具有挑战性且让玩家感到惊讶。 有意识的运动 Learn to Code with JavaScript 选择精灵在游戏中的移动方式非常有趣。该update功能是您的空白画布,您可以对实体进行神一般的控制。有什么理由不喜欢这个呢! 实体移动的方式取决于我们每帧改变其位置x和y位置的程度。 到目前为止,我们基本上用直线移动了东西。添加速度(乘以增量)会使精灵向右移动。减法将其移至左侧。改变y坐标将其上下移动。 为了让直线变得更有趣,注入一点三角函数。使用精灵会通过正弦波上下摆动。t * 10是波的频率。t是我们更新系统的时间(以秒为单位),因此它总是线性增加。使其Math.sin产生平滑的正弦波。更改乘数将改变频率:数字越小振荡越快。200是波的振幅。 您可以组合波浪以获得更有趣的结果。假设您在 y 位置添加了另一个正弦波。它几乎与第一个完全相同,但频率变化很小。现在,当两个波在同相和异相漂移时相互增强和抵消,实体上下摆动的速度更快或更慢。大幅度改变频率和幅度可以产生一些有趣的弹跳模式。改变你就得到了圆圈。 重要的是,可以组合动作来做出看起来更复杂的行为。
|
|