I’m working on a project where one set of particles eats another (predator / prey). I’ve got both particle classes interacting nicely (chasing / avoiding / etc), but I am having trouble taking the next step. When the predator catches up with the prey I want it to destroy it but at the moment it doesn’t.
I thought that by comparing their co-ordinates I’d be able to use a conditional to destroy one of the particles but it doesn’t seem to be working. If anyone could give me any pointers on how to do this I’d be most grateful. I’m new to oF so sorry if this is an obvious question! Many thanks!
if (predators[i].pos.x == prey[i].pos.x &&
predators[i].pos.y == prey[i].pos.y {
kill prey - not sure about the syntax in here...
}
Thanks for that - the detection is working really well now - I’m still having trouble with deactivating / kiling the prey though.
How would you go about creating this active variable? I assume it is a bool of some sort and I think it would go in the particle class something like this
void predator :: active() {
something in here...
}
but I’m very unsure about where to put it and more importantly what to put in it.
If I was to ‘deactivate’ the particle would this remove it completely? (ie my other particles (predators) wouldn’t be chasing after prey that isn’t being drawn?
What you can do if you want to make it efficient by only deactivate them is as you say having a bool called eg. activated. I suppose you got some loops for creating the objects and to loop thorugh to detect when they hit each other aswell as move them around. In all these loops you simply say if(predator.activated). And when you want to kill a predator, simple say activated = true, and it would’nt get counted any more. And if you want to make a new, simply look for a deactivated ovject, and reset and activate it. Hope it helps.