summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/entities/bug.rs7
-rw-r--r--src/entities/home.rs5
-rw-r--r--src/hitbox.rs5
-rw-r--r--src/main.rs16
4 files changed, 16 insertions, 17 deletions
diff --git a/src/entities/bug.rs b/src/entities/bug.rs
index f64669d..b5e31c7 100644
--- a/src/entities/bug.rs
+++ b/src/entities/bug.rs
@@ -13,13 +13,10 @@ const SPEED: f64 = 175.;
impl Bug {
pub fn new(x: f64, y: f64) -> Bug {
- let pos = Vec2d {
- x: x,
- y: y
- };
+ let pos = Vec2d::new(x, y);
let pos_unit = pos.unit();
Bug {
- pos: pos,
+ pos,
rotation: (-pos).angle(),
velocity: -pos_unit * SPEED,
alive: true
diff --git a/src/entities/home.rs b/src/entities/home.rs
index 2839f5d..5666a75 100644
--- a/src/entities/home.rs
+++ b/src/entities/home.rs
@@ -12,10 +12,7 @@ pub struct Home {
impl Home {
pub fn new(x: f64, y: f64) -> Home {
Home {
- pos: Vec2d {
- x: x,
- y: y
- },
+ pos: Vec2d::new(x, y),
animation_time: 0.,
sprite: SpriteId::Sleepypug1
}
diff --git a/src/hitbox.rs b/src/hitbox.rs
index 04de484..bd4170e 100644
--- a/src/hitbox.rs
+++ b/src/hitbox.rs
@@ -3,7 +3,10 @@ use geometry::*;
pub trait CircleHitbox {
fn pos(&self) -> Vec2d;
fn radius(&self) -> f64;
-
+
+ /**
+ * True if the point is inside the hitbox
+ */
fn touches_point(&self, point: Vec2d) -> bool {
self.pos().distance(point) <= self.radius()
}
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<AssetId> for BugBasherGame {
fn advance(&mut self, seconds: f64, _ctx: &mut AppContext<AssetId>) {
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<AssetId> 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<AssetId> 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<AssetId> 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<AssetId>, string: &str, alignment: Alignment, x: f64, y: f64) {
+ fn print_string(renderer: &mut Renderer<AssetId>, string: &str, alignment: &Alignment, x: f64, y: f64) {
let letter_spacing = 45.;
let left = match alignment {
Alignment::Left => x,