游戏开发论坛

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

GameMaker Studio 中的组合技(Combo)设置

[复制链接]

8364

主题

8525

帖子

1万

积分

版主

Rank: 7Rank: 7Rank: 7

积分
14833
发表于 2018-11-16 13:36:26 | 显示全部楼层 |阅读模式
01.gif

文/Nathan Ranney
译/highway

引言

这期我们来看看如何设置一个基本的连击系统。

同样,本文依旧面对新手。

概述:组合技,取消和连续技

在我们开始之前,我想指出有不同种类的组合技。一般来说,一个组合就是当一个攻击一个接一个地连接,你的敌人除了一直挨揍什么也干不了。但是,从第一次攻击到第二次攻击的方式可能会有所不同。

chain combo 就是说你的第二次攻击中断或者取消当前的攻击。你的第一次攻击在它所在的位置停止,接着打出第二次攻击。(取消攻击后摇,类似于鬼泣的JC斩)

link combo 是当你的第一次攻击完全结束,你的角色恢复到他们的中立状态时,你的对手仍然被击晕足够长的时间让你开始第二次攻击并击中他们。

译注:如果你是格斗游戏玩家,会对这些非常清楚,当然了,如果你在读这篇文章,我会假定你很喜欢动作格斗类游戏,咱们在这儿就不多啰嗦了。

攻击精灵图

我们还是用之前 hitbox 那篇文章中的精灵图,不过要做一些修改,因为我们要做 combo。

我们要加两个新的攻击动作。

sprPlayer_Attack_2

02.png

sprPlayer_Attack_3

03.png

这些有点小,但这是因为它们是游戏的原生分辨率。我还对之前的原始攻击动画做了一些更改。使用我们的新攻击有点太长了,所以我删除了一堆帧以使其适合我们的新精灵。

sprPlayer_Attack


04.png

导入精灵长带图(如果有疑问请看 F1),将原点设为16x32

初始化新变量

打开 oPlayer create 事件,加入下面代码:

  1. currentAttack = attacks.right;
  2. hitLanded = false;
复制代码

currentAttack 将用于根据玩家当前正在进行的攻击来定义不同的行为和动画。 hitLanded 将是我们的布尔值,我们用它来告诉我们可以取消当前攻击到下一次攻击。

打开 enum_init 脚本,让我们为新的攻击添加一些新的枚举。将此代码添加到脚本的底部。

  1. enum attacks {
  2.         right,
  3.         left,
  4.         upper
  5. }
复制代码

最后,我们需要扩展一下 hitbox_create 脚本,加一个参数。打开该脚本并将以下代码复制/粘贴到其上。

  1. _hitbox = instance_create(x,y,oHitbox);
  2. _hitbox.owner = id;
  3. _hitbox.image_xscale = argument0;
  4. _hitbox.image_yscale = argument1;
  5. _hitbox.xOffset = argument2;
  6. _hitbox.yOffset = argument3;
  7. _hitbox.life = argument4;
  8. _hitbox.xHit = argument5;
  9. _hitbox.yHit = argument6;
  10. _hitbox.hitStun = argument7;


  11. return _hitbox;
复制代码

我们添加了 _hitbox.yHit,这样做可以让我们把敌人打到浮空,而不是仅仅向后击退。

打开 normal_state 脚本,再最下面加入如下代码:

  1. //reset attack
  2. currentAttack = attacks.right;
复制代码

这可以确保我们的攻击始终从攻击链中的第一次攻击开始。这就是初始化新变量和枚举的全部内容。

扩展 switch 语句


现在我们已经拥有了所有这些新攻击,我们需要为每个攻击设置动画。使用我们刚刚初始化的新枚举和嵌套的 switch 语句可以轻松实现这一点。打开 animation_control 脚本,让我们更改 states.attack 以包含新的精灵图。

  1. case states.attack:
  2. switch(currentAttack){
  3.     case attacks.right:
  4.         sprite = sprPlayer_Attack;
  5.         break;
  6.     case attacks.left:
  7.         sprite = sprPlayer_Attack_2;
  8.         break;
  9.     case attacks.upper:
  10.         sprite = sprPlayer_Attack_3;
  11.         break;
  12. }
  13. break;
复制代码

