refactor to plugin
This commit is contained in:
@ -30,6 +30,9 @@ impl Size {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Resource)]
|
||||||
|
struct MovementTimer(Timer);
|
||||||
|
|
||||||
fn snake_movement_system(
|
fn snake_movement_system(
|
||||||
input: Res<ButtonInput<KeyCode>>,
|
input: Res<ButtonInput<KeyCode>>,
|
||||||
|
|
||||||
@ -100,8 +103,21 @@ fn setup_camera(mut commands: Commands) {
|
|||||||
commands.spawn((Camera2d {},));
|
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() {
|
fn main() {
|
||||||
let systems = snake_movement_system;
|
|
||||||
App::new()
|
App::new()
|
||||||
.add_plugins(
|
.add_plugins(
|
||||||
DefaultPlugins.set(WindowPlugin {
|
DefaultPlugins.set(WindowPlugin {
|
||||||
@ -118,8 +134,6 @@ fn main() {
|
|||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
.add_plugins(WorldInspectorPlugin::new())
|
.add_plugins(WorldInspectorPlugin::new())
|
||||||
.add_systems(Startup, (setup_camera, setup_player))
|
.add_plugins(SnakePlugin)
|
||||||
.add_systems(Update, systems)
|
|
||||||
.add_systems(PostUpdate, (scale_translation, position_translation))
|
|
||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user