Skip to content

Commit

Permalink
cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
rewin123 committed Dec 8, 2023
1 parent 86fcae6 commit 7890afa
Show file tree
Hide file tree
Showing 13 changed files with 244 additions and 198 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ dev = [
"bevy/dynamic_linking",
"dep:bevy-inspector-egui"
]
default = ["dev"]

# All of Bevy's default features exept for the audio related ones (bevy_audio, vorbis), since they clash with bevy_kira_audio
# and android_shared_stdcxx, since that is covered in `mobile`
Expand Down
12 changes: 9 additions & 3 deletions src/debug_diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ impl Plugin for DiagnosticPlugin {
)
.chain(),
)
.add_systems(Update, (fps_counting, sheep_counter_text).in_set(GameSet::Playing));
.add_systems(
Update,
(fps_counting, sheep_counter_text).in_set(GameSet::Playing),
);

#[cfg(debug_assertions)]
{
Expand Down Expand Up @@ -95,9 +98,12 @@ pub fn setup_sheep_counter(mut commands: Commands, panels: Query<Entity, With<Di
pub fn sheep_counter_text(
mut query: Query<&mut Text, With<ShipDebugCounter>>,
sheep_counter: Res<SheepCounter>,
start_sheep_count: Res<StartSheepCount>
start_sheep_count: Res<StartSheepCount>,
) {
for mut text in &mut query {
text.sections[0].value = format!("Sheep in safe area: {}/{}", sheep_counter.count, start_sheep_count.0);
text.sections[0].value = format!(
"Sheep in safe area: {}/{}",
sheep_counter.count, start_sheep_count.0
);
}
}
23 changes: 11 additions & 12 deletions src/finish_screen.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use bevy::prelude::*;

use crate::{GameState, storyteller::{Score, FailReason}, GameSet};
use crate::{
storyteller::{FailReason, Score},
GameSet, GameState,
};

pub struct FinishScreenPlugin;

Expand All @@ -16,11 +19,7 @@ impl Plugin for FinishScreenPlugin {
#[derive(Component)]
struct FinishScreen;

fn setup_finish_screen(
mut commands: Commands,
score : Res<Score>,
fail : Option<Res<FailReason>>
) {
fn setup_finish_screen(mut commands: Commands, score: Res<Score>, fail: Option<Res<FailReason>>) {
let mut text_style = TextStyle::default();
text_style.font_size = 24.0;

Expand Down Expand Up @@ -71,18 +70,18 @@ fn setup_finish_screen(
});
}

fn cleanup_finish_screen(
mut commands: Commands,
query: Query<Entity, With<FinishScreen>>
) {
fn cleanup_finish_screen(mut commands: Commands, query: Query<Entity, With<FinishScreen>>) {
for entity in query.iter() {
commands.entity(entity).despawn_recursive();
}
}

fn finish_screen_system(
mut next_state: ResMut<NextState<GameState>>,
mut interaction_query: Query<(&Interaction, &mut BackgroundColor), (Changed<Interaction>, With<Button>)>,
mut interaction_query: Query<
(&Interaction, &mut BackgroundColor),
(Changed<Interaction>, With<Button>),
>,
) {
for (interaction, mut color) in interaction_query.iter_mut() {
match *interaction {
Expand All @@ -97,4 +96,4 @@ fn finish_screen_system(
}
}
}
}
}
2 changes: 1 addition & 1 deletion src/level_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ fn create_level_ui_system(
..default()
},
LevelUi,
GameStuff
GameStuff,
))
.with_children(|parent| {
parent.spawn((
Expand Down
53 changes: 32 additions & 21 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

pub mod common_storage;
pub mod debug_diagnostic;
pub mod finish_screen;
pub mod level_ui;
pub mod menu;
pub mod physics;
pub mod player;
pub mod safe_area;
Expand All @@ -12,15 +14,13 @@ pub mod storyteller;
pub mod test_level;
pub mod torch;
pub mod wolf;
pub mod menu;
pub mod finish_screen;

use std::f32::consts::PI;

use bevy::{app::App, core_pipeline::clear_color::ClearColorConfig};
#[cfg(debug_assertions)]
use bevy::diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin};
use bevy::prelude::*;
use bevy::{app::App, core_pipeline::clear_color::ClearColorConfig};

// This example game uses States to separate logic
// See https://bevy-cheatbook.github.io/programming/states.html
Expand Down Expand Up @@ -54,15 +54,30 @@ impl Plugin for GamePlugin {
app.add_state::<GameState>();

//Terrible set configuration
app.configure_sets(Update, GameSet::Loading.run_if(in_state(GameState::Loading)));
app.configure_sets(
Update,
GameSet::Loading.run_if(in_state(GameState::Loading)),
);
app.configure_sets(Update, GameSet::Menu.run_if(in_state(GameState::Menu)));
app.configure_sets(Update, GameSet::Playing.run_if(in_state(GameState::Playing)));
app.configure_sets(
Update,
GameSet::Playing.run_if(in_state(GameState::Playing)),
);
app.configure_sets(Update, GameSet::Finish.run_if(in_state(GameState::Finish)));

app.configure_sets(FixedUpdate, GameSet::Loading.run_if(in_state(GameState::Loading)));
app.configure_sets(
FixedUpdate,
GameSet::Loading.run_if(in_state(GameState::Loading)),
);
app.configure_sets(FixedUpdate, GameSet::Menu.run_if(in_state(GameState::Menu)));
app.configure_sets(FixedUpdate, GameSet::Playing.run_if(in_state(GameState::Playing)));
app.configure_sets(FixedUpdate, GameSet::Finish.run_if(in_state(GameState::Finish)));
app.configure_sets(
FixedUpdate,
GameSet::Playing.run_if(in_state(GameState::Playing)),
);
app.configure_sets(
FixedUpdate,
GameSet::Finish.run_if(in_state(GameState::Finish)),
);

#[cfg(debug_assertions)]
{
Expand All @@ -83,13 +98,16 @@ impl Plugin for GamePlugin {
level_ui::LevelUiPlugin,
wolf::WolfPlugin,
menu::MenuPlugin,
finish_screen::FinishScreenPlugin
finish_screen::FinishScreenPlugin,
));

//For long term updates
app.insert_resource(Time::<Fixed>::from_seconds(1.0));

app.add_systems(OnEnter(GameState::Playing), (test_level::setup, sheep::setup));
app.add_systems(
OnEnter(GameState::Playing),
(test_level::setup, sheep::setup),
);

app.add_systems(Startup, (loading, camera_setup));

Expand All @@ -101,15 +119,11 @@ pub fn get_sprite_rotation() -> Quat {
Quat::from_euler(EulerRot::XYZ, -PI / 2.0 - PI / 4.0, 0.0, 0.0)
}

fn loading(
mut next_state : ResMut<NextState<GameState>>
) {
fn loading(mut next_state: ResMut<NextState<GameState>>) {
next_state.set(GameState::Menu);
}

fn camera_setup(
mut commands : Commands,
) {
fn camera_setup(mut commands: Commands) {
commands.spawn(Camera3dBundle {
transform: Transform::from_xyz(0.0, 30.0, 30.0).looking_at(Vec3::ZERO, Vec3::Y),
camera: Camera {
Expand All @@ -127,11 +141,8 @@ fn camera_setup(
#[derive(Component)]
pub struct GameStuff;

fn clear_game_stuff(
mut commands : Commands,
game_stuff : Query<Entity, With<GameStuff>>,
) {
fn clear_game_stuff(mut commands: Commands, game_stuff: Query<Entity, With<GameStuff>>) {
for entity in game_stuff.iter() {
commands.entity(entity).despawn_recursive();
}
}
}
90 changes: 44 additions & 46 deletions src/menu.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use bevy::prelude::*;

use crate::{GameState, GameSet};
use crate::{GameSet, GameState};

pub struct MenuPlugin;

Expand All @@ -15,71 +15,69 @@ impl Plugin for MenuPlugin {
#[derive(Component)]
pub struct MainMenu;

fn setup_main_menu(
mut commands: Commands,
) {
fn setup_main_menu(mut commands: Commands) {
let mut text_style = TextStyle::default();
text_style.font_size = 24.0;
commands.spawn((
MainMenu,
NodeBundle {
style: Style {
width: Val::Percent(100.),
height: Val::Percent(100.),
justify_content: JustifyContent::Center,
align_items: AlignItems::Center,
flex_direction: FlexDirection::Column,
commands
.spawn((
MainMenu,
NodeBundle {
style: Style {
width: Val::Percent(100.),
height: Val::Percent(100.),
justify_content: JustifyContent::Center,
align_items: AlignItems::Center,
flex_direction: FlexDirection::Column,
..default()
},
..default()
},
..default()
}
)).with_children(|parent| {

parent.spawn(TextBundle::from_section(
"You are a shepherd dog servant of a vampire shepherd. \n
))
.with_children(|parent| {
parent.spawn(TextBundle::from_section(
"You are a shepherd dog servant of a vampire shepherd. \n
Don't let the sheep flock run away and be eaten by wolves, and fulfill the vampire's tasks. \n
If you fail, you will be replaced. \n
Good luck!\n",
TextStyle::default()
));

parent.spawn(ButtonBundle {
style: Style {
width: Val::Px(100.0),
height: Val::Px(50.0),
border: UiRect::all(Val::Px(5.0)),
justify_content: JustifyContent::Center,
align_items: AlignItems::Center,
..default()
},
border_color: BorderColor(Color::WHITE),
background_color: BackgroundColor(Color::BLACK),
..default()
}).with_children(|parent| {
parent.spawn(TextBundle::from_section(
"Start",
text_style.clone()
TextStyle::default(),
));

parent
.spawn(ButtonBundle {
style: Style {
width: Val::Px(100.0),
height: Val::Px(50.0),
border: UiRect::all(Val::Px(5.0)),
justify_content: JustifyContent::Center,
align_items: AlignItems::Center,
..default()
},
border_color: BorderColor(Color::WHITE),
background_color: BackgroundColor(Color::BLACK),
..default()
})
.with_children(|parent| {
parent.spawn(TextBundle::from_section("Start", text_style.clone()));
});
});
});
}

fn clear_menu(
mut commands: Commands,
query: Query<Entity, With<MainMenu>>,
) {
fn clear_menu(mut commands: Commands, query: Query<Entity, With<MainMenu>>) {
for entity in query.iter() {
commands.entity(entity).despawn_recursive();
}
}

fn button_system(
mut next_state: ResMut<NextState<GameState>>,
mut interaction_query: Query<(&Interaction, &mut BackgroundColor), (Changed<Interaction>, With<Button>)>,
mut interaction_query: Query<
(&Interaction, &mut BackgroundColor),
(Changed<Interaction>, With<Button>),
>,
) {
for (interaction, mut color) in &mut interaction_query {
match *interaction {
Interaction::Pressed => {
Interaction::Pressed => {
next_state.set(GameState::Playing);
}
Interaction::Hovered => {
Expand All @@ -90,4 +88,4 @@ fn button_system(
}
}
}
}
}
7 changes: 6 additions & 1 deletion src/physics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ pub struct PhysicsPlugin;

impl Plugin for PhysicsPlugin {
fn build(&self, app: &mut App) {
app.add_systems(Update, (walk_system, apply_velocity).chain().in_set(GameSet::Playing));
app.add_systems(
Update,
(walk_system, apply_velocity)
.chain()
.in_set(GameSet::Playing),
);
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ use bevy::{input::mouse::MouseWheel, prelude::*, window::PrimaryWindow};
use crate::{
get_sprite_rotation,
physics::Velocity,
sprite_material::{create_plane_mesh, SpriteExtension, SpriteMaterial}, GameStuff,
sprite_material::{create_plane_mesh, SpriteExtension, SpriteMaterial},
GameStuff,
};

const DOG_PATH: &str = "test/dog.png";
Expand Down Expand Up @@ -108,7 +109,7 @@ fn spawn_player_by_event(
Player,
Dog,
Velocity::default(),
GameStuff
GameStuff,
));
}
event_reader.clear();
Expand Down
4 changes: 1 addition & 3 deletions src/safe_area.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,7 @@ fn count_sheeps(
count += 1;
commands.entity(e).remove::<OutOfSafeArea>();
} else {
commands
.entity(e)
.insert(OutOfSafeArea);
commands.entity(e).insert(OutOfSafeArea);
}
}
}
Expand Down
Loading

0 comments on commit 7890afa

Please sign in to comment.