summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs59
1 files changed, 56 insertions, 3 deletions
diff --git a/src/main.rs b/src/main.rs
index 08bc61c..c947f05 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -4,8 +4,8 @@ mod renderer;
mod sim;
use futures::executor;
-use glam::Vec2;
-use rand::random_range;
+use glam::{IVec2, Vec2};
+use rand::{random_range, random_ratio};
use std::{collections::VecDeque, sync::Arc, time::Instant};
use winit::{
application::ApplicationHandler,
@@ -23,7 +23,10 @@ use crate::{
config::{PHYSICS_DELTA_TIME, PHYSICS_FPS, SIM_FPS, WINDOW_TITLE},
renderer::RendererState,
sim::{
- cell::{cell::Cell, materials::MaterialId},
+ cell::{
+ cell::Cell,
+ materials::{MaterialId, fire::FireCellView},
+ },
cell_sim::{sim::sim_tick, world::World},
particle_sim::{ParticleManager, particle::Particle},
rb_sim::{DebugRenderMode, RbSimManager, debug_ops::DebugOperator},
@@ -54,6 +57,8 @@ struct Input {
trigger_test_1: bool,
trigger_test_2: bool,
trigger_test_3: bool,
+ trigger_test_4: bool,
+ trigger_test_5: bool,
// keybindings
is_up_pressed: bool,
@@ -144,6 +149,50 @@ impl App {
}
}
+ if self.input.trigger_test_4
+ && let Some(lm) = self.input.last_mouse_world_pos
+ && let Some(world) = &mut self.world
+ && let Some(pm) = &mut self.particle_manager
+ && let Some(rbsm) = &mut self.rb_sim_manager
+ {
+ let mouse = Vec2::new(lm.0, lm.1);
+ self.input.trigger_test_4 = false;
+ let r: i32 = 30;
+ for x in -r..r {
+ for y in -r..r {
+ if x.pow(2) + y.pow(2) < r.pow(2) {
+ // if there's a cell, convert it to a particle
+ let pos = Vec2::new(mouse.x + x as f32, mouse.y + y as f32);
+ let ipos = pos.round().as_ivec2();
+ if let Some(cell) = world.get_cell_from_game_position(ipos.x, ipos.y) {
+ let mut fire = Cell::from_material(MaterialId::Fire);
+ fire.set_ticks_lived(300);
+ fire.match_parity(self.sim_seqno + 1);
+ if cell.material == MaterialId::Void && random_range(0.0..1.0) > 0.5 {
+ world.set_cell_from_game_position(ipos.x, ipos.y, fire, false);
+ } else {
+ world.set_cell_from_game_position(ipos.x, ipos.y, fire, false);
+ if random_range(0.0..1.0) > 0.6 {
+ let d = pos.distance(mouse);
+ if d < 0.001 {
+ continue;
+ } // skip the center cell
+ let dir = (pos - mouse) / d; // normalize, reusing d
+ let falloff = 1.0 - (d / r as f32); // 1 at center, 0 at edge
+ let vel = (Vec2::new(0.0, -0.6) + dir)
+ * 300.0
+ * random_range(0.5..1.5)
+ * falloff;
+ pm.particles
+ .push(Particle::new(pos, vel, cell.material, 5.0));
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
// --TEST DRAWING--
if (self.input.is_lmb_pressed || self.input.is_rmb_pressed)
&& let Some(lm) = self.input.last_mouse_world_pos
@@ -273,6 +322,8 @@ impl Default for App {
trigger_test_1: false,
trigger_test_2: false,
trigger_test_3: false,
+ trigger_test_4: false,
+ trigger_test_5: false,
is_lmb_pressed: false,
is_rmb_pressed: false,
is_up_pressed: false,
@@ -406,6 +457,8 @@ impl ApplicationHandler for App {
KeyCode::Digit1 if pressed && !repeat => self.input.trigger_test_1 = true,
KeyCode::Digit2 if pressed && !repeat => self.input.trigger_test_2 = true,
KeyCode::Digit3 if pressed && !repeat => self.input.trigger_test_3 = true,
+ KeyCode::Digit4 if pressed && !repeat => self.input.trigger_test_4 = true,
+ KeyCode::Digit5 if pressed && !repeat => self.input.trigger_test_5 = true,
_ => {}
}
}