Browse Source

man firing when crawl mode

Bastien Sevajol 6 years ago
parent
commit
9b536af8e2

BIN
medias/images/actors/man_c1.png View File


BIN
medias/images/actors/man_c1_weap0.png View File


BIN
medias/images/actors/man_c1_weap1.png View File


BIN
medias/images/actors/man_c1_weap1_firing1.png View File


BIN
medias/images/actors/man_c1_weap1_firing2.png View File


BIN
medias/images/actors/man_c1_weap1_firing3.png View File


BIN
medias/images/actors/man_c2.png View File


BIN
medias/images/actors/man_c2_weap1.png View File


BIN
medias/images/actors/man_c3.png View File


BIN
medias/images/actors/man_c3_weap1.png View File


BIN
medias/images/actors/man_c4.png View File


BIN
medias/images/actors/man_c4_weap1.png View File


BIN
medias/images/actors/src/man_c1_weap1_firing.xcf View File


+ 4 - 0
opencombat/exception.py View File

11
 
11
 
12
 class UnknownFiringAnimation(OpenCombatException):
12
 class UnknownFiringAnimation(OpenCombatException):
13
     pass
13
     pass
14
+
15
+
16
+class WrongMode(OpenCombatException):
17
+    pass

+ 32 - 2
opencombat/gui/actor.py View File

11
 from synergine2_xyz.exception import UnknownAnimationIndex
11
 from synergine2_xyz.exception import UnknownAnimationIndex
12
 
12
 
13
 from opencombat.exception import UnknownWeapon
13
 from opencombat.exception import UnknownWeapon
14
+from opencombat.exception import WrongMode
14
 from opencombat.exception import UnknownFiringAnimation
15
 from opencombat.exception import UnknownFiringAnimation
15
 from opencombat.gui.animation import ANIMATION_CRAWL
16
 from opencombat.gui.animation import ANIMATION_CRAWL
16
 from opencombat.gui.animation import ANIMATION_WALK
17
 from opencombat.gui.animation import ANIMATION_WALK
19
 from opencombat.gui.image import TileImageCacheManager
20
 from opencombat.gui.image import TileImageCacheManager
20
 from opencombat.gui.weapon import RIFFLE
21
 from opencombat.gui.weapon import RIFFLE
21
 from opencombat.gui.weapon import WeaponImageApplier
22
 from opencombat.gui.weapon import WeaponImageApplier
23
+from opencombat.user_action import UserAction
22
 
24
 
23
 if typing.TYPE_CHECKING:
25
 if typing.TYPE_CHECKING:
24
     from opencombat.gui.fire import GuiFiringEvent
26
     from opencombat.gui.fire import GuiFiringEvent
40
     ]
42
     ]
41
     weapons_firing_image_scheme = {}
43
     weapons_firing_image_scheme = {}
42
     weapon_image_scheme = {}
44
     weapon_image_scheme = {}
45
+    move_for_gui_actions = {}
43
 
46
 
44
     def __init__(
47
     def __init__(
45
         self,
48
         self,
69
 
72
 
70
     @property
73
     @property
71
     def mode(self) -> str:
74
     def mode(self) -> str:
72
-        # FIXME: When man is moving (crawling for example), must change mode
73
-        # and man must stay "crawled"
74
         return self._mode
75
         return self._mode
75
 
76
 
77
+    @mode.setter
78
+    def mode(self, value) -> None:
79
+        if value not in self.get_modes():
80
+            raise WrongMode('Actor "{}" has no mode "{}" ({})'.format(
81
+                self.__class__.__name__,
82
+                value,
83
+                ', '.join(self.get_modes()),
84
+            ))
85
+
86
+        self._mode = value
87
+
88
+    def get_mode_for_gui_action(self, gui_action: str) -> str:
89
+        try:
90
+            return self.move_for_gui_actions[gui_action]
91
+        except KeyError:
92
+            return self.get_default_mode()
93
+
76
     @property
94
     @property
77
     def weapons(self) -> typing.List[str]:
95
     def weapons(self) -> typing.List[str]:
78
         return []
96
         return []
199
                 'actors/man_weap1_firing3.png',
217
                 'actors/man_weap1_firing3.png',
200
             ],
218
             ],
