#Regarding composition

18 messages · Page 1 of 1 (latest)

long relic
#

I'm going to have multiple enemies, which will all have specific enemy elements (health, xp, etc) as well as multiple types of hitboxes. Handling that will require code, and I don't want to have to write it for each one. Each enemy will have their own unique code as well, such as their movement, so I can't just inherit a base scene(, that's how it works, right?) I don't want to use components, since besides those characteristics, there will be very little similarity between the enemies. How should I go about this?

cinder hinge
# long relic I'm going to have multiple enemies, which will all have specific enemy elements ...

scene inheritance is possible, although a really buggy system (since it also kinda got hacked in). But that wouldn't really be a replacement of composition, but more one of the ways you can do it. Scene inheritance adds the ability to change the Node-composition of the scene.
The System you could use instead of composition would be class-inheritance, where you create a new script that inherits from another one.

long relic
cinder hinge
#

if your goal is to write less code i would say no. After all, script inheritance requires you to create a new script for every variant.

#

composition, i would say, is about creating a modular system where you can easily change out one component for a similar other one. It would still require some script inheritance fore type safety, but if done correctly a hitbox system utilizing a single one should be as easy as one utilizing a dozen.

#

Not entirely sure how your use for hitboxes would look like, but i mean the basics for hitbox components already exist with Areas and CollisionShapes being individual nodes where you can give an area any ammount of shapes.

long relic
#

It'd be just two hitboxes for giving and taking damage (with intentionally different sizes) and the stats. So... no simple way to do this I assume

cinder hinge
long relic
#

It's what I said earlier, with the health, xp, stuff that every enemy should have

cinder hinge
long relic
#

And it's not about the sizes I'm worried about, it's handling all of this simply so I don't have to reuse any code

#

The idea is that I'm trying to avoid recreating the same thing for every enemy

cinder hinge
#

huh, why?

#

didn't you start with not wanting to have to create a new script for each variant?

long relic
#

I'm stupid, I am trying to reuse stuff

cinder hinge
#

well that's literally what composition is about. its about "isolating" the things that are similar to their own systems you can easily reuse (that's also kinda the whole point about engines).

#

so even when you're enemies react differently to an attack, the way they recieve it using hitboxes/hurtboxes will still be the same

#

and even when enemies have different stat values, what stats they have and what those stats do will still be similar.