mirror of
https://github.com/Xevion/Pac-Man.git
synced 2025-12-09 02:07:56 -06:00
feat: begin tracking nodes of entity starting positions
This commit is contained in:
@@ -11,6 +11,14 @@ use sdl2::render::{Canvas, RenderTarget};
|
|||||||
use std::collections::{HashMap, VecDeque};
|
use std::collections::{HashMap, VecDeque};
|
||||||
use tracing::debug;
|
use tracing::debug;
|
||||||
|
|
||||||
|
pub struct NodePositions {
|
||||||
|
pub pacman: NodeId,
|
||||||
|
pub blinky: NodeId,
|
||||||
|
pub pinky: NodeId,
|
||||||
|
pub inky: NodeId,
|
||||||
|
pub clyde: NodeId,
|
||||||
|
}
|
||||||
|
|
||||||
/// The game map, responsible for holding the tile-based layout and the navigation graph.
|
/// The game map, responsible for holding the tile-based layout and the navigation graph.
|
||||||
///
|
///
|
||||||
/// The map is represented as a 2D array of `MapTile`s. It also stores a navigation
|
/// The map is represented as a 2D array of `MapTile`s. It also stores a navigation
|
||||||
@@ -23,6 +31,8 @@ pub struct Map {
|
|||||||
pub graph: Graph,
|
pub graph: Graph,
|
||||||
/// A mapping from grid positions to node IDs.
|
/// A mapping from grid positions to node IDs.
|
||||||
pub grid_to_node: HashMap<IVec2, NodeId>,
|
pub grid_to_node: HashMap<IVec2, NodeId>,
|
||||||
|
/// A mapping of the starting positions of the entities.
|
||||||
|
pub start_positions: NodePositions,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Map {
|
impl Map {
|
||||||
@@ -141,8 +151,17 @@ impl Map {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Build house structure
|
// Build house structure
|
||||||
|
let (house_entrance_node_id, left_center_node_id, center_center_node_id, right_center_node_id) =
|
||||||
Self::build_house(&mut graph, &grid_to_node, &house_door);
|
Self::build_house(&mut graph, &grid_to_node, &house_door);
|
||||||
|
|
||||||
|
let start_positions = NodePositions {
|
||||||
|
pacman: grid_to_node[&start_pos],
|
||||||
|
blinky: house_entrance_node_id,
|
||||||
|
pinky: left_center_node_id,
|
||||||
|
inky: right_center_node_id,
|
||||||
|
clyde: center_center_node_id,
|
||||||
|
};
|
||||||
|
|
||||||
// Build tunnel connections
|
// Build tunnel connections
|
||||||
Self::build_tunnels(&mut graph, &grid_to_node, &tunnel_ends);
|
Self::build_tunnels(&mut graph, &grid_to_node, &tunnel_ends);
|
||||||
|
|
||||||
@@ -150,6 +169,7 @@ impl Map {
|
|||||||
current: map,
|
current: map,
|
||||||
grid_to_node,
|
grid_to_node,
|
||||||
graph,
|
graph,
|
||||||
|
start_positions,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -193,7 +213,11 @@ impl Map {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Builds the house structure in the graph.
|
/// Builds the house structure in the graph.
|
||||||
fn build_house(graph: &mut Graph, grid_to_node: &HashMap<IVec2, NodeId>, house_door: &[Option<IVec2>; 2]) {
|
fn build_house(
|
||||||
|
graph: &mut Graph,
|
||||||
|
grid_to_node: &HashMap<IVec2, NodeId>,
|
||||||
|
house_door: &[Option<IVec2>; 2],
|
||||||
|
) -> (usize, usize, usize, usize) {
|
||||||
// Calculate the position of the house entrance node
|
// Calculate the position of the house entrance node
|
||||||
let (house_entrance_node_id, house_entrance_node_position) = {
|
let (house_entrance_node_id, house_entrance_node_position) = {
|
||||||
// Translate the grid positions to the actual node ids
|
// Translate the grid positions to the actual node ids
|
||||||
@@ -283,6 +307,13 @@ impl Map {
|
|||||||
.expect("Failed to connect house entrance to right top line");
|
.expect("Failed to connect house entrance to right top line");
|
||||||
|
|
||||||
debug!("House entrance node id: {house_entrance_node_id}");
|
debug!("House entrance node id: {house_entrance_node_id}");
|
||||||
|
|
||||||
|
(
|
||||||
|
house_entrance_node_id,
|
||||||
|
left_center_node_id,
|
||||||
|
center_center_node_id,
|
||||||
|
right_center_node_id,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Builds the tunnel connections in the graph.
|
/// Builds the tunnel connections in the graph.
|
||||||
|
|||||||
Reference in New Issue
Block a user