Skip to content

Commit

Permalink
Add rest indicators as "projectiles"
Browse files Browse the repository at this point in the history
  • Loading branch information
benfrankel committed Aug 21, 2024
1 parent 3d378d0 commit f4fb8cf
Show file tree
Hide file tree
Showing 13 changed files with 66 additions and 7 deletions.
2 changes: 1 addition & 1 deletion assets/config/actor.ron
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

attack: Attack(color: Srgba(Srgba(red: 0.855, green: 0.576, blue: 0.800, alpha: 1.000))),
health: Health(max: 100, current: 100),
deck: Deck(cards: ["step", "pair"]),
deck: Deck(cards: ["step", "pair", "half_rest"]),
),
},

Expand Down
24 changes: 20 additions & 4 deletions assets/config/card.ron
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,11 @@
max_level: 4,

action: Heal,
action_modifier: CardActionModifier(heal_flat: 10, immunity: 0.7),
action_modifier: CardActionModifier(
heal_flat: 10,
immunity: 0.5,
attack: Attack(projectile: Some("eighth_rest"), offset: 8.0),
),
),
"quarter_rest": Card(
name: "Quarter Rest",
Expand All @@ -316,7 +320,11 @@
weight: 0.7,

action: Heal,
action_modifier: CardActionModifier(heal_flat: 30, immunity: 0.8),
action_modifier: CardActionModifier(
heal_flat: 30,
immunity: 0.666,
attack: Attack(projectile: Some("quarter_rest"), offset: 8.0),
),
),
"half_rest": Card(
name: "Half Rest",
Expand All @@ -328,7 +336,11 @@
weight: 0.6,

action: Heal,
action_modifier: CardActionModifier(heal_percent: 25, immunity: 0.9),
action_modifier: CardActionModifier(
heal_percent: 25,
immunity: 0.833,
attack: Attack(projectile: Some("half_rest"), offset: 8.0),
),
),
"whole_rest": Card(
name: "Whole Rest",
Expand All @@ -339,7 +351,11 @@
weight: 0.5,

action: Heal,
action_modifier: CardActionModifier(heal_percent: 50, immunity: 1.0),
action_modifier: CardActionModifier(
heal_percent: 50,
immunity: 1.0,
attack: Attack(projectile: Some("whole_rest"), offset: 8.0),
),
),
}
)
20 changes: 20 additions & 0 deletions assets/config/projectile.ron
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
(
projectiles: {
"eighth_rest": Projectile(
name: "Eighth Rest",
texture: "image/projectile/eighth_rest.png",
lifetime: 0.55,
),
"quarter_rest": Projectile(
name: "Quarter Rest",
texture: "image/projectile/quarter_rest.png",
lifetime: 0.716,
),
"half_rest": Projectile(
name: "Half Rest",
texture: "image/projectile/half_rest.png",
lifetime: 0.9,
),
"whole_rest": Projectile(
name: "Whole Rest",
texture: "image/projectile/whole_rest.png",
lifetime: 1.05,
),
"eighth_note": Projectile(
name: "Eighth Note",

Expand Down
Binary file modified assets/image/card/icon/eighth_rest.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/image/card/icon/icons.aseprite
Binary file not shown.
Binary file added assets/image/projectile/eighth_rest.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/image/projectile/half_rest.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/image/projectile/projectiles.aseprite
Binary file not shown.
Binary file added assets/image/projectile/quarter_rest.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/image/projectile/whole_rest.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions src/game/card/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use serde::Deserialize;
use serde::Serialize;

use crate::game::actor::attack::Attack;
use crate::game::actor::attack::AttackController;
use crate::game::actor::health::Health;
use crate::game::actor::movement::Movement;
use crate::game::actor::player::IsPlayer;
Expand Down Expand Up @@ -93,10 +94,19 @@ impl FromWorld for CardActionMap {
|In((entity, modifier)): In<(Entity, CardActionModifier)>,
world: &mut World| {
let mut entity = r!(world.get_entity_mut(entity));

let mut health = r!(entity.get_mut::<Health>());
health.current += modifier.heal_flat;
health.current += modifier.heal_percent / 100.0 * health.max;

let mut attack_controller = r!(entity.get_mut::<AttackController>());
attack_controller.aim = Vec2::Y;
attack_controller.fire = true;

let mut attack = r!(entity.get_mut::<Attack>());
attack.projectile_key = modifier.attack.projectile_key.clone();
attack.offset = modifier.attack.offset;

// Player actor has extra benefits:
if entity.contains::<IsPlayer>() {
if modifier.contact_damage > 0.0 {
Expand Down
1 change: 1 addition & 0 deletions src/game/card/attack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ fn attack_on_beat(

attack.power = attack_on_beat.0.power;
attack.force = attack_on_beat.0.force;
attack.offset = attack_on_beat.0.offset;
attack.projectile_key = attack_on_beat.0.projectile_key.clone();
attack.multi_shot = attack_on_beat.0.multi_shot.clone();
attack.child_projectile = attack_on_beat.0.child_projectile.clone();
Expand Down
16 changes: 14 additions & 2 deletions src/game/combat/projectile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ impl Config for ProjectileConfig {
}

#[derive(Reflect, Serialize, Deserialize, Clone)]
#[serde(deny_unknown_fields)]
pub struct Projectile {
pub name: String,

Expand All @@ -88,12 +89,16 @@ pub struct Projectile {
#[serde(default = "one")]
pub spawn_sfx_volume: f64,

/// Lifetime in seconds, not beats.
/// Lifetime in seconds (not beats).
pub lifetime: f32,
/// Hitbox radius.
#[serde(default)]
pub radius: f32,
#[serde(default)]
pub speed: f32,
#[serde(default)]
pub damage: f32,
#[serde(default)]
pub knockback: f32,
#[serde(default)]
pub pierce: usize,
Expand Down Expand Up @@ -168,7 +173,14 @@ pub fn projectile(
(
RigidBody::Kinematic,
Collider::circle(projectile.radius),
CollisionLayers::new(GameLayer::Projectile, target_layers),
CollisionLayers::new(
if projectile.radius == 0.0 {
LayerMask::NONE
} else {
GameLayer::Projectile.into()
},
target_layers,
),
Sensor,
LockedAxes::ROTATION_LOCKED,
LinearVelocity(projectile.speed * force),
Expand Down

0 comments on commit f4fb8cf

Please sign in to comment.