Two Cat Games


Perang: 3 Card Battle

Choose a class below to learn about

State Machines

Picture of the winner state machine in Unreal Engine

The use of state machines is thanks to Recursoft and their Logic Driver Pro plugin. This is not the only way to create a 'state machine' but it is the one I use. It is amazing and I've barely scratched the surface of its functionality.

Pick Cards State Machine

Overview image of Pick Cards State Machine.

This State Machine is initiated at the start of the 'Pick Cards' level and has two states: pick cards and its final state.

Pick Cards State: Pick Cards

Pick Cards State: Pick Cards events.

It starts by shuffling the player's deck. This additional shuffle is good for when the player chooses to play again from the quit menu.

On State Update waits for the 'selection' array to reach a length of three. When it does, it saves the player's choices and sets the 'Cards Picked' boolean to true, which allows entry into the final state.

Pick Cards State: Save Game and Load Battle Board

Pick Cards State: Final State.

The final state in Pick Cards State Machine calls the 'Save Game Event' and the 'Go to Battle Board' from the LDA.

AI Attack State Machine

AI Attack State Machine Overview.

This is the most complex state machine in the game. If you look at the image above, the state machine can be broken into five columns: AI starts an attack, checks its card slots, chooses one of its card to attack with, chooses one of the player's cards to attack, and checks if it won the battle.

Winner State Machine

Picture of the winner state machine in Unreal Engine

The Winner State Machine sets the battle in motion and switches turns between the player and the AI. Its last few states declare the outcome of the game.

Winner State Machine State: Player's Turn

Player's turn state from Winner state machine.

The Player and the AI turn states are very similar. First it checks for a tie or a winner, then enables or disables the mouse depending on whose turn it is, and starts the Player or AI attack events. The AI and Player turn states go back and forth until there is tie game or a winner.

Winner State Machine State: AI Wins

AI Wins state from Winner State Machine.

Both the AI Wins and the Player Wins states do something similar. The mouse gets disabled, the camera is moved to its final destination and the 'Fade in End Game' event is fired off. If the player wins, an additional 'Player Wins' event is launched.

Winner State Machine State: Quit

Quit state from the Winner State Machine.

If the player wins, there is an additional 'Quit' state which dissolves the on screen cards before re-enabling the mouse and firing off the 'Fade in End Game' event.

Choose a class below to learn about

Card Card Slot Deck Board State Machines
Project Outline Button Widgets Level Database