File cleanup
This commit is contained in:
Binary file not shown.
|
Before Width: | Height: | Size: 266 B After Width: | Height: | Size: 266 B |
@@ -0,0 +1,2 @@
|
|||||||
|
pub mod pig;
|
||||||
|
pub mod rabbit;
|
||||||
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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 Rabbit {
|
||||||
|
ambulatory: Ambulatory,
|
||||||
|
sprite: Sprite,
|
||||||
|
transform: Transform,
|
||||||
|
visibility: Visibility,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Rabbit {
|
||||||
|
pub fn new(asset_server: &Res<AssetServer>, position: Vec3) -> Self {
|
||||||
|
Rabbit {
|
||||||
|
ambulatory: Ambulatory {
|
||||||
|
walk_speed: 1.,
|
||||||
|
run_speed: 6.,
|
||||||
|
target: None,
|
||||||
|
current_path: None,
|
||||||
|
path_index: 0,
|
||||||
|
step_recovery: 0,
|
||||||
|
},
|
||||||
|
sprite: Sprite {
|
||||||
|
image: asset_server.load("rabbit.png"),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
transform: Transform::from_translation(position).with_scale(Vec3::splat(PIXEL_RATIO)),
|
||||||
|
visibility: Visibility::Hidden,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn spawn_rabbits(
|
||||||
|
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 rabbits
|
||||||
|
for _ in 0..15 {
|
||||||
|
let cit = commands
|
||||||
|
.spawn(Rabbit::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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
pub mod livestock;
|
||||||
|
pub mod sentient;
|
||||||
|
pub mod shared_components;
|
||||||
|
pub mod shared_systems;
|
||||||
|
|
||||||
|
pub use shared_systems::*;
|
||||||
@@ -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 Dorf {
|
||||||
|
ambulatory: Ambulatory,
|
||||||
|
sprite: Sprite,
|
||||||
|
transform: Transform,
|
||||||
|
visibility: Visibility,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Dorf {
|
||||||
|
pub fn new(asset_server: &Res<AssetServer>, position: Vec3) -> Self {
|
||||||
|
Dorf {
|
||||||
|
ambulatory: Ambulatory {
|
||||||
|
walk_speed: 5.,
|
||||||
|
run_speed: 6.,
|
||||||
|
target: None,
|
||||||
|
current_path: None,
|
||||||
|
path_index: 0,
|
||||||
|
step_recovery: 0,
|
||||||
|
},
|
||||||
|
sprite: Sprite {
|
||||||
|
image: asset_server.load("dorf.png"),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
transform: Transform::from_translation(position).with_scale(Vec3::splat(PIXEL_RATIO)),
|
||||||
|
visibility: Visibility::Hidden,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn spawn_dorfs(
|
||||||
|
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 dorfs
|
||||||
|
for _ in 0..40 {
|
||||||
|
let cit = commands
|
||||||
|
.spawn(Dorf::new(
|
||||||
|
&asset_server,
|
||||||
|
Vec3::new(
|
||||||
|
rng.random_range(-8.0f32..8.0f32).round(),
|
||||||
|
rng.random_range(-8.0f32..8.0f32).round(),
|
||||||
|
35.0,
|
||||||
|
) * TILE_SIZE,
|
||||||
|
))
|
||||||
|
.id();
|
||||||
|
commands.entity(cit).insert(VisibleGameEntity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
pub mod dorf;
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
use bevy::prelude::*;
|
||||||
|
|
||||||
|
#[derive(Component)]
|
||||||
|
pub struct Ambulatory {
|
||||||
|
pub walk_speed: f32,
|
||||||
|
pub run_speed: f32,
|
||||||
|
pub current_path: Option<Vec<Vec3>>,
|
||||||
|
pub path_index: usize,
|
||||||
|
pub target: Option<Vec3>,
|
||||||
|
pub step_recovery: u32,
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
pub mod ambulatory;
|
||||||
|
pub use ambulatory::*; // replace with explicit imports/exports eventually
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
pub mod pathfinding;
|
||||||
@@ -2,7 +2,8 @@ use crate::constants::TILE_SIZE;
|
|||||||
use crate::tile::TileMap;
|
use crate::tile::TileMap;
|
||||||
use crate::{
|
use crate::{
|
||||||
constants::*,
|
constants::*,
|
||||||
tilemap::{ChunkMap, VisibleGameEntity, CHUNK_SIZE},
|
entities::shared_components::Ambulatory,
|
||||||
|
tilemap::{ChunkMap, CHUNK_SIZE},
|
||||||
};
|
};
|
||||||
use bevy::{math::ivec3, prelude::*};
|
use bevy::{math::ivec3, prelude::*};
|
||||||
use bevy_rand::prelude::*;
|
use bevy_rand::prelude::*;
|
||||||
@@ -12,45 +13,6 @@ use std::{
|
|||||||
process::exit,
|
process::exit,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Bundle)]
|
|
||||||
pub struct Citizen {
|
|
||||||
ambulatory: Ambulatory,
|
|
||||||
sprite: Sprite,
|
|
||||||
transform: Transform,
|
|
||||||
visibility: Visibility,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Citizen {
|
|
||||||
pub fn new(asset_server: &Res<AssetServer>, position: Vec3) -> Self {
|
|
||||||
Citizen {
|
|
||||||
ambulatory: Ambulatory {
|
|
||||||
walk_speed: 0.,
|
|
||||||
run_speed: 6.,
|
|
||||||
target: None,
|
|
||||||
current_path: None,
|
|
||||||
path_index: 0,
|
|
||||||
step_recovery: 0,
|
|
||||||
},
|
|
||||||
sprite: Sprite {
|
|
||||||
image: asset_server.load("dorf.png"),
|
|
||||||
..Default::default()
|
|
||||||
},
|
|
||||||
transform: Transform::from_translation(position).with_scale(Vec3::splat(PIXEL_RATIO)),
|
|
||||||
visibility: Visibility::Hidden,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Component)]
|
|
||||||
pub struct Ambulatory {
|
|
||||||
pub walk_speed: f32,
|
|
||||||
pub run_speed: f32,
|
|
||||||
pub current_path: Option<Vec<Vec3>>,
|
|
||||||
pub path_index: usize,
|
|
||||||
pub target: Option<Vec3>,
|
|
||||||
pub step_recovery: u32,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Eq, PartialEq, Debug)]
|
#[derive(Clone, Eq, PartialEq, Debug)]
|
||||||
struct PathNode {
|
struct PathNode {
|
||||||
position: IVec3,
|
position: IVec3,
|
||||||
@@ -74,15 +36,12 @@ pub struct PathfindingPlugin;
|
|||||||
|
|
||||||
impl Plugin for PathfindingPlugin {
|
impl Plugin for PathfindingPlugin {
|
||||||
fn build(&self, app: &mut App) {
|
fn build(&self, app: &mut App) {
|
||||||
app.add_systems(
|
app.add_systems(FixedUpdate, (update_wandering_targets, movement).chain());
|
||||||
FixedUpdate,
|
|
||||||
(update_citizen_wandering_targets, citizen_movement).chain(),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_citizen_wandering_targets(
|
pub fn update_wandering_targets(
|
||||||
mut query: Query<(&mut Ambulatory, &Transform)>,
|
mut query: Query<(&mut Ambulatory, &Transform)>, // add a 'with' here when behaviours are implemented
|
||||||
tilemap: Res<TileMap>,
|
tilemap: Res<TileMap>,
|
||||||
chunk_map: Res<ChunkMap>,
|
chunk_map: Res<ChunkMap>,
|
||||||
mut rng_q: Query<&mut Entropy<WyRand>, With<Global>>,
|
mut rng_q: Query<&mut Entropy<WyRand>, With<Global>>,
|
||||||
@@ -134,19 +93,12 @@ pub fn update_citizen_wandering_targets(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn citizen_movement(
|
pub fn movement(mut query: Query<(&mut Ambulatory, &mut Transform)>, tilemap: Res<TileMap>) {
|
||||||
mut query: Query<(
|
|
||||||
&mut Ambulatory,
|
|
||||||
&mut Transform,
|
|
||||||
&mut Visibility,
|
|
||||||
&mut Sprite,
|
|
||||||
)>,
|
|
||||||
tilemap: Res<TileMap>,
|
|
||||||
) {
|
|
||||||
query
|
query
|
||||||
.par_iter_mut()
|
.par_iter_mut()
|
||||||
.for_each(|(mut ambulatory, mut transform, _, _)| {
|
.for_each(|(mut ambulatory, mut transform)| {
|
||||||
let current_pos = transform.translation;
|
let current_pos = transform.translation;
|
||||||
|
// Apply gravity if in air
|
||||||
if !is_standable_tile(&tilemap, current_pos.as_ivec3()) {
|
if !is_standable_tile(&tilemap, current_pos.as_ivec3()) {
|
||||||
transform.translation.z -= TILE_SIZE;
|
transform.translation.z -= TILE_SIZE;
|
||||||
return;
|
return;
|
||||||
@@ -432,25 +384,3 @@ fn reconstruct_path(came_from: HashMap<IVec3, IVec3>, mut current: IVec3) -> Vec
|
|||||||
path.reverse();
|
path.reverse();
|
||||||
path
|
path
|
||||||
}
|
}
|
||||||
pub fn spawn_citizens(
|
|
||||||
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 citizens
|
|
||||||
for _ in 0..10 {
|
|
||||||
let cit = commands
|
|
||||||
.spawn(Citizen::new(
|
|
||||||
&asset_server,
|
|
||||||
Vec3::new(
|
|
||||||
rng.random_range(-8.0f32..8.0f32).round(),
|
|
||||||
rng.random_range(-8.0f32..8.0f32).round(),
|
|
||||||
35.0,
|
|
||||||
) * TILE_SIZE,
|
|
||||||
))
|
|
||||||
.id();
|
|
||||||
commands.entity(cit).insert(VisibleGameEntity);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+5
-3
@@ -2,9 +2,9 @@ use bevy::prelude::*;
|
|||||||
use bevy_rand::prelude::*;
|
use bevy_rand::prelude::*;
|
||||||
|
|
||||||
mod camera;
|
mod camera;
|
||||||
mod citizen;
|
|
||||||
mod constants;
|
mod constants;
|
||||||
mod cursor;
|
mod cursor;
|
||||||
|
mod entities;
|
||||||
mod game;
|
mod game;
|
||||||
mod item;
|
mod item;
|
||||||
mod tile;
|
mod tile;
|
||||||
@@ -36,13 +36,15 @@ fn main() {
|
|||||||
))
|
))
|
||||||
.insert_resource(ClearColor(Color::srgb(0., 0., 0.)))
|
.insert_resource(ClearColor(Color::srgb(0., 0., 0.)))
|
||||||
.add_plugins(tilemap::TilemapPlugin)
|
.add_plugins(tilemap::TilemapPlugin)
|
||||||
.add_plugins(citizen::PathfindingPlugin)
|
.add_plugins(entities::pathfinding::PathfindingPlugin)
|
||||||
.add_systems(
|
.add_systems(
|
||||||
Startup,
|
Startup,
|
||||||
(
|
(
|
||||||
camera::spawn_panning_camera,
|
camera::spawn_panning_camera,
|
||||||
cursor::setup_cursor,
|
cursor::setup_cursor,
|
||||||
citizen::spawn_citizens,
|
entities::sentient::dorf::spawn_dorfs,
|
||||||
|
entities::livestock::pig::spawn_pigs,
|
||||||
|
entities::livestock::rabbit::spawn_rabbits,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.add_systems(
|
.add_systems(
|
||||||
|
|||||||
+1
-1
@@ -398,7 +398,7 @@ fn generate_chunk_weathering_and_precipitation(// mut commands: Commands,
|
|||||||
// TODO: Generate weathering and precipitation
|
// TODO: Generate weathering and precipitation
|
||||||
// Temperature and humidity
|
// Temperature and humidity
|
||||||
// Erosion
|
// Erosion
|
||||||
// Hadley lines etc
|
// Hadley lines/cells etc
|
||||||
// Biomes
|
// Biomes
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user