Skip to content

Commit

Permalink
Scale projectiles, and actor health
Browse files Browse the repository at this point in the history
  • Loading branch information
benfrankel committed Jul 29, 2024
1 parent db01f5f commit 2e9785c
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 26 deletions.
9 changes: 7 additions & 2 deletions assets/config/actor.ron
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
),

attack: Attack(color: Srgba(Srgba(red: 0.929, green: 0.557, blue: 0.576, alpha: 1.000))),
health: Health(current: 10, max: 10),
deck: Deck(cards: ["step", "step", "pair"]),
),

Expand All @@ -86,6 +87,7 @@
),

attack: Attack(color: Srgba(Srgba(red: 0.694, green: 0.529, blue: 0.788, alpha: 1.000))),
health: Health(current: 15, max: 15),
deck: Deck(cards: ["step"]),
),

Expand All @@ -108,7 +110,8 @@
),

attack: Attack(color: Srgba(Srgba(red: 0.424, green: 0.694, blue: 0.725, alpha: 1.000))),
deck: Deck(cards: ["step", "pair"]),
health: Health(current: 25, max: 25),
deck: Deck(cards: ["step", "quarter_note"]),
),

"green": Actor(
Expand All @@ -129,7 +132,8 @@
),

attack: Attack(color: Srgba(Srgba(red: 0.557, green: 0.722, blue: 0.518, alpha: 1.000))),
deck: Deck(cards: ["pair"]),
health: Health(current: 40, max: 40),
deck: Deck(cards: ["half_note"]),
),

"yellow": Actor(
Expand All @@ -151,6 +155,7 @@
),

attack: Attack(color: Srgba(Srgba(red: 0.827, green: 0.761, blue: 0.537, alpha: 1.000))),
health: Health(current: 60, max: 60),
deck: Deck(cards: ["step", "whole_note", "quarter_rest"]),
),
},
Expand Down
32 changes: 17 additions & 15 deletions assets/config/projectile.ron
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
(
// TODO: Tune stats for each projectile.
projectiles: {
"eighth_note": Projectile(
name: "Eighth Note",
Expand All @@ -8,11 +7,11 @@
spawn_sfx: "audio/sfx/Projectile Hits Enemy.ogg",
spawn_sfx_volume: 0.5,

lifetime: 1,
lifetime: 0.5,
radius: 3.0,
speed: 20.0,
damage: 2.0,
knockback: 0.5,
speed: 80.0,
damage: 6.0,
knockback: 1.0,
),
"quarter_note": Projectile(
name: "Quarter Note",
Expand All @@ -23,9 +22,10 @@

lifetime: 1,
radius: 3.0,
speed: 20.0,
damage: 2.0,
knockback: 0.5,
speed: 60.0,
damage: 12.0,
knockback: 3.0,
pierce: 2,
),
"half_note": Projectile(
name: "Half Note",
Expand All @@ -34,11 +34,12 @@
spawn_sfx: "audio/sfx/Projectile Hits Enemy.ogg",
spawn_sfx_volume: 0.5,

lifetime: 1,
lifetime: 2,
radius: 3.0,
speed: 20.0,
damage: 2.0,
knockback: 0.5,
speed: 40.0,
damage: 30.0,
knockback: 10.0,
pierce: 6,
),
"whole_note": Projectile(
name: "Whole Note",
Expand All @@ -47,11 +48,12 @@
spawn_sfx: "audio/sfx/Projectile Hits Enemy.ogg",
spawn_sfx_volume: 0.5,

lifetime: 1,
lifetime: 4,
radius: 3.0,
speed: 20.0,
damage: 2.0,
knockback: 0.5,
damage: 60.0,
knockback: 20.0,
pierce: 100,
),
},
)
16 changes: 14 additions & 2 deletions src/game/actor/attack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ use std::f32::consts::TAU;

use avian2d::prelude::*;
use bevy::prelude::*;
use pyri_state::prelude::*;
use serde::Deserialize;
use serde::Serialize;

