Skip to content

Commit 1666aeb

Browse files
committed
easy to use CollisionPair on iter
1 parent 2ba6435 commit 1666aeb

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

examples/scenarios/car_shoot.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,8 @@ fn game_logic(engine: &mut Engine, game_state: &mut GameState) {
132132
if !event.pair.one_starts_with("marble") {
133133
continue;
134134
}
135-
for label in [event.pair.0, event.pair.1] {
135+
136+
for label in event.pair {
136137
engine.sprites.remove(&label);
137138
if label.starts_with("marble") {
138139
game_state.marble_labels.push(label);

src/physics.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,21 @@ impl CollisionPair {
8383
let b_matches = self.1.starts_with(&text);
8484
(a_matches && !b_matches) || (!a_matches && b_matches)
8585
}
86+
87+
pub fn array(&self) -> [&str; 2] {
88+
[self.0.as_str(), self.1.as_str()]
89+
}
90+
pub fn array_mut(&mut self) -> [&mut String; 2] {
91+
[&mut self.0, &mut self.1]
92+
}
93+
}
94+
95+
impl IntoIterator for CollisionPair {
96+
type Item = String;
97+
type IntoIter = std::array::IntoIter<Self::Item, 2>;
98+
fn into_iter(self) -> Self::IntoIter {
99+
[self.0, self.1].into_iter()
100+
}
86101
}
87102

88103
impl PartialEq for CollisionPair {

0 commit comments

Comments
 (0)