Polymorphism And Inheritance Flashcards
What is Polymorphism in Game dev?
Polymorphism is a concept that comes into play when we start using inheritance in our code, and using this concept correctly can give Game Debs the ability to alter inherited methods to better suite the derived class
Inheritance in code
When we use inheritance in code, we inherit variables and methods from the base class into the Derived class.
Inherited methods
Based on the problem we are working on, we would want inherited methods to work a bit differently than it did in the base class.
Ie.) In RPGs the player can wield multiple ranged weapons like, a Crossbow, a Longbow, A Ballista
Each will have a different execution as well as different range, fire power, damage, animation, etc, that needs to be coded for each method.
Polymorphism steps In game dev
Take methods defined in the base class
Inside the derived classes of that base class
We modify its execution, Ie, code
To do different things based on the derived class in question
This allows us to perform a single action in multiple different ways