I wanted to know if anyone could help me out understanding how to do a certain thing for y C++ SDL2 game.
It's a 2D Tile Map Final Fantasy / Zelda style game.
I wanted to know:
If I have an object for a monster like Skeleton.
When I spawn many "Skeleton" objects on the screen at the same time around a spawn point, how do I make it that all those Skeleton objects are actual different instances since they come from the same Object?
My problem is that the Skeleton Object has a Health Point member variable and so
if (healthpoint > 0) then skeleton will remain spawned and else he will die/disapear... My problem is that as soon as one of he skeletons reaches 0 health, they all disapear since they all come from the same object and are actually all related to the same object and health member variable...
So how can I do this? I know I could simply create X number of Skeleton00, Skeleton01 ... to SkeletonX objects, but I'd like to find the right way to do it... Thanks guyz really appreciate it!
when you set the life health point member, did you tell it to decrease all of the objects or, did you tell it to just take a health point off that certain object? like when you have your collision, did you have a function to find out which skeleton it was that was hit and then only take a health point from that one object? hope this helps
Well the collision hits the actual skeleton you are hitting on the screen at those exact coordinates, but as you hit when you retrieve a health point it retrieves a hitpoint from the:
object which is the basic object for all the spawned skeletons...
I can mke different skeletons appear at different locations on the screen with different collisions, but as one gets hit, this objects 50000 heathpoint variable drops and then when it reaches 0 or below all the skeletons disapear...
I know I can make different control structures with variables to have specific skeletons come and go, but it's not what im looking for.
I would like to use this called object and duplicate or copy or clone into different instances that stand on their own but i don't know how... thanks for the help though its really appreciated.
maybe you could create an array out of the object that makes the skeletons and each one will have a different identifier, then I think that would help separating the health points of each.
Yes I think that just might be the way to do it...
You make an array out of the object? Do you mean you create an array and in each position you store a skeleton and you access it through each array position?
How would you go about doing this...
Are Member variables unique under each array position or do I need to code it up and create a different new external variable per position that would represent skeleton health?
Well, is the function that takes away health from the skeleton called using the this pointer? That might help you out in this case (assuming that the function that calls the function to reduce health is also in the skeleton object).
I do believe that the member variables are unique, and you can call each skeleton using their number in the array, and you can make a function like getSeletonNo() {return i}; // i being the variable you used in your array
this should work
Ok well I got it to work... Meaning the Array has been initialized and filled with the CSprite Objects...
The only problem I have now is still the same basic one, which is.. my different Skeleton objects are not unique...
I thought that storing an Array with the Same Object made all those objects unique within each of those positions... They don't seem to be as STILL if I kill in-game one of the skeletons they still all disapear at once...
I'll keep working on it, if anyone has an idea or If i'm not getting something, please do tell me.