Collision Plugin
This commit is contained in:
+9
-1
@@ -15,7 +15,6 @@ fn check_collision(
|
||||
mut has_collided: Local<bool>,
|
||||
) {
|
||||
if *has_collided {
|
||||
println!("Collision!!!!!!!");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -28,6 +27,7 @@ fn check_collision(
|
||||
collider_transform.translation.truncate(),
|
||||
collider_collider.size / 2.0,
|
||||
) {
|
||||
println!("Collision!!!!!!!");
|
||||
player_sprite.color = Color::srgb(1.0, 0.0, 0.0);
|
||||
*has_collided = true;
|
||||
break;
|
||||
@@ -41,3 +41,11 @@ fn overlap(a_center: Vec2, a_half: Vec2, b_center: Vec2, b_half: Vec2) -> bool {
|
||||
let overlap_y = (a_center.y - b_center.y).abs() < (a_half.y + b_half.y);
|
||||
overlap_x && overlap_y
|
||||
}
|
||||
|
||||
pub struct CollisionPlugin;
|
||||
|
||||
impl Plugin for CollisionPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.add_systems(Update, check_collision);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ use bevy::{prelude::*, window::PresentMode};
|
||||
|
||||
use crate::background::BackgroundPlugin;
|
||||
use crate::camera::CameraPlugin;
|
||||
use crate::collision::CollisionPlugin;
|
||||
use crate::player::PlayerPlugin;
|
||||
|
||||
mod background;
|
||||
@@ -24,5 +25,6 @@ fn main() {
|
||||
.add_plugins(BackgroundPlugin) // Checkerboard background
|
||||
.add_plugins(PlayerPlugin) // Player
|
||||
.add_plugins(CameraPlugin) // Camera
|
||||
.add_plugins(CollisionPlugin) // Collisions
|
||||
.run();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user