Bastien Sevajol před 3 roky
rodič
revize
824c122e8d
5 změnil soubory, kde provedl 50 přidání a 25 odebrání
  1. 12 11
      src/behavior/animate.rs
  2. 5 1
      src/config.rs
  3. 2 2
      src/scene/item.rs
  4. 29 9
      src/scene/main.rs
  5. 2 2
      src/ui/mod.rs

+ 12 - 11
src/behavior/animate.rs Zobrazit soubor

@@ -11,14 +11,10 @@ pub fn digest_next_order(scene_item: &SceneItem) -> Vec<SceneItemModifier> {
11 11
     if let Some(next_order) = &scene_item.next_order {
12 12
         match next_order {
13 13
             Order::MoveTo(_) => {
14
-                scene_item_modifiers.push(SceneItemModifier::SwitchToCurrentOrder);
15
-            }
16
-            Order::MoveFastTo(_) => {
17
-                scene_item_modifiers.push(SceneItemModifier::SwitchToCurrentOrder)
18
-            }
19
-            Order::HideTo(_) => {
20
-                scene_item_modifiers.push(SceneItemModifier::SwitchToCurrentOrder)
14
+                scene_item_modifiers.push(SceneItemModifier::SwitchToNextOrder);
21 15
             }
16
+            Order::MoveFastTo(_) => scene_item_modifiers.push(SceneItemModifier::SwitchToNextOrder),
17
+            Order::HideTo(_) => scene_item_modifiers.push(SceneItemModifier::SwitchToNextOrder),
22 18
         }
23 19
     }
24 20
 
@@ -41,12 +37,14 @@ pub fn digest_current_order(scene_item: &SceneItem) -> Vec<SceneItemModifier> {
41 37
                 // FIXME BS NOW: Change order only if it is not the current order
42 38
                 scene_item_modifiers.push(SceneItemModifier::ChangeState(ItemState::new(
43 39
                     ItemBehavior::MoveFastTo(*move_to_scene_point),
44
-                )))}
40
+                )))
41
+            }
45 42
             Order::HideTo(move_to_scene_point) => {
46 43
                 // FIXME BS NOW: Change order only if it is not the current order
47 44
                 scene_item_modifiers.push(SceneItemModifier::ChangeState(ItemState::new(
48 45
                     ItemBehavior::HideTo(*move_to_scene_point),
49
-                )))}
46
+                )))
47
+            }
50 48
         }
51 49
     }
52 50
 
