|
@@ -7,8 +7,8 @@ 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::ItemBehavior;
|
11
|
10
|
use crate::behavior::order::Order;
|
|
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
|
14
|
DISPLAY_OFFSET_BY, DISPLAY_OFFSET_BY_SPEED, MAX_FRAME_I, META_EACH, PHYSICS_EACH,
|
|
@@ -63,16 +63,16 @@ impl MainState {
|
63
|
63
|
let mut scene_items = vec![];
|
64
|
64
|
for x in 0..1 {
|
65
|
65
|
for y in 0..4 {
|
66
|
|
- let current_behavior = if y % 2 == 0 {
|
67
|
|
- ItemBehavior::Walking(util::vec_from_angle(90.0))
|
68
|
|
- } else {
|
69
|
|
- ItemBehavior::Crawling
|
70
|
|
- };
|
|
66
|
+ // let current_behavior = if y % 2 == 0 {
|
|
67
|
+ // ItemBehavior::WalkingTo(util::vec_from_angle(90.0))
|
|
68
|
+ // } else {
|
|
69
|
+ // ItemBehavior::CrawlingTo()
|
|
70
|
+ // };
|
71
|
71
|
|
72
|
72
|
scene_items.push(SceneItem::new(
|
73
|
73
|
SceneItemType::Soldier,
|
74
|
74
|
ScenePoint::new((x as f32 * 24.0) + 100.0, (y as f32 * 24.0) + 100.0),
|
75
|
|
- ItemState::new(current_behavior),
|
|
75
|
+ ItemState::new(ItemBehavior::Standing(0)),
|
76
|
76
|
));
|
77
|
77
|
}
|
78
|
78
|
}
|
|
@@ -167,13 +167,6 @@ impl MainState {
|
167
|
167
|
SceneItemPrepareOrder::Move(scene_item_usize) => {
|
168
|
168
|
let mut scene_item = self.get_scene_item_mut(*scene_item_usize);
|
169
|
169
|
scene_item.next_order = Some(Order::MoveTo(scene_position));
|
170
|
|
-
|
171
|
|
- // TODO: remove this code when used in right place
|
172
|
|
- let angle = f32::atan2(
|
173
|
|
- scene_position.y - scene_item.position.y,
|
174
|
|
- scene_position.x - scene_item.position.x,
|
175
|
|
- ) + FRAC_PI_2;
|
176
|
|
- println!("{:?}", angle);
|
177
|
170
|
}
|
178
|
171
|
}
|
179
|
172
|
|
|
@@ -241,11 +234,14 @@ impl MainState {
|
241
|
234
|
// Scene items movements
|
242
|
235
|
for scene_item in self.scene_items.iter_mut() {
|
243
|
236
|
match scene_item.state.current_behavior {
|
244
|
|
- ItemBehavior::Walking(move_vector) => {
|
|
237
|
+ ItemBehavior::WalkingTo(scene_point) => {
|
|
238
|
+ // FIXME BS NOW: velocity
|
|
239
|
+ let move_vector = (scene_point - scene_item.position).normalize() * 1.0;
|
245
|
240
|
// TODO ici il faut calculer le déplacement réél (en fonction des ticks, etc ...)
|
246
|
241
|
scene_item.position.x += move_vector.x;
|
247
|
242
|
scene_item.position.y += move_vector.y;
|
248
|
|
- scene_item.grid_position = util::grid_position_from_scene_point(&scene_item.position);
|
|
243
|
+ scene_item.grid_position =
|
|
244
|
+ util::grid_position_from_scene_point(&scene_item.position);
|
249
|
245
|
}
|
250
|
246
|
_ => {}
|
251
|
247
|
}
|
|
@@ -273,13 +269,13 @@ impl MainState {
|
273
|
269
|
// TODO: ici il faut reflechir a comment organiser les comportements
|
274
|
270
|
|
275
|
271
|
for scene_item in self.scene_items.iter_mut() {
|
276
|
|
- for meta_event in &scene_item.meta_events {
|
277
|
|
- match meta_event {
|
278
|
|
- MetaEvent::FeelExplosion => {
|
279
|
|
- scene_item.state = ItemState::new(ItemBehavior::Standing(self.frame_i));
|
280
|
|
- }
|
281
|
|
- }
|
282
|
|
- }
|
|
272
|
+ // for meta_event in &scene_item.meta_events {
|
|
273
|
+ // match meta_event {
|
|
274
|
+ // MetaEvent::FeelExplosion => {
|
|
275
|
+ // scene_item.state = ItemState::new(ItemBehavior::Standing(self.frame_i));
|
|
276
|
+ // }
|
|
277
|
+ // }
|
|
278
|
+ // }
|
283
|
279
|
|
284
|
280
|
// match scene_item.state.current_behavior {
|
285
|
281
|
// ItemBehavior::Crawling => {
|
|
@@ -300,13 +296,10 @@ impl MainState {
|
300
|
296
|
scene_item.meta_events.drain(..);
|
301
|
297
|
|
302
|
298
|
if let Some(next_order) = &scene_item.next_order {
|
303
|
|
- // Compute here if it possible (fear, compatible with current order, etc)
|
|
299
|
+ // TODO: Compute here if it possible (fear, compatible with current order, etc)
|
304
|
300
|
match next_order {
|
305
|
301
|
Order::MoveTo(move_to_scene_point) => {
|
306
|
302
|
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));
|
310
|
303
|
}
|
311
|
304
|
}
|
312
|
305
|
scene_item.next_order = None;
|
|
@@ -316,11 +309,43 @@ impl MainState {
|
316
|
309
|
if let Some(current_order) = &scene_item.current_order {
|
317
|
310
|
match current_order {
|
318
|
311
|
Order::MoveTo(move_to_scene_point) => {
|
319
|
|
- let move_vector = (*move_to_scene_point - scene_item.position).normalize() * 1.0;
|
320
|
|
- println!("{:?}", move_vector);
|
|
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
|
+ }
|
321
|
322
|
}
|
322
|
323
|
}
|
323
|
324
|
}
|
|
325
|
+
|
|
326
|
+ match scene_item.state.current_behavior {
|
|
327
|
+ 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,
|
|
342
|
+ ) + FRAC_PI_2;
|
|
343
|
+ scene_item.display_angle = angle;
|
|
344
|
+
|
|
345
|
+ let move_vector = (scene_point - scene_item.position).normalize() * 1.0;
|
|
346
|
+ println!("{:?}", move_vector);
|
|
347
|
+ }
|
|
348
|
+ }
|
324
|
349
|
}
|
325
|
350
|
}
|
326
|
351
|
|