Skip to content

Commit

Permalink
homing
Browse files Browse the repository at this point in the history
  • Loading branch information
aratama committed Nov 16, 2024
1 parent 476146c commit e3add26
Show file tree
Hide file tree
Showing 11 changed files with 119 additions and 70 deletions.
14 changes: 2 additions & 12 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,6 @@ on:
branches: ["main"]

env:
# update with the name of the main binary
# binary: bevy_github_ci_template
# add_binaries_to_github_release: true
#itch_target: <itch.io-username>/<game-name>

# Before enabling LFS, please take a look at GitHub's documentation for costs and quota limits:
# https://docs.github.com/en/repositories/working-with-files/managing-large-files/about-storage-and-bandwidth-usage
use_git_lfs: false

jobs:
Expand All @@ -24,16 +17,13 @@ jobs:
steps:
- uses: olegtarasov/[email protected]
id: get_version

- uses: actions/checkout@v4
with:
lfs: ${{ env.use_git_lfs }}

- uses: dtolnay/rust-toolchain@stable
with:
targets: wasm32-unknown-unknown

- name: install target wasm
run: rustup target add wasm32-unknown-unknown

- name: install trunk
run: cargo install --locked trunk

Expand Down
7 changes: 7 additions & 0 deletions src/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,11 @@ pub fn cast_spell(
light_intensity,
light_radius,
light_color_hlsa,
homing: actor.homing,
},
);
actor.bullet_speed_buff_factor = 0.0;
actor.homing = 0.0;
wand.shift();

