|
@@ -7,6 +7,7 @@ use ggez::input::keyboard::KeyCode;
|
7
|
7
|
use ggez::timer::check_update_time;
|
8
|
8
|
use ggez::{event, graphics, input, Context, GameResult};
|
9
|
9
|
|
|
10
|
+use crate::behavior::animate::{digest_current_behavior, digest_current_order, digest_next_order};
|
10
|
11
|
use crate::behavior::order::Order;
|
11
|
12
|
use crate::behavior::ItemBehavior;
|
12
|
13
|
use crate::config::{
|
|
@@ -19,7 +20,9 @@ use crate::physics::util::scene_point_from_window_point;
|
19
|
20
|
use crate::physics::util::window_point_from_scene_point;
|
20
|
21
|
use crate::physics::GridPosition;
|
21
|
22
|
use crate::physics::{util, MetaEvent, PhysicEvent};
|
22
|
|
-use crate::scene::item::{ItemState, SceneItem, SceneItemType};
|
|
23
|
+use crate::scene::item::{
|
|
24
|
+ apply_scene_item_modifier, ItemState, SceneItem, SceneItemModifier, SceneItemType,
|
|
25
|
+};
|
23
|
26
|
use crate::ui::scene_item_menu::SceneItemMenuItem;
|
24
|
27
|
use crate::ui::{SceneItemPrepareOrder, UiItem, UiSpriteInfo, UserEvent};
|
25
|
28
|
use crate::{Offset, ScenePoint, WindowPoint};
|
|
@@ -73,7 +76,7 @@ impl MainState {
|
73
|
76
|
scene_items.push(SceneItem::new(
|
74
|
77
|
SceneItemType::Soldier,
|
75
|
78
|
ScenePoint::new((x as f32 * 24.0) + 100.0, (y as f32 * 24.0) + 100.0),
|
76
|
|
- ItemState::new(ItemBehavior::Standing(0)),
|
|
79
|
+ ItemState::new(ItemBehavior::Standing),
|
77
|
80
|
));
|
78
|
81
|
}
|
79
|
82
|
}
|
|
@@ -267,83 +270,10 @@ impl MainState {
|
267
|
270
|
}
|
268
|
271
|
|
269
|
272
|
fn animate(&mut self) {
|
270
|
|
- // TODO: ici il faut reflechir a comment organiser les comportements
|
271
|
|
-
|
272
|
|
- for scene_item in self.scene_items.iter_mut() {
|
273
|
|
- // for meta_event in &scene_item.meta_events {
|
274
|
|
- // match meta_event {
|
275
|
|
- // MetaEvent::FeelExplosion => {
|
276
|
|
- // scene_item.state = ItemState::new(ItemBehavior::Standing(self.frame_i));
|
277
|
|
- // }
|
278
|
|
- // }
|
279
|
|
- // }
|
280
|
|
-
|
281
|
|
- // match scene_item.state.current_behavior {
|
282
|
|
- // ItemBehavior::Crawling => {
|
283
|
|
- // scene_item.state =
|
284
|
|
- // ItemState::new(ItemBehavior::Walking(util::vec_from_angle(90.0)));
|
285
|
|
- // }
|
286
|
|
- // ItemBehavior::Walking(_) => {
|
287
|
|
- // scene_item.state = ItemState::new(ItemBehavior::Crawling);
|
288
|
|
- // }
|
289
|
|
- // ItemBehavior::Standing(since) => {
|
290
|
|
- // if self.frame_i - since >= 120 {
|
291
|
|
- // scene_item.state =
|
292
|
|
- // ItemState::new(ItemBehavior::Walking(util::vec_from_angle(90.0)));
|
293
|
|
- // }
|
294
|
|
- // }
|
295
|
|
- // }
|
296
|
|
- //
|
297
|
|
- // scene_item.meta_events.drain(..);
|
298
|
|
-
|
299
|
|
- if let Some(next_order) = &scene_item.next_order {
|
300
|
|
- // TODO: Compute here if it possible (fear, compatible with current order, etc)
|
301
|
|
- match next_order {
|
302
|
|
- Order::MoveTo(move_to_scene_point) => {
|
303
|
|
- scene_item.current_order = Some(Order::MoveTo(*move_to_scene_point));
|
304
|
|
- }
|
305
|
|
- }
|
306
|
|
- scene_item.next_order = None;
|
307
|
|
- }
|
308
|
|
-
|
309
|
|
- // TODO: here, compute state according to order. Ex: if too much fear, move order do not produce walking state
|
310
|
|
- if let Some(current_order) = &scene_item.current_order {
|
311
|
|
- match current_order {
|
312
|
|
- Order::MoveTo(move_to_scene_point) => {
|
313
|
|
- scene_item.state =
|
314
|
|
- ItemState::new(ItemBehavior::WalkingTo(*move_to_scene_point));
|
315
|
|
- }
|
316
|
|
- }
|
317
|
|
- }
|
318
|
|
-
|
319
|
|
- match scene_item.state.current_behavior {
|
320
|
|
- ItemBehavior::Standing(_) => {}
|
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,
|
327
|
|
- ) + FRAC_PI_2;
|
328
|
|
-
|
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
|
|
- }
|
345
|
|
- }
|
346
|
|
- }
|
|
273
|
+ for (i, scene_item) in self.scene_items.iter_mut().enumerate() {
|
|
274
|
+ apply_scene_item_modifier(scene_item, digest_next_order(&scene_item));
|
|
275
|
+ apply_scene_item_modifier(scene_item, digest_current_order(&scene_item));
|
|
276
|
+ apply_scene_item_modifier(scene_item, digest_current_behavior(&scene_item));
|
347
|
277
|
}
|
348
|
278
|
}
|
349
|
279
|
|