Skip to content

Commit fed7272

Browse files
author
Carter Hollman
committed
fix: formatting issues
1 parent 78d1f9f commit fed7272

File tree

4 files changed

+45
-59
lines changed

4 files changed

+45
-59
lines changed

game/src/camera.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
pub mod camera_plugin;
1+
pub mod camera_plugin;

game/src/camera/camera_plugin.rs

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10,45 +10,38 @@ pub struct CameraTarget;
1010
#[derive(Component)]
1111
pub struct MainCamera;
1212

13-
impl Plugin for CameraPlugin{
14-
fn build(&self, app: &mut App){
13+
impl Plugin for CameraPlugin {
14+
fn build(&self, app: &mut App) {
1515
app.add_systems(Startup, setup_main_camera);
1616
app.add_systems(Update, (update_camera, zoom_camera).chain());
1717
}
1818
}
1919

20-
21-
//Sets up a 2d camera and attaches the MainCamera marker to it
22-
fn setup_main_camera(
23-
mut commands: Commands
24-
) {
25-
commands.spawn((
26-
Camera2dBundle::default(),
27-
MainCamera
28-
));
20+
//Sets up a 2d camera and attaches the MainCamera marker to it
21+
fn setup_main_camera(mut commands: Commands) {
22+
commands.spawn((Camera2dBundle::default(), MainCamera));
2923
}
3024

31-
3225
//Update camera function will have our main camera follow any entity with the CameraTarget tag
3326
fn update_camera(
34-
mut camera_query : Query<&mut Transform, (With<MainCamera>, Without<CameraTarget>)>,
27+
mut camera_query: Query<&mut Transform, (With<MainCamera>, Without<CameraTarget>)>,
3528
target_query: Query<&Transform, (With<CameraTarget>, Without<MainCamera>)>,
36-
){
29+
) {
3730
//getting camera from query
38-
let Ok(mut camera) = camera_query.get_single_mut() else{
31+
let Ok(mut camera) = camera_query.get_single_mut() else {
3932
return;
4033
};
4134

4235
//getting target from query
43-
let Ok(target) = target_query.get_single() else{
36+
let Ok(target) = target_query.get_single() else {
4437
return;
4538
};
4639

4740
//Gets the x and y coordinates of our target
48-
let Vec3 {x,y,..} = target.translation;
41+
let Vec3 { x, y, .. } = target.translation;
4942

5043
//Stores the target x y with our camera z cuz our camera z not changing
51-
let direction = Vec3::new(x,y,camera.translation.z);
44+
let direction = Vec3::new(x, y, camera.translation.z);
5245

5346
//Debug statements if we want to use them :)
5447
//info!("Camera: {:?}", camera);
@@ -60,31 +53,28 @@ fn update_camera(
6053

6154
//Camera Zooming Function, uses MouseWheel Scrolling up/down for zooming in/out
6255
fn zoom_camera(
63-
mut scroll_event : EventReader<MouseWheel>,
64-
mut camera: Query<&mut OrthographicProjection, With<MainCamera>>
65-
){
66-
67-
56+
mut scroll_event: EventReader<MouseWheel>,
57+
mut camera: Query<&mut OrthographicProjection, With<MainCamera>>,
58+
) {
6859
//Zoom Sensitivity
6960
let zoom_factor = 0.1;
7061

7162
//Amount to zoom in this update cycle
7263
let mut zoom_amount = 0.0;
7364

74-
7565
//For every event read in this cycle increase the zoom amount by 1 event * sensitivity
76-
for event in scroll_event.read(){
66+
for event in scroll_event.read() {
7767
zoom_amount += -event.y * zoom_factor
7868
}
7969

8070
//If we have had any mouse scroll events in this update then apply it to the camera projection
81-
if zoom_amount != 0.0{
71+
if zoom_amount != 0.0 {
8272
//extracting the type of projection from camera, only ever going to be Orthographic since 2d but I don't know a better way lol
83-
for mut projection in camera.iter_mut(){
73+
for mut projection in camera.iter_mut() {
8474
projection.scale += zoom_amount;
8575

86-
//This statement makes sure that the amount of zoom is capped, can change if need be
87-
projection.scale = projection.scale.clamp(0.1,5.0);
76+
//This statement makes sure that the amount of zoom is capped, can change if need be
77+
projection.scale = projection.scale.clamp(0.1, 5.0);
8878
}
8979
}
9080
}

game/src/debug/debug_plugin.rs

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
use bevy::prelude::*;
2-
use avian2d::prelude::*;
31
use avian2d::math::*;
2+
use avian2d::prelude::*;
3+
use bevy::prelude::*;
44

5-
use crate::movement::plugin::*;
65
use crate::camera::camera_plugin::*;
6+
use crate::movement::plugin::*;
77

88
///This plugin provides terminal debug capabilities
99
///By adding systems, requested information will be printed to the terminal
@@ -23,26 +23,24 @@ fn print_debug_active_message() {
2323
info!("The debugger is active!");
2424
}
2525

26+
//Displays two pixel like sprites where one is stationary, then the other that has the CameraTarget component
27+
//falls forever. Used to test camera system tracking and zooming.
28+
fn display_dudes(mut commands: Commands) {
29+
commands
30+
.spawn((
31+
SpriteBundle::default(),
32+
CharacterControllerBundle::new(Collider::capsule(12.5, 20.0)).with_movement(
33+
1250.0,
34+
0.92,
35+
400.0,
36+
(30.0 as Scalar).to_radians(),
37+
),
38+
Friction::ZERO.with_combine_rule(CoefficientCombine::Min),
39+
Restitution::ZERO.with_combine_rule(CoefficientCombine::Min),
40+
ColliderDensity(2.0),
41+
GravityScale(1.5),
42+
))
43+
.insert(CameraTarget);
2644

27-
//Displays two pixel like sprites where one is stationary, then the other that has the CameraTarget component
28-
//falls forever. Used to test camera system tracking and zooming.
29-
fn display_dudes(mut commands : Commands){
30-
commands.spawn((
31-
SpriteBundle::default(),
32-
33-
CharacterControllerBundle::new(Collider::capsule(12.5, 20.0)).with_movement(
34-
1250.0,
35-
0.92,
36-
400.0,
37-
(30.0 as Scalar).to_radians(),
38-
),
39-
Friction::ZERO.with_combine_rule(CoefficientCombine::Min),
40-
Restitution::ZERO.with_combine_rule(CoefficientCombine::Min),
41-
ColliderDensity(2.0),
42-
GravityScale(1.5),
43-
)).insert(CameraTarget);
44-
45-
commands.spawn(
46-
SpriteBundle::default()
47-
);
48-
}
45+
commands.spawn(SpriteBundle::default());
46+
}

game/src/main.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1+
mod camera;
12
mod debug;
23
mod movement;
3-
mod camera;
44

55
use avian2d::prelude::*;
66
use bevy::prelude::*;
77
use bevy_ecs_ldtk::prelude::*;
8+
use camera::camera_plugin::CameraPlugin;
89
use debug::debug_plugin::DebugPlugin;
910
use movement::plugin::CharacterControllerPlugin;
10-
use camera::camera_plugin::CameraPlugin;
11-
1211

1312
fn main() {
1413
App::new()
@@ -21,4 +20,3 @@ fn main() {
2120
.add_plugins(CameraPlugin)
2221
.run();
2322
}
24-

0 commit comments

Comments
 (0)