New tiles
This commit is contained in:
parent
86b9134156
commit
dea1b8599a
5 changed files with 144 additions and 38 deletions
|
|
@ -16,6 +16,10 @@ enum GridAction{
|
|||
from: UVec3,
|
||||
to: UVec3,
|
||||
amount: u32,
|
||||
},
|
||||
SpawnLiquid {
|
||||
at: UVec3,
|
||||
amount: u32,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -52,29 +56,41 @@ pub fn tick(mut grid: ResMut<Grid>) {
|
|||
|
||||
transfer_amount = transfer_amount.min(MAX_HORIZONTAL_FLOW) / 4;
|
||||
if transfer_amount > 0 {
|
||||
for lookup_vector in [UVec3::new(1,0,0),UVec3::new(0,0,1)] {
|
||||
if let Some(toward_vector) = vector.checked_add(lookup_vector) {
|
||||
if let Some(index) = grid.indexify(toward_vector) {
|
||||
if let Some(toward_amount) = grid.data
|
||||
[index]
|
||||
.try_fill(transfer_amount.min(MAX_VERTICAL_FLOW)) {
|
||||
stack.push(GridAction::MoveLiquid { from: vector, to: toward_vector, amount: toward_amount });
|
||||
}
|
||||
}
|
||||
for lookup_vector in [IVec3::new(1,0,0),IVec3::new(0,0,1),IVec3::new(-1,0,0),IVec3::new(0,0,-1)] {
|
||||
let push_vector = (vector.as_ivec3() + lookup_vector).max(IVec3::ZERO).as_uvec3();
|
||||
if push_vector == vector {
|
||||
continue;
|
||||
}
|
||||
let Some(push_index) = grid.indexify(push_vector) else {
|
||||
continue;
|
||||
};
|
||||
|
||||
if let Some(toward_vector) = vector.checked_sub(lookup_vector) {
|
||||
if let Some(index) = grid.indexify(toward_vector) {
|
||||
if let Some(toward_amount) = grid.data
|
||||
[index]
|
||||
.try_fill(transfer_amount.min(MAX_VERTICAL_FLOW)) {
|
||||
stack.push(GridAction::MoveLiquid { from: vector, to: toward_vector, amount: toward_amount });
|
||||
}
|
||||
}
|
||||
}
|
||||
let Some(push_amount) = grid.data[push_index].try_fill(transfer_amount) else {
|
||||
continue;
|
||||
};
|
||||
stack.push(GridAction::MoveLiquid { from: vector, to: push_vector, amount: push_amount });
|
||||
}
|
||||
}
|
||||
},
|
||||
GridElement::Source { source_amount } => {
|
||||
if let Some(gravity_vector) = vector.checked_sub(UVec3::new(0,1,0)) {
|
||||
if grid.data[grid.indexify(gravity_vector).unwrap()].can_fill() {
|
||||
stack.push(GridAction::SpawnLiquid { at: gravity_vector, amount: source_amount });
|
||||
}
|
||||
}
|
||||
|
||||
for lookup_vector in [IVec3::new(1,0,0),IVec3::new(0,0,1),IVec3::new(-1,0,0),IVec3::new(0,0,-1)] {
|
||||
let push_vector = (vector.as_ivec3() + lookup_vector).max(IVec3::ZERO).as_uvec3();
|
||||
let Some(push_index) = grid.indexify(push_vector) else {
|
||||
continue;
|
||||
};
|
||||
|
||||
if grid.data[push_index].can_fill() == false {
|
||||
continue;
|
||||
}
|
||||
stack.push(GridAction::SpawnLiquid { at: push_vector, amount: source_amount });
|
||||
}
|
||||
},
|
||||
_ => {},
|
||||
}
|
||||
|
||||
|
|
@ -88,6 +104,10 @@ pub fn tick(mut grid: ResMut<Grid>) {
|
|||
let (from_index, to_index) = (grid.indexify(from).unwrap(), grid.indexify(to).unwrap());
|
||||
grid.tranfer_fluid(from_index, to_index, amount);
|
||||
},
|
||||
GridAction::SpawnLiquid { at, amount } => {
|
||||
let at_index = grid.indexify(at).unwrap();
|
||||
grid.fill(at_index, amount);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue