How can I organize classes of objects in my game?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By unfa

I would like to define some classes of objects inheriting properties and methods to organize the objects and scripting of my game. For example:

Character - extends KinematicBody. Has health, can take damage and respond to healing

Player - extends Character. Can pickup objects and respond to user input

Enemy - extends Character. Has an AI-driven behaviour.

Trigger - has collision, activates other objects on contact with a Player node

Pickup - detects collisions with Players, grants them health or items

HealthPickup - extends Pickup - heals players on contact

WeaponPickup - extends Pickup - grants a selected weapon to a Player on contact

AmmoPickup - extends Pickup - grants ammo of selected type and amount to a Player on contact

And so on…

I guess Godot has great tools to do this, but currently I have no idea how to organize my code and objects using this “tree” logic.

I’ve been reading up on classes, duck typing etc, but I’m still completely oblivious to how I can make this work for my game.

:bust_in_silhouette: Reply From: kidscancode

In Godot, you can use inheritance with both scripts and scenes.

See this tutorial for an example: Godot 3.0: Inheritance · KCC Blog

Thanks! I’m going through that, though the example in that article/video is pretty complex for the starters. I skip a lot of that, as I want to make myself the simplest implementation possible first, before going into deeper examples.

unfa | 2018-07-23 17:53