生活随笔
收集整理的這篇文章主要介紹了
GameMaker Studio 中的组合技(Combo)设置
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
引言
這期我們來看看如何設置一個基本的連擊系統(tǒng)。
同樣,本文依舊面對新手。
概述:組合技,取消和連續(xù)技
在我們開始之前,我想指出有不同種類的組合技。一般來說,一個組合就是當一個攻擊一個接一個地連接,你的敵人除了一直挨揍什么也干不了。但是,從第一次攻擊到第二次攻擊的方式可能會有所不同。
chain combo?就是說你的第二次攻擊中斷或者取消當前的攻擊。你的第一次攻擊在它所在的位置停止,接著打出第二次攻擊。(取消攻擊后搖,類似于鬼泣的JC斬)
link combo?是當你的第一次攻擊完全結束,你的角色恢復到他們的中立狀態(tài)時,你的對手仍然被擊暈足夠長的時間讓你開始第二次攻擊并擊中他們。
譯注:如果你是格斗游戲玩家,會對這些非常清楚,當然了,如果你在讀這篇文章,我會假定你很喜歡動作格斗類游戲,咱們在這兒就不多啰嗦了。
攻擊精靈圖
我們還是用之前 hitbox 那篇文章中的精靈圖,不過要做一些修改,因為我們要做 combo。
我們要加兩個新的攻擊動作。
sprPlayer_Attack_2
?
sprPlayer_Attack_3
這些有點小,但這是因為它們是游戲的原生分辨率。我還對之前的原始攻擊動畫做了一些更改。使用我們的新攻擊有點太長了,所以我刪除了一堆幀以使其適合我們的新精靈。
sprPlayer_Attack
?
導入精靈長帶圖(如果有疑問請看 F1),將原點設為16x32
初始化新變量
打開?oPlayer?的?create?事件,加入下面代碼:
?
currentAttack = attacks.right;hitLanded = false; 復制代碼
currentAttack?將用于根據(jù)玩家當前正在進行的攻擊來定義不同的行為和動畫。?hitLanded?將是我們的布爾值,我們用它來告訴我們可以取消當前攻擊到下一次攻擊。
打開?enum_init?腳本,讓我們?yōu)樾碌墓籼砑右恍┬碌拿杜e。將此代碼添加到腳本的底部。
?
enum attacks {? ?? ???right,? ?? ???left,? ?? ???upper} 復制代碼
最后,我們需要擴展一下 hitbox_create 腳本,加一個參數(shù)。打開該腳本并將以下代碼復制/粘貼到其上。
?
_hitbox = instance_create(x,y,oHitbox);_hitbox.owner = id;_hitbox.image_xscale = argument0;_hitbox.image_yscale = argument1;_hitbox.xOffset = argument2;_hitbox.yOffset = argument3;_hitbox.life = argument4;_hitbox.xHit = argument5;_hitbox.yHit = argument6;_hitbox.hitStun = argument7;return _hitbox; 復制代碼
我們添加了?_hitbox.yHit,這樣做可以讓我們把敵人打到浮空,而不是僅僅向后擊退。
打開?normal_state?腳本,再最下面加入如下代碼:
?
//reset attackcurrentAttack = attacks.right; 復制代碼
這可以確保我們的攻擊始終從攻擊鏈中的第一次攻擊開始。這就是初始化新變量和枚舉的全部內容。
擴展 switch 語句
現(xiàn)在我們已經(jīng)擁有了所有這些新攻擊,二手手機拍賣平臺我們需要為每個攻擊設置動畫。使用我們剛剛初始化的新枚舉和嵌套的?switch?語句可以輕松實現(xiàn)這一點。打開?animation_control?腳本,讓我們更改?states.attack?以包含新的精靈圖。
case states.attack:switch(currentAttack){? ? case attacks.right:? ?? ???sprite = sprPlayer_Attack;? ?? ???break;? ? case attacks.left:? ?? ???sprite = sprPlayer_Attack_2;? ?? ???break;? ? case attacks.upper:? ?? ???sprite = sprPlayer_Attack_3;? ?? ???break;}break; 復制代碼
attack_state?腳本也要更改:
?
switch(currentAttack){? ? case attacks.right:? ?? ???//create hitbox on the right frame? ?? ???if(floor(frame) == 1 && hitbox == -1){? ?? ?? ?? ?hitbox = hitbox_create(20 * facing,12,-3 * facing,-16,8,1 * facing,0,60);? ?? ???}? ?? ???//cancel into next attack? ?? ???if(attack && hitLanded){? ?? ?? ?? ?currentAttack = attacks.left;? ?? ?? ?? ?hitLanded = false;? ?? ?? ?? ?hitbox = -1;? ?? ?? ?? ?frame = 0;? ?? ???}? ? break;? ? case attacks.left:? ?? ???//create hitbox on the right frame? ?? ???if(floor(frame) == 1 && hitbox == -1){? ?? ?? ?? ?hitbox = hitbox_create(20 * facing,12,-3 * facing,-16,8,1 * facing,0,45);? ?? ?? ?? ?//also move forward? ?? ?? ?? ?xSpeed = 3 * facing;? ?? ???}? ?? ???//cancel into next attack? ?? ???if(attack && hitLanded){? ?? ?? ?? ?currentAttack = attacks.upper;? ?? ?? ?? ?hitLanded = false;? ?? ?? ?? ?hitbox = -1;? ?? ?? ?? ?frame = 0;? ?? ???}? ? break;? ? case attacks.upper:? ?? ???//create hitbox on the right frame? ?? ???if(floor(frame) == 1 && hitbox == -1){? ?? ?? ?? ?hitbox = hitbox_create(20 * facing,12,-3 * facing,-16,8,1 * facing,-4,45);? ?? ?? ?? ?//also move forward? ?? ?? ?? ?ySpeed = -3;? ?? ???}? ?? ???break;? ? } 復制代碼
我在這里要解釋一下。首先,我們完成了與?animation_control?腳本完全相同的操作,并加了一個?switch?語句,其中包含每種攻擊類型的情況。?hitbox_create?腳本已更新為包含我們的新?yHit?參數(shù)。這是倒數(shù)第二個值。你可能注意到前兩次攻擊已將其設置為零。那是因為我們不想在這些攻擊中將敵人打到浮空。
其次,我添加了一個檢查以允許取消進入下一次攻擊。我們檢查是否按下了攻擊按鈕并且?hitLanded?是否為?true。如果滿足兩個條件,則更改為另一個攻擊,將動畫幀重置為零,并將?hitbox?設置為?-1。如果?hitbox?變量未重置為?-1,則在下一次攻擊發(fā)生時不會創(chuàng)建新的?hitbox。我們還將?currentAttack?設置為我們想要取消當前攻擊后進入的下一次攻擊。
最后,當在第二次和第三次攻擊中創(chuàng)建了?hitbox?時,我們也會對玩家角色加點兒動勢。您將看到正在設置?xSpeed?和?ySpeed。在?attacks.left?情況下,這將使玩家向前移動一點,以確保在第一次攻擊擊退敵人后讓下一擊能夠擊中敵人。在?attacks.upper?案例中設置的?ySpeed?會將玩家打到空中,對,就等于是簡化出招的隆的升龍拳。
Applying yHit
雖然我們將?yHit?添加到?hitbox_create?腳本中,但還沒應用于敵人。在?oEnemy?對象中,打開?end step?事件,讓我們加點兒東西。
?
//get hitif(hit){? ? squash_stretch(1.3,1.3);? ? xSpeed = hitBy.xHit;? ? ySpeed = hitBy.yHit;? ? hitStun = hitBy.hitStun;? ? facing = hitBy.owner.facing * -1;? ? hit = false;? ? currentState = states.hit;} 復制代碼
設置和重置 hitLanded
最后一步,打開?oPlayer?的?end step?事件,當我們的?hitbox?打中敵人時,把?hitLanded?設為?true:
?
//hitboxif(hitbox != -1){? ? with(hitbox){? ?? ???x = other.x + xOffset;? ?? ???y = other.y + yOffset;? ?? ???//collision check? ?? ???//checking the collision from the hurtbox object? ?? ???with(oHurtbox){? ?? ?? ?? ?if(place_meeting(x,y,other) && other.owner != owner){? ?? ?? ?? ?? ? //ignore check? ?? ?? ?? ?? ? //checking collision from the hitbox object? ?? ?? ?? ?? ? with(other){? ?? ?? ?? ?? ?? ???//check to see if your target is on the ignore list? ?? ?? ?? ?? ?? ???//if it is on the ignore list, dont hit it again? ?? ?? ?? ?? ?? ???for(i = 0; i < ds_list_size(ignoreList); i ++){? ?? ?? ?? ?? ?? ?? ?? ?if(ignoreList[|i] = other.owner){? ?? ?? ?? ?? ?? ?? ?? ?? ?ignore = true;? ?? ?? ?? ?? ?? ?? ?? ?? ? break;? ?? ?? ?? ?? ?? ?? ?? ?}? ?? ?? ?? ?? ?? ???}? ?? ?? ?? ?? ?? ???//if it is NOT on the ignore list, hit it, and add it to? ?? ?? ?? ?? ?? ???//the ignore list? ?? ?? ?? ?? ?? ???if(!ignore){? ?? ?? ?? ?? ?? ?? ?? ?other.owner.hit = true;? ?? ?? ?? ?? ?? ?? ?? ?other.owner.hitBy = id;? ?? ?? ?? ?? ?? ?? ?? ?owner.hitLanded = true;? ?? ?? ?? ?? ?? ?? ?? ?ds_list_add(ignoreList,other.owner);? ?? ?? ?? ?? ?? ???}? ?? ?? ?? ?? ? }? ?? ?? ?? ?}? ?? ???}? ? }} 復制代碼
打開?normal_state?腳本并將其添加到腳本的末尾。
?
//reset hit landedhitLanded = false; 復制代碼
這將確保在攻擊發(fā)生之前始終將?hitLanded?設置為?false,因為我們的攻擊始終從?normal_state?腳本啟動。
運行游戲并開始打擊你的對手!如果你用不同的按鍵對應3種攻擊,你的角色應該執(zhí)行一個由三種攻擊組成的 chain combo~
感謝閱讀~
總結
以上是生活随笔為你收集整理的GameMaker Studio 中的组合技(Combo)设置的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網(wǎng)站內容還不錯,歡迎將生活随笔推薦給好友。