Skip to content

Commit

Permalink
Fixing single block height
Browse files Browse the repository at this point in the history
  • Loading branch information
moreirayokoyama committed Jul 26, 2024
1 parent f098434 commit 73702e1
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/game_world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,23 @@ impl GameWorld {
}

pub fn get_height_in_blocks(&self, x: usize) -> f32 {
self.surface_height[x % WORLD_WIDTH].trunc()
let height = self.surface_height[x % WORLD_WIDTH].trunc();
let left_height = if x > 0 {
self.surface_height[x - 1].trunc()
} else {
self.surface_height[WORLD_WIDTH - 1].trunc()
};
let right_height = if x < WORLD_WIDTH {
self.surface_height[x + 1].trunc()
} else {
self.surface_height[0].trunc()
};

if height > left_height && height > right_height {
left_height.max(right_height)
} else {
height
}
}

pub fn get_block_position(x: usize, y: usize) -> Vec2 {
Expand Down

0 comments on commit 73702e1

Please sign in to comment.