File cleanup
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
use crate::constants::TILE_SIZE;
|
||||
use crate::constants::*;
|
||||
use crate::entities::shared_components::Ambulatory;
|
||||
use crate::tilemap::VisibleGameEntity;
|
||||
use bevy::prelude::*;
|
||||
use bevy_rand::prelude::*;
|
||||
use rand::Rng;
|
||||
|
||||
#[derive(Bundle)]
|
||||
pub struct Pig {
|
||||
ambulatory: Ambulatory,
|
||||
sprite: Sprite,
|
||||
transform: Transform,
|
||||
visibility: Visibility,
|
||||
}
|
||||
|
||||
impl Pig {
|
||||
pub fn new(asset_server: &Res<AssetServer>, position: Vec3) -> Self {
|
||||
Pig {
|
||||
ambulatory: Ambulatory {
|
||||
walk_speed: 25.,
|
||||
run_speed: 6.,
|
||||
target: None,
|
||||
current_path: None,
|
||||
path_index: 0,
|
||||
step_recovery: 0,
|
||||
},
|
||||
sprite: Sprite {
|
||||
image: asset_server.load("pig.png"),
|
||||
..Default::default()
|
||||
},
|
||||
transform: Transform::from_translation(position).with_scale(Vec3::splat(PIXEL_RATIO)),
|
||||
visibility: Visibility::Hidden,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn spawn_pigs(
|
||||
mut commands: Commands,
|
||||
asset_server: Res<AssetServer>,
|
||||
mut rng_q: Query<&mut Entropy<WyRand>, With<Global>>,
|
||||
) {
|
||||
if let Ok(mut rng) = rng_q.single_mut() {
|
||||
// Spawn a handful of pigs
|
||||
for _ in 0..5 {
|
||||
let cit = commands
|
||||
.spawn(Pig::new(
|
||||
&asset_server,
|
||||
Vec3::new(
|
||||
rng.random_range(-32.0f32..32.0f32).round(),
|
||||
rng.random_range(-32.0f32..32.0f32).round(),
|
||||
35.0,
|
||||
) * TILE_SIZE,
|
||||
))
|
||||
.id();
|
||||
commands.entity(cit).insert(VisibleGameEntity);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user