Skip to content

Commit

Permalink
bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
tsukinoko-kun committed Jul 12, 2024
1 parent e594807 commit aa973a0
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
29 changes: 29 additions & 0 deletions src/ext.rs
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.
*/

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)
}
}
6 changes: 5 additions & 1 deletion src/gameplay/enemy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ fn projectile_hit_enemy(
#[cfg(feature = "storage")] mut score: ResMut<Persistent<Score>>,
#[cfg(not(feature = "storage"))] mut score: ResMut<Score>,
) {
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
Expand All @@ -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();
}
}
Expand Down
7 changes: 6 additions & 1 deletion src/gameplay/projectile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit aa973a0

Please sign in to comment.