aboutsummaryrefslogtreecommitdiff
path: root/pixel-client/src
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2024-07-23 00:36:25 +0200
committermetamuffin <metamuffin@disroot.org>2024-07-23 00:36:25 +0200
commite00fa55e4984377956a50ad980c53b43715bea6c (patch)
treefbeca868906397c5f0d6fef189899458e67512c7 /pixel-client/src
parentebc77dc48ef7f97ab946f334f642da9bf69a7e99 (diff)
downloadhurrycurry-e00fa55e4984377956a50ad980c53b43715bea6c.tar
hurrycurry-e00fa55e4984377956a50ad980c53b43715bea6c.tar.bz2
hurrycurry-e00fa55e4984377956a50ad980c53b43715bea6c.tar.zst
pc: menu background
Diffstat (limited to 'pixel-client/src')
-rw-r--r--pixel-client/src/main.rs2
-rw-r--r--pixel-client/src/menu.rs57
-rw-r--r--pixel-client/src/tilemap.rs2
3 files changed, 49 insertions, 12 deletions
diff --git a/pixel-client/src/main.rs b/pixel-client/src/main.rs
index 68c5b66a..0ebe7b44 100644
--- a/pixel-client/src/main.rs
+++ b/pixel-client/src/main.rs
@@ -88,7 +88,7 @@ fn main() {
let mut renderer = Renderer::init(&texture_creator);
let mut state = match args.action.unwrap_or_default() {
- Action::Menu => State::Menu(Menu::new()),
+ Action::Menu => State::Menu(Menu::new(renderer.atlas_layout())),
Action::Join { server_address } => State::Ingame(Box::new(Game::new(
Network::connect(&server_address).unwrap(),
renderer.atlas_layout(),
diff --git a/pixel-client/src/menu.rs b/pixel-client/src/menu.rs
index d9396e49..0fc0e880 100644
--- a/pixel-client/src/menu.rs
+++ b/pixel-client/src/menu.rs
@@ -1,21 +1,58 @@
-use crate::render::{AtlasLayout, Renderer};
-use hurrycurry_protocol::glam::Vec2;
+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;
-pub struct Menu {}
-
-impl Default for Menu {
- fn default() -> Self {
- Self::new()
- }
+#[derive(Debug)]
+pub struct Menu {
+ map: Tilemap,
}
impl Menu {
- pub fn new() -> Self {
- Self {}
+ 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, 8]];
+
+ 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 }
}
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!");
}
}
diff --git a/pixel-client/src/tilemap.rs b/pixel-client/src/tilemap.rs
index f52ffc1c..edab8b61 100644
--- a/pixel-client/src/tilemap.rs
+++ b/pixel-client/src/tilemap.rs
@@ -25,7 +25,7 @@ use crate::render::{
Renderer,
};
-#[derive(Default)]
+#[derive(Default, Debug)]
pub struct Tilemap {
connect_group_by_tile: Vec<Option<usize>>,
connect_members_by_group: Vec<HashSet<Option<TileIndex>>>,