summaryrefslogtreecommitdiffstats
path: root/src/texture.rs
diff options
context:
space:
mode:
authorsalmonik <raisersoft@proton.me>2026-07-10 21:16:59 +0200
committersalmonik <raisersoft@proton.me>2026-07-10 21:16:59 +0200
commitc8eae871002b57f45b29a2d158e384433e76a90c (patch)
treef521d4535649ee4d515271af58b842a8e192e20f /src/texture.rs
parentfix floor warping (diff)
downloaddungeon-c8eae871002b57f45b29a2d158e384433e76a90c.tar.gz
dungeon-c8eae871002b57f45b29a2d158e384433e76a90c.zip
Phase 2
Diffstat (limited to 'src/texture.rs')
-rw-r--r--src/texture.rs49
1 files changed, 48 insertions, 1 deletions
diff --git a/src/texture.rs b/src/texture.rs
index bdbb15c..e5720c0 100644
--- a/src/texture.rs
+++ b/src/texture.rs
@@ -60,6 +60,49 @@ pub fn generate_wall_texture(rng: &mut impl Rng) -> Vec<u32> {
60 tex 60 tex
61} 61}
62 62
63/// Gray stone-tile floor with a dark hole in the centre — the exit staircase.
64pub fn generate_exit_texture(rng: &mut impl Rng) -> Vec<u32> {
65 let mut tex = generate_floor_texture(rng);
66
67 let cx = TEX_SIZE as f64 / 2.0;
68 let cy = TEX_SIZE as f64 / 2.0;
69 let hole_radius = TEX_SIZE as f64 * 0.35;
70 let fade_zone = TEX_SIZE as f64 * 0.08;
71
72 for y in 0..TEX_SIZE {
73 for x in 0..TEX_SIZE {
74 let dx = x as f64 - cx;
75 let dy = y as f64 - cy;
76 let dist = (dx * dx + dy * dy).sqrt();
77
78 if dist < hole_radius {
79 // Deep black void.
80 let edge = (dist / hole_radius).clamp(0.0, 1.0);
81 // Slight blueish tint near the edge for depth.
82 let r = (8.0 * (1.0 - edge)) as u8;
83 let g = (6.0 * (1.0 - edge)) as u8;
84 let b = (12.0 * edge + 4.0 * (1.0 - edge)) as u8;
85 tex[y * TEX_SIZE + x] =
86 0xFF00_0000 | ((r as u32) << 16) | ((g as u32) << 8) | (b as u32);
87 } else if dist < hole_radius + fade_zone {
88 // Fade zone: blend from floor to darkness.
89 let t = ((dist - hole_radius) / fade_zone).clamp(0.0, 1.0);
90 let floor_color = tex[y * TEX_SIZE + x];
91 let fr = ((floor_color >> 16) & 0xFF) as f64;
92 let fg = ((floor_color >> 8) & 0xFF) as f64;
93 let fb = (floor_color & 0xFF) as f64;
94
95 let r = (fr * t + 8.0 * (1.0 - t)) as u8;
96 let g = (fg * t + 6.0 * (1.0 - t)) as u8;
97 let b = (fb * t + 12.0 * (1.0 - t)) as u8;
98 tex[y * TEX_SIZE + x] =
99 0xFF00_0000 | ((r as u32) << 16) | ((g as u32) << 8) | (b as u32);
100 }
101 }
102 }
103 tex
104}
105
63/// Gray stone-tile floor — 64×64, checkerboard with grout and subtle colour tint. 106/// Gray stone-tile floor — 64×64, checkerboard with grout and subtle colour tint.
64pub fn generate_floor_texture(rng: &mut impl Rng) -> Vec<u32> { 107pub fn generate_floor_texture(rng: &mut impl Rng) -> Vec<u32> {
65 let seed = rng.gen::<u64>(); 108 let seed = rng.gen::<u64>();
@@ -68,7 +111,11 @@ pub fn generate_floor_texture(rng: &mut impl Rng) -> Vec<u32> {
68 for y in 0..TEX_SIZE { 111 for y in 0..TEX_SIZE {
69 for x in 0..TEX_SIZE { 112 for x in 0..TEX_SIZE {
70 let h = hash(x as u32, y as u32, seed); 113 let h = hash(x as u32, y as u32, seed);
71 let h2 = hash(x.wrapping_add(2000) as u32, y.wrapping_add(2000) as u32, seed); 114 let h2 = hash(
115 x.wrapping_add(2000) as u32,
116 y.wrapping_add(2000) as u32,
117 seed,
118 );
72 119
73 let tile_x = x / 16; 120 let tile_x = x / 16;
74 let tile_y = y / 16; 121 let tile_y = y / 16;