diff --git a/crates/border-wars/src/camera.rs b/crates/border-wars/src/camera.rs index c8d5954..e682469 100644 --- a/crates/border-wars/src/camera.rs +++ b/crates/border-wars/src/camera.rs @@ -19,7 +19,7 @@ const MAX_SCALE: f32 = 5.; /// The keys movement of the camera. #[derive(Resource)] -pub struct KeysMovementSettings{ +pub struct KeysMovementSettings { /// Key to move the camera up. pub up: KeyCode, @@ -40,9 +40,9 @@ pub struct CameraPlugin; impl Plugin for CameraPlugin { fn build(&self, app: &mut App) { app.add_systems(Startup, init_camera) - .add_systems(Startup, init_key_movement) - .add_systems(Update, movement_system.run_if(in_state(CurrentScene::Game))) - .add_systems(Update, scale_system.run_if(in_state(CurrentScene::Game))); + .add_systems(Startup, init_key_movement) + .add_systems(Update, movement_system.run_if(in_state(CurrentScene::Game))) + .add_systems(Update, scale_system.run_if(in_state(CurrentScene::Game))); } } @@ -52,8 +52,8 @@ fn init_camera(mut commands: Commands) { } /// The fonction that initialize the key movement settings. -fn init_key_movement(mut commands: Commands){ - commands.insert_resource(KeysMovementSettings{ +fn init_key_movement(mut commands: Commands) { + commands.insert_resource(KeysMovementSettings { up: KeyCode::Z, down: KeyCode::S, right: KeyCode::D, @@ -62,9 +62,12 @@ fn init_key_movement(mut commands: Commands){ } /// The fonction that move the camera with the keyboard. -fn movement_system(mut query: Query<&mut Transform, With>, keys: Res>, keys_settings: Res) { +fn movement_system( + mut query: Query<&mut Transform, With>, + keys: Res>, + keys_settings: Res, +) { for mut transform in query.iter_mut() { - let mut target = Vec3::ZERO; for key in keys.get_pressed() { match *key { @@ -74,28 +77,27 @@ fn movement_system(mut query: Query<&mut Transform, With>, keys: Res target.x -= CAMERRA_SPEED_MOVEMENT, _ => continue, } - } transform.translation += target; - } + } } /// The fonction that scale the camera with the mouse. -fn scale_system(mut scroll_evr: EventReader, mut query: Query<&mut OrthographicProjection, With>){ +fn scale_system( + mut scroll_evr: EventReader, + mut query: Query<&mut OrthographicProjection, With>, +) { for ev in scroll_evr.read() { for mut projection in query.iter_mut() { - if ev.unit != MouseScrollUnit::Line { return; } let future_scale = ev.y.mul_add(CAMERRA_SPEED_SCALE, projection.scale); - if MIN_SCALE < future_scale && future_scale < MAX_SCALE { - + if MIN_SCALE < future_scale && future_scale < MAX_SCALE { projection.scale = future_scale; } } } } - diff --git a/crates/border-wars/src/lib.rs b/crates/border-wars/src/lib.rs index a7cfaae..a4acdb8 100644 --- a/crates/border-wars/src/lib.rs +++ b/crates/border-wars/src/lib.rs @@ -2,9 +2,9 @@ use bevy::prelude::*; +pub mod camera; pub mod map; pub mod scenes; -pub mod camera; /// The current scene of the game. #[derive(Debug, Clone, Copy, Default, Eq, PartialEq, Hash, States)] diff --git a/crates/border-wars/src/main.rs b/crates/border-wars/src/main.rs index 753f2a3..2d6933e 100644 --- a/crates/border-wars/src/main.rs +++ b/crates/border-wars/src/main.rs @@ -1,7 +1,8 @@ //! The main entry point of the game. use bevy::prelude::*; -use border_wars::{camera::CameraPlugin, scenes::ScenesPlugin}; +use border_wars::camera::CameraPlugin; +use border_wars::scenes::ScenesPlugin; fn main() { App::new() @@ -13,8 +14,8 @@ fn main() { } fn init_shap(mut commands: Commands, assets_server: Res) { - commands.spawn(SpriteBundle{ + commands.spawn(SpriteBundle { texture: assets_server.load("caca.png"), ..Default::default() }); -} \ No newline at end of file +}