Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tweaks #16

Merged
merged 4 commits into from
Apr 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 31 additions & 21 deletions src/enemy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,18 +103,18 @@ fn spawn_enemy(mut ev_r: EventReader<SpawnEnemyEv>, 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))
Expand All @@ -127,6 +127,7 @@ fn spawn_enemy(mut ev_r: EventReader<SpawnEnemyEv>, mut cmd: Commands, tex: Res<
.insert(EcholocationHitColor(Color::CRIMSON))
.insert(FollowEchoOnHit)
.insert(Killable)
.insert(Killer)
.insert(StopOnCollision::<Wall>::new())
.insert(Speed(220.))
.insert(MovementDirection::default())
Expand Down Expand Up @@ -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),
});
}
}
}
}
10 changes: 5 additions & 5 deletions src/level/map.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -183,13 +183,13 @@ pub fn generate(width: i32, height: i32, difficulty: usize) -> Option<Map> {
&& ADJACENTS
.iter()
.all(|[dx, dy]| map.xy(x + dx, y + dy) == &TileType::Floor)
&& rand::random::<f32>() > 0.5
&& rand::random::<f32>() > 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::<f32>() > 0.95 {
// Next, have a 3% chance of spawning following ones.
if map.xy(x, y) == &TileType::Floor && rand::random::<f32>() > 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);
Expand All @@ -199,7 +199,7 @@ pub fn generate(width: i32, height: i32, difficulty: usize) -> Option<Map> {
}
}
// 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::<usize>() % follow_spawns.len());
*map.xy_mut(x, y) = TileType::Floor;
Expand Down
2 changes: 1 addition & 1 deletion src/player/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub(super) fn spawn_player(
textures: Res<TextureAssets>,
entry_q: Query<&Transform, Added<LevelEntry>>,
) {
let radius = 20.;
let radius = 12.;

if let Some(transform) = entry_q.iter().next() {
bevy::log::info!("Spawning player");
Expand Down