A Basic Turn-Based Battle System

27

Index

Features on these Courses

Attached Files

The following files have been attached to this tutorial:

.c3p

basic-tb-battle.c3p

Download now 63.64 KB

Stats

12,675 visits, 27,608 views

Tools

Translations

This tutorial hasn't been translated.

License

This tutorial is licensed under CC BY 4.0. Please refer to the license text if you wish to reuse, share or remix the content contained within this tutorial.

Published on 5 Mar, 2021.

Now we've defined the functions, we can look at the rest of the event sheet.

When the project starts, we need to map a couple of functions so they can be called later on. When mapping a function, you need to assign a string to the map you want to use and to each function you want to add to that map. In this case, our map is called "AttackFunctions":

Condition

System ▶︎ On start of layout

Action

Function▶︎ Map "AttackFunctions" string "PlayerAttack" to PlayerAtt

Function▶︎ Map "AttackFunctions" string "OpponentAttack" to OppAtt

Next up, we need an event to set the HP values in the HP text objects. Because this is a small demo project, we'll be using the Every Tick method – but in a larger project, it's worth having as few things happening every tick as possible.

Condition

System ▶︎ Every tick

Action

OppHP ▶︎ Set text to Opponent.HP

PlayerHP ▶︎ Set text to Player.HP

This demo project is controlled using the mouse – press the attack button and it sets off the battle turn. So, an event is needed to trigger these functions:

Condition

System ▶︎ Is PlayerTurn

Sub-event Condition

Mouse ▶︎ On Left button clicked on AttackButton

Sub-event Action

Function ▶︎ Call BeginAttackSequence

As this example is staying as simple as possible, the Flash behavior is used to show when the combatants take damage, and trigger when the turn phases end:

Condition

Player ▶︎ On Flash ended

Sub-event Condition

System ▶︎ NextAction = "PlayerMove"

Sub-event Action

Function ▶︎ Call PlayerAtt

Sub-event Condition

System ▶︎ NextAction = "EndTurn"

Sub-event Action

Function▶︎ Call EndTurn

These events need to be repeated for the Opponent:

If both of the 'HaveMoved' Booleans are set to true, the 'NextAction' variable is set to "EndTurn" which means when either of the two combatants complete their flash animation, the EndTurn function is called as per the above events.

When one of the combatants hits 0 HP, the battle needs to end.

Condition

Player ▶︎ HP ≤ 0

OR

Opponent ▶︎ HP ≤ 0

Action

System ▶︎ Set GameOver to True

Condition

System ▶︎ Is GameOver

Action

BattleText ▶︎ Set visibility to Visible

Sub-event Condition

System ▶︎ Compare two values ▶︎ Player.HP > Opponent.HP

Sub-event Action

BattleText ▶︎ Set text to "Player wins!"

Sub-event Condition

System ▶︎ Compare two values ▶︎ Player.HP < Opponent.HP

Sub-event Action

BattleText ▶︎ Set text to "Player loses!"

And that's about all of the events in this project's event sheet! You should now have a simple but functioning turn-based battle demo. This small project should lay the groundwork for something much more complex – it's always handy to start with the basics before trying to build a complicated mechanic.

In the next part of the course, we'll be adding accuracy checks to this system.

  • 9 Comments

  • Order by
Want to leave a comment? Login or Register an account!