summaryrefslogtreecommitdiff
path: root/src/content/entities/entity_cube.rs
blob: dbbd93ec2571155ac47ca40205fce90a241735b5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
use glam::{IVec2, Vec2};

use crate::{
    content::materials::MaterialId,
    sim::{
        cell::Cell,
        entity::{EntityCells, EntityDef},
    },
};

pub fn entity_cube_def(position: Vec2, material: MaterialId) -> EntityDef {
    let w = 10;
    let h = 10;
    let mut raw_cells = vec![Cell::void(); (w * h) as usize];

    for x in 0..w {
        for y in 0..h {
            let cell_idx = x + y * w;
            raw_cells[cell_idx as usize] = Cell::from_material(material);
            raw_cells[cell_idx as usize].set_entity_integrated(true);
        }
    }

    let entity_cells = EntityCells {
        cells: raw_cells,
        size: IVec2::new(w, h),
    };

    EntityDef::from_cells(position, entity_cells, None)
}