Skip to content

Commit

Permalink
Merge branch 'add_snake'
Browse files Browse the repository at this point in the history
  • Loading branch information
Ablesius committed Apr 2, 2024
2 parents fbb93da + b3ae8bd commit 3dcb092
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,43 @@ fn main() {
// but behaves otherwise; see
// https://github.com/bevyengine/bevy/issues/11734
.add_systems(Startup, setup_camera)
.add_systems(Startup, spawn_snake)
// needs to be in Update; if we leave it in
// Startup, it'll only be executed once. Makes sense!
.add_systems(Update, move_snake)
.add_plugins(DefaultPlugins)
.run();
}

fn setup_camera(mut commands: Commands) {
commands.spawn(Camera2dBundle::default());
}

#[derive(Component)]
struct SnakeHead;

const SNAKE_HEAD_COLOUR: Color = Color::rgb(102.0, 0.0, 204.0);

fn spawn_snake(mut commands: Commands) {
commands
.spawn(SpriteBundle {
sprite: Sprite {
color: SNAKE_HEAD_COLOUR,
..default()
},
transform: Transform {
scale: Vec3::new(10.0, 10.0, 10.0),
..default()
},
..default()
})
.insert(SnakeHead);
}

fn move_snake(mut head_positions: Query<(&SnakeHead, &mut Transform)>) {
for (_head, mut transform) in head_positions.iter_mut() {
// for now just move the head 2 upwards
// as we don't have user input yet
transform.translation.y += 2.0;
}
}

0 comments on commit 3dcb092

Please sign in to comment.