How would you design/program an abstraction for multiple fighting characters?

Godot Version

4.2.2

Question

This is a “design pattern” question. Imagine games such as Super Smash that you have so many characters that you or AI could control. If we are to program something like that, I believe we will need to create something like:

  1. an abstract character class that has abstracted functions/methods which will be defined further in each character class itself. Each character should be its own “state machine”.
  2. “something” that takes your inputs and send all these input messages to the “character object” you are controlling. This “something” should have a reference to the “character object” and invoke the appropriate function/method along with passing the inputs.
  3. In the case of having an AI opponent, the “something” in number 2 would evaluate the game world and send appropriate messages to its character to attack, save itself, etc.

So in Godot, how could the above be accomplished? How does Godot deal with abstraction, and calling function/methods of a class?

You can just create a script with a class_name:

class_name Character extends CharacterBody2D # for example

var health: int
func attack1():
    return

Then all your characters can extend this character-script and will inherit all its parents-variables/methods:

class_name character1 extends Character

func _ready():
    attack1()

and can also override it:

class_name character2 extends Character

func attack1():
    print("Im attacking")
    return