diff --git a/src/main.rs b/src/main.rs index 4e5e685..26fd977 100644 --- a/src/main.rs +++ b/src/main.rs @@ -66,6 +66,7 @@ fn main() { player_movement, player_regen, player_attack, + attack_movement, enemy_movement, change_enemy_color, ), diff --git a/src/player.rs b/src/player.rs index e273112..c9a82a2 100644 --- a/src/player.rs +++ b/src/player.rs @@ -78,43 +78,39 @@ pub fn player_movement( #[allow(clippy::type_complexity)] pub fn player_attack( keys: Res>, - mut set: ParamSet<( - Query<&mut Transform, With>, - Query<&Transform, With>, - )>, - mut player_query: Query<&mut Player>, + mut player_query: Query<(&Transform, &mut Player), With>, mut commands: Commands, asset_server: Res, ) { - let mut player = player_query.single_mut(); + let (transform, mut player) = player_query.single_mut(); + let attack_position = transform.translation + (transform.rotation * Vec3::Y * 100.); - for player_transform in set.p1().iter_mut() { - let attack_position = - player_transform.translation + (player_transform.rotation * Vec3::Y * 100.); + if keys.just_pressed(KeyCode::Enter) { + commands + .spawn(SpriteBundle { + texture: asset_server.load("attacks/stone_cannon.png"), + transform: Transform { + scale: Vec3::splat(0.3), + translation: attack_position, + rotation: transform.rotation, + }, + ..default() + }) + .insert(Attack { + velocity: 20., + damage: 20., + }); - if keys.just_pressed(KeyCode::Enter) { - commands - .spawn(SpriteBundle { - texture: asset_server.load("attacks/stone_cannon.png"), - transform: Transform { - scale: Vec3::splat(0.3), - translation: attack_position, - rotation: player_transform.rotation, - }, - ..default() - }) - .insert(Attack { - velocity: 10., - damage: 20., - }); - - player.mana -= 1.; - } + player.mana -= 1.; } +} - for mut attack_transform in set.p0().iter_mut() { - let direction = attack_transform.rotation * Vec3::Y; - attack_transform.translation += direction * 20.; +pub fn attack_movement(mut attack_query: Query<(&mut Transform, Option<&Attack>), With>) { + for (mut transform, attack) in attack_query.iter_mut() { + if let Some(attack) = attack { + let direction = transform.rotation * Vec3::Y; + transform.translation += direction * attack.velocity; + } } }