|
@@ -11,8 +11,9 @@ use crate::behavior::order::Order;
|
11
|
11
|
use crate::behavior::ItemBehavior;
|
12
|
12
|
use crate::config::{
|
13
|
13
|
ANIMATE_EACH, DEBUG, DEFAULT_SELECTED_SQUARE_SIDE, DEFAULT_SELECTED_SQUARE_SIDE_HALF,
|
14
|
|
- DISPLAY_OFFSET_BY, DISPLAY_OFFSET_BY_SPEED, MAX_FRAME_I, META_EACH, PHYSICS_EACH,
|
15
|
|
- SCENE_ITEMS_CHANGE_ERR_MSG, SPRITE_EACH, TARGET_FPS,
|
|
14
|
+ DISPLAY_OFFSET_BY, DISPLAY_OFFSET_BY_SPEED, MAX_FRAME_I, META_EACH,
|
|
15
|
+ MOVE_TO_REACHED_WHEN_DISTANCE_INFERIOR_AT, PHYSICS_EACH, SCENE_ITEMS_CHANGE_ERR_MSG,
|
|
16
|
+ SPRITE_EACH, TARGET_FPS,
|
16
|
17
|
};
|
17
|
18
|
use crate::physics::util::scene_point_from_window_point;
|
18
|
19
|
use crate::physics::util::window_point_from_scene_point;
|
|
@@ -292,8 +293,8 @@ impl MainState {
|
292
|
293
|
// }
|
293
|
294
|
// }
|
294
|
295
|
// }
|
295
|
|
-
|
296
|
|
- scene_item.meta_events.drain(..);
|
|
296
|
+ //
|
|
297
|
+ // scene_item.meta_events.drain(..);
|
297
|
298
|
|
298
|
299
|
if let Some(next_order) = &scene_item.next_order {
|
299
|
300
|
// TODO: Compute here if it possible (fear, compatible with current order, etc)
|
|
@@ -305,45 +306,42 @@ impl MainState {
|
305
|
306
|
scene_item.next_order = None;
|
306
|
307
|
}
|
307
|
308
|
|
308
|
|
- // FIXME BS NOW: stop move when move is accomplished; warn: recompute move_vector here
|
|
309
|
+ // TODO: here, compute state according to order. Ex: if too much fear, move order do not produce walking state
|
309
|
310
|
if let Some(current_order) = &scene_item.current_order {
|
310
|
311
|
match current_order {
|
311
|
312
|
Order::MoveTo(move_to_scene_point) => {
|
312
|
|
- let change_to_walk = match scene_item.state.current_behavior {
|
313
|
|
- ItemBehavior::Standing(_) => true,
|
314
|
|
- ItemBehavior::CrawlingTo(_) => true,
|
315
|
|
- ItemBehavior::WalkingTo(_) => false,
|
316
|
|
- };
|
317
|
|
-
|
318
|
|
- if change_to_walk {
|
319
|
|
- scene_item.state =
|
320
|
|
- ItemState::new(ItemBehavior::WalkingTo(*move_to_scene_point));
|
321
|
|
- }
|
|
313
|
+ scene_item.state =
|
|
314
|
+ ItemState::new(ItemBehavior::WalkingTo(*move_to_scene_point));
|
322
|
315
|
}
|
323
|
316
|
}
|
324
|
317
|
}
|
325
|
318
|
|
326
|
319
|
match scene_item.state.current_behavior {
|
327
|
320
|
ItemBehavior::Standing(_) => {}
|
328
|
|
- ItemBehavior::CrawlingTo(scene_point) => {
|
329
|
|
- let angle = f32::atan2(
|
330
|
|
- scene_point.y - scene_item.position.y,
|
331
|
|
- scene_point.x - scene_item.position.x,
|
332
|
|
- ) + FRAC_PI_2;
|
333
|
|
- scene_item.display_angle = angle;
|
334
|
|
-
|
335
|
|
- let move_vector = (scene_point - scene_item.position).normalize() * 1.0;
|
336
|
|
- println!("{:?}", move_vector);
|
337
|
|
- }
|
338
|
|
- ItemBehavior::WalkingTo(scene_point) => {
|
339
|
|
- let angle = f32::atan2(
|
340
|
|
- scene_point.y - scene_item.position.y,
|
341
|
|
- scene_point.x - scene_item.position.x,
|
|
321
|
+ ItemBehavior::WalkingTo(going_to_scene_point)
|
|
322
|
+ | ItemBehavior::CrawlingTo(going_to_scene_point) => {
|
|
323
|
+ // Note: angle computed by adding FRAC_PI_2 because sprites are north oriented
|
|
324
|
+ scene_item.display_angle = f32::atan2(
|
|
325
|
+ going_to_scene_point.y - scene_item.position.y,
|
|
326
|
+ going_to_scene_point.x - scene_item.position.x,
|
342
|
327
|
) + FRAC_PI_2;
|
343
|
|
- scene_item.display_angle = angle;
|
344
|
328
|
|
345
|
|
- let move_vector = (scene_point - scene_item.position).normalize() * 1.0;
|
346
|
|
- println!("{:?}", move_vector);
|
|
329
|
+ // Check if scene_point reached
|
|
330
|
+ let distance = going_to_scene_point.distance(scene_item.position);
|
|
331
|
+ println!("{:?}", distance);
|
|
332
|
+ if distance < MOVE_TO_REACHED_WHEN_DISTANCE_INFERIOR_AT {
|
|
333
|
+ scene_item.state = ItemState::new(ItemBehavior::Standing(self.frame_i));
|
|
334
|
+ if let Some(current_order) = &scene_item.current_order {
|
|
335
|
+ match current_order {
|
|
336
|
+ Order::MoveTo(move_to_scene_point) => {
|
|
337
|
+ if *move_to_scene_point == going_to_scene_point {
|
|
338
|
+ // TODO: If multiple moves, setup next move order
|
|
339
|
+ scene_item.current_order = None;
|
|
340
|
+ }
|
|
341
|
+ }
|
|
342
|
+ }
|
|
343
|
+ }
|
|
344
|
+ }
|
347
|
345
|
}
|
348
|
346
|
}
|
349
|
347
|
}
|