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,3 +11,7 @@ class UnknownWeapon(OpenCombatException):
11 11
 
12 12
 class UnknownFiringAnimation(OpenCombatException):
13 13
     pass
14
+
15
+
16
+class WrongMode(OpenCombatException):
17
+    pass

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

@@ -11,6 +11,7 @@ from synergine2_cocos2d.actor import Actor
11 11
 from synergine2_xyz.exception import UnknownAnimationIndex
12 12
 
13 13
 from opencombat.exception import UnknownWeapon
14
+from opencombat.exception import WrongMode
14 15
 from opencombat.exception import UnknownFiringAnimation
15 16
 from opencombat.gui.animation import ANIMATION_CRAWL
16 17
 from opencombat.gui.animation import ANIMATION_WALK
@@ -19,6 +20,7 @@ from opencombat.gui.const import MODE_MAN_CRAWLING
19 20
 from opencombat.gui.image import TileImageCacheManager
20 21
 from opencombat.gui.weapon import RIFFLE
21 22
 from opencombat.gui.weapon import WeaponImageApplier
23
+from opencombat.user_action import UserAction
22 24
 
23 25
 if typing.TYPE_CHECKING:
24 26
     from opencombat.gui.fire import GuiFiringEvent
@@ -40,6 +42,7 @@ class BaseActor(Actor):
40 42
     ]
41 43
     weapons_firing_image_scheme = {}
42 44
     weapon_image_scheme = {}
45
+    move_for_gui_actions = {}
43 46
 
44 47
     def __init__(
45 48
         self,
@@ -69,10 +72,25 @@ class BaseActor(Actor):
69 72
 
70 73
     @property
71 74
     def mode(self) -> str:
72
-        # FIXME: When man is moving (crawling for example), must change mode
73
-        # and man must stay "crawled"
74 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 94
     @property
77 95
     def weapons(self) -> typing.List[str]:
78 96
         return []
@@ -199,6 +217,18 @@ class Man(BaseActor):
199 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 234
     def __init__(

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

@@ -267,6 +267,7 @@ class Game(TMXGui):
267 267
     def start_move_subject(self, event: StartMoveEvent):
268 268
         actor = self.layer_manager.subject_layer.subjects_index[event.subject_id]
269 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 272
         if event.gui_action == UserAction.ORDER_MOVE:
272 273
             animation = ANIMATION_WALK
@@ -287,6 +288,7 @@ class Game(TMXGui):
287 288
         actor.do(move_action)
288 289
         actor.do(Animate(animation, duration=move_duration, cycle_duration=cycle_duration))
289 290
         actor.rotation = get_angle(event.from_position, event.to_position)
291
+        actor.mode = actor_mode
290 292
 
291 293
     def new_visible_opponent(self, event: NewVisibleOpponent):
292 294
         self.visible_or_no_longer_visible_opponent(event, (153, 0, 153))
@@ -349,7 +351,6 @@ class Game(TMXGui):
349 351
             self.sound_lib.get_sound('gunshot_default').play()
350 352
 
351 353
         firing_event = GuiFiringEvent(shooter_actor, event.weapon_type)
352
-        original_actor_image = shooter_actor.image
353 354
 
354 355
         def actor_rotate():
355 356
             shooter_actor.rotation = get_angle(
@@ -361,7 +362,7 @@ class Game(TMXGui):
361 362
             shooter_actor.firing(firing_event)
362 363
 
363 364
         def actor_end_firing():
364
-            shooter_actor.update_image(original_actor_image)
365
+            shooter_actor.reset_default_texture()
365 366
 
366 367
         # To avoid all in same time
367 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,7 +69,7 @@ class TileImageCacheManager(ImageCacheManager):
69 69
 
70 70
     def build_firing(self) -> None:
71 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 73
             mode_image = Image.open(self.path_manager.path(mode_image_path))
74 74
 
75 75
             for weapon in self.actor.weapons: