block/
block.rs

1use basic_collision::*;
2 
3#[derive(Debug)]
4pub struct Block {
5    x: f32,
6    y: f32,
7    width: f32,
8    height: f32,
9}
10 
11impl Block {
12    pub fn new(x: f32, y: f32, width: f32, height: f32) -> Block {
13        Block {
14            x, y, width, height
15        }
16    }
17}
18 
19impl Object for Block {
20    fn boundary(&self) -> Boundary {
21        Boundary::new(self.x, self.y, self.width, self.height)
22    }
23}
24 
25fn main() {
26    let blocks: Vec<Box<dyn Object>> = vec![
27        Box::new(Block::new(100., 150., 60., 50.)),
28        Box::new(Block::new(150., 150., 40., 50.)),
29        Box::new(Block::new(200., 150., 60., 50.)),
30    ];
31    for block in blocks.iter() {
32        if block.does_collide(&blocks[..]) {
33            println!("Collision occurred!");
34        }
35    }
36}