MCPcopy Create free account
hub / github.com/17cupsofcoffee/rl / process_movement

Function process_movement

src/systems.rs:52–76  ·  view source on GitHub ↗
(world: &mut World, resources: &mut Resources)

Source from the content-addressed store, hash-verified

50}
51
52pub fn process_movement(world: &mut World, resources: &mut Resources) {
53 for (_, (movement, position)) in world.query::<(&mut Movement, &mut Position)>().iter() {
54 let (target_x, target_y) = match movement.move_queue.pop_front() {
55 Some(MoveAction::Up) => (position.x, position.y - 1),
56 Some(MoveAction::Down) => (position.x, position.y + 1),
57 Some(MoveAction::Left) => (position.x - 1, position.y),
58 Some(MoveAction::Right) => (position.x + 1, position.y),
59 _ => continue,
60 };
61
62 if let Some(tile) = resources.map.get(target_x, target_y) {
63 if tile.solid {
64 continue;
65 }
66 }
67
68 position.x = target_x;
69 position.y = target_y;
70 movement.energy = 0;
71
72 if movement.player_input {
73 resources.turn_state.waiting = false;
74 }
75 }
76}

Callers 1

updateMethod · 0.85

Calls 1

getMethod · 0.80

Tested by

no test coverage detected