I have a quad tree set up to organize all my game entities.
All game entities are children of an entity class, and that is what the quad tree sees all its data as.
Almost all entities simply get a list of nearby entities for their update function. The player, however, needs this in addition to the keyboard info and mouse info. (I think in typing this I've figured out the solution but I'll ask anyways.) How do I make the tree recognize that it is a Player object and know that it is ok to pass the keyboard and mouse states to it?
I've thought of two ways to solve the problem, I'm just wondering which is most effective (or if there's a better way all together).
1.) When I loop through each nodes data, check if each data object's class equals the player class. Create a new player object equal to this data object, update it, and then replace the original with the new one.
Example:
if(data[i].getClass() == new Player().getClass()){
Player p = (Player)data[i];
p.update(keyboard, mouse);
data[i] = p;
}
2.) (And this is the way I think is best right now.) Create an update function in the Entity class that takes in the keyboard and mouse, which only its Player child class will ever call. In the Player class I just override it, and put in the player update code. Then all I have to do is check if the data's class is the same as Player (as I did above).I'm still new at this, so I'm just looking for input.
If there's a better way, please let me know.
Thanks,
Peter






