mirror of
https://github.com/Xevion/Pac-Man.git
synced 2025-12-14 18:12:28 -06:00
fix: allow key holddown
This commit is contained in:
@@ -18,9 +18,9 @@ use crate::{
|
||||
pub fn ghost_movement_system(
|
||||
map: Res<Map>,
|
||||
delta_time: Res<DeltaTime>,
|
||||
mut ghosts: Query<(&mut Ghost, &mut Velocity, &mut Position)>,
|
||||
mut ghosts: Query<(&Ghost, &mut Velocity, &mut Position)>,
|
||||
) {
|
||||
for (mut ghost, mut velocity, mut position) in ghosts.iter_mut() {
|
||||
for (_ghost, mut velocity, mut position) in ghosts.iter_mut() {
|
||||
let mut distance = velocity.speed * 60.0 * delta_time.0;
|
||||
loop {
|
||||
match *position {
|
||||
@@ -32,10 +32,10 @@ pub fn ghost_movement_system(
|
||||
|
||||
// Collect all available directions that ghosts can traverse
|
||||
for edge in Direction::DIRECTIONS.iter().flat_map(|d| intersection.get(*d)) {
|
||||
if edge.traversal_flags.contains(crate::entity::graph::TraversalFlags::GHOST) {
|
||||
if edge.direction != opposite {
|
||||
non_opposite_options.push(edge);
|
||||
}
|
||||
if edge.traversal_flags.contains(crate::entity::graph::TraversalFlags::GHOST)
|
||||
&& edge.direction != opposite
|
||||
{
|
||||
non_opposite_options.push(edge);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,39 +67,3 @@ pub fn ghost_movement_system(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Chooses a random available direction for a ghost at an intersection.
|
||||
///
|
||||
/// This function mirrors the behavior from the old ghost implementation,
|
||||
/// preferring not to reverse direction unless it's the only option.
|
||||
fn choose_random_direction(map: &Map, velocity: &mut Velocity, position: &Position) {
|
||||
let current_node = position.current_node();
|
||||
let intersection = &map.graph.adjacency_list[current_node];
|
||||
|
||||
// Collect all available directions that ghosts can traverse
|
||||
let mut available_directions = SmallVec::<[Direction; 4]>::new();
|
||||
for direction in Direction::DIRECTIONS {
|
||||
if let Some(edge) = intersection.get(direction) {
|
||||
// Check if ghosts can traverse this edge
|
||||
if edge.traversal_flags.contains(crate::entity::graph::TraversalFlags::GHOST) {
|
||||
available_directions.push(direction);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Choose a random direction (avoid reversing unless necessary)
|
||||
if !available_directions.is_empty() {
|
||||
let mut rng = SmallRng::from_os_rng();
|
||||
|
||||
// Filter out the opposite direction if possible, but allow it if we have limited options
|
||||
let opposite = velocity.direction.opposite();
|
||||
let filtered_directions: Vec<_> = available_directions
|
||||
.iter()
|
||||
.filter(|&&dir| dir != opposite || available_directions.len() <= 2)
|
||||
.collect();
|
||||
|
||||
if let Some(&random_direction) = filtered_directions.choose(&mut rng) {
|
||||
velocity.direction = *random_direction;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user