refactor to plugin

This commit is contained in:
Christian Nieves
2024-12-08 02:34:26 -06:00
parent 9dda1a1a50
commit dc7e53c58d

View File

@ -30,6 +30,9 @@ impl Size {
}
}
#[derive(Resource)]
struct MovementTimer(Timer);
fn snake_movement_system(
input: Res<ButtonInput<KeyCode>>,
@ -100,8 +103,21 @@ fn setup_camera(mut commands: Commands) {
commands.spawn((Camera2d {},));
}
pub struct SnakePlugin;
impl Plugin for SnakePlugin {
fn build(&self, app: &mut App) {
app.add_systems(Startup, (setup_camera, setup_player));
app.add_systems(Update, snake_movement_system);
app.add_systems(PostUpdate, (scale_translation, position_translation));
app.insert_resource(MovementTimer(Timer::from_seconds(
1.0,
TimerMode::Repeating,
)));
}
}
fn main() {
let systems = snake_movement_system;
App::new()
.add_plugins(
DefaultPlugins.set(WindowPlugin {
@ -118,8 +134,6 @@ fn main() {
}),
)
.add_plugins(WorldInspectorPlugin::new())
.add_systems(Startup, (setup_camera, setup_player))
.add_systems(Update, systems)
.add_systems(PostUpdate, (scale_translation, position_translation))
.add_plugins(SnakePlugin)
.run();
}