201
         },
219
         },
220
+        MODE_MAN_CRAWLING: {
221
+            RIFFLE: [
222
+                'actors/man_weap1_firing1.png',
223
+                'actors/man_weap1_firing2.png',
224
+                'actors/man_weap1_firing3.png',
225
+            ]
226
+        }
227
+    }
228
+    move_for_gui_actions = {
229
+        UserAction.ORDER_MOVE: MODE_MAN_STAND_UP,
230
+        UserAction.ORDER_MOVE_FAST: MODE_MAN_STAND_UP,
231
+        UserAction.ORDER_MOVE_CRAWL: MODE_MAN_CRAWLING,
202
     }
232
     }
203
 
233
 
204
     def __init__(
234
     def __init__(

+ 3 - 2
opencombat/gui/base.py View File

267
     def start_move_subject(self, event: StartMoveEvent):
267
     def start_move_subject(self, event: StartMoveEvent):
268
         actor = self.layer_manager.subject_layer.subjects_index[event.subject_id]
268
         actor = self.layer_manager.subject_layer.subjects_index[event.subject_id]
269
         new_world_position = self.layer_manager.grid_manager.get_world_position_of_grid_position(event.to_position)
269
         new_world_position = self.layer_manager.grid_manager.get_world_position_of_grid_position(event.to_position)
270
+        actor_mode = actor.get_mode_for_gui_action(event.gui_action)
270
 
271
 
271
         if event.gui_action == UserAction.ORDER_MOVE:
272
         if event.gui_action == UserAction.ORDER_MOVE:
272
             animation = ANIMATION_WALK
273
             animation = ANIMATION_WALK
287
         actor.do(move_action)
288
         actor.do(move_action)
288
         actor.do(Animate(animation, duration=move_duration, cycle_duration=cycle_duration))
289
         actor.do(Animate(animation, duration=move_duration, cycle_duration=cycle_duration))
289
         actor.rotation = get_angle(event.from_position, event.to_position)
290
         actor.rotation = get_angle(event.from_position, event.to_position)
291
+        actor.mode = actor_mode
290
 
292
 
291
     def new_visible_opponent(self, event: NewVisibleOpponent):
293
     def new_visible_opponent(self, event: NewVisibleOpponent):
292
         self.visible_or_no_longer_visible_opponent(event, (153, 0, 153))
294
         self.visible_or_no_longer_visible_opponent(event, (153, 0, 153))
349
             self.sound_lib.get_sound('gunshot_default').play()
351
             self.sound_lib.get_sound('gunshot_default').play()
350
 
352
 
351
         firing_event = GuiFiringEvent(shooter_actor, event.weapon_type)
353
         firing_event = GuiFiringEvent(shooter_actor, event.weapon_type)
352
-        original_actor_image = shooter_actor.image
353
 
354
 
354
         def actor_rotate():
355
         def actor_rotate():
355
             shooter_actor.rotation = get_angle(
356
             shooter_actor.rotation = get_angle(
361
             shooter_actor.firing(firing_event)
362
             shooter_actor.firing(firing_event)
362
 
363
 
363
         def actor_end_firing():
364
         def actor_end_firing():
364
-            shooter_actor.update_image(original_actor_image)
365
+            shooter_actor.reset_default_texture()
365
 
366
 
366
         # To avoid all in same time
367
         # To avoid all in same time
367
         # TODO BS 2018-01-24: This should be unecessary when core events sending will be
368
         # TODO BS 2018-01-24: This should be unecessary when core events sending will be

+ 1 - 1
opencombat/gui/image.py View File

69
 
69
 
70
     def build_firing(self) -> None:
70
     def build_firing(self) -> None:
71
         for mode in self.actor.get_modes():
71
         for mode in self.actor.get_modes():
72
-            mode_image_path = self.actor.default_image_path  # FIXME !
72
+            mode_image_path = self.actor.get_mode_image_path(mode)
73
             mode_image = Image.open(self.path_manager.path(mode_image_path))
73
             mode_image = Image.open(self.path_manager.path(mode_image_path))
74
 
74
 
75
             for weapon in self.actor.weapons:
75
             for weapon in self.actor.weapons: