Created
January 13, 2019 12:58
-
-
Save davidpdrsn/3e510d65f2c3eff3417c7b33ccacebe7 to your computer and use it in GitHub Desktop.
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
pub struct CollisionSystem; | |
impl<'a> System<'a> for CollisionSystem { | |
type SystemData = ( | |
Entities<'a>, | |
WriteStorage<'a, Position>, | |
ReadStorage<'a, Velocity>, | |
WriteStorage<'a, Collision>, | |
); | |
fn run(&mut self, data: Self::SystemData) { | |
let (entities, mut positions, velocities, mut collisions) = data; | |
for (e1, p1, v1, c1) in (&entities, &mut positions, &velocities, &mut collisions).join() { | |
for (e2, p2, v2, c2) in (&entities, &mut positions, &velocities, &mut collisions).join() { | |
if e1 == e2 { | |
continue; | |
} | |
// do collision detection and response | |
} | |
} | |
} | |
} | |
// Components | |
#[derive(Debug, Component)] | |
#[storage(VecStorage)] | |
pub struct Position(pub Point2); | |
#[derive(Debug, Component)] | |
#[storage(VecStorage)] | |
pub struct Velocity(pub Vector2); | |
#[derive(Debug, Component)] | |
#[storage(VecStorage)] | |
pub struct Collision { | |
pub hitboxes: Vec<Hitbox>, | |
} | |
#[derive(Debug)] | |
pub struct Hitbox { | |
pub size: Size, | |
pub relative_position: Vector2, | |
} | |
#[derive(Debug, Default, Copy, Clone)] | |
pub struct Size { | |
pub height: f32, | |
pub width: f32, | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment