Jump to content
  • Advertisement
Plotnus

Advice Good design for damage and death response?

Recommended Posts

Hello,

The current questionable design:
I have lava that kills the player when it hits it.
The logic to play the death explosion is in the object the player hits.
When I did this I was influenced by what I read about Sims object design.
By placing the logic in the object it's easy to add more objects with different logic.

The downside is that responses are distributed in all the objects.

The upside is that I don't have to write code for handling damage events and responses, and mapping damage types to death animations etc.
I do feel this would be inappropriate for things like projectiles, and enemy attacks.
However because the object it hits is Static I figured it'd be ok.
 

The Ask:
So, what are your thoughts and what would you consider a good design?

Share this post


Link to post
Share on other sites
Advertisement

I would separate logic from the object. So basically you have three "parts":

The object (you only have one of these, call it the "template". It contains the geometry and root data for the object)
The object's state (stores information about the current animation, transform etc, determines the number of instances of an object you have in the scene, contains a pointer to the base object and a logic handler)
The logic handler (this could be a callback, a script or whatever - doesn't really matter)

To initialize the game state you load all object data from disk, create states per instance of an object (eg for each monster), attach a logic handler to each instance and then, to update:

(eg per frame)
for(auto& o : objInstances)  o.handler->OnTick(o)

(eg when an object receives damage)
for(auto& o : objInstances)  o.handler->OnDamage(o)

 

Share this post


Link to post
Share on other sites

As mentioned, objects that can be damaged should inherit from “CDamageable” and implement virtual bool CDamageable::OnDamage( Amt, Type );.

Presumably anything that can be damaged can die, so you would also implement CDamageable::OnDie( Reason );.

Your object can select how it wants to die based on the reason it is dying (too much damage, flattened, hit lava, etc.) and then each object can be damaged and die in their own unique ways.


L. Spiro


PS: The parameters I mentioned can change depending on your needs.  I omitted sending the object that deals damage or death as I usually don’t see the reason (the scene manager will tell both objects what to do) but if you have a reason then add it.

Edited by L. Spiro
PS.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!