diff options
author | Justin Worthe <justin@worthe-it.co.za> | 2018-05-01 11:15:14 +0200 |
---|---|---|
committer | Justin Worthe <justin@worthe-it.co.za> | 2018-05-01 11:15:14 +0200 |
commit | 934efcccaa5a82f993c13c91511afe1943caa3b4 (patch) | |
tree | 2544ba42a341de7a2b5d45cb74ad6928f0f11258 /src | |
parent | a70b7befc08646ea92282fa30b12bae811f22203 (diff) |
Added escalating difficulty
Diffstat (limited to 'src')
-rw-r--r-- | src/geometry.rs | 6 | ||||
-rw-r--r-- | src/hitbox.rs | 2 | ||||
-rw-r--r-- | src/main.rs | 24 |
3 files changed, 22 insertions, 10 deletions
diff --git a/src/geometry.rs b/src/geometry.rs index be903d7..c49fe2a 100644 --- a/src/geometry.rs +++ b/src/geometry.rs @@ -8,8 +8,12 @@ pub struct Vec2d { impl Vec2d { pub fn distance(&self, other: Vec2d) -> f64 { - ((other.x-self.x).powi(2) + (other.y-self.y).powi(2)).sqrt() + self.distance_squared(other).sqrt() } + pub fn distance_squared(&self, other: Vec2d) -> f64 { + ((other.x-self.x).powi(2) + (other.y-self.y).powi(2)) + } + pub fn angle(&self) -> f64 { self.y.atan2(self.x) } diff --git a/src/hitbox.rs b/src/hitbox.rs index df87b68..04de484 100644 --- a/src/hitbox.rs +++ b/src/hitbox.rs @@ -9,6 +9,6 @@ pub trait CircleHitbox { } fn touches_circle(&self, other: &CircleHitbox) -> bool { - self.pos().distance(other.pos()) <= self.radius() + other.radius() + self.pos().distance_squared(other.pos()) <= (self.radius() + other.radius()).powi(2) } } diff --git a/src/main.rs b/src/main.rs index 5547479..98dd39f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,13 +10,13 @@ extern crate rand; use rand::distributions::IndependentSample; use rand::Isaac64Rng; use std::f64::consts::PI; - + mod asset_id { include!(concat!(env!("OUT_DIR"), "/asset_id.rs")); } use asset_id::*; mod geometry; use geometry::*; - + mod hitbox; use hitbox::*; @@ -31,7 +31,8 @@ struct BugBasherGame { points: i64, lives: i64, game_over: bool, - time_to_next_bug: f64 + time_to_next_bug: f64, + total_time: f64 } impl App<AssetId> for BugBasherGame { @@ -53,8 +54,12 @@ impl App<AssetId> for BugBasherGame { } self.time_to_next_bug -= seconds; + self.total_time += seconds; + if self.time_to_next_bug <= 0. { - let time_dist = rand::distributions::Normal::new(2.0, 1.0); + let mean = f64::max(4. - (self.total_time as f64 * 0.25), 0.5); + let sd = mean / 3.; + let time_dist = rand::distributions::Normal::new(mean, sd); self.time_to_next_bug = time_dist.ind_sample(&mut self.rng); let angle_dist = rand::distributions::Range::new(0., 2.*PI); @@ -140,25 +145,28 @@ impl BugBasherGame { let mut game = BugBasherGame { rng: Isaac64Rng::new_unseeded(), home: Home::new(0., 0.), - bugs: Vec::new(), + bugs: Vec::with_capacity(1000), points: 0, lives: 0, game_over: true, - time_to_next_bug: 0. + time_to_next_bug: 0., + total_time: 0. }; game.reset(); game } fn reset(&mut self) { - self.bugs = Vec::new(); + self.bugs = Vec::with_capacity(1000); self.points = 0; self.lives = 3; self.game_over = false; + self.time_to_next_bug = 0.; + self.total_time = 0.; } fn print_string(renderer: &mut Renderer<AssetId>, string: &str, alignment: Alignment, x: f64, y: f64) { - let letter_spacing = 25.; + let letter_spacing = 45.; let left = match alignment { Alignment::Left => x, Alignment::Right => x - string.len() as f64 * letter_spacing, |