Splash arrows in lava
This commit is contained in:
1 parent
3b710516d8
commit
ee88fc04a5
3 files changed
+116
-7
No files matched your search
@@ -10,6 +10,7 @@ pub const STUCK_MAX: usize = 400; // arrows and scorch marks
|
||||
pub const STUCK_LIFE: f32 = 300.0; // seconds an arrow stays
|
||||
const PARTS_MAX: usize = 900;
|
||||
const GRAVITY: f32 = 6.0;
|
||||
const LIQ_H: f32 = -0.3; // river surface, matching the depth used in render3d.rs
|
||||
|
||||
// particle kinds
|
||||
pub const EMBER: u8 = 0; // glowing, falls
|
||||
@@ -22,6 +23,7 @@ pub const ARROW: u8 = 6; // stuck arrow (vx, vy, vh = its direction)
|
||||
pub const SCORCH: u8 = 7; // dark mark on the floor
|
||||
pub const FLASH: u8 = 8; // expanding fireball
|
||||
pub const RING: u8 = 9; // shock wave
|
||||
pub const SPLASH: u8 = 10; // liquid droplets, bounce on the river surface
|
||||
|
||||
// projectile styles (Fx::style)
|
||||
pub const ST_PLAIN: u8 = 0;
|
||||
@@ -186,6 +188,7 @@ impl Game {
|
||||
for f in impacts {
|
||||
self.impact(&f);
|
||||
}
|
||||
self.spawn_lava_particles(dt);
|
||||
// particles
|
||||
for p in self.parts.iter_mut() {
|
||||
p.t += dt;
|
||||
@@ -204,6 +207,24 @@ impl Game {
|
||||
p.h += p.vh * dt;
|
||||
}
|
||||
FLASH | RING => {}
|
||||
SPLASH => {
|
||||
p.vh -= GRAVITY * 0.75 * dt;
|
||||
p.x += p.vx * dt;
|
||||
p.y += p.vy * dt;
|
||||
p.h += p.vh * dt;
|
||||
if p.h <= LIQ_H {
|
||||
p.h = LIQ_H;
|
||||
if p.vh < -0.6 {
|
||||
p.vh = -p.vh * 0.30;
|
||||
p.vx *= 0.55;
|
||||
p.vy *= 0.55;
|
||||
} else {
|
||||
p.vh = 0.0;
|
||||
p.vx *= 0.65;
|
||||
p.vy *= 0.65;
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
// falling: embers drift down slower than sparks and debris
|
||||
let g = if p.kind == EMBER { GRAVITY * 0.35 } else { GRAVITY };
|
||||
@@ -267,6 +288,10 @@ impl Game {
|
||||
self.stick(Part { kind: SCORCH, x, y, h: 0.0, vx: 0.0, vy: 0.0, vh: 0.0, t: 0.0, max: 20.0, col: 0, size: 0.6 });
|
||||
}
|
||||
ST_ARROW | ST_ARROW_WALL => {
|
||||
if let Some(kind) = self.liquid_kind_at(x, y) {
|
||||
self.liquid_impact(kind, x, y, size);
|
||||
return;
|
||||
}
|
||||
let (dx, dy) = (f.x2 - f.x, f.y2 - f.y);
|
||||
let l = (dx * dx + dy * dy).sqrt().max(0.01);
|
||||
let (dx, dy) = (dx / l, dy / l);
|
||||
@@ -294,6 +319,71 @@ impl Game {
|
||||
}
|
||||
}
|
||||
|
||||
fn liquid_kind_at(&self, x: f32, y: f32) -> Option<Kind> {
|
||||
self.map.get(x as i32, y as i32).filter(|t| t.liquid()).map(|t| t.kind)
|
||||
}
|
||||
|
||||
fn liquid_impact(&mut self, kind: Kind, x: f32, y: f32, size: f32) {
|
||||
let at = (x, y, LIQ_H + 0.04);
|
||||
match kind {
|
||||
Kind::Lava => {
|
||||
self.burst(SPLASH, at, 8.max((10.0 * size) as usize), 1.3, 1.9, 0.38, abgr(255, 110, 25), 0.045);
|
||||
self.burst(MOTE, at, 4, 0.7, 1.2, 0.7, abgr(255, 150, 45), 0.035);
|
||||
self.part(FLASH, at, (0.0, 0.0, 0.0), 0.12, abgr(255, 155, 45), 0.18 * size.max(0.7));
|
||||
// short burning arrow smoke: small, quickly fading
|
||||
self.part(SMOKE, (x, y, LIQ_H + 0.10), (0.0, 0.0, 0.70), 0.65, abgr(115, 55, 25), 0.09);
|
||||
self.burst(SMOKE, (x, y, LIQ_H + 0.18), 1, 0.1, 0.35, 0.45, abgr(85, 42, 20), 0.06);
|
||||
}
|
||||
_ => {
|
||||
self.burst(SPLASH, at, 10.max((12.0 * size) as usize), 1.2, 1.8, 0.42, abgr(140, 220, 255), 0.04);
|
||||
self.part(RING, (x, y, LIQ_H), (0.0, 0.0, 0.0), 0.25, abgr(150, 225, 255), 0.35 * size.max(0.7));
|
||||
self.part(SMOKE, (x, y, LIQ_H + 0.08), (0.0, 0.0, 0.35), 0.45, abgr(180, 210, 235), 0.07);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn spawn_lava_particles(&mut self, dt: f32) {
|
||||
if self.parts.len() >= PARTS_MAX {
|
||||
return;
|
||||
}
|
||||
let rate = 7.0;
|
||||
let mut count = (rate * dt).floor() as usize;
|
||||
if self.vrng.f() < (rate * dt).fract() {
|
||||
count += 1;
|
||||
}
|
||||
if count == 0 {
|
||||
return;
|
||||
}
|
||||
let max_x = self.map.w as i32 - 1;
|
||||
let max_y = self.map.h as i32 - 1;
|
||||
if max_x <= 1 || max_y <= 1 {
|
||||
return;
|
||||
}
|
||||
for _ in 0..count {
|
||||
if self.parts.len() >= PARTS_MAX {
|
||||
break;
|
||||
}
|
||||
let mut spot = None;
|
||||
for _ in 0..16 {
|
||||
let x = self.vrng.range(1, max_x - 1);
|
||||
let y = self.vrng.range(1, max_y - 1);
|
||||
let i = idx(x, y);
|
||||
if self.map.shown(i) && self.map.t[i].kind == Kind::Lava {
|
||||
spot = Some((x as f32 + 0.5, y as f32 + 0.5));
|
||||
break;
|
||||
}
|
||||
}
|
||||
if let Some((cx, cy)) = spot {
|
||||
let at = (cx, cy, LIQ_H + 0.03);
|
||||
self.burst(MOTE, at, 1, 0.15, 0.40, 1.40, abgr(255, 115, 30), 0.035);
|
||||
let spark = self.vrng.f() < 0.25;
|
||||
if spark {
|
||||
self.burst(SPLASH, at, 1, 0.70, 1.10, 0.38, abgr(255, 170, 45), 0.028);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// the last projectile gets a style
|
||||
pub(crate) fn style_last_fx(&mut self, style: u8) {
|
||||
if let Some(f) = self.fx.last_mut() {
|
||||
|
||||
Reference in new issue
Block a user