return props.cast_delay as i32;
Expand Down Expand Up @@ -133,6 +135,11 @@ pub fn cast_spell(
}
return delay;
}
SpellCast::Homing => {
wand.shift();
actor.homing = (actor.homing + 0.01).max(-0.1).min(0.1);
return props.cast_delay as i32;
}
}
} else {
wand.shift();
Expand Down
4 changes: 4 additions & 0 deletions src/controller/remote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ pub enum RemoteMessage {
light_intensity: f32,
light_radius: f32,
light_color_hlsa: [f32; 4],
homing: f32,
},
// ダメージを受けたことを通知します
Hit {
Expand Down Expand Up @@ -257,6 +258,7 @@ fn receive_events(
3.0,
&audio,
false,
[None, None, None, None],
);
info!("Remote player spawned: {}", uuid);
}
Expand All @@ -276,6 +278,7 @@ fn receive_events(
light_intensity,
light_radius,
light_color_hlsa,
homing,
} => {
spawn_bullet(
&mut commands,
Expand All @@ -295,6 +298,7 @@ fn receive_events(
light_intensity,
light_radius,
light_color_hlsa,
homing,
},
);
}
Expand Down
1 change: 1 addition & 0 deletions src/enemy/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ pub fn spawn_basic_enemy<T: Component>(
filter: ENTITY_GROUP | WALL_GROUP | WITCH_GROUP,
current_wand: 0,
bullet_speed_buff_factor: 0.0,
homing: 0.0,
wands: [
Some(Wand {
wand_type: WandType::CypressWand,
Expand Down
1 change: 1 addition & 0 deletions src/entity/actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ pub struct Actor {
pub bullet_speed_buff_factor: f32,
// マルチキャストで待機中の弾丸
// pub multicasts: Vec<SpawnBulletProps>,
pub homing: f32,
}

impl Actor {
Expand Down
33 changes: 32 additions & 1 deletion src/entity/bullet.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::asset::GameAssets;
use crate::command::GameCommand;
use crate::controller::enemy::Enemy;
use crate::controller::remote::{RemoteMessage, RemotePlayer};
use crate::entity::actor::Actor;
use crate::entity::breakable::Breakable;
Expand Down Expand Up @@ -33,6 +34,7 @@ pub struct Bullet {
damage: i32,
impulse: f32,
owner: Option<Uuid>,
homing: f32,
}

#[derive(Bundle)]
Expand Down Expand Up @@ -73,6 +75,7 @@ pub fn spawn_bullets(
light_intensity: props.light_intensity,
light_radius: props.light_radius,
light_color_hlsa: props.light_color_hlsa,
homing: props.homing,
})
.unwrap();
writer.send(ClientMessage::Binary(serialized));
Expand All @@ -93,6 +96,7 @@ pub struct SpawnBulletProps {
pub light_intensity: f32,
pub light_radius: f32,
pub light_color_hlsa: [f32; 4],
pub homing: f32,
}

/// 指定された位置、方向、弾丸種別などから実際にエンティティを生成します
Expand All @@ -112,6 +116,7 @@ pub fn spawn_bullet(
damage: spawning.damage,
impulse: spawning.impulse,
owner: spawning.owner,
homing: spawning.homing,
},
EntityDepth,
AsepriteSliceBundle {
Expand Down Expand Up @@ -178,6 +183,32 @@ fn despawn_bullet_by_lifetime(
}
}

fn bullet_homing(
mut bullet_query: Query<(&mut Bullet, &mut Transform, &mut Velocity)>,
enemy_query: Query<&Transform, (With<Enemy>, Without<Bullet>)>,
) {
for (bullet, mut bullet_transform, mut velocity) in bullet_query.iter_mut() {
if 0.0 < bullet.homing {
let bullet_position = bullet_transform.translation.truncate();
let mut enemies = Vec::from_iter(enemy_query.iter());
enemies.sort_by(|a, b| {
let x = a.translation.truncate().distance(bullet_position);
let y = b.translation.truncate().distance(bullet_position);
x.total_cmp(&y)
});
if let Some(nearest) = enemies.first() {
let bullet_angle = velocity.linvel.to_angle();
let target_angle = (nearest.translation.truncate() - bullet_position).to_angle();
let angle_diff = target_angle - bullet_angle;
let next_angle = angle_diff.signum() * angle_diff.abs().min(bullet.homing);
velocity.linvel =
Vec2::from_angle(bullet_angle + next_angle) * velocity.linvel.length();
bullet_transform.rotation = Quat::from_rotation_z(velocity.linvel.to_angle());
}
}
}
}

fn bullet_collision(
mut commands: Commands,
mut bullet_query: Query<(Entity, &mut Bullet, &Transform, &Velocity)>,
Expand Down Expand Up @@ -333,7 +364,7 @@ impl Plugin for BulletPlugin {
fn build(&self, app: &mut App) {
app.add_systems(
FixedUpdate,
(despawn_bullet_by_lifetime, bullet_collision)
(despawn_bullet_by_lifetime, bullet_collision, bullet_homing)
.run_if(in_state(GameState::InGame))
.before(PhysicsSet::SyncBackend),
);
Expand Down
52 changes: 5 additions & 47 deletions src/entity/witch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ use crate::entity::breakable::{Breakable, BreakableSprite};
use crate::entity::EntityDepth;
use crate::hud::life_bar::{spawn_life_bar, LifeBarResource};
use crate::interaction_sensor::spawn_interaction_sensor;
use crate::spell::SpellType;
use crate::states::GameState;
use crate::wand::{Wand, WandType};
use crate::wand::Wand;
use crate::wand_props::wand_to_props;
use bevy::prelude::*;
use bevy_aseprite_ultra::prelude::*;
Expand Down Expand Up @@ -48,6 +47,8 @@ pub fn spawn_witch<T: Component>(
footstep_audio: &Res<Audio>,

interaction: bool,

wands: [Option<Wand>; 4],
) {
let audio_instance = footstep_audio
.play(assets.taiikukan.clone())
Expand Down Expand Up @@ -76,51 +77,8 @@ pub fn spawn_witch<T: Component>(
filter: ENTITY_GROUP | WALL_GROUP | WITCH_GROUP | ENEMY_GROUP,
current_wand: 0,
bullet_speed_buff_factor: 0.0,
wands: [
Some(Wand {
wand_type: WandType::CypressWand,
slots: [
Some(SpellType::MagicBolt),
None,
None,
None,
None,
None,
None,
None,
],
index: 0,
}),
Some(Wand {
wand_type: WandType::CypressWand,
slots: [
Some(SpellType::PurpleBolt),
None,
None,
None,
None,
None,
None,
None,
],
index: 0,
}),
Some(Wand {
wand_type: WandType::KeyWand,
slots: [
Some(SpellType::Heal),
None,
None,
None,
None,
None,
None,
None,
],
index: 0,
}),
None,
],
homing: 0.0,
wands,
},
Witch,
controller,
Expand Down
1 change: 1 addition & 0 deletions src/spell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ pub enum SpellType {
BulletSpeedDoown,
DualCast,
TripleCast,
Homing,
}
18 changes: 14 additions & 4 deletions src/spell_props.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ pub enum SpellCast {
MultipleCast {
amount: u32,
},
Homing,
}

/// 呪文の基礎情報
Expand Down Expand Up @@ -197,6 +198,18 @@ pub fn spell_to_props(spell: SpellType) -> SpellProps {
SpellType::BulletSpeedDoown => BULLET_SPEED_DOWN,
SpellType::DualCast => DUAL_CAST,
SpellType::TripleCast => TRIPLE_CAST,
SpellType::Homing => SpellProps {
name: Dict {
ja: "ホーミング",
en: "Homing",
},
description: Dict { ja: "次に発射する魔法弾が敵に向かって追尾します。",
en: "The next magic bullet you fire will home in on the enemy." },
mana_drain: 20,
cast_delay: 5,
icon: "spell_triple_cast",
cast: SpellCast::Homing,
}
}
}

Expand Down Expand Up @@ -249,10 +262,6 @@ pub fn get_spell_appendix(cast: SpellCast, language: Languages) -> String {
light_radius: _,
light_color_hlsa: _,
} => {




format!(
"{}:{} {}:{}\n{}:{} {}:{}\n{}:{} {}:{}",
DAMAGE.get(language),
Expand All @@ -274,5 +283,6 @@ pub fn get_spell_appendix(cast: SpellCast, language: Languages) -> String {
}
SpellCast::BulletSpeedUpDown { delta: _ } => format!(""),
SpellCast::MultipleCast { amount: _ } => format!(""),
SpellCast::Homing => format!(""),
}
}
7 changes: 2 additions & 5 deletions src/ui/inventory.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
use std::collections::HashSet;

use crate::entity::dropped_item::spawn_dropped_item;
use crate::ui::floating::{Floating, FloatingContent};
use crate::ui::item_information::{SpellInformation, SpellInformationItem};
use crate::{
asset::GameAssets, constant::MAX_ITEMS_IN_INVENTORY, controller::player::Player,
entity::actor::Actor, inventory_item::InventoryItem, states::GameState,
};
use bevy::prelude::*;
use bevy::render::view::visibility;
use bevy_aseprite_ultra::prelude::{AsepriteSlice, AsepriteSliceUiBundle};

use super::item_information::{SpellInformation, SpellInformationItem};
use std::collections::HashSet;

#[derive(Component)]
struct InventoryItemSlot(usize);
Expand Down
Loading

0 comments on commit e3add26

Please sign in to comment.