From aa973a0d468330acf3cdc2007d33997895584135 Mon Sep 17 00:00:00 2001 From: Frank Mayer Date: Fri, 12 Jul 2024 03:12:24 +0200 Subject: [PATCH] bugfixes --- src/ext.rs | 29 +++++++++++++++++++++++++++++ src/gameplay/enemy.rs | 6 +++++- src/gameplay/projectile.rs | 7 ++++++- 3 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 src/ext.rs diff --git a/src/ext.rs b/src/ext.rs new file mode 100644 index 0000000..3198fee --- /dev/null +++ b/src/ext.rs @@ -0,0 +1,29 @@ +/* + * Mageanoid - A computer game + * Copyright (C) 2024 Frank Mayer + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +use bevy::prelude::{Vec2, Vec3}; + +pub trait IntoVec3 { + fn xyz(self) -> Vec3; +} + +impl IntoVec3 for Vec2 { + fn xyz(self) -> Vec3 { + Vec3::new(self.x, self.y, 0.0) + } +} diff --git a/src/gameplay/enemy.rs b/src/gameplay/enemy.rs index e788f4b..6dcdeb5 100644 --- a/src/gameplay/enemy.rs +++ b/src/gameplay/enemy.rs @@ -163,6 +163,7 @@ fn projectile_hit_enemy( #[cfg(feature = "storage")] mut score: ResMut>, #[cfg(not(feature = "storage"))] mut score: ResMut, ) { + let mut fx = false; for (projectile_entity, projectile_transform) in projectile_q.iter() { for (enemy_entity, enemy_transform, mut enemy_health) in enemy_q.iter_mut() { if projectile_transform @@ -174,7 +175,10 @@ fn projectile_hit_enemy( commands.entity(enemy_entity).despawn_recursive(); score.increase(1); } - enemy_hit_fx(&mut commands, &asset_server); + if !fx { + fx = true; + enemy_hit_fx(&mut commands, &asset_server); + } commands.entity(projectile_entity).despawn_recursive(); } } diff --git a/src/gameplay/projectile.rs b/src/gameplay/projectile.rs index d492402..f9c25c2 100644 --- a/src/gameplay/projectile.rs +++ b/src/gameplay/projectile.rs @@ -19,6 +19,7 @@ use bevy::audio::PlaybackMode; use bevy::prelude::*; +use crate::ext::IntoVec3; use crate::gameplay::anim::*; use crate::gameplay::movement::*; use crate::state::{AppState, ON_EXIT_GAMEPLAY}; @@ -52,7 +53,11 @@ impl ProjectileBundle { animated_sprite: AnimatedSpriteBundle { sprite: SpriteBundle { texture, - transform: Transform::from_scale(Vec3::splat(1.0)).with_translation(position), + transform: Transform { + translation: position + (direction * 64.0).xyz(), + rotation: Quat::IDENTITY, + scale: Vec3::ONE, + }, ..default() }, atlas: TextureAtlas {