diff options
author | metamuffin <metamuffin@disroot.org> | 2024-07-25 17:11:38 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2024-07-25 17:11:38 +0200 |
commit | a8ce0f8cf64a89c18cbb08dd10f2b2d9b22ad56f (patch) | |
tree | 7e94d7ef0e9d62a2266d593eb4fbfc30f204277b /pixel-client/src/menu/background.rs | |
parent | 6c4b81d58272371bc76e79dd086be3161f6b7193 (diff) | |
download | hurrycurry-a8ce0f8cf64a89c18cbb08dd10f2b2d9b22ad56f.tar hurrycurry-a8ce0f8cf64a89c18cbb08dd10f2b2d9b22ad56f.tar.bz2 hurrycurry-a8ce0f8cf64a89c18cbb08dd10f2b2d9b22ad56f.tar.zst |
menus
Diffstat (limited to 'pixel-client/src/menu/background.rs')
-rw-r--r-- | pixel-client/src/menu/background.rs | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/pixel-client/src/menu/background.rs b/pixel-client/src/menu/background.rs new file mode 100644 index 00000000..daf89360 --- /dev/null +++ b/pixel-client/src/menu/background.rs @@ -0,0 +1,79 @@ +use crate::{ + render::{sprite::SpriteDraw, AtlasLayout, Renderer}, + tilemap::Tilemap, +}; +use hurrycurry_protocol::{ + glam::{IVec2, Vec2}, + TileIndex, +}; +use rand::{random, seq::IndexedRandom, thread_rng}; + +pub struct MenuBackground { + background: Vec2, + map: Tilemap, +} + +impl MenuBackground { + pub fn new(layout: &AtlasLayout) -> Self { + let mut map = Tilemap::default(); + map.init( + &[ + "floor", + "tomato-crate", + "raw-steak-crate", + "table", + "chair", + "counter", + "sink", + "stove", + ] + .map(String::from), + layout, + ); + static BUCKETS: &[&[usize]] = &[&[], &[0, 0, 0, 0, 1, 2], &[3, 4, 5], &[6, 7]]; + + for x in -10..11 { + for y in -10..11 { + let p = Vec2::new(x as f32, y as f32); + let w = (-p.length() * 0.15).exp(); + let k = ((random::<f32>() * w) * BUCKETS.len() as f32) as usize; + if let Some(ti) = BUCKETS[k.min(BUCKETS.len())].choose(&mut thread_rng()) { + map.set(IVec2::new(x, y), Some(TileIndex(*ti)), [None; 4]) + } + } + } + Self { + map, + background: Vec2::ZERO, + } + } + + pub fn tick(&mut self, dt: f32) { + self.background += Vec2::new(2., 3.) * dt; + } + pub fn draw(&self, ctx: &mut Renderer) { + ctx.set_world_view( + ctx.size / ctx.get_world_scale() * Vec2::new(0.8, 0.2), + ctx.size.max_element() / 32. / 15., + ); + + for x in -1..=2 { + for y in -1..=2 { + ctx.draw_ui(SpriteDraw::underlay( + ctx.misc_textures.clouds, + Vec2::new(x as f32, y as f32) * 256. + self.background, + Vec2::ONE * 256., + None, + )); + } + } + ctx.draw_ui(SpriteDraw::underlay( + ctx.misc_textures.solid, + Vec2::ZERO, + ctx.ui_size, + Some([0, 0, 0, 50]), + )); + + self.map.draw(ctx); + } +} |