actor.py 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. # coding: utf-8
  2. import typing
  3. from PIL import Image
  4. from synergine2.config import Config
  5. from synergine2.simulation import Subject
  6. from synergine2_cocos2d.actor import Actor
  7. from opencombat.gui.animation import ANIMATION_WALK
  8. from opencombat.gui.animation import ANIMATION_CRAWL
  9. from opencombat.gui.weapon import WeaponImageApplier
  10. from opencombat.gui.weapon import RIFFLE
  11. FLAG_DE = 'DE'
  12. FLAG_URSS = 'URSS'
  13. FLAG_COLORS = {
  14. FLAG_DE
  15. }
  16. MAN_STAND_UP = 'MAN_STAND_UP'
  17. class BaseActor(Actor):
  18. def __init__(
  19. self,
  20. image_path: str,
  21. config: Config,
  22. subject: Subject,
  23. ) -> None:
  24. self.weapon_image_applier = WeaponImageApplier(config, self)
  25. super().__init__(image_path, subject=subject, config=config)
  26. @property
  27. def mode(self) -> str:
  28. return MAN_STAND_UP
  29. @property
  30. def weapons(self) -> typing.List[str]:
  31. return []
  32. def get_default_appliable_images(self) -> typing.List[Image.Image]:
  33. if not self.weapons:
  34. return []
  35. return [
  36. self.weapon_image_applier.get_default_image_for_weapon(
  37. self.mode,
  38. self.weapons[0],
  39. )
  40. ]
  41. def firing(self) -> None:
  42. pass
  43. class Man(BaseActor):
  44. animation_image_paths = {
  45. ANIMATION_WALK: [
  46. 'actors/man.png',
  47. 'actors/man_w1.png',
  48. 'actors/man_w2.png',
  49. 'actors/man_w3.png',
  50. 'actors/man_w4.png',
  51. 'actors/man_w5.png',
  52. 'actors/man_w6.png',
  53. 'actors/man_w7.png',
  54. ],
  55. ANIMATION_CRAWL: [
  56. 'actors/man_c1.png',
  57. 'actors/man_c2.png',
  58. 'actors/man_c3.png',
  59. 'actors/man_c4.png',
  60. ]
  61. }
  62. def __init__(
  63. self,
  64. config: Config,
  65. subject: Subject,
  66. ) -> None:
  67. super().__init__('actors/man.png', subject=subject, config=config)
  68. @property
  69. def weapons(self) -> typing.List[str]:
  70. # TODO BS 2018-01-26: Will be managed by complex part of code
  71. return [RIFFLE]
  72. class HeavyVehicle(Actor):
  73. animation_image_paths = {
  74. ANIMATION_WALK: [
  75. 'actors/tank1.png',
  76. ],
  77. ANIMATION_CRAWL: [
  78. 'actors/tank1.png',
  79. ]
  80. }
  81. def __init__(
  82. self,
  83. config: Config,
  84. subject: Subject,
  85. ) -> None:
  86. super().__init__('actors/tank1.png', subject=subject, config=config)