X-Git-Url: http://dolda2000.com/gitweb/?a=blobdiff_plain;f=src%2Fcore%2Fgame.rs;h=f48d9b38356ac7def1c62cbaf2775882f3ff0bb9;hb=eca2559123ae3c7ef184bf42ec60680fcddb38f6;hp=f938245c48bff8d94437a885ad7feac6935772fc;hpb=dbf33b0d211241b7546e299e10c94af9b512bd60;p=kaka%2Frust-sdl-test.git diff --git a/src/core/game.rs b/src/core/game.rs index f938245..f48d9b3 100644 --- a/src/core/game.rs +++ b/src/core/game.rs @@ -170,7 +170,7 @@ impl Object for Character { for _i in 0..100 { objects.push(Box::new(Boll { pos: self.pos, - vel: ctrl.aim.to_adjusted_point() * (3.0 + rand::random::()) + point!(normal.sample(&mut rand::thread_rng()), normal.sample(&mut rand::thread_rng())) + self.vel, + vel: ctrl.aim.to_point() * (3.0 + rand::random::()) + point!(normal.sample(&mut rand::thread_rng()), normal.sample(&mut rand::thread_rng())) + self.vel, bounces: 2, })); } @@ -207,12 +207,12 @@ impl Object for Character { let l = 300.0; let pos = (self.pos.x as i32, self.pos.y as i32); // axis values - let p = (self.pos + ctrl.aim.to_point() * l).to_i32().into(); + let p = (self.pos + ctrl.aim.to_axis_point() * l).to_i32().into(); canvas.set_draw_color((0, 255, 0)); canvas.draw_line(pos, p).unwrap(); draw_cross(canvas, p); - // adjusted values - let p = (self.pos + ctrl.aim.to_adjusted_point() * l).to_i32().into(); + // values limited to unit vector + let p = (self.pos + ctrl.aim.to_point() * l).to_i32().into(); canvas.set_draw_color((255, 0, 0)); canvas.draw_line(pos, p).unwrap(); draw_cross(canvas, p); @@ -238,7 +238,7 @@ pub struct Boll { } impl Object for Boll { - fn update(&mut self, _objects: &mut Objects, lvl: &Level, _dt: Duration) -> ObjectState { + fn update(&mut self, objects: &mut Objects, lvl: &Level, _dt: Duration) -> ObjectState { self.vel += lvl.gravity; self.pos += self.vel; @@ -252,6 +252,18 @@ impl Object for Boll { } } + if self.pos.x <= 0.0 || self.pos.x >= 1280.0 { // only for testing + self.pos.x = self.pos.x.max(0.0).min(1280.0); + self.vel.x = -self.vel.x; + self.bounces = 0; + use rand::distributions::{Distribution, Normal}; + let normal = Normal::new(0.5, 0.4); + objects.push(Box::new(Boll { + vel: self.vel * normal.sample(&mut rand::thread_rng()), + ..*self + })); + } + Alive }