start work on placing tiles

This commit is contained in:
zoe 2022-05-19 19:50:00 +02:00
parent 13ae90769b
commit 2a47a75b91
5 changed files with 20 additions and 5 deletions

View file

@ -59,8 +59,9 @@ impl StateServer {
}
#[export]
fn put_tile_at(&mut self, _owner: &Node, x: usize, y: usize, z: usize, id: usize){
self.world.put_tile_at(x, y, z, id);
fn put_tile_at(&mut self, _owner: &Node, x: usize, y: usize, z: usize, id: usize) -> bool{
let success = self.world.put_tile_at(x, y, z, id);
success
}
}

View file

@ -90,11 +90,18 @@ impl World {
positions
}
pub fn put_tile_at(&mut self, x: usize, y: usize, z: usize, id: usize){
pub fn put_tile_at(&mut self, x: usize, y: usize, z: usize, id: usize) -> bool{
if !self.can_put_tile_at(x, y, z, id){
return false;
}
self.tiles[x][y][z] = tiles::Tiletypes::from_repr(id as u8).unwrap();
true
}
pub fn can_put_tile_at(&self, x: usize, y: usize, z: usize, id: usize) -> bool{
if self.tiles[x][y][z] == tiles::Tiletypes::Air{
return true;
}
false
}