use crate::{ render::{AtlasLayout, Renderer}, tilemap::Tilemap, }; use hurrycurry_protocol::{ glam::{IVec2, Vec2}, TileIndex, }; use rand::{random, seq::IndexedRandom, thread_rng}; use sdl2::keyboard::KeyboardState; #[derive(Debug)] pub struct Menu { map: Tilemap, } impl Menu { 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::() * 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 } } pub fn tick(&mut self, _dt: f32, _keyboard: &KeyboardState, _layout: &AtlasLayout) {} 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., ); self.map.draw(ctx); ctx.draw_text(Vec2::new(1., 1.), "Hello world!"); } }