forked from karx/catbox
necessary point collision; will revise later
This commit is contained in:
parent
ffd257fc7b
commit
1301ab4b0b
|
@ -39,6 +39,28 @@ pub fn check_for_collision(sprite1: &Sprite, sprite2: &Sprite) -> bool {
|
||||||
collided(sprite1, sprite2)
|
collided(sprite1, sprite2)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
|
pub fn check_for_collision_with_point(sprite1: &Sprite, point: &crate::math::vec2::Vec2Int) -> bool {
|
||||||
|
let coll_rad = max(sprite1.rect.width(), sprite1.rect.height()) as i32;
|
||||||
|
|
||||||
|
let coll2 = coll_rad * coll_rad;
|
||||||
|
|
||||||
|
let diff_x = sprite1.position().x - point.x;
|
||||||
|
let diff_x2 = diff_x * diff_x;
|
||||||
|
|
||||||
|
if diff_x2 > coll2 { return false; }
|
||||||
|
|
||||||
|
let diff_y = sprite1.position().y - point.y;
|
||||||
|
let diff_y2 = diff_y * diff_y;
|
||||||
|
|
||||||
|
if diff_y2 > coll2 {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/// Check if the sprite is colliding with any sprite in the collection, and return a list of
|
/// Check if the sprite is colliding with any sprite in the collection, and return a list of
|
||||||
/// references to the sprites which are colliding
|
/// references to the sprites which are colliding
|
||||||
#[must_use]
|
#[must_use]
|
||||||
|
|
Loading…
Reference in a new issue