Initial tile push with item cycle
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
use crate::game::PIXEL_RATIO;
|
||||
use bevy::prelude::*;
|
||||
use rand::prelude::*;
|
||||
|
||||
#[derive(Component)]
|
||||
#[require(Transform)]
|
||||
pub struct Ambulatory {
|
||||
speed: f32,
|
||||
}
|
||||
|
||||
#[derive(Bundle)]
|
||||
pub struct Citizen {
|
||||
walker: Ambulatory,
|
||||
sprite: Sprite,
|
||||
transform: Transform,
|
||||
}
|
||||
|
||||
impl Citizen {
|
||||
pub fn new(asset_server: &Res<AssetServer>, position: Vec3) -> Self {
|
||||
Citizen {
|
||||
walker: Ambulatory { speed: 64. },
|
||||
sprite: Sprite {
|
||||
image: asset_server.load("character.png"),
|
||||
..Default::default()
|
||||
},
|
||||
transform: Transform::from_translation(position).with_scale(Vec3::splat(PIXEL_RATIO)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn citizen_movement(
|
||||
mut query: Query<(&Ambulatory, &mut Transform), With<Ambulatory>>,
|
||||
) {
|
||||
for (citizen, mut transform) in query.iter_mut() {
|
||||
if random::<f32>() < 0.66666{
|
||||
continue;
|
||||
}
|
||||
let mut direction = Vec2::ZERO;
|
||||
|
||||
direction.y += rand::random::<f32>();
|
||||
direction.y -= rand::random::<f32>();
|
||||
direction.x -= rand::random::<f32>();
|
||||
direction.x += rand::random::<f32>();
|
||||
|
||||
if direction.length() > 0.0 {
|
||||
direction.x = direction.x.round();
|
||||
direction.y = direction.y.round();
|
||||
|
||||
let movement = direction * citizen.speed;
|
||||
transform.translation.x += movement.x;
|
||||
transform.translation.y += movement.y;
|
||||
|
||||
if direction.x > 0.0 {
|
||||
transform.scale.x = PIXEL_RATIO.abs();
|
||||
} else if direction.x < 0.0 {
|
||||
transform.scale.x = -PIXEL_RATIO.abs();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user