Skip to content

Commit

Permalink
Added spawning animated enemies
Browse files Browse the repository at this point in the history
  • Loading branch information
PurityLake committed Dec 5, 2023
1 parent c50d1a0 commit 361e665
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/enemy.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use bevy::prelude::*;
use rand::prelude::*;

use crate::state::GameState;
use crate::{animation::EnemyAnimations, state::GameState};

pub struct EnemySpawnPlugin;

Expand Down Expand Up @@ -49,24 +49,28 @@ impl Plugin for EnemySpawnPlugin {
}
}

fn spawn_enemy(time: Res<Time>, mut commands: Commands, mut spawn_data: ResMut<EnemySpawnData>) {
fn spawn_enemy(
time: Res<Time>,
mut commands: Commands,
mut spawn_data: ResMut<EnemySpawnData>,
enemy_anims: Res<EnemyAnimations>,
) {
if spawn_data.curr_time > spawn_data.spawn_time {
if spawn_data.curr_spawned + 1 < spawn_data.max_spawn {
let mut rng = thread_rng();
let anim = enemy_anims.enemies.get("demon").unwrap();
commands.spawn((
SpriteBundle {
sprite: Sprite {
color: Color::rgb(0.5, 0.0, 0.0),
custom_size: Some(Vec2::new(40., 40.)),
..default()
},
SpriteSheetBundle {
texture_atlas: anim.walk_handle.clone(),
transform: Transform::from_translation(Vec3::new(
500.,
rng.gen_range(-250.0..250.0),
0.,
)),
))
.with_scale(Vec3::splat(3.0)),
..default()
},
anim.clone(),
Enemy::default(),
));
spawn_data.curr_spawned += 1;
Expand Down

0 comments on commit 361e665

Please sign in to comment.