Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extern crate rand;
- use rand::Rng;
- use ggez::graphics;
- use ggez::nalgebra as na;
- use ggez::{Context, GameResult};
- #[derive(Debug)]
- pub struct Blob{
- pub radius: f32,
- pub position: cgmath::Point2<f32>
- }
- impl Blob{
- pub fn new() -> Blob {
- let mut rng = rand::thread_rng();
- Blob {
- radius: rng.gen_range(10.0, 100.0),
- position: cgmath::Point2::new(
- rng.gen_range(0.0, 600.0),
- rng.gen_range(0.0, 300.0)
- )
- }
- }
- }
- pub struct Rain<'a>{
- pub blobs: Vec<Blob>,
- ctx: &'a mut Context
- }
- impl Rain<'_>{
- fn new(ctx: &mut Context, maxCount: isize)->Rain{
- Rain {
- blobs: (1..maxCount).map(|_x| Blob::new()).collect::<Vec<Blob>>(),
- ctx
- }
- }
- fn draw(&mut self) -> GameResult{
- for blob in &self.blobs {
- let circle = graphics::Mesh::new_circle(
- self.ctx,
- graphics::DrawMode::fill(),
- na::Point2::new(blob.position.x, blob.position.y),
- blob.radius,
- 0.1,
- graphics::WHITE,
- );
- graphics::draw(self.ctx, &circle, (na::Point2::new(blob.position.x, blob.position.y),));
- }
- Ok(())
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement