Skip to content

Commit 548c1de

Browse files
committed
style: apply rustfmt
1 parent 4808b85 commit 548c1de

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1711
-809
lines changed

src/entities/blade_saw.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ impl Component for BladeSawSprite {
77
}
88

99
#[derive(Debug, Clone, Deserialize)]
10-
pub struct BladeSaw{
10+
pub struct BladeSaw {
1111
pub direction_x: f32,
1212
pub direction_y: f32,
1313
pub start_x: f32,
@@ -20,4 +20,4 @@ pub struct BladeSaw{
2020

2121
impl Component for BladeSaw {
2222
type Storage = DenseVecStorage<Self>;
23-
}
23+
}

src/entities/bonus.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@ use amethyst::core::ecs::{Component, DenseVecStorage};
33
pub struct Bonus {
44
pub initial_sprite: usize,
55
pub kind: BonusKind,
6-
pub taken: bool
6+
pub taken: bool,
77
}
88

99
impl Component for Bonus {
1010
type Storage = DenseVecStorage<Self>;
1111
}
1212

13-
pub enum BonusKind{
14-
Fuel, Wrench, Coin
15-
}
13+
pub enum BonusKind {
14+
Fuel,
15+
Wrench,
16+
Coin,
17+
}

src/entities/canons.rs

+12-9
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
1-
use amethyst::core::ecs::{DenseVecStorage, Component};
21
use crate::utils::Direction;
2+
use amethyst::core::ecs::{Component, DenseVecStorage};
33
#[derive(Debug, Clone)]
44
pub enum CanonKind {
5-
Bullet, Smg, Air, _Plasma,
5+
Bullet,
6+
Smg,
7+
Air,
8+
_Plasma,
69
}
710

8-
pub fn canon_to_shooting_timer(kind: &CanonKind) -> f32{
11+
pub fn canon_to_shooting_timer(kind: &CanonKind) -> f32 {
912
match kind {
1013
CanonKind::Bullet => 1.5,
1114
CanonKind::Smg => 0.4,
1215
CanonKind::Air => 0.5,
13-
_ => 0.
16+
_ => 0.,
1417
}
1518
}
1619

@@ -19,7 +22,7 @@ pub struct Canon {
1922
pub direction: Direction,
2023
pub kind: CanonKind,
2124
pub bullet_x_start: f32,
22-
pub bullet_y_start: f32
25+
pub bullet_y_start: f32,
2326
}
2427

2528
impl Component for Canon {
@@ -29,25 +32,25 @@ impl Component for Canon {
2932
pub struct Bullet {
3033
pub direction: Direction,
3134
pub kind: CanonKind,
32-
pub life_duration: f32
35+
pub life_duration: f32,
3336
}
3437

3538
pub fn canon_kind_to_bullet_life_duration(kind: &CanonKind) -> f32 {
3639
match kind {
3740
CanonKind::Bullet | CanonKind::Smg => 3.,
3841
CanonKind::Air => 1.2,
39-
_ =>0.
42+
_ => 0.,
4043
}
4144
}
4245

4346
pub fn canon_kind_to_bullet_speed(kind: &CanonKind) -> f32 {
4447
match kind {
4548
CanonKind::Bullet | CanonKind::Smg => 180.,
4649
CanonKind::Air => 40.,
47-
_ =>0.
50+
_ => 0.,
4851
}
4952
}
5053

5154
impl Component for Bullet {
5255
type Storage = DenseVecStorage<Self>;
53-
}
56+
}

src/entities/collision.rs

+93-29
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
use crate::utils::{Point2D, min_of_f32_vec, max_of_f32_vec};
1+
use crate::utils::{max_of_f32_vec, min_of_f32_vec, Point2D};
22
use amethyst::core::ecs::{Component, DenseVecStorage};
3-
use geo::{Polygon, LineString};
43
use geo::intersects::Intersects;
4+
use geo::{LineString, Polygon};
55
use std::cmp::Ordering;
66

77
pub struct ButtonPlatform;
@@ -42,24 +42,52 @@ impl Colliders {
4242
pub fn from_vec(colliders: Vec<Collider>) -> Colliders {
4343
let (min_x, min_y, max_x, max_y) = {
4444
(
45-
colliders.iter().map(|col| min_of_f32_vec([col.a.x, col.b.x, col.c.x, col.d.x])).min_by(|a, b| a.partial_cmp(b).unwrap_or(Ordering::Equal)).unwrap(),
46-
colliders.iter().map(|col| min_of_f32_vec([col.a.y, col.b.y, col.c.y, col.d.y])).min_by(|a, b| a.partial_cmp(b).unwrap_or(Ordering::Equal)).unwrap(),
47-
colliders.iter().map(|col| max_of_f32_vec([col.a.x, col.b.x, col.c.x, col.d.x])).max_by(|a, b| a.partial_cmp(b).unwrap_or(Ordering::Equal)).unwrap(),
48-
colliders.iter().map(|col| max_of_f32_vec([col.a.y, col.b.y, col.c.y, col.d.y])).max_by(|a, b| a.partial_cmp(b).unwrap_or(Ordering::Equal)).unwrap()
45+
colliders
46+
.iter()
47+
.map(|col| min_of_f32_vec([col.a.x, col.b.x, col.c.x, col.d.x]))
48+
.min_by(|a, b| a.partial_cmp(b).unwrap_or(Ordering::Equal))
49+
.unwrap(),
50+
colliders
51+
.iter()
52+
.map(|col| min_of_f32_vec([col.a.y, col.b.y, col.c.y, col.d.y]))
53+
.min_by(|a, b| a.partial_cmp(b).unwrap_or(Ordering::Equal))
54+
.unwrap(),
55+
colliders
56+
.iter()
57+
.map(|col| max_of_f32_vec([col.a.x, col.b.x, col.c.x, col.d.x]))
58+
.max_by(|a, b| a.partial_cmp(b).unwrap_or(Ordering::Equal))
59+
.unwrap(),
60+
colliders
61+
.iter()
62+
.map(|col| max_of_f32_vec([col.a.y, col.b.y, col.c.y, col.d.y]))
63+
.max_by(|a, b| a.partial_cmp(b).unwrap_or(Ordering::Equal))
64+
.unwrap(),
4965
)
5066
};
51-
Colliders { polygons: colliders.iter().map(|collider| collider.to_polygon()).collect(), colliders, min_x, min_y, max_x, max_y }
67+
Colliders {
68+
polygons: colliders
69+
.iter()
70+
.map(|collider| collider.to_polygon())
71+
.collect(),
72+
colliders,
73+
min_x,
74+
min_y,
75+
max_x,
76+
max_y,
77+
}
5278
}
5379
pub fn from_points(a: Point2D, b: Point2D, c: Point2D, d: Point2D) -> Colliders {
5480
Colliders {
55-
polygons: vec![
56-
Polygon::new(
57-
LineString::from(
58-
vec![(a.x, a.y), (b.x, b.y), (c.x, c.y), (d.x, d.y), (a.x, a.y)]
59-
),
60-
vec![],
61-
)
62-
],
81+
polygons: vec![Polygon::new(
82+
LineString::from(vec![
83+
(a.x, a.y),
84+
(b.x, b.y),
85+
(c.x, c.y),
86+
(d.x, d.y),
87+
(a.x, a.y),
88+
]),
89+
vec![],
90+
)],
6391
colliders: Vec::new(),
6492
min_x: min_of_f32_vec([a.x, b.x, c.x, d.x]),
6593
min_y: min_of_f32_vec([a.y, b.y, c.y, d.y]),
@@ -71,7 +99,9 @@ impl Colliders {
7199
pub fn polygons(&self) -> &Vec<Polygon<f32>> {
72100
&self.polygons
73101
}
74-
pub fn colliders(&self) -> &Vec<Collider> { &self.colliders }
102+
pub fn colliders(&self) -> &Vec<Collider> {
103+
&self.colliders
104+
}
75105
pub fn to_owned_polygons(&self) -> Vec<Polygon<f32>> {
76106
self.polygons.clone()
77107
}
@@ -92,18 +122,31 @@ pub struct Collider {
92122
impl Collider {
93123
pub fn new(starting_point: Point2D, width: f32, height: f32) -> Self {
94124
Collider {
95-
b: Point2D { x: starting_point.x + width, y: starting_point.y },
96-
d: Point2D { x: starting_point.x, y: starting_point.y + height },
97-
c: Point2D { x: starting_point.x + width, y: starting_point.y + height },
125+
b: Point2D {
126+
x: starting_point.x + width,
127+
y: starting_point.y,
128+
},
129+
d: Point2D {
130+
x: starting_point.x,
131+
y: starting_point.y + height,
132+
},
133+
c: Point2D {
134+
x: starting_point.x + width,
135+
y: starting_point.y + height,
136+
},
98137
a: starting_point,
99138
}
100139
}
101140

102141
pub fn to_polygon(&self) -> Polygon<f32> {
103142
Polygon::new(
104-
LineString::from(
105-
vec![(self.a.x, self.a.y), (self.b.x, self.b.y), (self.c.x, self.c.y), (self.d.x, self.d.y), (self.a.x, self.a.y)]
106-
),
143+
LineString::from(vec![
144+
(self.a.x, self.a.y),
145+
(self.b.x, self.b.y),
146+
(self.c.x, self.c.y),
147+
(self.d.x, self.d.y),
148+
(self.a.x, self.a.y),
149+
]),
107150
vec![],
108151
)
109152
}
@@ -116,7 +159,10 @@ impl Collider {
116159
}
117160
}
118161

119-
pub fn are_colliding(ship_polygon: &Vec<Polygon<f32>>, struct_polygons: &Vec<Polygon<f32>>) -> bool {
162+
pub fn are_colliding(
163+
ship_polygon: &Vec<Polygon<f32>>,
164+
struct_polygons: &Vec<Polygon<f32>>,
165+
) -> bool {
120166
for polygon in ship_polygon.iter() {
121167
for struct_polygon in struct_polygons.iter() {
122168
if polygon.intersects(struct_polygon) {
@@ -128,15 +174,33 @@ pub fn are_colliding(ship_polygon: &Vec<Polygon<f32>>, struct_polygons: &Vec<Pol
128174
}
129175

130176
pub fn compute_is_eligible_for_collision(col1: &Colliders, col2: &Colliders) -> bool {
131-
!(col1.min_x < col2.min_x && col1.max_x < col2.min_x && col1.min_x < col2.max_x && col1.max_x < col2.max_x)
132-
&& !(col1.min_x > col2.min_x && col1.max_x > col2.min_x && col1.min_x > col2.max_x && col1.max_x > col2.max_x)
133-
&& !(col1.min_y < col2.min_y && col1.max_y < col2.min_y && col1.min_y < col2.max_y && col1.max_y < col2.max_y)
134-
&& !(col1.min_y > col2.min_y && col1.max_y > col2.min_y && col1.min_y > col2.max_y && col1.max_y > col2.max_y)
177+
!(col1.min_x < col2.min_x
178+
&& col1.max_x < col2.min_x
179+
&& col1.min_x < col2.max_x
180+
&& col1.max_x < col2.max_x)
181+
&& !(col1.min_x > col2.min_x
182+
&& col1.max_x > col2.min_x
183+
&& col1.min_x > col2.max_x
184+
&& col1.max_x > col2.max_x)
185+
&& !(col1.min_y < col2.min_y
186+
&& col1.max_y < col2.min_y
187+
&& col1.min_y < col2.max_y
188+
&& col1.max_y < col2.max_y)
189+
&& !(col1.min_y > col2.min_y
190+
&& col1.max_y > col2.min_y
191+
&& col1.min_y > col2.max_y
192+
&& col1.max_y > col2.max_y)
135193
}
136194

137-
pub fn compute_ship_is_eligible_for_collision(col1: &Colliders, min_x: f32, max_x: f32, min_y: f32, max_y: f32) -> bool {
195+
pub fn compute_ship_is_eligible_for_collision(
196+
col1: &Colliders,
197+
min_x: f32,
198+
max_x: f32,
199+
min_y: f32,
200+
max_y: f32,
201+
) -> bool {
138202
!(col1.min_x < min_x && col1.max_x < min_x && col1.min_x < max_x && col1.max_x < max_x)
139203
&& !(col1.min_x > min_x && col1.max_x > min_x && col1.min_x > max_x && col1.max_x > max_x)
140204
&& !(col1.min_y < min_y && col1.max_y < min_y && col1.min_y < max_y && col1.max_y < max_y)
141205
&& !(col1.min_y > min_y && col1.max_y > min_y && col1.min_y > max_y && col1.max_y > max_y)
142-
}
206+
}

src/entities/doors.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
use amethyst::core::ecs::{Component, DenseVecStorage};
22

3-
pub enum DoorState{
4-
Open, Closed
3+
pub enum DoorState {
4+
Open,
5+
Closed,
56
}
67

7-
pub struct PlasmaDoor{
8+
pub struct PlasmaDoor {
89
pub initial_sprite: usize,
9-
pub state: DoorState
10+
pub state: DoorState,
1011
}
1112

1213
impl Component for PlasmaDoor {
1314
type Storage = DenseVecStorage<Self>;
14-
}
15+
}

src/entities/explosion.rs

-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,3 @@ pub struct Explosion;
55
impl Component for Explosion {
66
type Storage = DenseVecStorage<Self>;
77
}
8-

src/entities/main_menu.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use amethyst::core::ecs::{Component, DenseVecStorage};
22

3-
pub struct MenuBackground{
4-
pub parallax_index: usize
3+
pub struct MenuBackground {
4+
pub parallax_index: usize,
55
}
66

77
impl Component for MenuBackground {
@@ -11,4 +11,4 @@ impl Component for MenuBackground {
1111
pub struct PushEnter;
1212
impl Component for PushEnter {
1313
type Storage = DenseVecStorage<Self>;
14-
}
14+
}

src/entities/mod.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
use amethyst::core::ecs::{Component, DenseVecStorage};
22

3-
pub mod ship;
4-
pub mod collision;
5-
pub mod explosion;
3+
pub mod blade_saw;
4+
pub mod bonus;
65
pub mod canons;
6+
pub mod collision;
77
pub mod doors;
8+
pub mod explosion;
89
pub mod main_menu;
9-
pub mod blade_saw;
10-
pub mod bonus;
10+
pub mod ship;
1111
pub mod sound;
1212

1313
pub struct TransitionFade;
1414

1515
impl Component for TransitionFade {
1616
type Storage = DenseVecStorage<Self>;
17-
}
17+
}

src/entities/ship.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -31,25 +31,25 @@ impl Component for ShipPowerRightNumber {
3131
}
3232

3333
pub struct ShipLife {
34-
pub life_point: u8
34+
pub life_point: u8,
3535
}
3636

3737
impl Component for ShipLife {
3838
type Storage = DenseVecStorage<Self>;
3939
}
4040

4141
pub struct ShipFuel {
42-
pub fuel_point: u8
42+
pub fuel_point: u8,
4343
}
4444

4545
impl Component for ShipFuel {
4646
type Storage = DenseVecStorage<Self>;
4747
}
4848

4949
pub struct Coin {
50-
pub coin_id: usize
50+
pub coin_id: usize,
5151
}
5252

5353
impl Component for Coin {
5454
type Storage = DenseVecStorage<Self>;
55-
}
55+
}

src/entities/sound.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ pub struct MenuSound;
44

55
impl Component for MenuSound {
66
type Storage = DenseVecStorage<Self>;
7-
}
7+
}

0 commit comments

Comments
 (0)