Skip to content

Commit

Permalink
Changed textures. Added water level
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyliann committed Dec 2, 2022
1 parent 40a509c commit 8d08a1c
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 17 deletions.
Binary file modified assets/texture_atlas.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 9 additions & 4 deletions src/block_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pub struct BlockType {
pub texture_id: Option<[u32; 6]>, //front, back, top, bottom, right, left
}

pub const BLOCKTYPES: [BlockType; 5] = [
pub const BLOCKTYPES: [BlockType; 6] = [
BlockType {
name: "air",
is_solid: false,
Expand All @@ -13,7 +13,7 @@ pub const BLOCKTYPES: [BlockType; 5] = [
BlockType {
name: "stone",
is_solid: true,
texture_id: Some([0, 0, 0, 0, 0, 0]),
texture_id: Some([1, 1, 1, 1, 1, 1]),
},
BlockType {
name: "bedrock",
Expand All @@ -23,11 +23,16 @@ pub const BLOCKTYPES: [BlockType; 5] = [
BlockType {
name: "grass",
is_solid: true,
texture_id: Some([2, 2, 7, 1, 2, 2]),
texture_id: Some([3, 3, 0, 1, 2, 3]),
},
BlockType {
name: "dirt",
is_solid: true,
texture_id: Some([1, 1, 1, 1, 1, 1]),
texture_id: Some([2, 2, 2, 2, 2, 2]),
},
BlockType {
name: "water",
is_solid: true,
texture_id: Some([207, 207, 207, 207, 207, 207]),
},
];
6 changes: 3 additions & 3 deletions src/voxel_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ use super::block_types;
use super::world;

pub const CHUNK_WIDTH: usize = 16;
pub const CHUNK_HEIGHT: usize = 128;
pub const WORLD_SIZE_IN_CHUNKS: usize = 50;
pub const RENDER_DISTANCE: usize = 16;
pub const CHUNK_HEIGHT: usize = 120;
pub const WORLD_SIZE_IN_CHUNKS: usize = 30;
pub const RENDER_DISTANCE: usize = 8;

pub const VERTICES: [[Vec3; 4]; 6] = [
[
Expand Down
19 changes: 11 additions & 8 deletions src/voxel_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ impl VoxelMap {

pub fn populate_voxel_map(&mut self, chunk_pos: world::ChunkCoord) {
let noise = Perlin::new();
let scale = 200.;
let scale = 300.;
let octave_number = 4;
let start = Key::new(-1., 100., Interpolation::Linear);
let start = Key::new(-1., 5., Interpolation::Linear);
let point1 = Key::new(-0.8, 10., Interpolation::Linear);
let point2 = Key::new(-0.3, 10., Interpolation::Linear);
let point3 = Key::new(-0.2, 40., Interpolation::Linear);
let point4 = Key::new(0., 40., Interpolation::Linear);
let point5= Key::new(0.1, 100., Interpolation::Linear);
let point6= Key::new(0.4, 120., Interpolation::Linear);
let point5= Key::new(0.1, 110., Interpolation::Linear);
// let point6= Key::new(0.4, 120., Interpolation::Linear);
let end = Key::new(1., 127., Interpolation::default());
let spline = Spline::from_vec(vec![start, point1, point2, point3, point4, point5, point6, end]);
let spline = Spline::from_vec(vec![start, point1, point2, point3, point4, point5, end]);

let shifted_x = (chunk_pos.x * CHUNK_WIDTH as i32 + (WORLD_SIZE / 2) as i32) as usize;
let shifted_z = (chunk_pos.z * CHUNK_WIDTH as i32 + (WORLD_SIZE / 2) as i32) as usize;
Expand All @@ -53,14 +53,17 @@ impl VoxelMap {
frequency *= 2.0;
amplitude /= 2.0;
}
let threshold = spline.sample(noise_value/1.875).unwrap().floor() as usize;//((noise_value / 1.875 + 1.0) / 2.0 * CHUNK_HEIGHT as f64).floor() as usize;
let threshold = spline.sample(noise_value/1.875).unwrap().floor() as usize; //((noise_value / 1.875 + 1.0) / 2.0 * CHUNK_HEIGHT as f64).floor() as usize;

for y in 0..CHUNK_HEIGHT {
if y < 50 {
self.voxels[[global_x, y, global_z]] = 5;
}
match y.cmp(&threshold) {
Ordering::Less => {
if y == 0 {
if y == 0 {
self.voxels[[global_x, y, global_z]] = 2;
} else if (threshold - y) == 1 {
} else if (threshold - y) == 1 {
self.voxels[[global_x, y, global_z]] = 4;
} else {
self.voxels[[global_x, y, global_z]] = 1;
Expand Down
5 changes: 3 additions & 2 deletions src/world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ use crate::voxel_map;
use bevy::prelude::*;
use itertools::Itertools;
use ndarray::Array2;
use crate::voxel_map::VoxelMap;

pub const WORLD_SIZE: usize = WORLD_SIZE_IN_CHUNKS * CHUNK_WIDTH;
pub const TEXTURE_ATLAS_SIZE_IN_BLOCKS: u8 = 4;
pub const TEXTURE_ATLAS_SIZE_IN_BLOCKS: u8 = 16;
pub const NORMALIZED_BLOCK_TEXTURE_SIZE: f32 = 1.0 / TEXTURE_ATLAS_SIZE_IN_BLOCKS as f32;

#[derive(Clone, Debug)]
Expand Down Expand Up @@ -54,7 +55,7 @@ impl ChunkMap {
}
}

pub fn spawn_world(mut ev_spawn_chunk: EventWriter<SpawnChunkEvent>) {
pub fn spawn_world(mut ev_spawn_chunk: EventWriter<SpawnChunkEvent>, voxel_map: Res<VoxelMap>) {
for (x, z) in (RENDER_DISTANCE as isize * -1..RENDER_DISTANCE as isize)
.cartesian_product(RENDER_DISTANCE as isize * -1..RENDER_DISTANCE as isize)
{
Expand Down

0 comments on commit 8d08a1c

Please sign in to comment.