-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
362 additions
and
77 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
|
||
|
||
|
||
|
||
|
||
⬜⬜⬜⬜⬜⬜🙂 | ||
⬜⬜⬜⬜⬜🟩🟩🟩🟩🟩🟩🟩🟩🟩 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,94 @@ | ||
# Displaying the Level | ||
|
||
```rust | ||
# extern crate bevy; | ||
# use bevy::prelude::*; | ||
# #[derive(Asset, TypePath)] | ||
# struct Level {pub tiles: Vec<Vec<Tile>>} | ||
# enum Tile {Empty, Ground, Start} | ||
# #[derive(Resource)] | ||
# struct GameAssets { | ||
# player_image: Handle<Image>, | ||
# player_layout: Handle<TextureAtlasLayout>, | ||
# ground_image: Handle<Image>, | ||
# ground_layout: Handle<TextureAtlasLayout>, | ||
# } | ||
# #[derive(Resource)] | ||
# pub struct LoadedLevel { pub level: Handle<Level> } | ||
# #[derive(Component)] | ||
# struct Player; | ||
# #[derive(Component)] | ||
# struct Ground; | ||
# #[derive(Debug, Clone, Copy, Eq, PartialEq, Hash, States, Default)] | ||
# enum GameState { #[default] Game } | ||
fn ground_tile_index(line: &[Tile], i: usize) -> usize { | ||
match ( | ||
i == 0 || !matches!(line.get(i - 1).unwrap_or(&Tile::Empty), Tile::Ground), | ||
!matches!(line.get(i + 1).unwrap_or(&Tile::Empty), Tile::Ground), | ||
) { | ||
(true, true) => 8, | ||
(true, false) => 14, | ||
(false, true) => 0, | ||
(false, false) => 7, | ||
} | ||
} | ||
|
||
fn display_tile( | ||
commands: &mut Commands, | ||
tile: &Tile, | ||
i: usize, | ||
x: f32, | ||
y: f32, | ||
line: &[Tile], | ||
assets: &GameAssets, | ||
) { | ||
match tile { | ||
Tile::Ground => { | ||
let index = ground_tile_index(line, i); | ||
commands.spawn(( | ||
Sprite::from_atlas_image( | ||
assets.ground_image.clone(), | ||
TextureAtlas { | ||
layout: assets.ground_layout.clone(), | ||
index, | ||
}, | ||
), | ||
Transform::from_xyz(x, y, 0.0).with_scale(Vec3::splat(0.5)), | ||
Ground, | ||
StateScoped(GameState::Game), | ||
)); | ||
} | ||
Tile::Start => { | ||
commands.spawn(( | ||
Sprite::from_atlas_image( | ||
assets.player_image.clone(), | ||
TextureAtlas { | ||
layout: assets.player_layout.clone(), | ||
index: 0, | ||
}, | ||
), | ||
Transform::from_xyz(x, y + 32.0, 0.0).with_scale(Vec3::splat(0.5)), | ||
StateScoped(GameState::Game), | ||
Player, | ||
)); | ||
} | ||
Tile::Empty => {} | ||
} | ||
} | ||
|
||
fn display_level( | ||
mut commands: Commands, | ||
assets: Res<GameAssets>, | ||
level: Res<LoadedLevel>, | ||
levels: Res<Assets<Level>>, | ||
) { | ||
let level = levels.get(&level.level).unwrap(); | ||
|
||
for (j, line) in level.tiles.iter().enumerate() { | ||
for (i, tile) in line.iter().enumerate() { | ||
let (x, y) = ((i as f32 - 9.0) * 64.0, -(j as f32 - 5.0) * 64.0); | ||
display_tile(&mut commands, tile, i, x, y, line, &assets); | ||
} | ||
} | ||
} | ||
``` |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.