-
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.
Basic movement of yups, collision detection
- Loading branch information
Showing
7 changed files
with
106 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
use avian2d::prelude::*; | ||
use bevy::prelude::*; | ||
|
||
use crate::screens::ingame::playing::MovementSpeed; | ||
|
||
pub fn plugin(app: &mut App) { | ||
app.add_systems(FixedUpdate, movement); | ||
} | ||
|
||
fn movement(mut moving_objects: Query<(&mut LinearVelocity, &MovementSpeed)>) { | ||
for (mut lv, speed) in &mut moving_objects { | ||
lv.x = speed.0; | ||
} | ||
} |
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,29 @@ | ||
use avian2d::prelude::*; | ||
use bevy::prelude::*; | ||
|
||
use crate::screens::ingame::playing::{MovementSpeed, Obstacle}; | ||
|
||
#[derive(Component, Debug)] | ||
pub struct Yup; | ||
|
||
pub fn plugin(app: &mut App) { | ||
app.add_systems(PostProcessCollisions, collision_handler); | ||
} | ||
|
||
fn collision_handler( | ||
mut collisions: ResMut<Collisions>, | ||
obstacles: Query<Entity, With<Obstacle>>, | ||
mut yups: Query<(Entity, &mut MovementSpeed), With<Yup>>, | ||
) { | ||
// For now, we'll ignore all collisions between yups. | ||
// TODO: sometimes blockers will need to be collided with! | ||
collisions.retain(|c| yups.get(c.entity1).is_err() || yups.get(c.entity2).is_err()); | ||
|
||
for (yup, mut speed) in &mut yups { | ||
for obstacle in &obstacles { | ||
if collisions.contains(yup, obstacle) { | ||
*speed = MovementSpeed(-speed.0); | ||
} | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
mod ingame; | ||
pub mod ingame; | ||
mod loading; | ||
mod splash; | ||
mod title; | ||
|
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
mod pause; | ||
mod playing; | ||
pub mod pause; | ||
pub mod playing; | ||
|
||
use crate::game::Game; | ||
use bevy::prelude::*; | ||
|
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