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

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

+ 1 - 0
src/main.rs View File

11
 mod physics;
11
 mod physics;
12
 mod scene;
12
 mod scene;
13
 mod ui;
13
 mod ui;
14
+mod util;
14
 
15
 
15
 type WindowPoint = Vec2;
16
 type WindowPoint = Vec2;
16
 type Offset = Vec2;
17
 type Offset = Vec2;

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

27
 use crate::ui::vertical_menu::{vertical_menu_sprite_info, VerticalMenuSpriteInfo};
27
 use crate::ui::vertical_menu::{vertical_menu_sprite_info, VerticalMenuSpriteInfo};
28
 use crate::ui::MenuItem;
28
 use crate::ui::MenuItem;
29
 use crate::ui::{SceneItemPrepareOrder, UiComponent, UserEvent};
29
 use crate::ui::{SceneItemPrepareOrder, UiComponent, UserEvent};
30
+use crate::util::velocity_for_behavior;
30
 use crate::{Offset, ScenePoint, WindowPoint};
31
 use crate::{Offset, ScenePoint, WindowPoint};
31
 
32
 
32
 pub struct MainState {
33
 pub struct MainState {
260
                 ItemBehavior::MoveTo(move_to_scene_point)
261
                 ItemBehavior::MoveTo(move_to_scene_point)
261
                 | ItemBehavior::MoveFastTo(move_to_scene_point)
262
                 | ItemBehavior::MoveFastTo(move_to_scene_point)
262
                 | ItemBehavior::HideTo(move_to_scene_point) => {
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
                     let move_vector =
266
                     let move_vector =
273
                         (move_to_scene_point - scene_item.position).normalize() * velocity;
267
                         (move_to_scene_point - scene_item.position).normalize() * velocity;
274
                     // TODO ici il faut calculer le déplacement réél (en fonction des ticks, etc ...)
268
                     // TODO ici il faut calculer le déplacement réél (en fonction des ticks, etc ...)

+ 11 - 0
src/util.rs View File

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
+}