item flashing
This commit is contained in:
@@ -1,24 +1,20 @@
|
||||
use crate::constants::TILE_SIZE;
|
||||
use crate::constants::*;
|
||||
use crate::entities::item::{
|
||||
create_decorated_item, spawn_prefab, FoodType, Item, ItemBundle, ItemDecorations, ItemType,
|
||||
Material, MiscPrefab, Quality, WoodType,
|
||||
};
|
||||
use crate::entities::item::{spawn_prefab, MiscPrefab};
|
||||
use crate::entities::shared_components::Ambulatory;
|
||||
use crate::world::tiles::tilemap;
|
||||
use crate::world::VisibleGameEntity;
|
||||
use bevy::ecs::spawn;
|
||||
use bevy::prelude::*;
|
||||
use bevy_rand::prelude::*;
|
||||
use rand::Rng;
|
||||
|
||||
// Pig bundle
|
||||
#[derive(Bundle)]
|
||||
pub struct Pig {
|
||||
ambulatory: Ambulatory,
|
||||
sprite: Sprite,
|
||||
transform: Transform,
|
||||
visibility: Visibility,
|
||||
drop_timer: PigDropTimer, // NEW
|
||||
drop_timer: PigDropTimer,
|
||||
}
|
||||
|
||||
impl Pig {
|
||||
@@ -43,11 +39,9 @@ impl Pig {
|
||||
}
|
||||
}
|
||||
|
||||
// Timer component for pigs dropping items
|
||||
#[derive(Component, Deref, DerefMut)]
|
||||
pub struct PigDropTimer(pub Timer);
|
||||
|
||||
// Spawn a handful of pigs
|
||||
pub fn spawn_pigs(
|
||||
mut commands: Commands,
|
||||
asset_server: Res<AssetServer>,
|
||||
@@ -70,12 +64,12 @@ pub fn spawn_pigs(
|
||||
}
|
||||
}
|
||||
|
||||
// System: make pigs drop items every 5 seconds
|
||||
pub fn pig_drop_system(
|
||||
mut commands: Commands,
|
||||
asset_server: Res<AssetServer>,
|
||||
time: Res<Time>,
|
||||
mut pigs: Query<(&mut PigDropTimer, &Transform)>,
|
||||
mut tilemap: ResMut<tilemap::TileMap>,
|
||||
) {
|
||||
for (mut timer, transform) in &mut pigs {
|
||||
timer.tick(time.delta());
|
||||
@@ -87,6 +81,7 @@ pub fn pig_drop_system(
|
||||
&asset_server,
|
||||
MiscPrefab::RawMeat,
|
||||
transform.translation,
|
||||
&mut tilemap,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user