How do you make map for game (pacman) in bevy #7065
Unanswered
Abubakar1122331
asked this question in
Q&A
Replies: 1 comment 20 replies
-
You will need to spawn the sprites making up the map with different const GRID_SIZE: f32 = 30.;
pub fn create_simple_map(mut commands: Commands, asset_server: ResMut<AssetServer>) {
let file = File::open("assets/map.txt").expect("No map file found");
for (row, line) in BufReader::new(file).lines().flatten().enumerate() {
for (col, char) in line.chars().enumerate() {
if char == '#' {
commands.spawn(SpriteBundle {
texture: asset_server.load("dot.png"),
transform: Transform {
translation: Vec3::new(col as f32 * GRID_SIZE, row as f32 * GRID_SIZE, 0.),
scale: Vec3::new(1.0, 1.0, 1.0),
..default()
},
..default()
});
}
}
}
} |
Beta Was this translation helpful? Give feedback.
20 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi! There,
Im Trying to make pacman clone.
Here is my txt file that im trying to use
map.txt.
`pub fn create_simple_map(mut commands: Commands, asset_server: Res) {
let file = File::open("assets/map.txt").expect("No map file found");
}`
But when i start the game it's like this.

Look at the center of image.
there is the whole map. (if you can see it!)
Beta Was this translation helpful? Give feedback.
All reactions