Skip to content

Commit

Permalink
Fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
rewin123 committed Dec 6, 2023
1 parent 6f1b84d commit 0ed77b3
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 16 deletions.
4 changes: 1 addition & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ opt-level = 3
[profile.dev]
opt-level = 1

[profile.release]
lto = true
codegen-units = 1


# The profile that 'cargo dist' will build with
[profile.dist]
Expand Down
6 changes: 4 additions & 2 deletions src/debug_diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ impl Plugin for DiagnosticPlugin {
.chain(),
)
.add_systems(Update, (fps_counting, sheep_counter_text));
#[cfg(feature = "dev")]
app.add_plugins(bevy_inspector_egui::quick::WorldInspectorPlugin::default());

#[cfg(debug_assertions)] {
app.add_plugins(bevy_inspector_egui::quick::WorldInspectorPlugin::default());
}
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,12 @@ impl Plugin for GamePlugin {

#[cfg(debug_assertions)]
{
app.add_plugins(debug_diagnostic::DiagnosticPlugin);

app.add_plugins((FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin::default()));
}

app.add_plugins(debug_diagnostic::DiagnosticPlugin);

app.add_plugins((
player::PlayerPlugin,
physics::PhysicsPlugin,
Expand Down
21 changes: 11 additions & 10 deletions src/sheep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ impl StateChance {
pub fn scared_sheeps(
mut commands: Commands,
mut event_reader: EventReader<Bark>,
mut sheeps: Query<(Entity, &Transform, &mut WalkController), With<Sheep>>,
mut sheeps: Query<(Entity, &Transform, &mut WalkController, &mut Decision), With<Sheep>>,
) {
if let Some(bark) = event_reader.read().next() {
let bark_origin = bark.position;
Expand All @@ -130,6 +130,7 @@ pub fn scared_sheeps(
sheep.2 .target_velocity = (sheep.1.translation - bark_origin).normalize_or_zero() * SHEEP_SPEED;
sheep.2 .target_velocity.y = 0.0; //sheep must not fly and be in fixed height
commands.entity(sheep.0).insert(scare);
*sheep.3 = Decision::Scared;
}
}
}
Expand All @@ -155,15 +156,15 @@ fn init_random_walk(
let mut rand = rand::thread_rng();
for ev in event_reader.read() {
if let Ok(t) = poses.get_component::<Transform>(ev.e) {
info!("init random walk for {:?}", ev.e);
// info!("init random walk for {:?}", ev.e);
let r = rand.gen_range(0.0..RANDOM_WALK_RANGE);
let angle = rand.gen_range(0.0..PI*2.0);

commands.entity(ev.e).insert(RandomWalk {
target: t.translation + Vec3::new(angle.cos() * r, 0.0, angle.sin() * r),
});
} else {
warn!("init random walk for {:?} failed", ev.e);
// warn!("init random walk for {:?} failed", ev.e);
}
}
event_reader.clear();
Expand Down Expand Up @@ -208,29 +209,29 @@ pub fn sheep_state(

match next_dec {
Decision::Idle => {
info!("new idle for {:?}", e);
// info!("new idle for {:?}", e);
},
Decision::Feed => {
info!("new feed for {:?}", e);
*dec = Decision::Idle;
},
Decision::RandomWalk => {
info!("new random walk for {:?}", e);
// info!("new random walk for {:?}", e);
init_random_walk.send(InitRandomWalk { e });
},
Decision::MoveToSafeZone => {
info!("new move to safe zone for {:?}", e);
*dec = Decision::Idle;
},
Decision::MoveOutSafeZone => {
info!("new move out safe zone for {:?}", e);
*dec = Decision::Idle;
},
Decision::IdleFeeding => {
info!("new idle feeding for {:?}", e);
// info!("new idle feeding for {:?}", e);
commands.entity(e).insert(IdleFeeding {
time: rand.gen_range(0.0..IDLE_FEEDING_TIME_RANGE) + IDLE_FEEDING_TIME,
});
},
Decision::Scared => {

*dec = Decision::Idle;
},
}
}
Expand Down

0 comments on commit 0ed77b3

Please sign in to comment.