From 934efcccaa5a82f993c13c91511afe1943caa3b4 Mon Sep 17 00:00:00 2001 From: Justin Worthe Date: Tue, 1 May 2018 11:15:14 +0200 Subject: Added escalating difficulty --- src/main.rs | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'src/main.rs') 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 for BugBasherGame { @@ -53,8 +54,12 @@ impl App 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, 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, -- cgit v1.2.3