|
@@ -13,9 +13,9 @@ use crate::behavior::order::Order;
|
13
|
13
|
use crate::behavior::ItemBehavior;
|
14
|
14
|
use crate::config::{
|
15
|
15
|
ANIMATE_EACH, DEBUG, DEFAULT_SELECTED_SQUARE_SIDE, DEFAULT_SELECTED_SQUARE_SIDE_HALF,
|
16
|
|
- DISPLAY_OFFSET_BY, DISPLAY_OFFSET_BY_SPEED, MAX_FRAME_I, META_EACH,
|
17
|
|
- MOVE_TO_REACHED_WHEN_DISTANCE_INFERIOR_AT, PHYSICS_EACH, SCENE_ITEMS_CHANGE_ERR_MSG,
|
18
|
|
- SPRITE_EACH, TARGET_FPS,
|
|
16
|
+ DISPLAY_OFFSET_BY, DISPLAY_OFFSET_BY_SPEED, MAX_FRAME_I, META_EACH, MOVE_FAST_VELOCITY,
|
|
17
|
+ MOVE_HIDE_VELOCITY, MOVE_TO_REACHED_WHEN_DISTANCE_INFERIOR_AT, MOVE_VELOCITY, PHYSICS_EACH,
|
|
18
|
+ SCENE_ITEMS_CHANGE_ERR_MSG, SPRITE_EACH, TARGET_FPS,
|
19
|
19
|
};
|
20
|
20
|
use crate::physics::util::scene_point_from_window_point;
|
21
|
21
|
use crate::physics::util::window_point_from_scene_point;
|
|
@@ -27,6 +27,7 @@ use crate::scene::item::{
|
27
|
27
|
use crate::ui::vertical_menu::{vertical_menu_sprite_info, VerticalMenuSpriteInfo};
|
28
|
28
|
use crate::ui::MenuItem;
|
29
|
29
|
use crate::ui::{SceneItemPrepareOrder, UiComponent, UserEvent};
|
|
30
|
+use crate::util::velocity_for_behavior;
|
30
|
31
|
use crate::{Offset, ScenePoint, WindowPoint};
|
31
|
32
|
|
32
|
33
|
pub struct MainState {
|
|
@@ -174,12 +175,19 @@ impl MainState {
|
174
|
175
|
}
|
175
|
176
|
|
176
|
177
|
if let Some(scene_item_prepare_order) = &self.scene_item_prepare_order {
|
177
|
|
- // TODO: Add order to scene_item
|
178
|
178
|
match scene_item_prepare_order {
|
179
|
179
|
SceneItemPrepareOrder::Move(scene_item_usize) => {
|
180
|
180
|
let mut scene_item = self.get_scene_item_mut(*scene_item_usize);
|
181
|
181
|
scene_item.next_order = Some(Order::MoveTo(scene_click_point));
|
182
|
182
|
}
|
|
183
|
+ SceneItemPrepareOrder::MoveFast(scene_item_usize) => {
|
|
184
|
+ let mut scene_item = self.get_scene_item_mut(*scene_item_usize);
|
|
185
|
+ scene_item.next_order = Some(Order::MoveFastTo(scene_click_point));
|
|
186
|
+ }
|
|
187
|
+ SceneItemPrepareOrder::Hide(scene_item_usize) => {
|
|
188
|
+ let mut scene_item = self.get_scene_item_mut(*scene_item_usize);
|
|
189
|
+ scene_item.next_order = Some(Order::HideTo(scene_click_point));
|
|
190
|
+ }
|
183
|
191
|
}
|
184
|
192
|
|
185
|
193
|
self.scene_item_prepare_order = None;
|
|
@@ -197,8 +205,16 @@ impl MainState {
|
197
|
205
|
Some(SceneItemPrepareOrder::Move(scene_item_usize));
|
198
|
206
|
self.scene_item_menu = None;
|
199
|
207
|
}
|
200
|
|
- MenuItem::MoveFast => {}
|
201
|
|
- MenuItem::Hide => {}
|
|
208
|
+ MenuItem::MoveFast => {
|
|
209
|
+ self.scene_item_prepare_order =
|
|
210
|
+ Some(SceneItemPrepareOrder::MoveFast(scene_item_usize));
|
|
211
|
+ self.scene_item_menu = None;
|
|
212
|
+ }
|
|
213
|
+ MenuItem::Hide => {
|
|
214
|
+ self.scene_item_prepare_order =
|
|
215
|
+ Some(SceneItemPrepareOrder::Hide(scene_item_usize));
|
|
216
|
+ self.scene_item_menu = None;
|
|
217
|
+ }
|
202
|
218
|
}
|
203
|
219
|
};
|
204
|
220
|
self.scene_item_menu = None;
|
|
@@ -241,16 +257,20 @@ impl MainState {
|
241
|
257
|
// Scene items movements
|
242
|
258
|
for scene_item in self.scene_items.iter_mut() {
|
243
|
259
|
match scene_item.state.current_behavior {
|
244
|
|
- ItemBehavior::WalkingTo(scene_point) => {
|
245
|
|
- // FIXME BS NOW: velocity
|
246
|
|
- let move_vector = (scene_point - scene_item.position).normalize() * 1.0;
|
|
260
|
+ ItemBehavior::Standing => {}
|
|
261
|
+ ItemBehavior::MoveTo(move_to_scene_point)
|
|
262
|
+ | ItemBehavior::MoveFastTo(move_to_scene_point)
|
|
263
|
+ | ItemBehavior::HideTo(move_to_scene_point) => {
|
|
264
|
+ let velocity = velocity_for_behavior(&scene_item.state.current_behavior)
|
|
265
|
+ .expect("must have velocity here");
|
|
266
|
+ let move_vector =
|
|
267
|
+ (move_to_scene_point - scene_item.position).normalize() * velocity;
|
247
|
268
|
// TODO ici il faut calculer le déplacement réél (en fonction des ticks, etc ...)
|
248
|
269
|
scene_item.position.x += move_vector.x;
|
249
|
270
|
scene_item.position.y += move_vector.y;
|
250
|
271
|
scene_item.grid_position =
|
251
|
272
|
util::grid_position_from_scene_point(&scene_item.position);
|
252
|
273
|
}
|
253
|
|
- _ => {}
|
254
|
274
|
}
|
255
|
275
|
}
|
256
|
276
|
|
|
@@ -322,7 +342,7 @@ impl MainState {
|
322
|
342
|
for scene_item in self.scene_items.iter() {
|
323
|
343
|
self.sprite_sheet_batch.add(
|
324
|
344
|
scene_item
|
325
|
|
- .as_draw_param(scene_item.current_frame as f32)
|
|
345
|
+ .as_draw_param(scene_item.current_frame)
|
326
|
346
|
.dest(scene_item.position.clone()),
|
327
|
347
|
);
|
328
|
348
|
}
|
|
@@ -449,7 +469,15 @@ impl MainState {
|
449
|
469
|
) -> GameResult<MeshBuilder> {
|
450
|
470
|
if let Some(scene_item_prepare_order) = &self.scene_item_prepare_order {
|
451
|
471
|
match scene_item_prepare_order {
|
452
|
|
- SceneItemPrepareOrder::Move(scene_item_usize) => {
|
|
472
|
+ SceneItemPrepareOrder::Move(scene_item_usize)
|
|
473
|
+ | SceneItemPrepareOrder::MoveFast(scene_item_usize)
|
|
474
|
+ | SceneItemPrepareOrder::Hide(scene_item_usize) => {
|
|
475
|
+ let color = match &scene_item_prepare_order {
|
|
476
|
+ SceneItemPrepareOrder::Move(_) => graphics::BLUE,
|
|
477
|
+ SceneItemPrepareOrder::MoveFast(_) => graphics::MAGENTA,
|
|
478
|
+ SceneItemPrepareOrder::Hide(_) => graphics::YELLOW,
|
|
479
|
+ };
|
|
480
|
+
|
453
|
481
|
let scene_item = self.get_scene_item(*scene_item_usize);
|
454
|
482
|
mesh_builder.line(
|
455
|
483
|
&vec![
|
|
@@ -460,7 +488,7 @@ impl MainState {
|
460
|
488
|
),
|
461
|
489
|
],
|
462
|
490
|
2.0,
|
463
|
|
- graphics::WHITE,
|
|
491
|
+ color,
|
464
|
492
|
)?;
|
465
|
493
|
}
|
466
|
494
|
}
|