generated from NiklasEi/bevy_game_template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
59 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
use bevy::prelude::*; | ||
use bevy_rapier3d::prelude::*; | ||
|
||
use crate::{ball::Ball, GameState}; | ||
|
||
pub struct HolePlugin; | ||
|
||
impl Plugin for HolePlugin { | ||
fn build(&self, app: &mut App) { | ||
app.register_type::<Hole>() | ||
.add_system(win_condition.in_set(OnUpdate(GameState::Playing))); | ||
} | ||
} | ||
|
||
#[derive(Component, Reflect, Clone, Copy, Debug)] | ||
pub struct Hole; | ||
|
||
fn win_condition( | ||
mut collision_events: EventReader<CollisionEvent>, | ||
ball_query: Query<Entity, With<Ball>>, | ||
hole_query: Query<Entity, With<Hole>>, | ||
hole_mesh_query: Query<&Parent, With<Collider>>, | ||
) { | ||
if let Ok(ball) = ball_query.get_single() { | ||
let hole = hole_query.single(); | ||
|
||
for collision in collision_events.iter() { | ||
if let CollisionEvent::Started(entity0, entity1, _) = collision { | ||
let other = if *entity0 == ball { | ||
*entity1 | ||
} else if *entity1 == ball { | ||
*entity0 | ||
} else { | ||
continue; | ||
}; | ||
|
||
if let Ok(parent) = hole_mesh_query.get(other) { | ||
if parent.get() == hole { | ||
println!("you win!!"); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters