Bastien Sevajol 3 years ago
parent
commit
824c122e8d
5 changed files with 50 additions and 25 deletions
  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 View File

11
     if let Some(next_order) = &scene_item.next_order {
11
     if let Some(next_order) = &scene_item.next_order {
12
         match next_order {
12
         match next_order {
13
             Order::MoveTo(_) => {
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
                 // FIXME BS NOW: Change order only if it is not the current order
37
                 // FIXME BS NOW: Change order only if it is not the current order
42
                 scene_item_modifiers.push(SceneItemModifier::ChangeState(ItemState::new(
38
                 scene_item_modifiers.push(SceneItemModifier::ChangeState(ItemState::new(
43
                     ItemBehavior::MoveFastTo(*move_to_scene_point),
39
                     ItemBehavior::MoveFastTo(*move_to_scene_point),
44
-                )))}
40
+                )))
41
+            }
45
             Order::HideTo(move_to_scene_point) => {
42
             Order::HideTo(move_to_scene_point) => {
46
                 // FIXME BS NOW: Change order only if it is not the current order
43
                 // FIXME BS NOW: Change order only if it is not the current order
47
                 scene_item_modifiers.push(SceneItemModifier::ChangeState(ItemState::new(
44
                 scene_item_modifiers.push(SceneItemModifier::ChangeState(ItemState::new(
48
                     ItemBehavior::HideTo(*move_to_scene_point),
45
                     ItemBehavior::HideTo(*move_to_scene_point),
49
-                )))}
46
+                )))
47
+            }
50
         }
48
         }
51
     }
49
     }
52
 
50
 
59
     match scene_item.state.current_behavior {
57
     match scene_item.state.current_behavior {
60
         ItemBehavior::Standing => {}
58
         ItemBehavior::Standing => {}
61
         ItemBehavior::MoveTo(going_to_scene_point)
59
         ItemBehavior::MoveTo(going_to_scene_point)
60
+        | ItemBehavior::MoveFastTo(going_to_scene_point)
62
         | ItemBehavior::HideTo(going_to_scene_point) => {
61
         | ItemBehavior::HideTo(going_to_scene_point) => {
63
             // Note: angle computed by adding FRAC_PI_2 because sprites are north oriented
62
             // Note: angle computed by adding FRAC_PI_2 because sprites are north oriented
64
             scene_item_modifiers.push(SceneItemModifier::ChangeDisplayAngle(
63
             scene_item_modifiers.push(SceneItemModifier::ChangeDisplayAngle(
76
                 )));
75
                 )));
77
                 if let Some(current_order) = &scene_item.current_order {
76
                 if let Some(current_order) = &scene_item.current_order {
78
                     match current_order {
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
                             if *move_to_scene_point == going_to_scene_point {
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 View File

35
 //
35
 //
36
 pub const DEBUG: bool = true;
36
 pub const DEBUG: bool = true;
37
 // Distance from move target point to consider reached
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 View File

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

+ 29 - 9
src/scene/main.rs View File

13
 use crate::behavior::ItemBehavior;
13
 use crate::behavior::ItemBehavior;
14
 use crate::config::{
14
 use crate::config::{
15
     ANIMATE_EACH, DEBUG, DEFAULT_SELECTED_SQUARE_SIDE, DEFAULT_SELECTED_SQUARE_SIDE_HALF,
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
 use crate::physics::util::scene_point_from_window_point;
20
 use crate::physics::util::scene_point_from_window_point;
21
 use crate::physics::util::window_point_from_scene_point;
21
 use crate::physics::util::window_point_from_scene_point;
185
                 }
185
                 }
186
                 SceneItemPrepareOrder::Hide(scene_item_usize) => {
186
                 SceneItemPrepareOrder::Hide(scene_item_usize) => {
187
                     let mut scene_item = self.get_scene_item_mut(*scene_item_usize);
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
             self.scene_item_prepare_order = None;
192
             self.scene_item_prepare_order = None;
255
         // Scene items movements
256
         // Scene items movements
256
         for scene_item in self.scene_items.iter_mut() {
257
         for scene_item in self.scene_items.iter_mut() {
257
             match scene_item.state.current_behavior {
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
                     // FIXME BS NOW: velocity
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
                     // TODO ici il faut calculer le déplacement réél (en fonction des ticks, etc ...)
274
                     // TODO ici il faut calculer le déplacement réél (en fonction des ticks, etc ...)
262
                     scene_item.position.x += move_vector.x;
275
                     scene_item.position.x += move_vector.x;
263
                     scene_item.position.y += move_vector.y;
276
                     scene_item.position.y += move_vector.y;
264
                     scene_item.grid_position =
277
                     scene_item.grid_position =
265
                         util::grid_position_from_scene_point(&scene_item.position);
278
                         util::grid_position_from_scene_point(&scene_item.position);
266
                 }
279
                 }
267
-                _ => {}
268
             }
280
             }
269
         }
281
         }
270
 
282
 
463
     ) -> GameResult<MeshBuilder> {
475
     ) -> GameResult<MeshBuilder> {
464
         if let Some(scene_item_prepare_order) = &self.scene_item_prepare_order {
476
         if let Some(scene_item_prepare_order) = &self.scene_item_prepare_order {
465
             match scene_item_prepare_order {
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
                     let scene_item = self.get_scene_item(*scene_item_usize);
487
                     let scene_item = self.get_scene_item(*scene_item_usize);
468
                     mesh_builder.line(
488
                     mesh_builder.line(
469
                         &vec![
489
                         &vec![
474
                             ),
494
                             ),
475
                         ],
495
                         ],
476
                         2.0,
496
                         2.0,
477
-                        graphics::WHITE,
497
+                        color,
478
                     )?;
498
                     )?;
479
                 }
499
                 }
480
             }
500
             }

+ 2 - 2
src/ui/mod.rs View File

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