Newer
Older
use bevy::math::ivec2;
use bevy::prelude::*;
use crate::entities::animations::{PositionBundle, PositionTween};
use crate::entities::lifecycle::Player;
use crate::entities::timing::ActionCooldown;
use crate::world::level_map::{GridPosition, WORLD_TILE_SIZE};
mut player_query: Query<
(Entity, &mut GridPosition),
(With<Player>, With<ShouldAct>, Without<ActionCooldown>),
>,
npc_query: Query<Entity, (With<Automated>, Without<ShouldAct>)>,
) {
let mut dx = 0;
let mut dy = 0;
if input.pressed(KeyCode::D) || input.pressed(KeyCode::Right) {
if input.pressed(KeyCode::W) || input.pressed(KeyCode::Up) {
if input.pressed(KeyCode::A) || input.pressed(KeyCode::Left) {
if input.pressed(KeyCode::S) || input.pressed(KeyCode::Down) {
if dx != 0 || dy != 0 {
for (entity, mut position) in &mut player_query {
if dx != 0 || dy != 0 {
let current_position = **position;
let next_position = ((current_position.as_ivec2()) + ivec2(dx, dy)).as_uvec2();
**position = next_position;
// .insert_bundle(PositionBundle::from(PositionTween::new(
// next_position.as_vec2() * WORLD_TILE_SIZE + WORLD_TILE_SIZE / 2.0,
// current_position.as_vec2() * WORLD_TILE_SIZE + WORLD_TILE_SIZE / 2.0,
// Duration::from_millis(100),
// )))
.insert(ActionCooldown::from(Duration::from_millis(250)))
.remove::<ShouldAct>();
}
}
for entity in &npc_query {
commands.entity(entity).insert(ShouldAct);
}
}
}
pub fn reset_player_action(
mut commands: Commands,
player_query: Query<Entity, (With<Player>, Without<ShouldAct>)>,
npc_query: Query<(), (With<Automated>, With<ShouldAct>)>,
) {
if npc_query.iter().len() == 0 {
for entity in &player_query {
commands.entity(entity).insert(ShouldAct);