Skip to content

Commit

Permalink
fix rock
Browse files Browse the repository at this point in the history
  • Loading branch information
aratama committed Jan 28, 2025
1 parent 223eac4 commit 1d915ec
Show file tree
Hide file tree
Showing 13 changed files with 214 additions and 276 deletions.
5 changes: 3 additions & 2 deletions assets/registry.actor.ron
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ ActorRegistry(
strategies: {}
),
"Rock": (
collider: Ball(5.0),
collider: Ball(16.0),
move_force: 0.0,
jump: 0.0,
linear_damping: 60.0,
Expand Down Expand Up @@ -571,7 +571,8 @@ ActorRegistry(
[None, None, None, None, None, None, None, None],
[None, None, None, None, None, None, None, None],
],
strategies: {}
strategies: {},
impact_radius: 24.0,
),
"Bomb": (
collider: Ball(5.0),
Expand Down
2 changes: 1 addition & 1 deletion assets/registry.game.ron
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ GameRegistry(


debug_wands: [
["DualCast", "Levitation", "MagicBolt"],
["RockFall"],
["QuickCast", "QuickCast", "TripleCast", "Slash", "Slash", "MagicBolt"],
["DualCast", "Levitation", "MagicBolt"],
["DualCast", "Dash", "Jump", "Lantern"]
Expand Down
65 changes: 35 additions & 30 deletions src/actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ pub mod bomb;
pub mod book_shelf;
pub mod chest;
pub mod chicken;
pub mod rock;
pub mod stone_lantern;
pub mod witch;

Expand Down Expand Up @@ -160,7 +159,6 @@ pub struct ActorAppearanceSprite;
#[derive(Component, Reflect, Debug, Clone, Deserialize)]
#[require(
HomingTarget,
Vertical,
StateScoped<GameState>(||StateScoped(GameState::InGame)),
Visibility,
Damping,
Expand Down Expand Up @@ -1359,6 +1357,7 @@ pub fn spawn_actor(
asset_server: &Res<AssetServer>,
registry: &Registry,
position: Vec2,
vertical: f32,
mut actor: Actor,
) -> Entity {
let actor_type = actor.actor_type.clone();
Expand All @@ -1371,6 +1370,10 @@ pub fn spawn_actor(
Name::new(format!("{:?}", &actor.actor_type)),
actor,
Transform::from_translation(position.extend(0.0)),
Vertical {
v: vertical,
..default()
},
Counter::default(),
match props.collider {
ActorCollider::Ball(radius) => Collider::ball(radius),
Expand All @@ -1391,39 +1394,41 @@ pub fn spawn_actor(
));
}

parent.spawn(ActorSpriteGroup).with_children(|parent| {
// 浮遊効果の輪
parent.spawn((
ActorLevitationEffect,
AseSpriteSlice {
aseprite: registry.assets.atlas.clone(),
name: "levitation".into(),
},
Transform::from_xyz(0.0, 0.0, -0.0002),
));

// 本体
parent.spawn((
ActorAppearanceSprite,
CounterAnimated,
AseSpriteAnimation {
aseprite: asset_server.load(props.aseprite.clone()),
animation: Animation::default().with_tag(props.animations.idle_r.clone()),
},
Transform::from_xyz(0.0, 0.0, 0.0),
));

if actor_type == ActorType::new("Witch") {
parent
.spawn((ActorSpriteGroup, Transform::from_xyz(0.0, vertical, 0.0)))
.with_children(|parent| {
// 浮遊効果の輪
parent.spawn((
WitchWandSprite,
ActorLevitationEffect,
AseSpriteSlice {
aseprite: registry.assets.atlas.clone(),
name: "wand_cypress".into(),
name: "levitation".into(),
},
Transform::from_xyz(0.0, 4.0, -0.0001),
Transform::from_xyz(0.0, 0.0, -0.0002),
));
}
});

// 本体
parent.spawn((
ActorAppearanceSprite,
CounterAnimated,
AseSpriteAnimation {
aseprite: asset_server.load(props.aseprite.clone()),
animation: Animation::default().with_tag(props.animations.idle_r.clone()),
},
Transform::from_xyz(0.0, 0.0, 0.0),
));

if actor_type == ActorType::new("Witch") {
parent.spawn((
WitchWandSprite,
AseSpriteSlice {
aseprite: registry.assets.atlas.clone(),
name: "wand_cypress".into(),
},
Transform::from_xyz(0.0, 4.0, -0.0001),
));
}
});
});

if actor_type == ActorType::new("Witch") {
Expand Down
145 changes: 0 additions & 145 deletions src/actor/rock.rs

This file was deleted.

13 changes: 11 additions & 2 deletions src/cast.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::actor::get_default_actor;
use crate::actor::jump_actor;
use crate::actor::rock::spawn_falling_rock;
use crate::actor::spawn_actor;
use crate::actor::Actor;
use crate::actor::ActorFireState;
use crate::actor::ActorGroup;
Expand Down Expand Up @@ -349,7 +350,15 @@ pub fn cast_spell(
}
SpellCast::RockFall => {
let position = actor_position + actor.pointer;
spawn_falling_rock(&mut commands, registry, position);
let actor = get_default_actor(&registry, &ActorType::new("Rock"));
spawn_actor(
&mut commands,
asset_server,
registry,
position,
100.0,
actor,
);
se.send(SEEvent::pos(STATUS2, position));
}
SpellCast::Fireball => {
Expand Down
1 change: 1 addition & 0 deletions src/component/metamorphosis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ pub fn cast_metamorphosis(
&asset_server,
&registry,
position,
0.0,
dest_actor,
);

Expand Down
47 changes: 33 additions & 14 deletions src/component/vertical.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use crate::set::FixedUpdateGameActiveSet;
use crate::{
actor::Actor, entity::impact::SpawnImpact, registry::Registry, set::FixedUpdateGameActiveSet,
};
use bevy::prelude::*;

/// 子エンティティのスプライトに付与し
Expand Down Expand Up @@ -28,23 +30,40 @@ impl Vertical {
Self {
velocity,
gravity,
just_landed: false,
v: 0.0,
..default()
}
}
}

fn fall(mut child_query: Query<&mut Vertical>) {
for mut vertical in child_query.iter_mut() {
let next = vertical.v + vertical.velocity;
if next <= 0.0 {
vertical.just_landed = 0.0 < vertical.v;
vertical.v = 0.0;
vertical.velocity = 0.0;
} else {
vertical.just_landed = false;
vertical.v = next;
vertical.velocity += vertical.gravity;
fn fall(
registry: Registry,
mut child_query: Query<(Entity, &Actor, &mut Vertical, &Transform)>,
mut spawn: EventWriter<SpawnImpact>,
) {
for (entity, actor, mut vertical, transform) in child_query.iter_mut() {
if 0.0 < vertical.v {
let next = vertical.v + vertical.velocity;
if next <= 0.0 {
vertical.just_landed = 0.0 < vertical.v;
vertical.v = 0.0;
vertical.velocity = 0.0;
if vertical.just_landed {
let props = registry.get_actor_props(&actor.actor_type);
if 0.0 < props.impact_radius {
let position = transform.translation.truncate();
spawn.send(SpawnImpact {
position,
radius: props.impact_radius,
impulse: 16.0,
owner: Some(entity),
});
}
}
} else {
vertical.just_landed = false;
vertical.v = next;
vertical.velocity += vertical.gravity;
}
}
}
}
Expand Down
Loading

0 comments on commit 1d915ec

Please sign in to comment.