Skip to content

Commit

Permalink
Add staggered water texture based on distance from land
Browse files Browse the repository at this point in the history
  • Loading branch information
bglw committed Oct 26, 2024
1 parent d2b92ca commit 7e53dc1
Show file tree
Hide file tree
Showing 8 changed files with 478 additions and 361 deletions.
1 change: 1 addition & 0 deletions truncate_client/img/tile_order
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ CHECKERBOARD_NW
CHECKERBOARD_NE
CHECKERBOARD_SW
CHECKERBOARD_SE
BASE_WATER_WAVES
BASE_WATER
WATER_WITH_LAND_SE
WATER_WITH_LAND_S
Expand Down
Binary file modified truncate_client/img/truncate.aseprite
Binary file not shown.
Binary file modified truncate_client/img/truncate_packed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 8 additions & 2 deletions truncate_client/src/utils/mapper/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use eframe::egui;
use epaint::{hex_color, pos2, Color32, ColorImage, Mesh, Rect, Shape, TextureHandle};
use instant::Duration;
use truncate_core::{
board::{Board, Coordinate, Direction, SignedCoordinate, Square},
board::{Board, BoardDistances, Coordinate, Direction, SignedCoordinate, Square},
reporting::Change,
};

Expand Down Expand Up @@ -123,6 +123,7 @@ pub struct MappedBoard {
forecasted_wind: u8,
incoming_wind: u8,
winds: VecDeque<u8>,
distance_to_land: BoardDistances,
}

