I have a game (toy) that works in PyGamek, and I'm trying to port it to Blender. I'm very familiar with both Blender and Python individually, but not together.
In this case, I have a class called "Critter." Each critter knows how to do things like drawSelf()
and chooseNewOrientation()
and predate(other_critter)
and getPredated(other_critter)
other fun things like that.
What is the "Blenderic" method for me to implement this class in BGE?
It seems like each OBJECT (mesh) is the parallel to an instance of the class
, and that has worked well enough. But I suspect that if I just define the class in a script and attach it to an object (even a single object that never gets duplicated), the class will get defined every frame... which I'd like to avoid, obviously. Right now, I have individual functions in a script on each critter, and that works well enough so long as those are static functions (or would qualify to be static). I'm not sure how to handle things like class member functions/variables. I.e. it'd be nice for each critter to have a "self.diameter" that can tell the "self.drawSelf()" function how big this instance is supposed to be.
So, what's the best way (conceptually) to handle the equivalent of a class in BGE that can spawn instances of itself, which know about members?