#help with turn based combat system
1 messages · Page 1 of 1 (latest)
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?).
Breaking it down a little:
- 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.
- You want to sort the population of battler by these scores (an array of the battlers? With sorting?)
- You want something to model & manage the turn.
Making choices without delving too deeply into why or how:
- 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!)
-
Somewhere, we'll have a
battlers: Array[Battler]and we'll needBattler._enter_treetoadd_to_group("battlers")and (obsessive alert!)_exit_treetoremove_from_group("battlers").
That means you can snapshot the current battlers withget_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 useArray::sort_customto sort by theiragilityscore. -
We'll have a
BattleManagernode 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.