From 57f412d73a151f7a4fa35feaf249808dcbe5b5dc Mon Sep 17 00:00:00 2001 From: Justin Worthe Date: Sat, 11 Aug 2018 16:59:15 +0200 Subject: Clippy-suggested improvements --- src/main.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index 55c8594..6ed2dbf 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,5 @@ +#![warn(clippy)] + #[macro_use] extern crate gate; @@ -46,7 +48,7 @@ impl App for BugBasherGame { fn advance(&mut self, seconds: f64, _ctx: &mut AppContext) { if !self.game_over { self.bugs.retain(|b| b.alive); - for bug in self.bugs.iter_mut() { + for bug in &mut self.bugs { bug.advance(seconds); if self.home.touches_circle(bug) { bug.alive = false; @@ -92,8 +94,8 @@ impl App for BugBasherGame { match key { KeyCode::MouseLeft => { let mut hit = false; - for bug in self.bugs.iter_mut().filter(|bug| bug.touches_point(Vec2d { x, y })) { - if !self.game_over && bug.alive == true { + for bug in self.bugs.iter_mut().filter(|bug| bug.touches_point(Vec2d::new(x, y))) { + if !self.game_over && bug.alive { self.points += 1; } bug.alive = false; @@ -119,8 +121,8 @@ impl App for BugBasherGame { { let points_str = format!("{}", self.points); let lives_str = format!("{}", self.lives); - BugBasherGame::print_string(renderer, &points_str, Alignment::Left, 50., app_height - 50.); - BugBasherGame::print_string(renderer, &lives_str, Alignment::Right, app_width - 50., app_height - 50.); + BugBasherGame::print_string(renderer, &points_str, &Alignment::Left, 50., app_height - 50.); + BugBasherGame::print_string(renderer, &lives_str, &Alignment::Right, app_width - 50., app_height - 50.); } { let mut renderer = renderer.sprite_mode(); @@ -152,7 +154,7 @@ impl App for BugBasherGame { } { let points_str = format!("{}", self.points); - BugBasherGame::print_string(renderer, &points_str, Alignment::Center, app_width/2., app_height/2.-25.); + BugBasherGame::print_string(renderer, &points_str, &Alignment::Center, app_width/2., app_height/2.-25.); } } @@ -199,7 +201,7 @@ impl BugBasherGame { self.total_time = 0.; } - fn print_string(renderer: &mut Renderer, string: &str, alignment: Alignment, x: f64, y: f64) { + fn print_string(renderer: &mut Renderer, string: &str, alignment: &Alignment, x: f64, y: f64) { let letter_spacing = 45.; let left = match alignment { Alignment::Left => x, -- cgit v1.2.3