base.py 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # coding: utf-8
  2. from opencc.simulation.event import NewVisibleOpponent
  3. from opencc.simulation.event import FireEvent
  4. from opencc.simulation.event import DieEvent
  5. from opencc.simulation.event import NoLongerVisibleOpponent
  6. from opencc.simulation.physics import TilePhysics
  7. from opencc.simulation.subject import TileSubject as ManSubject
  8. from opencc.gui.actor import Man as ManActor
  9. from synergine2_cocos2d.terminal import GameTerminal
  10. from synergine2_cocos2d.util import get_map_file_path_from_dir
  11. from synergine2_xyz.move.simulation import FinishMoveEvent
  12. from synergine2_xyz.move.simulation import StartMoveEvent
  13. class CocosTerminal(GameTerminal):
  14. subscribed_events = [
  15. FinishMoveEvent,
  16. StartMoveEvent,
  17. NewVisibleOpponent,
  18. NoLongerVisibleOpponent,
  19. FireEvent,
  20. DieEvent,
  21. ]
  22. def __init__(self, *args, asynchronous: bool, map_dir_path: str, **kwargs):
  23. super().__init__(*args, **kwargs)
  24. self.asynchronous = asynchronous
  25. map_file_path = get_map_file_path_from_dir(map_dir_path)
  26. self.physics = TilePhysics(
  27. self.config,
  28. map_file_path=map_file_path,
  29. )
  30. self.map_dir_path = map_dir_path
  31. def run(self):
  32. from opencc.gui.base import Game
  33. from synergine2_cocos2d.gui import SubjectMapper
  34. self.gui = Game(
  35. self.config,
  36. self.logger,
  37. self,
  38. physics=self.physics,
  39. map_dir_path=self.map_dir_path,
  40. )
  41. # TODO: Defind on some other place ?
  42. self.gui.subject_mapper_factory.register_mapper(
  43. ManSubject,
  44. SubjectMapper(ManActor),
  45. )
  46. self.gui.run()