use crate::core::pause::Pause;
use crate::core::UpdateSet;
use crate::game::actor::facing::Facing;
use crate::game::actor::faction::Faction;
Expand Down Expand Up @@ -45,7 +47,12 @@ pub struct Attack {
impl Configure for Attack {
fn configure(app: &mut App) {
app.register_type::<Self>();
app.add_systems(Update, apply_attack.in_set(UpdateSet::Spawn));
app.add_systems(
Update,
apply_attack
.in_set(UpdateSet::Spawn)
.run_if(Pause::is_disabled),
);
}
}

Expand Down Expand Up @@ -160,7 +167,12 @@ pub struct AttackController {
impl Configure for AttackController {
fn configure(app: &mut App) {
app.register_type::<Self>();
app.add_systems(Update, reset_attack_controller.in_set(UpdateSet::SyncEarly));
app.add_systems(
Update,
reset_attack_controller
.in_set(UpdateSet::SyncEarly)
.run_if(Pause::is_disabled),
);
}
}

Expand Down
17 changes: 14 additions & 3 deletions src/game/actor/movement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ pub mod smoke;

use avian2d::prelude::*;
use bevy::prelude::*;
use pyri_state::prelude::*;
use serde::Deserialize;
use serde::Serialize;

use crate::core::pause::Pause;
use crate::core::UpdateSet;
use crate::util::prelude::*;

Expand Down Expand Up @@ -38,7 +40,12 @@ pub struct Movement {
impl Configure for Movement {
fn configure(app: &mut App) {
app.register_type::<Self>();
app.add_systems(Update, apply_movement.in_set(UpdateSet::Update));
app.add_systems(
Update,
apply_movement
.in_set(UpdateSet::Update)
.run_if(Pause::is_disabled),
);
}
}

Expand Down Expand Up @@ -79,7 +86,9 @@ impl Configure for MovementController {
app.register_type::<Self>();
app.add_systems(
Update,
reset_movement_controller.in_set(UpdateSet::SyncEarly),
reset_movement_controller
.in_set(UpdateSet::SyncEarly)
.run_if(Pause::is_disabled),
);
}
}
Expand All @@ -99,7 +108,9 @@ impl Configure for OldMovementController {
app.register_type::<Self>();
app.add_systems(
Update,
sync_old_movement_controller.in_set(UpdateSet::SyncLate),
sync_old_movement_controller
.in_set(UpdateSet::SyncLate)
.run_if(Pause::is_disabled),
);
}
}
Expand Down
9 changes: 6 additions & 3 deletions src/game/cleanup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub(super) fn plugin(app: &mut App) {

#[derive(Component, Reflect)]
#[reflect(Component)]
pub struct DespawnOnHit;
pub struct DespawnOnHit(pub usize);

impl Configure for DespawnOnHit {
fn configure(app: &mut App) {
Expand All @@ -29,11 +29,14 @@ impl Configure for DespawnOnHit {
fn apply_despawn_on_hit(
trigger: Trigger<OnHit>,
mut despawn: ResMut<LateDespawn>,
despawn_query: Query<(), With<DespawnOnHit>>,
mut despawn_query: Query<&mut DespawnOnHit>,
) {
let hitbox = trigger.event().0;
if despawn_query.contains(hitbox) {
let mut hits = rq!(despawn_query.get_mut(hitbox));
if hits.0 == 0 {
despawn.recursive(hitbox);
} else {
hits.0 -= 1;
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/game/combat/projectile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ pub struct Projectile {
pub speed: f32,
pub damage: f32,
pub knockback: f32,
#[serde(default)]
pub pierce: usize,
}

fn one() -> f64 {
Expand Down Expand Up @@ -172,7 +174,7 @@ pub fn projectile(
// TODO: Additional cleanup conditions that could be added: entity cap.
// Cleanup:
(
DespawnOnHit,
DespawnOnHit(projectile.pierce),
DespawnRadiusSq::new(200.0),
DespawnOnTimer(Timer::from_seconds(projectile.lifetime, TimerMode::Once)),
),
Expand Down

0 comments on commit 2e9785c

Please sign in to comment.