Skip to content

Commit

Permalink
Fix level sizes and black borders
Browse files Browse the repository at this point in the history
  • Loading branch information
rewin123 committed Dec 6, 2023
1 parent 070cfbe commit e86bc5f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 19 deletions.
6 changes: 3 additions & 3 deletions src/sheep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::f32::consts::PI;
use bevy::{pbr::ExtendedMaterial, prelude::*, gltf::GltfMesh, render::{render_resource::PrimitiveTopology, mesh::Indices}};
use rand::Rng;

use crate::{physics::Velocity, player::Bark, sprite_material::{SpriteExtension, create_plane_mesh}, get_sprite_rotation};
use crate::{physics::Velocity, player::Bark, sprite_material::{SpriteExtension, create_plane_mesh}, get_sprite_rotation, test_level::TEST_LEVEL_SIZE};

const SHEEP_PATH: &str = "test/sheep.png";

Expand Down Expand Up @@ -109,9 +109,9 @@ pub fn setup(
});

//spawn sheeps
let r = 10.0;
let r = TEST_LEVEL_SIZE;
let mut rng = rand::thread_rng();
let sheep_count = 10;
let sheep_count = 100;

for _ in 0..sheep_count {
let x = rng.gen_range(-r..r);
Expand Down
44 changes: 28 additions & 16 deletions src/test_level.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
use bevy::{pbr::CascadeShadowConfigBuilder, prelude::*};
use bevy::{pbr::CascadeShadowConfigBuilder, prelude::*, core_pipeline::clear_color::ClearColorConfig};
use rand::prelude::*;
use std::f32::consts::PI;

use crate::{player::SpawnPlayer, safe_area::SafeArea, torch::SpawnTorch, sprite_material::create_plane_mesh, get_sprite_rotation};

const TREE_PATH: &str = "test/pine.png";

pub const TEST_LEVEL_SIZE: f32 = 30.0;

pub fn setup(
mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>,
Expand All @@ -20,23 +22,14 @@ pub fn setup(
hdr: true,
..default()
},
..default()
});

//green plane
commands.spawn(PbrBundle {
mesh: meshes.add(Mesh::from(shape::Plane {
size: 300.0,
camera_3d : Camera3d {
clear_color: ClearColorConfig::Custom(Color::BLACK),
..default()
})),
material: materials.add(StandardMaterial {
base_color: Color::rgb(0.0, 0.5, 0.0),
..default()
}),
transform: Transform::from_xyz(0.0, 0.0, 0.0),
},
..default()
});


//spawn sun
let mut cascades = CascadeShadowConfigBuilder::default();
cascades.maximum_distance = 100.0;
Expand All @@ -63,7 +56,7 @@ pub fn setup(
);
let tree_texture: Handle<Image> = asset_server.load(TREE_PATH);

let r = 10.0;
let r = TEST_LEVEL_SIZE;
let mut rng = rand::thread_rng();

//spawn trees
Expand All @@ -75,9 +68,13 @@ pub fn setup(
..default()
});

let tree_r = 50.0;
let tree_r = r * 2.0;
let cut_r = r + 10.0;

let tree_area_size = PI * tree_r * tree_r - PI * cut_r * cut_r;
let tree_per_meter = 1.0;
let tree_count = (tree_area_size * tree_per_meter) as usize;

for _ in 0..tree_count {
let x = rng.gen_range(-tree_r..tree_r);
let y = 0.0;
Expand All @@ -98,6 +95,21 @@ pub fn setup(
});
}


//green plane
commands.spawn(PbrBundle {
mesh: meshes.add(Mesh::from(shape::Plane {
size: tree_r * 2.0,
..default()
})),
material: materials.add(StandardMaterial {
base_color: Color::rgb(0.0, 0.5, 0.0),
..default()
}),
transform: Transform::from_xyz(0.0, 0.0, 0.0),
..default()
});

spawn_player_event.send(SpawnPlayer {
position: Vec3::new(-r - 2.0, 0.0, 0.0),
});
Expand Down

0 comments on commit e86bc5f

Please sign in to comment.