From bc14d6e69c942efd8cb9e27b78cd99aab46eb0ed Mon Sep 17 00:00:00 2001 From: SecretPocketCat Date: Mon, 10 Apr 2023 18:16:44 +0200 Subject: [PATCH 1/4] both enemies killed on hit --- src/enemy/mod.rs | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/src/enemy/mod.rs b/src/enemy/mod.rs index 5ec2005..8402526 100644 --- a/src/enemy/mod.rs +++ b/src/enemy/mod.rs @@ -127,6 +127,7 @@ fn spawn_enemy(mut ev_r: EventReader, mut cmd: Commands, tex: Res< .insert(EcholocationHitColor(Color::CRIMSON)) .insert(FollowEchoOnHit) .insert(Killable) + .insert(Killer) .insert(StopOnCollision::::new()) .insert(Speed(220.)) .insert(MovementDirection::default()) @@ -198,22 +199,31 @@ pub(super) fn enemy_hit( .iter() .filter_map(|ev| check_collision_start_pair(ev, &killable_q, &killer_q)) { - enemy_ev_w.send(EnemyEv::Killed); + let mut killable = vec![coll.0]; - cmd.entity(coll.0) - .try_insert(ColliderDisabled) - .try_insert(get_relative_scale_anim( - Vec2::ZERO.extend(1.), - 300, - TweenDoneAction::DespawnSelfRecursive, - )); + if killer_q.contains(coll.0) && killer_q.contains(coll.1) { + // both are killable + killable.push(coll.1); + } - if let Ok((t, color, dir)) = wave_data_q.get(coll.0) { - cmd.spawn(Wave { - position: t.translation() + dir.map_or(Vec2::ZERO, |d| d.0 * 50.).extend(0.), - radius: 80., - color: color.map_or(COL_ENEMY, |c| c.0), - }); + enemy_ev_w.send(EnemyEv::Killed); + + for e in killable.iter() { + cmd.entity(*e) + .try_insert(ColliderDisabled) + .try_insert(get_relative_scale_anim( + Vec2::ZERO.extend(1.), + 300, + TweenDoneAction::DespawnSelfRecursive, + )); + + if let Ok((t, color, dir)) = wave_data_q.get(*e) { + cmd.spawn(Wave { + position: t.translation() + dir.map_or(Vec2::ZERO, |d| d.0 * 50.).extend(0.), + radius: 80., + color: color.map_or(COL_ENEMY, |c| c.0), + }); + } } } } From 431302e66b4e7ff4379996299c7a78039c566513 Mon Sep 17 00:00:00 2001 From: SecretPocketCat Date: Mon, 10 Apr 2023 18:19:45 +0200 Subject: [PATCH 2/4] smaller player --- src/player/player.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/player/player.rs b/src/player/player.rs index c98dbed..c5e7fd4 100644 --- a/src/player/player.rs +++ b/src/player/player.rs @@ -34,7 +34,7 @@ pub(super) fn spawn_player( textures: Res, entry_q: Query<&Transform, Added>, ) { - let radius = 20.; + let radius = 12.; if let Some(transform) = entry_q.iter().next() { bevy::log::info!("Spawning player"); From 6753d0239513e382d3af16213029df6bc10603fe Mon Sep 17 00:00:00 2001 From: SecretPocketCat Date: Mon, 10 Apr 2023 18:25:37 +0200 Subject: [PATCH 3/4] better follower rotation --- src/enemy/mod.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/enemy/mod.rs b/src/enemy/mod.rs index 8402526..d52159f 100644 --- a/src/enemy/mod.rs +++ b/src/enemy/mod.rs @@ -103,18 +103,18 @@ fn spawn_enemy(mut ev_r: EventReader, mut cmd: Commands, tex: Res< EnemyType::FollowPing => { let half_width = 15.; let height = 30.; - let btm = 5.; + let offset = 15.; sprite_bundle.texture = tex.charge.clone(); sprite_bundle.sprite.custom_size = Some(Vec2::new(half_width * 2.25, height * 1.125)); - sprite_bundle.sprite.anchor = Anchor::BottomCenter; - sprite_bundle.transform.translation.y -= height / 2.; + // sprite_bundle.sprite.anchor = Anchor::BottomCenter; + sprite_bundle.transform.translation.y -= height / 2. + offset; let verts = vec![ - (-half_width, btm), - (half_width, btm), - (0., height), - (-half_width, btm), + (-half_width, -offset), + (half_width, -offset), + (0., height - offset), + (-half_width, -offset), ] .iter() .map(|(x, y)| Vec2::new(*x, *y)) From 592f17e90b7d5aa21d38d38d20ad29ca65bc9e0a Mon Sep 17 00:00:00 2001 From: SecretPocketCat Date: Mon, 10 Apr 2023 18:41:49 +0200 Subject: [PATCH 4/4] lower follow spawns --- src/level/map.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/level/map.rs b/src/level/map.rs index 4da1832..eb08208 100644 --- a/src/level/map.rs +++ b/src/level/map.rs @@ -1,4 +1,4 @@ -use bevy::prelude::{IVec2, Resource}; +use bevy::prelude::{warn, IVec2, Resource}; use bracket_algorithm_traits::prelude::{BaseMap, SmallVec}; use bracket_geometry::prelude::{DistanceAlg, Point}; use bracket_pathfinding::prelude::DijkstraMap; @@ -183,13 +183,13 @@ pub fn generate(width: i32, height: i32, difficulty: usize) -> Option { && ADJACENTS .iter() .all(|[dx, dy]| map.xy(x + dx, y + dy) == &TileType::Floor) - && rand::random::() > 0.5 + && rand::random::() > 0.3 { *map.xy_mut(x, y) = TileType::Enemy(EnemyType::Spiky); } - // Next, have a 5% chance of spawning following ones. - if map.xy(x, y) == &TileType::Floor && rand::random::() > 0.95 { + // Next, have a 3% chance of spawning following ones. + if map.xy(x, y) == &TileType::Floor && rand::random::() > 0.97 { let idx = map.xy_idx(x, y); if map.get_pathing_distance(idx, start_idx) > 2.0 { *map.xy_mut(x, y) = TileType::Enemy(EnemyType::FollowPing); @@ -199,7 +199,7 @@ pub fn generate(width: i32, height: i32, difficulty: usize) -> Option { } } // Remove followers if there's too many - let max_follow_spawns: usize = difficulty.pow(2); + let max_follow_spawns = (difficulty as f32).powf(1.3) as usize; while follow_spawns.len() > max_follow_spawns { let (x, y) = follow_spawns.swap_remove(rand::random::() % follow_spawns.len()); *map.xy_mut(x, y) = TileType::Floor;