#help with turn based combat system

1 messages · Page 1 of 1 (latest)

viral bluff
#

I'm struggling to even find a tutorial for turn based combat that isn't like 6 years old. What I'm attempting to accomplish first is to have several characters with agility scores that decide who goes first. What should I be looking into if I wanna do that?

bitter grotto
#

it shouldnt be horribly difficult to build your own system, although I don't know of any tutorials for what you want to do specifically, but the way I'd make a basic system like that is with a game manager that keeps track of which characters turn it is (simply sorting by agility score), then it goes character by character simply telling a character its their turn. Once the character is done with its turn it can notify the game manager to move onto the next character.
But also I think your question is pretty vague, turn based combat can mean alot of things (do you mean pokemon combat or roguelike combat or something else?).

naive wind
#

Breaking it down a little:

  1. You want to model characters with scores. (Nodes? Resources?). Because the word "character" is overloaded (CharacterBody2D, anyone?) I'm going to call these Battlers. Same idea, just using a different word to avoid confusion.
  2. You want to sort the population of battler by these scores (an array of the battlers? With sorting?)
  3. You want something to model & manage the turn.

Making choices without delving too deeply into why or how:

  1. Characters will be modeled in Battler.gd, which extends CharacterBody2D (so that it'll avoid walls). It'll use composition for its various parts, eg:
Battler (CharBody2D)
\ CollisionShape2D [circle radius 4]
\ AnimationPlayer
\ Sprite2D [grr! arg!]

(Battler.gd has @export var agility := 10, naturally!)

  1. Somewhere, we'll have a battlers: Array[Battler] and we'll need Battler._enter_tree to add_to_group("battlers") and (obsessive alert!)_exit_tree to remove_from_group("battlers").
    That means you can snapshot the current battlers with get_tree().get_nodes_in_group("battlers"), so that's the unsorted array.
    Because the Array is parameterized by type Battler, you can know its content are all Battlers, and so access the fields and methods of that script. Which lets you use Array::sort_custom to sort by their agility score.

  2. We'll have a BattleManager node in the scene that runs a battle. It'll have to manage the code & array from #2 . It'll be responsible for knowing which battler's turn it is now, and calling methods on them to have them take the various steps of their turn.

#

I made lots of choices here, you can absolutely make different choices (esp in step 3)

#

Even if the tutorials are 6 years old, you can break them apart and go through their pockets for loose design decisions.