-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support visualization of automatic solution process
- Loading branch information
Showing
8 changed files
with
203 additions
and
79 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
use bevy::prelude::*; | ||
use itertools::Itertools; | ||
|
||
use crate::components::*; | ||
use crate::resources::*; | ||
use crate::AppState; | ||
|
||
pub fn spawn_crate_pushable_marks( | ||
mut commands: Commands, | ||
mut auto_crate_push_state: ResMut<AutoCratePushState>, | ||
board: Query<&Board>, | ||
mut next_state: ResMut<NextState<AppState>>, | ||
) { | ||
let crate_position = &auto_crate_push_state.selected_crate; | ||
let Board { board, tile_size } = board.single(); | ||
|
||
let paths = board.level.crate_pushable_paths(crate_position); | ||
|
||
// spawn crate pushable marks | ||
for crate_position in paths.keys().map(|state| state.crate_position).unique() { | ||
commands.spawn(( | ||
SpriteBundle { | ||
sprite: Sprite { | ||
color: Color::GREEN.with_a(0.8), | ||
custom_size: Some(Vec2::new(tile_size.x / 4.0, tile_size.y / 4.0)), | ||
..default() | ||
}, | ||
transform: Transform::from_xyz( | ||
crate_position.x as f32 * tile_size.x, | ||
(board.level.dimensions.y - crate_position.y) as f32 * tile_size.y, | ||
10.0, | ||
), | ||
..default() | ||
}, | ||
CratePushableMark, | ||
)); | ||
} | ||
|
||
if paths.is_empty() { | ||
next_state.set(AppState::Main); | ||
return; | ||
} | ||
|
||
auto_crate_push_state.paths = paths; | ||
} | ||
|
||
pub fn despawn_crate_pushable_marks( | ||
mut commands: Commands, | ||
marks: Query<Entity, With<CratePushableMark>>, | ||
) { | ||
marks.for_each(|entity| commands.entity(entity).despawn()); | ||
} |
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.