Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
use crate::deref_as;
use bevy::prelude::{Color, Component, Rect, Vec2};
#[derive(Clone, Copy, Debug, Component)]
pub struct BoxSize(Vec2);
deref_as!(BoxSize => Vec2);
impl From<Vec2> for BoxSize {
fn from(value: Vec2) -> Self {
BoxSize(value)
}
}
pub fn check_box_collisions(first: Rect, second: Rect) -> bool {
first.min.x < second.max.x
&& first.max.x > second.min.x
&& first.min.y < second.max.y
&& first.max.y > second.min.y
}
#[derive(Clone, Copy, Debug, Component)]
pub enum CollisionGroup {
Player,
Pickup,
FriendlyProjectile,
HostileProjectile,
Enemy,
}
impl CollisionGroup {
pub fn color(&self) -> Color {
use CollisionGroup::*;
match self {
Player => Color::rgb_u8(0, 116, 217),
Pickup => Color::rgb_u8(177, 13, 201),
FriendlyProjectile => Color::rgb_u8(46, 204, 64),
HostileProjectile => Color::rgb_u8(255, 65, 54),
Enemy => Color::rgb_u8(133, 20, 75),
}
}
}