X-Git-Url: http://dolda2000.com/gitweb/?a=blobdiff_plain;f=src%2Fboll.rs;h=35dd97e61fac2032b56d687015c85a557db28123;hb=6c5dd5cf7007081ce7ea87e59aac21c0e7007a2c;hp=f936fca261df8cc6142e896db502a171e9e2fbd8;hpb=c315bb317cbd779063cb0135abe731886de30838;p=kaka%2Frust-sdl-test.git diff --git a/src/boll.rs b/src/boll.rs index f936fca..35dd97e 100644 --- a/src/boll.rs +++ b/src/boll.rs @@ -6,6 +6,7 @@ use sdl2::video::Window; use {SCREEN_HEIGHT, SCREEN_WIDTH}; use common::Point2D; +use sdl2::gfx::primitives::DrawRenderer; pub trait Boll { fn update(&mut self); @@ -51,3 +52,35 @@ impl Boll for SquareBoll { canvas.fill_rect(r).unwrap(); } } + + +pub struct CircleBoll { + pub boll: SquareBoll, +} + +impl CircleBoll { + pub fn new(pos: Point2D, vel: Point2D) -> CircleBoll { + CircleBoll { + boll: SquareBoll { + pos, + vel, + } + } + } +} + +impl Boll for CircleBoll { + fn update(&mut self) { + self.boll.update(); + } + + fn draw(&mut self, canvas: &mut Canvas, size: u32) { + let val = 255 - std::cmp::min(255, (self.boll.vel.length() * 20.0) as u8); + canvas.filled_circle(self.boll.pos.x as i16, self.boll.pos.y as i16, size as i16, Color::RGBA( + val, + val, + val, + 128, + )).unwrap(); + } +}