• Evan McGrath

Evan's Dev Blog 1/4 - An Entry Approaches!

Hello everyone!

Today, I'd like to share my newest project! I recently made the switch to Android and am jumping at the chance to make a game for my phone. Currently under the working title of "Random Encounter" this project is a turn-based battle game designed for mobile. Partially inspired by a game jam game I worked on, "Random Encounter" is an endless turn-based battle where the player's spells are random each turn!

Most of my game projects have been action based, so attempting a turn-based game presented a number of challenges from the very beginning. Though some of the more visible aspects of the game including Actions and Creatures only needed to be simple scriptable objects, the core functions of the game, specifically regarding sequence of events, became the first big hurdle. I had recently attended a Boston Unity Group talk discussing how Unity's coroutine can aid in sequencing, and with that knowledge, I split up turns into three parts: a beginning phase before an action is selected, an action phase, and an ending phase. This structure had made it extremely easy to add behavior to each part of a turn. This project also makes heavy use of the extremely useful ScriptableObjectArchitecture, removing the need for a clunky game manager.

Unity's built in animation components are not well designed for an exponentially increasing move list. While I could build out an animator that has one animation for each attack, this solution would become clunky and unreadable very quickly. To solve this, I wrote my own simple animation scripting solution. I could write an entire blog post on the development of the animation system, but to keep it simple for now, an animation consists of a text file detailing all instructions that the animation will execute in order. I will definitely want to simplify this in the future to optimize attack creation.

A sample script

By far, the biggest issue related to sequencing is arguably the most important part of an RPG: the visuals. In a standard RPG, a standard attack begins with a text sequence announcing the move, followed by the move's animation. However, a move must be able to inflict an arbitrary amount of effects afterwards, some with their own animations.

Though this sequence is simple, replicating this proved to be a challenge.

My solution saw the creation of a master Sequence class, which the animation and text sequences inherit from. An animation sequence loops its Running function until the animation ends while a text sequence loops until all text is printed out. My text processor is similar to the one used in "Journey to Blackwood," but has been simplified, and text is now queued up using a custom SequenceEvent instead of a call to a static variable. Sequences are managed by a Sequencer class. When the Sequencer's Play function is called, all Sequences will run in order. Key parts of the turn, including the action and end phase wait until the Sequencer has stopped playing to advance.

A sample sequence using the animation script above.

Though a simple damaging attack is easy to develop, what happens if we want an attack that decreases in accuracy by 20% each turn it is used in succession and if the attack misses it resets? This question became the basis of the Effect system. An Effect is defined as any action that activates if a move connects. Effects can be set to linger on an given target which allows them to last until a condition is met. The effect system is still such a massive part of this project that I plan to write more about later, but to keep it simple, an effect is a scriptable object that uses UnityEvent callbacks to execute specific actions at key parts of a turn, such as the beginning and ending. Provided the right functions exist, this allows for new types of effects to be created without code.

For a simple example, the block effect applies a defensive modifier to the user.

Overall, while "Random Encounter" still has a long way to go especially in the visual and Unity Editor areas, this project has been a complete joy to work on as it is a vastly different type of game than what I normally work on.

See you next week!