From e03cd06c789b36b45a7a88882085d124416cf7c5 Mon Sep 17 00:00:00 2001 From: Dominic Date: Sat, 6 Jul 2024 21:19:24 +0000 Subject: [PATCH] Add fence to static worldgen (#4) Fence Assets Reviewed-on: https://msrd0.dev/spielemarmelade/turtlegame/pulls/4 Co-authored-by: Dominic Co-committed-by: Dominic --- assets/overworld/fence-bottom-left.svg | 21 +++ assets/overworld/fence-bottom-right.svg | 9 ++ assets/overworld/fence-horiz.svg | 20 +++ assets/overworld/fence-top-left.svg | 21 +++ assets/overworld/fence-top-right.svg | 9 ++ assets/overworld/fence-vert.svg | 18 +++ src/activities/overworld/worldgen.rs | 167 ++++++++++++++++++++---- 7 files changed, 242 insertions(+), 23 deletions(-) create mode 100644 assets/overworld/fence-bottom-left.svg create mode 100644 assets/overworld/fence-bottom-right.svg create mode 100644 assets/overworld/fence-horiz.svg create mode 100644 assets/overworld/fence-top-left.svg create mode 100644 assets/overworld/fence-top-right.svg create mode 100644 assets/overworld/fence-vert.svg diff --git a/assets/overworld/fence-bottom-left.svg b/assets/overworld/fence-bottom-left.svg new file mode 100644 index 0000000..2c388b0 --- /dev/null +++ b/assets/overworld/fence-bottom-left.svg @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/assets/overworld/fence-bottom-right.svg b/assets/overworld/fence-bottom-right.svg new file mode 100644 index 0000000..9a59cae --- /dev/null +++ b/assets/overworld/fence-bottom-right.svg @@ -0,0 +1,9 @@ + + + + + + + diff --git a/assets/overworld/fence-horiz.svg b/assets/overworld/fence-horiz.svg new file mode 100644 index 0000000..a5c1f01 --- /dev/null +++ b/assets/overworld/fence-horiz.svg @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + diff --git a/assets/overworld/fence-top-left.svg b/assets/overworld/fence-top-left.svg new file mode 100644 index 0000000..f11ef20 --- /dev/null +++ b/assets/overworld/fence-top-left.svg @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/assets/overworld/fence-top-right.svg b/assets/overworld/fence-top-right.svg new file mode 100644 index 0000000..e716150 --- /dev/null +++ b/assets/overworld/fence-top-right.svg @@ -0,0 +1,9 @@ + + + + + + + diff --git a/assets/overworld/fence-vert.svg b/assets/overworld/fence-vert.svg new file mode 100644 index 0000000..5c0d88c --- /dev/null +++ b/assets/overworld/fence-vert.svg @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + diff --git a/src/activities/overworld/worldgen.rs b/src/activities/overworld/worldgen.rs index 427ba72..8b07e31 100644 --- a/src/activities/overworld/worldgen.rs +++ b/src/activities/overworld/worldgen.rs @@ -28,6 +28,13 @@ pub enum Tile { bottom: bool }, + Fence { + left: bool, + right: bool, + top: bool, + bottom: bool + }, + House { texture: TextureHandle, door: bool @@ -71,6 +78,38 @@ impl Tile { vec![ASSETS.overworld.grass, path_texture] }, + Self::Fence { + left, + right, + top, + bottom + } => { + let path_texture = match (left, right, top, bottom) { + (true, true, false, false) => ASSETS.overworld.fence_horiz, + (false, false, true, true) => ASSETS.overworld.fence_vert, + + (true, false, true, false) => ASSETS.overworld.fence_top_left, + (true, false, false, true) => ASSETS.overworld.fence_bottom_left, + (false, true, true, false) => ASSETS.overworld.fence_top_right, + (false, true, false, true) => ASSETS.overworld.fence_bottom_right, + + (true, true, true, false) + | (true, true, false, true) + | (true, false, true, true) + | (false, true, true, true) => unimplemented!(), + + (true, true, true, true) => unimplemented!(), + + (true, false, false, false) + | (false, true, false, false) + | (false, false, true, false) + | (false, false, false, true) => panic!("We don't have no dead ends"), + (false, false, false, false) => panic!("I think you meant grass?!?") + }; + + vec![ASSETS.overworld.grass, path_texture] + }, + Self::House { texture, .. } => { vec![ASSETS.overworld.grass, *texture] } @@ -123,15 +162,6 @@ impl Chunk { // TODO real worldgen // for the time being we just copy this pre-made house block into the chunk - fn path(left: bool, right: bool, top: bool, bottom: bool) -> Tile { - Tile::Path { - left, - right, - top, - bottom - } - } - fn house(texture: TextureHandle) -> Tile { Tile::House { texture, @@ -139,14 +169,42 @@ impl Chunk { } } - let path_horiz = path(true, true, false, false); - let path_vert = path(false, false, true, true); - let path_crossing = path(true, true, true, true); + let path_horiz = Tile::Path { + left: true, + right: true, + top: false, + bottom: false + }; + let path_vert = Tile::Path { + left: false, + right: false, + top: true, + bottom: true + }; + let path_crossing = Tile::Path { + left: true, + right: true, + top: true, + bottom: true + }; + let fence_horiz = Tile::Fence { + left: true, + right: true, + top: false, + bottom: false + }; + let fence_vert = Tile::Fence { + left: false, + right: false, + top: true, + bottom: true + }; let grass = Tile::Grass; let block = [ [ - path_crossing, + path_horiz, + path_horiz, path_horiz, path_horiz, path_horiz, @@ -159,7 +217,31 @@ impl Chunk { path_crossing ], [ - path_vert, + Tile::Fence { + left: false, + right: true, + top: false, + bottom: true + }, + fence_horiz, + fence_horiz, + fence_horiz, + fence_horiz, + fence_horiz, + fence_horiz, + fence_horiz, + fence_horiz, + fence_horiz, + Tile::Fence { + left: true, + right: false, + top: false, + bottom: true + }, + path_vert + ], + [ + fence_vert, grass, grass, grass, @@ -169,10 +251,11 @@ impl Chunk { grass, grass, grass, + fence_vert, path_vert ], [ - path_vert, + fence_vert, grass, grass, house(ASSETS.overworld.house_roof_mid_left), @@ -182,10 +265,11 @@ impl Chunk { grass, grass, grass, + fence_vert, path_vert ], [ - path_vert, + fence_vert, grass, house(ASSETS.overworld.house_roof_left), house(ASSETS.overworld.house_mid_window), @@ -195,10 +279,11 @@ impl Chunk { grass, grass, grass, + fence_vert, path_vert ], [ - path_vert, + fence_vert, grass, house(ASSETS.overworld.house_bottom_left), house(ASSETS.overworld.house_bottom_door), @@ -208,27 +293,63 @@ impl Chunk { grass, grass, grass, + fence_vert, path_vert ], [ - path_vert, + fence_vert, grass, grass, - path(false, true, true, false), + Tile::Path { + left: false, + right: true, + top: true, + bottom: false + }, path_horiz, path_horiz, path_horiz, path_horiz, path_horiz, path_horiz, - path(true, false, true, true) + fence_vert, + Tile::Path { + left: true, + right: false, + top: true, + bottom: true + } ], [ - path_vert, grass, grass, grass, grass, grass, grass, grass, grass, grass, - path_vert + fence_vert, grass, grass, grass, grass, grass, grass, grass, grass, + grass, fence_vert, path_vert ], [ - path_vert, grass, grass, grass, grass, grass, grass, grass, grass, grass, + fence_vert, grass, grass, grass, grass, grass, grass, grass, grass, + grass, fence_vert, path_vert + ], + [ + Tile::Fence { + left: false, + right: true, + top: true, + bottom: false + }, + fence_horiz, + fence_horiz, + fence_horiz, + fence_horiz, + fence_horiz, + fence_horiz, + fence_horiz, + fence_horiz, + fence_horiz, + Tile::Fence { + left: true, + right: false, + top: true, + bottom: false + }, path_vert ] ];