2 Commits 824c122e8d ... b5f352a086

Author SHA1 Message Date
  Bastien Sevajol b5f352a086 wip 3 years ago
  Bastien Sevajol 824c122e8d wip 3 years ago
5 changed files with 25 additions and 12 deletions
  1. 6 1
      src/behavior/animate.rs
  2. 4 2
      src/config.rs
  3. 1 0
      src/main.rs
  4. 3 9
      src/scene/main.rs
  5. 11 0
      src/util.rs

+ 6 - 1
src/behavior/animate.rs View File

@@ -2,6 +2,7 @@ use crate::behavior::order::Order;
2 2
 use crate::behavior::ItemBehavior;
3 3
 use crate::config::MOVE_TO_REACHED_WHEN_DISTANCE_INFERIOR_AT;
4 4
 use crate::scene::item::{ItemState, SceneItem, SceneItemModifier};
5
+use crate::util::velocity_for_behavior;
5 6
 use std::f32::consts::FRAC_PI_2;
6 7
 
7 8
 pub fn digest_next_order(scene_item: &SceneItem) -> Vec<SceneItemModifier> {
@@ -69,10 +70,14 @@ pub fn digest_current_behavior(scene_item: &SceneItem) -> Vec<SceneItemModifier>
69 70
 
70 71
             // Check if scene_point reached
71 72
             let distance = going_to_scene_point.distance(scene_item.position);
72
-            if distance < MOVE_TO_REACHED_WHEN_DISTANCE_INFERIOR_AT {
73
+            let velocity = velocity_for_behavior(&scene_item.state.current_behavior)
74
+                .expect("must have velocity here");
75
+            if distance < MOVE_TO_REACHED_WHEN_DISTANCE_INFERIOR_AT * velocity {
73 76
                 scene_item_modifiers.push(SceneItemModifier::ChangeState(ItemState::new(
74 77
                     ItemBehavior::Standing,
75 78
                 )));
79
+
80
+                // Test if reached destination is from an order. If it is, switch to next order.
76 81
                 if let Some(current_order) = &scene_item.current_order {
77 82
                     match current_order {
78 83
                         Order::MoveTo(move_to_scene_point)

+ 4 - 2
src/config.rs View File

@@ -35,8 +35,10 @@ 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 = 2.0;
39
-//
38
+pub const MOVE_TO_REACHED_WHEN_DISTANCE_INFERIOR_AT: f32 = 3.0;
39
+// Velocity of move vector
40 40
 pub const MOVE_VELOCITY: f32 = 1.0;
41
+// Velocity of move fast vector
41 42
 pub const MOVE_FAST_VELOCITY: f32 = 2.0;
43
+// Velocity of move hide vector
42 44
 pub const MOVE_HIDE_VELOCITY: f32 = 0.5;

+ 1 - 0
src/main.rs View File

@@ -11,6 +11,7 @@ mod config;
11 11
 mod physics;
12 12
 mod scene;
13 13
 mod ui;
14
+mod util;
14 15
 
15 16
 type WindowPoint = Vec2;
16 17
 type Offset = Vec2;

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

@@ -27,6 +27,7 @@ use crate::scene::item::{
27 27
 use crate::ui::vertical_menu::{vertical_menu_sprite_info, VerticalMenuSpriteInfo};
28 28
 use crate::ui::MenuItem;
29 29
 use crate::ui::{SceneItemPrepareOrder, UiComponent, UserEvent};
30
+use crate::util::velocity_for_behavior;
30 31
 use crate::{Offset, ScenePoint, WindowPoint};
31 32
 
32 33
 pub struct MainState {
@@ -260,15 +261,8 @@ impl MainState {
260 261
                 ItemBehavior::MoveTo(move_to_scene_point)
261 262
                 | ItemBehavior::MoveFastTo(move_to_scene_point)
262 263
                 | 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
-                    };
271
-                    // FIXME BS NOW: velocity
264
+                    let velocity = velocity_for_behavior(&scene_item.state.current_behavior)
265
+                        .expect("must have velocity here");
272 266
                     let move_vector =
273 267
                         (move_to_scene_point - scene_item.position).normalize() * velocity;
274 268
                     // TODO ici il faut calculer le déplacement réél (en fonction des ticks, etc ...)

+ 11 - 0
src/util.rs View File

@@ -0,0 +1,11 @@
1
+use crate::behavior::ItemBehavior;
2
+use crate::config::{MOVE_FAST_VELOCITY, MOVE_HIDE_VELOCITY, MOVE_VELOCITY};
3
+
4
+pub fn velocity_for_behavior(behavior: &ItemBehavior) -> Option<f32> {
5
+    match behavior {
6
+        ItemBehavior::MoveTo(_) => Some(MOVE_VELOCITY),
7
+        ItemBehavior::MoveFastTo(_) => Some(MOVE_FAST_VELOCITY),
8
+        ItemBehavior::HideTo(_) => Some(MOVE_HIDE_VELOCITY),
9
+        _ => None,
10
+    }
11
+}