summaryrefslogtreecommitdiff
path: root/src/sim/board.rs
diff options
context:
space:
mode:
authorKai Stevenson <kai@kaistevenson.com>2026-08-11 00:46:56 -0700
committerKai Stevenson <kai@kaistevenson.com>2026-08-11 00:46:56 -0700
commit6f67586b8fc6efdb86d0c9a9744c546da97c4dab (patch)
tree2c0b328f7427efc5647cde810a361405d914a37c /src/sim/board.rs
parent167e31655b63aa4d4548532cf0410cea9fd145ca (diff)
physics for sand and water
Diffstat (limited to 'src/sim/board.rs')
-rw-r--r--src/sim/board.rs24
1 files changed, 12 insertions, 12 deletions
diff --git a/src/sim/board.rs b/src/sim/board.rs
index 4cc5756..7af19be 100644
--- a/src/sim/board.rs
+++ b/src/sim/board.rs
@@ -1,24 +1,24 @@
-use crate::config::{PIXEL_BUFFER_HEIGHT, PIXEL_BUFFER_WIDTH};
-
-type MaterialId = u16;
+use crate::{
+ config::{PIXEL_BUFFER_HEIGHT, PIXEL_BUFFER_WIDTH},
+ sim::materials::MaterialId,
+};
#[derive(Clone, Copy)]
pub struct Cell {
pub material: MaterialId,
- pub velocity_x: i8,
- pub velocity_y: i8,
pub flags: u8,
}
impl Cell {
- fn empty() -> Cell {
+ pub fn void() -> Cell {
Cell {
- material: 0,
- velocity_x: 0,
- velocity_y: 0,
+ material: MaterialId::Void,
flags: 0,
}
}
+ pub fn from_material(material: MaterialId) -> Cell {
+ Cell { material, flags: 0 }
+ }
}
pub struct Board {
@@ -40,8 +40,8 @@ impl Board {
let idx = self.position_to_index(x, y).unwrap();
self.cells[idx] = c;
}
- pub fn cell_at_position(&self, x: i32, y: i32) -> Option<&Cell> {
- Some(&self.cells[self.position_to_index(x, y)?])
+ pub fn cell_at_position(&self, x: i32, y: i32) -> Option<Cell> {
+ Some(self.cells[self.position_to_index(x, y)?])
}
pub fn position_to_index(&self, x: i32, y: i32) -> Option<usize> {
let board_x = x + self.size_x as i32 / 2;
@@ -61,7 +61,7 @@ impl Board {
pub fn empty() -> Board {
let size_x = PIXEL_BUFFER_WIDTH * 2;
let size_y = PIXEL_BUFFER_HEIGHT * 2;
- let cells: Vec<Cell> = vec![Cell::empty(); (size_x * size_y) as usize];
+ let cells: Vec<Cell> = vec![Cell::void(); (size_x * size_y) as usize];
Board {
size_x,