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,674 visits, 27,607 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.

This project uses several functions to run. One to start the battle turn, two to run the combatants' attacks and one to end the turn. We'll define each of those here.

BeginAttackSequence

Condition

On function BeginAttackSequence

Action

System ▶︎ Set PlayerTurn to False

Sub-event Condition

System ▶︎ Opponent.Speed > Player.Speed

Sub-event Action

Function ▶︎ Call OppAtt

Sub-event Condition

System ▶︎ Opponent.Speed < Player.Speed

Sub-event Action

Function ▶︎ Call PlayerAtt

If the two combatants speed is equal, then one of these two functions needs to be picked randomly. In order to do this, the functions must be mapped to strings. This will be explained a little further below. But, with the functions mapped to strings, the sub-event looks like this:

Sub-event Condition

System ▶︎ Opponent.Speed = Player.Speed

Sub-event Action

Function ▶︎ Call function from "AttackFunctions" map with string choose("PlayerAttack","OpponentAttack"), (forward parameters from index 0)

The two attack functions are essentially the same, just applied to the two separate combatant objects. We'll break down one of them, and then include screenshots of both functions.

OppAtt

First, we check if the opponent has any HP – if their HP value is 0, the function will not run.

Condition

On function OppAtt

Sub-event Condition

Opponent ▶︎ HP > 0

Sub-event Condition

System ▶︎ Is not PlayerMoved

Sub-event Action

System ▶︎ Set NextAction to "PlayerMove"

The next set of actions are applied to a blank sub-event:

Sub-event Action

System ▶︎ Set CurTurn to "Opp"

System ▶︎ Set OppMoved to True

Player ▶︎ Set HP to Self.HP-Opponent.Attack

Player ▶︎ Flash ▶︎ Flash on 0.1s off 0.1s for 1 second

PlayerAtt

Swap the combatant objects around, and you've got the PlayerAtt function:

EndTurn

When both combatants have moved, the EndTurn function closes the turn and sets up the next turn.

Condition

On function EndTurn

Action

System ▶︎ Set NextAction to "PlayerPick"

System ▶︎ Set CurTurn to ""

System ▶︎ Set PlayerTurn to True

System ▶︎ Set PlayerMoved to False

System ▶︎ Set OppMoved to False

And that's all of the functions the game needs. In the example project, these are all grouped together in a group called Functions - mostly for organisational purposes. In the next section, we'll look at the rest of the event sheet.

  • 9 Comments

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