Skip to content

Commit 47ddc36

Browse files
Run cargo fmt
1 parent 8ee79d9 commit 47ddc36

File tree

3 files changed

+109
-74
lines changed

3 files changed

+109
-74
lines changed

src/game.rs

Lines changed: 82 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
use std::{collections::HashMap, io::Read, process::exit, sync::Mutex};
22

3-
use ggez::{Context, GameResult, audio::{SoundSource, Source}, event::KeyCode, graphics::{self, Color, DrawParam, Drawable, Shader, Text}, mint, nalgebra::Point2, timer};
3+
use ggez::{
4+
audio::{SoundSource, Source},
5+
event::KeyCode,
6+
graphics::{self, Color, DrawParam, Drawable, Shader, Text},
7+
mint,
8+
nalgebra::Point2,
9+
timer, Context, GameResult,
10+
};
411
use ggez_goodies::{
512
camera::{Camera, CameraDraw},
613
nalgebra_glm::Vec2,
@@ -10,14 +17,19 @@ use graphics::{Font, GlBackendSpec, Image, Scale, ShaderGeneric, TextFragment};
1017
use mint::Vector2;
1118
use rand::Rng;
1219

13-
use crate::{HEIGHT, Screen, WIDTH, components::{
20+
use crate::{
21+
components::{
1422
barrel::Barrel,
1523
bullet::Turbofish,
1624
cloud::Cloud,
1725
enemy::Enemy,
1826
player::{Direction, Player},
1927
tile::Tile,
20-
}, map::Map, utils::{lerp, remap}};
28+
},
29+
map::Map,
30+
utils::{lerp, remap},
31+
Screen, HEIGHT, WIDTH,
32+
};
2133

2234
use gfx::*;
2335

@@ -60,7 +72,7 @@ pub struct Game {
6072
end: Option<String>,
6173

6274
draw_end_text: (bool, Option<usize>, bool, bool), // Thread Sleeped?, Current Iters, Done?, Win?
63-
can_die: bool
75+
can_die: bool,
6476
}
6577

6678
impl Game {
@@ -160,7 +172,7 @@ impl Game {
160172
camera,
161173

162174
consolas: graphics::Font::new(ctx, "/fonts/Consolas.ttf").unwrap(),
163-
175+
164176
elapsed_shake: None,
165177
tics: None,
166178
particles: vec![],
@@ -171,7 +183,7 @@ impl Game {
171183
draw_end_text: (false, None, false, false),
172184

173185
end: map_1.end,
174-
can_die: true
186+
can_die: true,
175187
})
176188
}
177189

@@ -187,29 +199,38 @@ impl Game {
187199
let mut draw_pos = 0.;
188200

189201
// You Win
190-
let end_frag = &Text::new(TextFragment::new("You Win!")
191-
.font(self.consolas)
192-
.scale(Scale::uniform(50.))
202+
let end_frag = &Text::new(
203+
TextFragment::new("You Win!")
204+
.font(self.consolas)
205+
.scale(Scale::uniform(50.)),
193206
);
194207

195208
let end_dimensions = end_frag.dimensions(ctx);
196209

197-
graphics::draw(ctx, end_frag, DrawParam::default()
198-
.dest(Point2::new((WIDTH / 2.0) - (end_dimensions.0 / 2) as f32, 50.0))
210+
graphics::draw(
211+
ctx,
212+
end_frag,
213+
DrawParam::default().dest(Point2::new(
214+
(WIDTH / 2.0) - (end_dimensions.0 / 2) as f32,
215+
50.0,
216+
)),
199217
)?;
200-
218+
201219
// End quote
202220
for line in self.end.as_ref().unwrap().split("\\n").collect::<Vec<_>>() {
203-
let end_frag = &Text::new(TextFragment::new(line)
204-
.font(self.consolas)
205-
);
206-
221+
let end_frag = &Text::new(TextFragment::new(line).font(self.consolas));
222+
207223
let end_dimensions = end_frag.dimensions(ctx);
208-
209-
graphics::draw(ctx, end_frag, DrawParam::default()
210-
.dest(Point2::new((WIDTH / 2.0) - (end_dimensions.0 / 2) as f32, HEIGHT / 2. + draw_pos))
224+
225+
graphics::draw(
226+
ctx,
227+
end_frag,
228+
DrawParam::default().dest(Point2::new(
229+
(WIDTH / 2.0) - (end_dimensions.0 / 2) as f32,
230+
HEIGHT / 2. + draw_pos,
231+
)),
211232
)?;
212-
233+
213234
draw_pos += 20.0;
214235
}
215236

@@ -228,24 +249,32 @@ impl Game {
228249

229250
let menu_rect_dim = menu_rect.dimensions(ctx).unwrap();
230251

231-
let menu_frag_to = &Text::new(TextFragment::new("Press & go to the")
232-
.font(self.consolas)
233-
);
252+
let menu_frag_to =
253+
&Text::new(TextFragment::new("Press & go to the").font(self.consolas));
234254

235-
let menu_screen = &Text::new(TextFragment::new("MENU SCREEN")
236-
.font(self.consolas)
237-
.scale(Scale::uniform(20.0))
255+
let menu_screen = &Text::new(
256+
TextFragment::new("MENU SCREEN")
257+
.font(self.consolas)
258+
.scale(Scale::uniform(20.0)),
238259
);
239260

240261
graphics::draw(ctx, &menu_rect, DrawParam::default())?;
241262
graphics::draw(
242-
ctx, menu_frag_to, DrawParam::default()
243-
.dest(Point2::new((WIDTH / 2.) + 20., ((HEIGHT / 2.) + (draw_pos * 2.)) - 20.0))
263+
ctx,
264+
menu_frag_to,
265+
DrawParam::default().dest(Point2::new(
266+
(WIDTH / 2.) + 20.,
267+
((HEIGHT / 2.) + (draw_pos * 2.)) - 20.0,
268+
)),
244269
)?;
245270

246271
graphics::draw(
247-
ctx, menu_screen, DrawParam::default()
248-
.dest(Point2::new((WIDTH / 2.) + 70., ((HEIGHT / 2.) + (draw_pos * 2.)) + 12.0))
272+
ctx,
273+
menu_screen,
274+
DrawParam::default().dest(Point2::new(
275+
(WIDTH / 2.) + 70.,
276+
((HEIGHT / 2.) + (draw_pos * 2.)) + 12.0,
277+
)),
249278
)?;
250279

251280
// Press * to quit
@@ -261,24 +290,31 @@ impl Game {
261290
[36.0 / 255.0, 36.0 / 255.0, 36.0 / 255.0, 0.9].into(),
262291
)?;
263292

264-
let quit_frag_to = &Text::new(TextFragment::new("Press * to")
265-
.font(self.consolas)
266-
);
293+
let quit_frag_to = &Text::new(TextFragment::new("Press * to").font(self.consolas));
267294

268-
let press_quit = &Text::new(TextFragment::new("QUIT")
269-
.font(self.consolas)
270-
.scale(Scale::uniform(20.))
295+
let press_quit = &Text::new(
296+
TextFragment::new("QUIT")
297+
.font(self.consolas)
298+
.scale(Scale::uniform(20.)),
271299
);
272300

273301
graphics::draw(ctx, &quit_rect, DrawParam::default())?;
274302
graphics::draw(
275-
ctx, quit_frag_to, DrawParam::default()
276-
.dest(Point2::new(((WIDTH / 2.) - menu_rect_dim.w) - 20., ((HEIGHT / 2.) + (draw_pos * 2.)) - 20.))
303+
ctx,
304+
quit_frag_to,
305+
DrawParam::default().dest(Point2::new(
306+
((WIDTH / 2.) - menu_rect_dim.w) - 20.,
307+
((HEIGHT / 2.) + (draw_pos * 2.)) - 20.,
308+
)),
277309
)?;
278310

279311
graphics::draw(
280-
ctx, press_quit, DrawParam::default()
281-
.dest(Point2::new((((WIDTH / 2.) - menu_rect_dim.w) - 20.) + 90., (((HEIGHT / 2.) + (draw_pos * 2.)) - 20.) + 30.))
312+
ctx,
313+
press_quit,
314+
DrawParam::default().dest(Point2::new(
315+
(((WIDTH / 2.) - menu_rect_dim.w) - 20.) + 90.,
316+
(((HEIGHT / 2.) + (draw_pos * 2.)) - 20.) + 30.,
317+
)),
282318
)?;
283319
}
284320
} else {
@@ -439,16 +475,12 @@ impl Game {
439475

440476
if self.draw_end_text.1.is_none() {
441477
self.draw_end_text.1 = Some(timer::ticks(ctx));
442-
}
443-
444-
else if !self.draw_end_text.2 {
478+
} else if !self.draw_end_text.2 {
445479
if timer::ticks(ctx) - self.draw_end_text.1.unwrap() > 30 {
446480
self.draw_end_text.0 = true;
447481
self.draw_end_text.2 = true;
448482
}
449-
}
450-
451-
else {
483+
} else {
452484
self.tics = Some(1);
453485

454486
if self.dim_constant.rate != 0.0 {
@@ -457,7 +489,7 @@ impl Game {
457489
}
458490
}
459491
}
460-
492+
461493
let ferris_pos_x = self.player.pos_x;
462494
let ferris_pos_y = self.player.pos_y;
463495

@@ -646,13 +678,13 @@ impl Game {
646678
match v.0.as_str() {
647679
"ammo" => {
648680
self.player.ammo = lerp(self.player.ammo, *v.1, 0.3);
649-
},
681+
}
650682

651683
"health" => {
652684
// TODO: Health lerping
653685
}
654686

655-
_ => panic!()
687+
_ => panic!(),
656688
}
657689
}
658690

@@ -690,7 +722,7 @@ impl Game {
690722
}
691723
KeyCode::Up => {
692724
self.tics = Some(6);
693-
},
725+
}
694726
KeyCode::Key7 => {
695727
return Some(Screen::Menu);
696728
}

src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ use ggez::{
1010

1111
mod dead;
1212
mod game;
13+
mod map;
1314
mod menu;
1415
mod utils;
15-
mod map;
1616

1717
mod components {
1818
pub mod barrel;
@@ -105,7 +105,7 @@ impl EventHandler for MyGame {
105105
}
106106

107107
Ok(())
108-
},
108+
}
109109
Screen::Dead => self.death_screen.draw(ctx),
110110
}
111111
}

src/map.rs

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
use crate::components::{barrel::Barrel, enemy::Enemy, player::Player, tile::{Tile, TileType}};
1+
use crate::components::{
2+
barrel::Barrel,
3+
enemy::Enemy,
4+
player::Player,
5+
tile::{Tile, TileType},
6+
};
27

38
pub struct Map {
49
draw_pos: f32,
@@ -9,21 +14,21 @@ pub struct Map {
914
pub barrels: Vec<Barrel>,
1015

1116
pub player: Option<Player>,
12-
pub end: Option<String>
17+
pub end: Option<String>,
1318
}
1419

1520
impl Map {
1621
pub fn new() -> Self {
1722
Self {
1823
draw_pos: 0.,
1924
draw_inc: 64.,
20-
25+
2126
ground: vec![],
2227
enemies: vec![],
2328
barrels: vec![],
24-
29+
2530
player: None,
26-
end: None
31+
end: None,
2732
}
2833
}
2934

@@ -33,58 +38,56 @@ impl Map {
3338

3439
if exp[0].starts_with(".end") {
3540
self.end = Some(exp[1..].join(" "));
36-
}
37-
38-
else {
41+
} else {
3942
for id in line.chars() {
4043
match id {
4144
'[' => {
4245
self.ground.push(Tile::new(self.draw_pos, TileType::LEFT));
43-
46+
4447
self.draw_pos += self.draw_inc;
4548
}
46-
49+
4750
'-' => {
4851
self.ground.push(Tile::new(self.draw_pos, TileType::CENTER));
49-
52+
5053
self.draw_pos += self.draw_inc;
5154
}
52-
55+
5356
']' => {
5457
self.ground.push(Tile::new(self.draw_pos, TileType::RIGHT));
55-
58+
5659
self.draw_pos += self.draw_inc;
5760
}
58-
61+
5962
'_' => {
6063
self.draw_pos += self.draw_inc;
6164
}
62-
65+
6366
'8' => {
6467
self.ground.push(Tile::new(self.draw_pos, TileType::CENTER));
6568
self.enemies.push(Enemy::new(self.draw_pos));
66-
69+
6770
self.draw_pos += self.draw_inc;
6871
}
69-
72+
7073
'4' => {
7174
self.ground.push(Tile::new(self.draw_pos, TileType::CENTER));
7275
self.player = Some(Player::new(self.draw_pos));
73-
76+
7477
self.draw_pos += self.draw_inc;
7578
}
76-
79+
7780
'*' => {
7881
self.ground.push(Tile::new(self.draw_pos, TileType::CENTER));
7982
self.barrels.push(Barrel::new(self.draw_pos));
80-
83+
8184
self.draw_pos += self.draw_inc;
8285
}
83-
86+
8487
_ => {}
8588
}
8689
}
8790
}
8891
}
8992
}
90-
}
93+
}

0 commit comments

Comments
 (0)