|
@@ -8,6 +8,7 @@ use ggez::timer::check_update_time;
|
8
|
8
|
use ggez::{event, graphics, input, Context, GameResult};
|
9
|
9
|
|
10
|
10
|
use crate::behavior::ItemBehavior;
|
|
11
|
+use crate::behavior::order::Order;
|
11
|
12
|
use crate::config::{
|
12
|
13
|
ANIMATE_EACH, DEBUG, DEFAULT_SELECTED_SQUARE_SIDE, DEFAULT_SELECTED_SQUARE_SIDE_HALF,
|
13
|
14
|
DISPLAY_OFFSET_BY, DISPLAY_OFFSET_BY_SPEED, MAX_FRAME_I, META_EACH, PHYSICS_EACH,
|
|
@@ -112,7 +113,7 @@ impl MainState {
|
112
|
113
|
.expect(SCENE_ITEMS_CHANGE_ERR_MSG)
|
113
|
114
|
}
|
114
|
115
|
|
115
|
|
- fn get_scene_item_mut(&mut self, index: usize) -> &SceneItem {
|
|
116
|
+ fn get_scene_item_mut(&mut self, index: usize) -> &mut SceneItem {
|
116
|
117
|
self.scene_items
|
117
|
118
|
.get_mut(index)
|
118
|
119
|
.expect(SCENE_ITEMS_CHANGE_ERR_MSG)
|
|
@@ -164,7 +165,9 @@ impl MainState {
|
164
|
165
|
// TODO: Add order to scene_item
|
165
|
166
|
match scene_item_prepare_order {
|
166
|
167
|
SceneItemPrepareOrder::Move(scene_item_usize) => {
|
167
|
|
- let scene_item = self.get_scene_item(*scene_item_usize);
|
|
168
|
+ let mut scene_item = self.get_scene_item_mut(*scene_item_usize);
|
|
169
|
+ scene_item.next_order = Some(Order::MoveTo(scene_position));
|
|
170
|
+
|
168
|
171
|
// TODO: remove this code when used in right place
|
169
|
172
|
let angle = f32::atan2(
|
170
|
173
|
scene_position.y - scene_item.position.y,
|
|
@@ -238,11 +241,11 @@ impl MainState {
|
238
|
241
|
// Scene items movements
|
239
|
242
|
for scene_item in self.scene_items.iter_mut() {
|
240
|
243
|
match scene_item.state.current_behavior {
|
241
|
|
- ItemBehavior::Walking(_vector) => {
|
|
244
|
+ ItemBehavior::Walking(move_vector) => {
|
242
|
245
|
// TODO ici il faut calculer le déplacement réél (en fonction des ticks, etc ...)
|
243
|
|
- scene_item.position.x += 1.0;
|
244
|
|
- scene_item.grid_position =
|
245
|
|
- util::grid_position_from_scene_point(&scene_item.position);
|
|
246
|
+ scene_item.position.x += move_vector.x;
|
|
247
|
+ scene_item.position.y += move_vector.y;
|
|
248
|
+ scene_item.grid_position = util::grid_position_from_scene_point(&scene_item.position);
|
246
|
249
|
}
|
247
|
250
|
_ => {}
|
248
|
251
|
}
|
|
@@ -278,23 +281,46 @@ impl MainState {
|
278
|
281
|
}
|
279
|
282
|
}
|
280
|
283
|
|
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)));
|
|
284
|
+ // match scene_item.state.current_behavior {
|
|
285
|
+ // ItemBehavior::Crawling => {
|
|
286
|
+ // scene_item.state =
|
|
287
|
+ // ItemState::new(ItemBehavior::Walking(util::vec_from_angle(90.0)));
|
|
288
|
+ // }
|
|
289
|
+ // ItemBehavior::Walking(_) => {
|
|
290
|
+ // scene_item.state = ItemState::new(ItemBehavior::Crawling);
|
|
291
|
+ // }
|
|
292
|
+ // ItemBehavior::Standing(since) => {
|
|
293
|
+ // if self.frame_i - since >= 120 {
|
|
294
|
+ // scene_item.state =
|
|
295
|
+ // ItemState::new(ItemBehavior::Walking(util::vec_from_angle(90.0)));
|
|
296
|
+ // }
|
|
297
|
+ // }
|
|
298
|
+ // }
|
|
299
|
+
|
|
300
|
+ scene_item.meta_events.drain(..);
|
|
301
|
+
|
|
302
|
+ if let Some(next_order) = &scene_item.next_order {
|
|
303
|
+ // Compute here if it possible (fear, compatible with current order, etc)
|
|
304
|
+ match next_order {
|
|
305
|
+ Order::MoveTo(move_to_scene_point) => {
|
|
306
|
+ scene_item.current_order = Some(Order::MoveTo(*move_to_scene_point));
|
|
307
|
+ // FIXME BS NOW: velocity
|
|
308
|
+ let move_vector = (*move_to_scene_point - scene_item.position).normalize() * 1.0;
|
|
309
|
+ scene_item.state = ItemState::new(ItemBehavior::Walking(move_vector));
|
293
|
310
|
}
|
294
|
311
|
}
|
|
312
|
+ scene_item.next_order = None;
|
295
|
313
|
}
|
296
|
314
|
|
297
|
|
- scene_item.meta_events.drain(..);
|
|
315
|
+ // FIXME BS NOW: stop move when move is accomplished; warn: recompute move_vector here
|
|
316
|
+ if let Some(current_order) = &scene_item.current_order {
|
|
317
|
+ match current_order {
|
|
318
|
+ Order::MoveTo(move_to_scene_point) => {
|
|
319
|
+ let move_vector = (*move_to_scene_point - scene_item.position).normalize() * 1.0;
|
|
320
|
+ println!("{:?}", move_vector);
|
|
321
|
+ }
|
|
322
|
+ }
|
|
323
|
+ }
|
298
|
324
|
}
|
299
|
325
|
}
|
300
|
326
|
|