Skip to content

Commit d0667f0

Browse files
authored
Very Initial Very probably not working at all Sprite Implementation (#20)
* Initial porting work for BasicSprite * Add module include for BasicSprite * Linting fixes
1 parent 0afdda2 commit d0667f0

3 files changed

Lines changed: 449 additions & 1 deletion

File tree

src/hitbox.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ impl HitBox {
8888
}
8989

9090
impl HitBox {
91-
pub fn get_adjusted_points_native(self) -> Vec<(f32, f32)> {
91+
pub fn get_adjusted_points_native(&self) -> Vec<(f32, f32)> {
9292
let mut new_points: Vec<(f32, f32)> = Vec::with_capacity(self.points.len());
9393

9494
for point in self.points.iter() {
@@ -99,6 +99,30 @@ impl HitBox {
9999

100100
new_points
101101
}
102+
103+
pub fn left_native(&self) -> f32 {
104+
let mut converted: Vec<(f32, f32)> = self.get_adjusted_points_native();
105+
converted.sort_by(|a, b| a.0.partial_cmp(&b.0).unwrap());
106+
converted[0].0
107+
}
108+
109+
pub fn right_native(&self) -> f32 {
110+
let mut converted: Vec<(f32, f32)> = self.get_adjusted_points_native();
111+
converted.sort_by(|a, b| b.0.partial_cmp(&a.0).unwrap());
112+
converted[0].0
113+
}
114+
115+
pub fn bottom_native(&self) -> f32 {
116+
let mut converted: Vec<(f32, f32)> = self.get_adjusted_points_native();
117+
converted.sort_by(|a, b| a.1.partial_cmp(&b.1).unwrap());
118+
converted[0].1
119+
}
120+
121+
pub fn top_native(&self) -> f32 {
122+
let mut converted: Vec<(f32, f32)> = self.get_adjusted_points_native();
123+
converted.sort_by(|a, b| b.1.partial_cmp(&a.1).unwrap());
124+
converted[0].1
125+
}
102126
}
103127

104128
#[derive(Clone)]

src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ pub use geometry::{
1111
is_point_in_polygon,
1212
};
1313

14+
mod sprite;
15+
pub use sprite::BasicSprite;
16+
1417
mod sprite_list;
1518
pub use sprite_list::{check_for_collision_with_list, check_for_collision_with_lists};
1619

@@ -19,6 +22,7 @@ pub use sprite_list::{check_for_collision_with_list, check_for_collision_with_li
1922
fn arcade_accelerate(_py: Python, m: &PyModule) -> PyResult<()> {
2023
m.add_class::<HitBox>()?;
2124
m.add_class::<RotatableHitBox>()?;
25+
m.add_class::<BasicSprite>()?;
2226
m.add_function(wrap_pyfunction!(math::rotate_point, m)?)?;
2327
m.add_function(wrap_pyfunction!(math::clamp, m)?)?;
2428
m.add_function(wrap_pyfunction!(math::lerp, m)?)?;

0 commit comments

Comments
 (0)