@@ -59,6 +57,7 @@ pub fn digest_current_behavior(scene_item: &SceneItem) -> Vec<SceneItemModifier>
59 57
     match scene_item.state.current_behavior {
60 58
         ItemBehavior::Standing => {}
61 59
         ItemBehavior::MoveTo(going_to_scene_point)
60
+        | ItemBehavior::MoveFastTo(going_to_scene_point)
62 61
         | ItemBehavior::HideTo(going_to_scene_point) => {
63 62
             // Note: angle computed by adding FRAC_PI_2 because sprites are north oriented
64 63
             scene_item_modifiers.push(SceneItemModifier::ChangeDisplayAngle(
@@ -76,9 +75,11 @@ pub fn digest_current_behavior(scene_item: &SceneItem) -> Vec<SceneItemModifier>
76 75
                 )));
77 76
                 if let Some(current_order) = &scene_item.current_order {
78 77
                     match current_order {
79
-                        Order::MoveTo(move_to_scene_point) => {
78
+                        Order::MoveTo(move_to_scene_point)
79
+                        | Order::MoveFastTo(move_to_scene_point)
80
+                        | Order::HideTo(move_to_scene_point) => {
80 81
                             if *move_to_scene_point == going_to_scene_point {
81
-                                scene_item_modifiers.push(SceneItemModifier::SwitchToCurrentOrder);
82
+                                scene_item_modifiers.push(SceneItemModifier::SwitchToNextOrder);
82 83
                             }
83 84
                         }
84 85
                     }

+ 5 - 1
src/config.rs Zobrazit soubor

@@ -35,4 +35,8 @@ pub const SCENE_ITEMS_CHANGE_ERR_MSG: &str = "scene_items content change !";
35 35
 //
36 36
 pub const DEBUG: bool = true;
37 37
 // Distance from move target point to consider reached
38
-pub const MOVE_TO_REACHED_WHEN_DISTANCE_INFERIOR_AT: f32 = 1.0;
38
+pub const MOVE_TO_REACHED_WHEN_DISTANCE_INFERIOR_AT: f32 = 2.0;
39
+//
40
+pub const MOVE_VELOCITY: f32 = 1.0;
41
+pub const MOVE_FAST_VELOCITY: f32 = 2.0;
42
+pub const MOVE_HIDE_VELOCITY: f32 = 0.5;

+ 2 - 2
src/scene/item.rs Zobrazit soubor

@@ -120,7 +120,7 @@ impl SceneItem {
120 120
 }
121 121
 
122 122
 pub enum SceneItemModifier {
123
-    SwitchToCurrentOrder,
123
+    SwitchToNextOrder,
124 124
     ChangeDisplayAngle(f32),
125 125
     ChangeState(ItemState),
126 126
 }
@@ -128,7 +128,7 @@ pub enum SceneItemModifier {
128 128
 pub fn apply_scene_item_modifier(scene_item: &mut SceneItem, modifiers: Vec<SceneItemModifier>) {
129 129
     for modifier in modifiers {
130 130
         match modifier {
131
-            SceneItemModifier::SwitchToCurrentOrder => {
131
+            SceneItemModifier::SwitchToNextOrder => {
132 132
                 let next_order = scene_item.next_order.clone();
133 133
                 scene_item.current_order = next_order;
134 134
                 scene_item.next_order = None;

+ 29 - 9
src/scene/main.rs Zobrazit soubor

@@ -13,9 +13,9 @@ use crate::behavior::order::Order;
13 13
 use crate::behavior::ItemBehavior;
14 14
 use crate::config::{
15 15
     ANIMATE_EACH, DEBUG, DEFAULT_SELECTED_SQUARE_SIDE, DEFAULT_SELECTED_SQUARE_SIDE_HALF,
16
-    DISPLAY_OFFSET_BY, DISPLAY_OFFSET_BY_SPEED, MAX_FRAME_I, META_EACH,
17
-    MOVE_TO_REACHED_WHEN_DISTANCE_INFERIOR_AT, PHYSICS_EACH, SCENE_ITEMS_CHANGE_ERR_MSG,
18
-    SPRITE_EACH, TARGET_FPS,
16
+    DISPLAY_OFFSET_BY, DISPLAY_OFFSET_BY_SPEED, MAX_FRAME_I, META_EACH, MOVE_FAST_VELOCITY,
17
+    MOVE_HIDE_VELOCITY, MOVE_TO_REACHED_WHEN_DISTANCE_INFERIOR_AT, MOVE_VELOCITY, PHYSICS_EACH,
18
+    SCENE_ITEMS_CHANGE_ERR_MSG, SPRITE_EACH, TARGET_FPS,
19 19
 };
20 20
 use crate::physics::util::scene_point_from_window_point;
21 21
 use crate::physics::util::window_point_from_scene_point;
@@ -185,7 +185,8 @@ impl MainState {
185 185
                 }
186 186
                 SceneItemPrepareOrder::Hide(scene_item_usize) => {
187 187
                     let mut scene_item = self.get_scene_item_mut(*scene_item_usize);
188
-                    scene_item.next_order = Some(Order::HideTo(scene_click_point));}
188
+                    scene_item.next_order = Some(Order::HideTo(scene_click_point));
189
+                }
189 190
             }
190 191
 
191 192
             self.scene_item_prepare_order = None;
@@ -255,16 +256,27 @@ impl MainState {
255 256
         // Scene items movements
256 257
         for scene_item in self.scene_items.iter_mut() {
257 258
             match scene_item.state.current_behavior {
258
-                ItemBehavior::MoveTo(scene_point) => {
259
+                ItemBehavior::Standing => {}
260
+                ItemBehavior::MoveTo(move_to_scene_point)
261
+                | ItemBehavior::MoveFastTo(move_to_scene_point)
262
+                | ItemBehavior::HideTo(move_to_scene_point) => {
263
+                    let velocity = match &scene_item.state.current_behavior {
264
+                        ItemBehavior::MoveTo(_) => MOVE_VELOCITY,
265
+                        ItemBehavior::MoveFastTo(_) => MOVE_FAST_VELOCITY,
266
+                        ItemBehavior::HideTo(_) => MOVE_HIDE_VELOCITY,
267
+                        _ => {
268
+                            panic!("This code should not be reached")
269
+                        }
270
+                    };
259 271
                     // FIXME BS NOW: velocity
260
-                    let move_vector = (scene_point - scene_item.position).normalize() * 1.0;
272
+                    let move_vector =
273
+                        (move_to_scene_point - scene_item.position).normalize() * velocity;
261 274
                     // TODO ici il faut calculer le déplacement réél (en fonction des ticks, etc ...)
262 275
                     scene_item.position.x += move_vector.x;
263 276
                     scene_item.position.y += move_vector.y;
264 277
                     scene_item.grid_position =
265 278
                         util::grid_position_from_scene_point(&scene_item.position);
266 279
                 }
267
-                _ => {}
268 280
             }
269 281
         }
270 282
 
@@ -463,7 +475,15 @@ impl MainState {
463 475
     ) -> GameResult<MeshBuilder> {
464 476
         if let Some(scene_item_prepare_order) = &self.scene_item_prepare_order {
465 477
             match scene_item_prepare_order {
466
-                SceneItemPrepareOrder::Move(scene_item_usize) => {
478
+                SceneItemPrepareOrder::Move(scene_item_usize)
479
+                | SceneItemPrepareOrder::MoveFast(scene_item_usize)
480
+                | SceneItemPrepareOrder::Hide(scene_item_usize) => {
481
+                    let color = match &scene_item_prepare_order {
482
+                        SceneItemPrepareOrder::Move(_) => graphics::BLUE,
483
+                        SceneItemPrepareOrder::MoveFast(_) => graphics::MAGENTA,
484
+                        SceneItemPrepareOrder::Hide(_) => graphics::YELLOW,
485
+                    };
486
+
467 487
                     let scene_item = self.get_scene_item(*scene_item_usize);
468 488
                     mesh_builder.line(
469 489
                         &vec![
@@ -474,7 +494,7 @@ impl MainState {
474 494
                             ),
475 495
                         ],
476 496
                         2.0,
477
-                        graphics::WHITE,
497
+                        color,
478 498
                     )?;
479 499
                 }
480 500
             }

+ 2 - 2
src/ui/mod.rs Zobrazit soubor

@@ -22,9 +22,9 @@ pub enum UserEvent {
22 22
 }
23 23
 
24 24
 pub enum SceneItemPrepareOrder {
25
-    Move(usize), // scene_item usize
25
+    Move(usize),     // scene_item usize
26 26
     MoveFast(usize), // scene_item usize
27
-    Hide(usize), // scene_item usize
27
+    Hide(usize),     // scene_item usize
28 28
 }
29 29
 
30 30
 #[derive(Clone)]