Make use of bundle in snake

This commit is contained in:
2022-12-19 21:38:40 +01:00
parent def2337f0e
commit c771e5f95e

View File

@@ -75,8 +75,16 @@ struct Segments(Vec<Entity>);
#[derive(Component, Debug)]
struct Snake;
// #[derive(Bundle)]
// struct SnakeBundle;
#[derive(Bundle)]
struct SnakeBundle {
snake: Snake,
direction_buffer: DirectionBuffer,
collision: Collision,
segments: Segments,
#[bundle]
spatial_bundle: SpatialBundle,
}
#[derive(Component, Copy, Clone, Debug)]
enum Direction {
@@ -135,14 +143,14 @@ fn setup_snake_system(mut commands: Commands) {
.insert(SnakeHead);
commands
.spawn((
Snake,
Name::new("Snake"),
SpatialBundle::default(),
DirectionBuffer::default(),
Collision::default(),
Segments(vec![snake_head]),
))
.spawn(SnakeBundle {
snake: Snake,
direction_buffer: Default::default(),
collision: Default::default(),
segments: Segments(vec![snake_head]),
spatial_bundle: Default::default(),
})
.insert(Name::new("Snake"))
.add_child(snake_head);
}