attack_state 脚本也要更改:

  1. switch(currentAttack){
  2.     case attacks.right:
  3.         //create hitbox on the right frame
  4.         if(floor(frame) == 1 && hitbox == -1){
  5.             hitbox = hitbox_create(20 * facing,12,-3 * facing,-16,8,1 * facing,0,60);
  6.         }
  7.         //cancel into next attack
  8.         if(attack && hitLanded){
  9.             currentAttack = attacks.left;
  10.             hitLanded = false;
  11.             hitbox = -1;
  12.             frame = 0;
  13.         }
  14.     break;
  15.     case attacks.left:
  16.         //create hitbox on the right frame
  17.         if(floor(frame) == 1 && hitbox == -1){
  18.             hitbox = hitbox_create(20 * facing,12,-3 * facing,-16,8,1 * facing,0,45);
  19.             //also move forward
  20.             xSpeed = 3 * facing;
  21.         }
  22.         //cancel into next attack
  23.         if(attack && hitLanded){
  24.             currentAttack = attacks.upper;
  25.             hitLanded = false;
  26.             hitbox = -1;
  27.             frame = 0;
  28.         }
  29.     break;
  30.     case attacks.upper:
  31.         //create hitbox on the right frame
  32.         if(floor(frame) == 1 && hitbox == -1){
  33.             hitbox = hitbox_create(20 * facing,12,-3 * facing,-16,8,1 * facing,-4,45);
  34.             //also move forward
  35.             ySpeed = -3;
  36.         }
  37.         break;
  38.     }
复制代码

我在这里要解释一下。首先,我们完成了与 animation_control 脚本完全相同的操作,并加了一个 switch 语句,其中包含每种攻击类型的情况。 hitbox_create 脚本已更新为包含我们的新 yHit 参数。这是倒数第二个值。你可能注意到前两次攻击已将其设置为零。那是因为我们不想在这些攻击中将敌人打到浮空。

其次,我添加了一个检查以允许取消进入下一次攻击。我们检查是否按下了攻击按钮并且 hitLanded 是否为 true。如果满足两个条件,则更改为另一个攻击,将动画帧重置为零,并将 hitbox 设置为 -1。如果 hitbox 变量未重置为 -1,则在下一次攻击发生时不会创建新的 hitbox。我们还将 currentAttack 设置为我们想要取消当前攻击后进入的下一次攻击。

最后,当在第二次和第三次攻击中创建了 hitbox 时,我们也会对玩家角色加点儿动势。您将看到正在设置 xSpeedySpeed。在 attacks.left 情况下,这将使玩家向前移动一点,以确保在第一次攻击击退敌人后让下一击能够击中敌人。在 attacks.upper 案例中设置的 ySpeed 会将玩家打到空中,对,就等于是简化出招的隆的升龙拳。

Applying yHit

虽然我们将 yHit 添加到 hitbox_create 脚本中,但还没应用于敌人。在 oEnemy 对象中,打开 end step 事件,让我们加点儿东西。

  1. //get hit
  2. if(hit){
  3.     squash_stretch(1.3,1.3);
  4.     xSpeed = hitBy.xHit;
  5.     ySpeed = hitBy.yHit;
  6.     hitStun = hitBy.hitStun;
  7.     facing = hitBy.owner.facing * -1;
  8.     hit = false;
  9.     currentState = states.hit;
  10. }
复制代码

设置和重置 hitLanded

最后一步,打开 oPlayer end step 事件,当我们的 hitbox 打中敌人时,把 hitLanded 设为 true

  1. //hitbox
  2. if(hitbox != -1){
  3.     with(hitbox){
  4.         x = other.x + xOffset;
  5.         y = other.y + yOffset;
  6.         //collision check
  7.         //checking the collision from the hurtbox object
  8.         with(oHurtbox){
  9.             if(place_meeting(x,y,other) && other.owner != owner){
  10.                 //ignore check
  11.                 //checking collision from the hitbox object
  12.                 with(other){
  13.                     //check to see if your target is on the ignore list
  14.                     //if it is on the ignore list, dont hit it again
  15.                     for(i = 0; i < ds_list_size(ignoreList); i ++){
  16.                         if(ignoreList[|i] = other.owner){
  17.                            ignore = true;
  18.                             break;
  19.                         }
  20.                     }
  21.                     //if it is NOT on the ignore list, hit it, and add it to
  22.                     //the ignore list
  23.                     if(!ignore){
  24.                         other.owner.hit = true;
  25.                         other.owner.hitBy = id;
  26.                         owner.hitLanded = true;
  27.                         ds_list_add(ignoreList,other.owner);
  28.                     }
  29.                 }
  30.             }
  31.         }
  32.     }
  33. }
复制代码

打开 normal_state 脚本并将其添加到脚本的末尾。

  1. //reset hit landed
  2. hitLanded = false;
复制代码

这将确保在攻击发生之前始终将 hitLanded 设置为 false,因为我们的攻击始终从 normal_state 脚本启动。
运行游戏并开始打击你的对手!如果你用不同的按键对应3种攻击,你的角色应该执行一个由三种攻击组成的 chain combo~

感谢阅读~

工程文件


项目的工程文件点我下载

来源:INDIENOVA
地址:https://www.indienova.com/indie-game-development/combo-in-gms/


相关阅读: GameMaker Studio 之中的攻击与受击判定盒
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2024-3-29 05:06

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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