X-Git-Url: http://www.dolda2000.com/gitweb/?a=blobdiff_plain;f=src%2Fboll.rs;fp=src%2Fboll.rs;h=0000000000000000000000000000000000000000;hb=b1002380f9a0de4510043b09d15fec4590365ab0;hp=07c7b2807b11f3fece94d7e000a50985fb1ce868;hpb=5d7eff9e9c0f585e9c4d57907f2e72003d39c757;p=kaka%2Frust-sdl-test.git diff --git a/src/boll.rs b/src/boll.rs deleted file mode 100644 index 07c7b28..0000000 --- a/src/boll.rs +++ /dev/null @@ -1,82 +0,0 @@ -use core::render::Renderer; -use geometry::Point; -use sdl2::gfx::primitives::DrawRenderer; -use sdl2::rect::Rect; -use {SCREEN_HEIGHT, SCREEN_WIDTH}; - -pub trait Boll { - fn update(&mut self); - fn draw(&self, renderer: &mut Renderer, size: u32); -} - -pub struct SquareBoll { - pub pos: Point, - pub vel: Point, -} - -impl Boll for SquareBoll { - fn update(&mut self) { - self.vel.y += 0.1; - self.pos += self.vel; - - if self.pos.x < 0.0 { - self.pos.x = -self.pos.x; - self.vel.x = -self.vel.x; - } - if self.pos.x > SCREEN_WIDTH as f64 { - self.pos.x = SCREEN_WIDTH as f64 - (self.pos.x - SCREEN_WIDTH as f64); - self.vel.x = -self.vel.x; - } - if self.pos.y < 0.0 { - self.pos.y = -self.pos.y; - self.vel.y = -self.vel.y; - } - if self.pos.y > SCREEN_HEIGHT as f64 { - self.pos.y = SCREEN_HEIGHT as f64 - (self.pos.y - SCREEN_HEIGHT as f64); - self.vel.y = -self.vel.y; - } - } - - fn draw(&self, renderer: &mut Renderer, size: u32) { - renderer.canvas().set_draw_color(( - 255 - std::cmp::min(255, (self.vel.length() * 25.0) as u8), - (255.0 * (self.pos.x / SCREEN_WIDTH as f64)) as u8, - (255.0 * (self.pos.y / SCREEN_HEIGHT as f64)) as u8, - 128, - )); - let mut r = Rect::new(0, 0, size, size); - r.center_on((self.pos.x as i32, self.pos.y as i32)); - renderer.canvas().fill_rect(r).unwrap(); - } -} - -pub struct CircleBoll { - pub boll: SquareBoll, -} - -impl CircleBoll { - pub fn new(pos: Point, vel: Point) -> CircleBoll { - CircleBoll { - boll: SquareBoll { pos, vel }, - } - } -} - -impl Boll for CircleBoll { - fn update(&mut self) { - self.boll.update(); - } - - fn draw(&self, renderer: &mut Renderer, size: u32) { - let val = 255 - std::cmp::min(255, (self.boll.vel.length() * 20.0) as u8); - renderer - .canvas() - .filled_circle( - self.boll.pos.x as i16, - self.boll.pos.y as i16, - size as i16, - (val, val, val, 128), - ) - .unwrap(); - } -}