Browse Source

implement crawl

Bastien Sevajol 7 years ago
parent
commit
3622cfde45

+ 1 - 0
sandbox/tile/config.yaml View File

@@ -7,3 +7,4 @@ game:
7 7
     move:
8 8
         walk_ref_time: 3
9 9
         run_ref_time: 1
10
+        crawl_ref_time: 10

+ 7 - 6
sandbox/tile/gui/actor.py View File

@@ -4,6 +4,7 @@ import pyglet
4 4
 from synergine2.simulation import Subject
5 5
 from synergine2_cocos2d.actor import Actor
6 6
 from synergine2_cocos2d.animation import ANIMATION_WALK
7
+from synergine2_cocos2d.animation import ANIMATION_CRAWL
7 8
 
8 9
 
9 10
 class Man(Actor):
@@ -18,12 +19,12 @@ class Man(Actor):
18 19
             'actors/man_w6.png',
19 20
             'actors/man_w7.png',
20 21
         ],
21
-        # ANIMATION_CRAWL: [
22
-        #     'actors/man_c1.png',
23
-        #     'actors/man_c2.png',
24
-        #     'actors/man_c3.png',
25
-        #     'actors/man_c4.png',
26
-        # ]
22
+        ANIMATION_CRAWL: [
23
+            'actors/man_c1.png',
24
+            'actors/man_c2.png',
25
+            'actors/man_c3.png',
26
+            'actors/man_c4.png',
27
+        ]
27 28
     }
28 29
 
29 30
     def __init__(self, subject: Subject) -> None:

+ 2 - 0
sandbox/tile/gui/base.py View File

@@ -2,12 +2,14 @@
2 2
 from synergine2_cocos2d.gui import TMXGui
3 3
 from synergine2_cocos2d.interaction import MoveActorInteraction
4 4
 from synergine2_cocos2d.interaction import MoveFastActorInteraction
5
+from synergine2_cocos2d.interaction import MoveCrawlActorInteraction
5 6
 
6 7
 
7 8
 class Game(TMXGui):
8 9
     def before_run(self) -> None:
9 10
         self.layer_manager.interaction_manager.register(MoveActorInteraction, self.layer_manager)
10 11
         self.layer_manager.interaction_manager.register(MoveFastActorInteraction, self.layer_manager)
12
+        self.layer_manager.interaction_manager.register(MoveCrawlActorInteraction, self.layer_manager)
11 13
 
12 14
         # Test
13 15
         # from sandbox.tile.gui.actor import Man

+ 8 - 1
synergine2_cocos2d/gui.py View File

@@ -18,7 +18,7 @@ from synergine2.terminals import Terminal
18 18
 from synergine2.terminals import TerminalPackage
19 19
 from synergine2_cocos2d.actions import MoveTo
20 20
 from synergine2_cocos2d.actor import Actor
21
-from synergine2_cocos2d.animation import Animate
21
+from synergine2_cocos2d.animation import Animate, ANIMATION_CRAWL
22 22
 from synergine2_cocos2d.animation import ANIMATION_WALK
23 23
 from synergine2_cocos2d.exception import InteractionNotFound
24 24
 from synergine2_cocos2d.exception import OuterWorldPosition
@@ -400,6 +400,8 @@ class EditLayer(cocos.layer.Layer):
400 400
                 self.user_action_pending = UserAction.ORDER_MOVE
401 401
             if k == key.R:
402 402
                 self.user_action_pending = UserAction.ORDER_MOVE_FAST
403
+            if k == key.C:
404
+                self.user_action_pending = UserAction.ORDER_MOVE_CRAWL
403 405
 
404 406
         if k in binds:
405 407
             self.buttons[binds[k]] = 1
@@ -761,6 +763,7 @@ class TMXGui(Gui):
761 763
         # configs
762 764
         self.move_duration_ref = float(self.config.resolve('game.move.walk_ref_time'))
763 765
         self.move_fast_duration_ref = float(self.config.resolve('game.move.run_ref_time'))
766
+        self.move_crawl_duration_ref = float(self.config.resolve('game.move.crawl_ref_time'))
764 767
 
765 768
     def get_layer_middleware(self) -> MapMiddleware:
766 769
         return TMXMiddleware(
@@ -801,6 +804,10 @@ class TMXGui(Gui):
801 804
             animation = ANIMATION_WALK
802 805
             cycle_duration = 0.5
803 806
             move_duration = self.move_fast_duration_ref
807
+        elif event.gui_action == UserAction.ORDER_MOVE_CRAWL:
808
+            animation = ANIMATION_CRAWL
809
+            cycle_duration = 2
810
+            move_duration = self.move_crawl_duration_ref
804 811
         else:
805 812
             raise NotImplementedError()
806 813
 

+ 5 - 0
synergine2_cocos2d/interaction.py View File

@@ -117,3 +117,8 @@ class MoveActorInteraction(BaseMoveActorInteraction):
117 117
 class MoveFastActorInteraction(BaseMoveActorInteraction):
118 118
     gui_action = UserAction.ORDER_MOVE_FAST
119 119
     color = (72, 244, 66)
120
+
121
+
122
+class MoveCrawlActorInteraction(BaseMoveActorInteraction):
123
+    gui_action = UserAction.ORDER_MOVE_CRAWL
124
+    color = (235, 244, 66)

+ 1 - 0
synergine2_cocos2d/user_action.py View File

@@ -5,3 +5,4 @@ from enum import Enum
5 5
 class UserAction(Enum):
6 6
     ORDER_MOVE = 'ORDER_MOVE'
7 7
     ORDER_MOVE_FAST = 'ORDER_MOVE_FAST'
8
+    ORDER_MOVE_CRAWL = 'ORDER_MOVE_CRAWL'

+ 3 - 0
synergine2_xyz/move.py View File

@@ -181,6 +181,7 @@ class MoveToBehaviour(SubjectBehaviour):
181 181
         super().__init__(config, simulation, subject)
182 182
         self._walk_duration = float(self.config.resolve('game.move.walk_ref_time'))
183 183
         self._run_duration = float(self.config.resolve('game.move.run_ref_time'))
184
+        self._crawl_duration = float(self.config.resolve('game.move.crawl_ref_time'))
184 185
 
185 186
     def run(self, data):
186 187
         move_to_data = data[self.move_to_mechanism]
@@ -202,6 +203,8 @@ class MoveToBehaviour(SubjectBehaviour):
202 203
             return time.time() - move_to_data['last_intention_time'] >= self._walk_duration
203 204
         if move_to_data['gui_action'] == UserAction.ORDER_MOVE_FAST:
204 205
             return time.time() - move_to_data['last_intention_time'] >= self._run_duration
206
+        if move_to_data['gui_action'] == UserAction.ORDER_MOVE_CRAWL:
207
+            return time.time() - move_to_data['last_intention_time'] >= self._crawl_duration
205 208
 
206 209
     def _is_fresh_new_step(self, move_to_data: dict) -> bool:
207 210
         return move_to_data['just_reach'] or move_to_data['initial']