impl MappedBoard {
Expand Down Expand Up @@ -156,6 +157,7 @@ impl MappedBoard {
forecasted_wind: 0,
incoming_wind: 0,
winds: vec![0; board.width() + board.height()].into(),
distance_to_land: board.flood_fill_water_from_land(),
};

mapper.remap_texture(ctx, aesthetics, &TimingDepot::default(), None, None, board);
Expand Down Expand Up @@ -313,7 +315,9 @@ impl MappedBoard {
seed_at_coord,
tick,
wind_at_coord,
dest_coord,
coord,
(board.width(), board.height()),
&self.distance_to_land,
);

if square.is_foggy() {
Expand Down Expand Up @@ -934,6 +938,7 @@ impl MappedBoard {

if !board_eq {
memory.prev_board = board.clone();
self.distance_to_land = board.flood_fill_water_from_land();
}
if !selected_tile_eq {
memory.prev_selected_tile = selected_tile;
Expand Down Expand Up @@ -1026,6 +1031,7 @@ impl MappedBoard {
}

let source_coord = SignedCoordinate::new(source_col, source_row);

let square = source_coord
.real_coord()
.and_then(|c| board.get(c).ok())
Expand Down
70 changes: 64 additions & 6 deletions truncate_client/src/utils/tex/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use epaint::{
hex_color, pos2, vec2, Color32, ColorImage, Mesh, Pos2, Rect, Shape, TextureHandle, TextureId,
Vec2,
};
use truncate_core::board::{Coordinate, Direction, Square};
use truncate_core::board::{BoardDistances, Coordinate, Direction, SignedCoordinate, Square};

use crate::{app_outer::TEXTURE_MEASUREMENT, regions::lobby::BoardEditingMode};

Expand Down Expand Up @@ -607,6 +607,54 @@ impl Tex {
.with_piece_texture(tinted, Some(color))
}

fn water(
seed: usize,
source_coord: SignedCoordinate,
board_size: (usize, usize),
distance_to_land: &BoardDistances,
) -> Tex {
let mut added_distance = 0;
let mut lookup_x = 0;
let mut lookup_y = 0;

if source_coord.x < 0 {
added_distance += source_coord.x.unsigned_abs();
} else if source_coord.x as usize >= board_size.0 {
lookup_x = board_size.0 - 1;
added_distance += source_coord.x as usize - lookup_x;
} else {
lookup_x = source_coord.x as _;
}

if source_coord.y < 0 {
added_distance += source_coord.y.unsigned_abs();
} else if source_coord.y as usize >= board_size.1 {
lookup_y = board_size.1 - 1;
added_distance += source_coord.y as usize - lookup_y;
} else {
lookup_y = source_coord.y as _;
}

let dist = distance_to_land
.direct_distance(&Coordinate::new(lookup_x, lookup_y))
.unwrap_or_default()
+ added_distance;

let rand = quickrand(seed + 1982367);
let threshold = match dist {
0 => 100,
1 => 70,
2 => 30,
_ => 0,
};

if threshold > rand {
tiles::BASE_WATER_WAVES
} else {
tiles::BASE_WATER
}
}

/// Determine the tiles to use based on a given square and its neighbors,
/// provided clockwise from northwest.
pub fn terrain(
Expand All @@ -616,7 +664,9 @@ impl Tex {
seed: usize,
tick: u64,
wind_at_coord: u8,
coord: Coordinate,
coord: SignedCoordinate,
board_size: (usize, usize),
distance_to_land: &BoardDistances,
) -> TexLayers {
debug_assert_eq!(neighbors.len(), 8);
if neighbors.len() != 8 {
Expand Down Expand Up @@ -669,7 +719,9 @@ impl Tex {
(Land, Land | WaterOrFog, WaterOrFog) => tiles::WATER_WITH_LAND_W,
(WaterOrFog, Land | WaterOrFog, Land) => tiles::WATER_WITH_LAND_N,
(WaterOrFog, Land, WaterOrFog) => tiles::WATER_WITH_LAND_NW,
(WaterOrFog, WaterOrFog, WaterOrFog) => tiles::BASE_WATER,
(WaterOrFog, WaterOrFog, WaterOrFog) => {
Tex::water(seed, coord, board_size, distance_to_land)
}
},
};

Expand All @@ -680,7 +732,9 @@ impl Tex {
(Land, Land | WaterOrFog, WaterOrFog) => tiles::WATER_WITH_LAND_N,
(WaterOrFog, Land | WaterOrFog, Land) => tiles::WATER_WITH_LAND_E,
(WaterOrFog, Land, WaterOrFog) => tiles::WATER_WITH_LAND_NE,
(WaterOrFog, WaterOrFog, WaterOrFog) => tiles::BASE_WATER,
(WaterOrFog, WaterOrFog, WaterOrFog) => {
Tex::water(seed + 1, coord, board_size, distance_to_land)
}
},
};

Expand All @@ -691,7 +745,9 @@ impl Tex {
(Land, Land | WaterOrFog, WaterOrFog) => tiles::WATER_WITH_LAND_E,
(WaterOrFog, Land | WaterOrFog, Land) => tiles::WATER_WITH_LAND_S,
(WaterOrFog, Land, WaterOrFog) => tiles::WATER_WITH_LAND_SE,
(WaterOrFog, WaterOrFog, WaterOrFog) => tiles::BASE_WATER,
(WaterOrFog, WaterOrFog, WaterOrFog) => {
Tex::water(seed + 2, coord, board_size, distance_to_land)
}
},
};

Expand All @@ -702,7 +758,9 @@ impl Tex {
(Land, Land | WaterOrFog, WaterOrFog) => tiles::WATER_WITH_LAND_S,
(WaterOrFog, Land | WaterOrFog, Land) => tiles::WATER_WITH_LAND_W,
(WaterOrFog, Land, WaterOrFog) => tiles::WATER_WITH_LAND_SW,
(WaterOrFog, WaterOrFog, WaterOrFog) => tiles::BASE_WATER,
(WaterOrFog, WaterOrFog, WaterOrFog) => {
Tex::water(seed + 3, coord, board_size, distance_to_land)
}
},
};

Expand Down
Loading

0 comments on commit 7e53dc1

Please sign in to comment.