summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/config.rs2
-rw-r--r--src/sim/cell/materials/mod.rs13
-rw-r--r--src/sim/entity/entities/entity_grenade.rs2
-rw-r--r--src/sim/entity/mod.rs24
4 files changed, 30 insertions, 11 deletions
diff --git a/src/config.rs b/src/config.rs
index 5ce5d1f..17c75b3 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -11,5 +11,7 @@ pub const PHYSICS_FPS: u32 = 60;
pub const PHYSICS_DELTA_TIME: f32 = 1.0 / PHYSICS_FPS as f32;
pub const CELLS_TO_METRES: f32 = 20.0;
+// 10x10 square of steel = 0.5m^2 = 150kg with density 150
+pub const MASS_SCALING: f32 = 1.0 / 200.0;
pub const SETTLED_THRESOHLD: u8 = 7;
diff --git a/src/sim/cell/materials/mod.rs b/src/sim/cell/materials/mod.rs
index 5439cca..8116565 100644
--- a/src/sim/cell/materials/mod.rs
+++ b/src/sim/cell/materials/mod.rs
@@ -14,6 +14,7 @@ pub enum MaterialId {
Water,
Fire,
Smoke,
+ Steel,
}
#[repr(u8)]
@@ -34,7 +35,7 @@ pub struct MaterialDef {
pub sim_update: Option<fn(ctx: &mut UpdateCtx) -> PostUpdateAction>,
}
-static MATERIALS: [MaterialDef; 6] = [
+static MATERIALS: [MaterialDef; 7] = [
MaterialDef {
name: "Void",
color: (0x00, 0x00, 0x00, 0x00),
@@ -80,16 +81,24 @@ static MATERIALS: [MaterialDef; 6] = [
form: MaterialForm::Gas,
sim_update: Some(gas::sim_update),
},
+ MaterialDef {
+ name: "Steel",
+ color: (0x60, 0x60, 0x60, 0xFF),
+ density: 150,
+ form: MaterialForm::Solid,
+ sim_update: None,
+ },
];
impl MaterialId {
- pub const ALL: [MaterialId; 6] = [
+ pub const ALL: [MaterialId; 7] = [
MaterialId::Void,
MaterialId::Sand,
MaterialId::Wood,
MaterialId::Water,
MaterialId::Fire,
MaterialId::Smoke,
+ MaterialId::Steel,
];
#[inline]
pub fn def(self) -> &'static MaterialDef {
diff --git a/src/sim/entity/entities/entity_grenade.rs b/src/sim/entity/entities/entity_grenade.rs
index abc57d9..952fb14 100644
--- a/src/sim/entity/entities/entity_grenade.rs
+++ b/src/sim/entity/entities/entity_grenade.rs
@@ -39,7 +39,7 @@ pub fn entity_grenade_def(position: Vec2, fuse: f32) -> EntityDef {
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(MaterialId::Wood);
+ raw_cells[cell_idx as usize] = Cell::from_material(MaterialId::Steel);
raw_cells[cell_idx as usize].set_entity(true);
}
}
diff --git a/src/sim/entity/mod.rs b/src/sim/entity/mod.rs
index 555d2c6..0f4ae3c 100644
--- a/src/sim/entity/mod.rs
+++ b/src/sim/entity/mod.rs
@@ -5,7 +5,7 @@ use rapier2d::{
};
use crate::{
- config::CELLS_TO_METRES,
+ config::{CELLS_TO_METRES, MASS_SCALING},
sim::{
cell::{cell::Cell, materials::MaterialId},
lib::marching_squares::Marchable,
@@ -48,16 +48,16 @@ impl Marchable for EntityCells {
pub trait EntityBehaviour {
fn update(
&mut self,
- update_ctx: &mut EntityUpdateCtx,
- ctx: &mut SimCtx,
- delta_time: f32,
+ _update_ctx: &mut EntityUpdateCtx,
+ _ctx: &mut SimCtx,
+ _delta_time: f32,
) -> () {
}
fn physics_update(
&mut self,
- update_ctx: &mut EntityUpdateCtx,
- ctx: &mut SimCtx,
- delta_time: f32,
+ _update_ctx: &mut EntityUpdateCtx,
+ _ctx: &mut SimCtx,
+ _delta_time: f32,
) -> () {
}
}
@@ -79,7 +79,15 @@ impl EntityDef {
.translation(position / CELLS_TO_METRES)
.build();
- let collider = RbManager::convex_hull_collider_from_marchable(&cells, None).build();
+ let mass = cells
+ .cells
+ .iter()
+ .fold(0, |acc, cur| acc + cur.material.def().density) as f32
+ * MASS_SCALING;
+
+ let collider = RbManager::convex_hull_collider_from_marchable(&cells, None)
+ .mass(mass)
+ .build();
EntityDef {
rb: Some(rb),