ミニゲームのコアの動作は、verse_commander_minigame
Verse の仕掛けで定義します。 この仕掛けはミニゲームを開始し、UI とキャラクター間の通信を処理し、ゲームで使用されるボードを実行します。
この仕掛けには、エディタで変更できる次のフィールドがあります。
HUDController:デフォルトのすべてのフォートナイトの HUD 要素を削除するための HUD 制御の仕掛け。
PlayVerseCommanderButton:ミニゲームを開始するボタンの仕掛け。
NPCSpawner:ミニゲームのキャラクターをスポーンできるようにするための NPC スポナーの仕掛け。
Gameboards:ゲームのボードのリスト。 ボードはリストに表示される順序で再生されます。
UICommandLimit:リストの下部で画面にキューできるコマンドの最大制限。
仕掛けには、キャラクターと通信し、キャラクターに情報 (キャラクターが実行するコマンド リストや、ボードのリセット時にキャラクターがテレポートするトランスフォーム) を渡すカスタム イベントも含まれています。
# A Verse-authored creative device that can be placed in a level
verse_commander_minigame := class(creative_device):
# The HUD Controller device for the minigame.
@editable
HUDController<private>:hud_controller_device = hud_controller_device{}
# The button that starts the minigame.
@editable
PlayVerseCommanderButton:button_device = button_device{}
ミニゲームを開始する
Verse コマンダー ミニゲームの仕掛けは、すべてのプレイヤーに対してミニゲームを開始する前に、コンピューターでプレイヤーがボタンの仕掛けとインタラクトするのを待機します。 この待機はループで行われます。 すべてのレベルを完了すると、必要なだけ何回でもミニゲームをプレイできます。
# Runs when the device is started in a running game.
OnBegin<override>()<suspends>:void=
spawn{Cinematic.EnterCinematicModeForAll(GetPlayspace().GetPlayers())}
loop:
PlayVerseCommanderButton.InteractedWithEvent.Await()
Setup()
# Wait for all Gameboards to be set up.
Sleep(2.0)
ゲームのループ
ゲーム ループは現在のボードを取得して開始します。 プレイヤーにとってこれが初めてのボードである場合、キャラクターはボードの開始位置にテレポートし、ボードがカメラに切り替わり、オープニング ムービーを再生します。
次に、レベル ループと UI からリセット イベントでの待機の間にレースがあります。 これらのいずれかが最初に終了すると、もう一方をキャンセルします。 ループ内の式が繰り返し、現在のボードの取得とレースの再開に戻ります。
# Loops over the current gameboard and resets them.
GameLoop<private>()<suspends>:void=
# For the current board, swap to that gameboard's camera and reset the character to the gameboard's starting position.
loop:
if:
Gameboard := Gameboards[CurrentBoard]
then:
# If first time on this board, set up the board
# and move character to starting position.
if:
ループ レベル
LevelLoop()
関数はゲームボードのロジックを管理します。 キャラクターのコマンド ループと到達するボードの最終目標の待機との間でレースを行います。 最終目標に到達すると、コマンド ループをキャンセルし、リストの次のボードを呼び出します。
コマンド ループは、プレイヤーが [Execute (実行)] ボタンを押して実行するコマンドのリストを受信するのを待機します。 ボタンはリセット ボタン以外、非アクティブ化されます。 キャラクターはコマンドを実行するように通知され、Verse の仕掛けは、ループを再開してその後のコマンドを待機する前に完了したシグナルの受信を待機します。
defer をこのループで使用して、コマンド ループまたは LevelLoop()
関数がキャンセルされた場合に UI をクリーンアップします。 defer 式はスコープを終了してボタンのインタラクティビティをリセットする直前に ResetUIForAllPlayers()
を呼び出すと、再度有効にして、一番下にあるコマンドのリストをクリアします。
# Handles command logic for the current gameboard.
LevelLoop<private>(Gameboard:gameboard)<suspends>:void=
# On the current board, race between completing the board and looping player commands.
# The race expression will cancel whichever action doesn't finish first.
race:
loop:
defer:
# If the loop is canceled because the character reached the end goal of the level,
# Or the character finished performing their commands,
# reset the UI for all the players so they can interact with it and have no commands in the queue.
ゲームをリセットする
AwaitReset()
関数は、プレイヤーがリセット ボタンを選択するのを待機します。 実行後、ボード自体がリセットし、キャラクターにボードの開始位置にテレポートするように指示します。
# Waits for the Reset button to be selected, then resets the current gameboard
# and NPC.
AwaitReset<private>(Gameboard:gameboard)<suspends>:void=
ResetButtonSelected.Await()
# Reset the current gameboard, returning the game character to the starting position and
# resetting any barriers or triggers on the board.
BoardResetEvent.Signal(Gameboard.GetStartingCharacterPosition())
# Reset Gameboard
次のステップ
ここでは、ミニゲームの Verse の仕掛けの主な機能について説明しました。 Verse コマンダー ミニゲームの仕掛けを作成するためのコードの完全なリストについては、次のステップおよび最終ステップを参照してください。
7. Final Result
Find all the Verse code used to create the Verse Starter Template.