AIDGameObject.py 1.2 KB

1234567891011121314151617181920212223242526272829
  1. from direct.distributed.DistributedObject import DistributedObject
  2. class AIDGameObject(DistributedObject):
  3. """ This class is a DirectObject which will be created and managed by the
  4. AI Repository. """
  5. def __init__(self, cr):
  6. DistributedObject.__init__(self, cr)
  7. def announceGenerate(self):
  8. """ The AI has created this object, so we send it's distributed object ID
  9. over to the client. That way the client can actually grab the object
  10. and use it to communicate with the AI. Alternatively store it in the
  11. Client Repository in self.cr """
  12. base.messenger.send(self.cr.uniqueName('AIDGameObjectGenerated'), [self.doId])
  13. # call the base class method
  14. DistributedObject.announceGenerate(self)
  15. def d_requestDataFromAI(self):
  16. """ Request some data from the AI and passing it some data from us. """
  17. data = ("Some Data", 1, -1.25)
  18. print("Sending game data:", data)
  19. self.sendUpdate('messageRoundtripToAI', [data])
  20. def messageRoundtripToClient(self, data):
  21. """ Here we expect the answer from the AI from a previous
  22. messageRoundtripToAI call """
  23. print("Got Data:", data)
  24. print("Roundtrip message complete")