Advertisement
Guest User

Untitled

a guest
Jan 25th, 2020
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 1.14 KB | None | 0 0
  1. extern crate rand;
  2. use rand::Rng;
  3.  
  4. use ggez::graphics;
  5. use ggez::nalgebra as na;
  6. use ggez::{Context, GameResult};
  7.  
  8. #[derive(Debug)]
  9. pub struct Blob{
  10.   pub radius: f32,
  11.   pub position: cgmath::Point2<f32>
  12. }
  13.  
  14. impl Blob{
  15.   pub fn new() -> Blob {
  16.     let mut rng = rand::thread_rng();
  17.     Blob {
  18.       radius: rng.gen_range(10.0, 100.0),
  19.       position: cgmath::Point2::new(
  20.         rng.gen_range(0.0, 600.0),
  21.         rng.gen_range(0.0, 300.0)
  22.       )
  23.     }
  24.   }
  25. }
  26.  
  27. pub struct Rain<'a>{
  28.  pub blobs: Vec<Blob>,
  29.  ctx: &'a mut Context
  30. }
  31.  
  32. impl Rain<'_>{
  33.  fn new(ctx: &mut Context, maxCount: isize)->Rain{
  34.    Rain {
  35.      blobs: (1..maxCount).map(|_x| Blob::new()).collect::<Vec<Blob>>(),
  36.      ctx
  37.    }
  38.  }
  39.  
  40.  fn draw(&mut self) -> GameResult{
  41.    for blob in &self.blobs {
  42.      let circle = graphics::Mesh::new_circle(
  43.        self.ctx,
  44.        graphics::DrawMode::fill(),
  45.        na::Point2::new(blob.position.x, blob.position.y),
  46.        blob.radius,
  47.        0.1,
  48.        graphics::WHITE,
  49.      );
  50.      graphics::draw(self.ctx, &circle, (na::Point2::new(blob.position.x, blob.position.y),));
  51.    }
  52.    Ok(())
  53.  }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement