curver ability
This commit is contained in:
@@ -6,7 +6,7 @@
|
|||||||
/*04*/(key:"field medic", ability:Medic, aps:20),
|
/*04*/(key:"field medic", ability:Medic, aps:20),
|
||||||
/*05*/(key:"geisha"),
|
/*05*/(key:"geisha"),
|
||||||
/*06*/(key:"goblin", ability:Arrow, aps:2, ammo:5, range:90, damage:50),
|
/*06*/(key:"goblin", ability:Arrow, aps:2, ammo:5, range:90, damage:50),
|
||||||
/*07*/(key:"green grocer", range:60, ammo:10, damage:25),
|
/*07*/(key:"green grocer", ability:Curver, range:60, ammo:10, damage:25, projectile:"carrot"),
|
||||||
/*08*/(key:"highland hammer thrower", ability:Thrown, aps:2, ammo:10, damage:25, range:80, projectile:"hammer"),
|
/*08*/(key:"highland hammer thrower", ability:Thrown, aps:2, ammo:10, damage:25, range:80, projectile:"hammer"),
|
||||||
/*09*/(key:"legionnaire", ability:Gun, aps:1.5, ammo:25, range:60, damage:13),
|
/*09*/(key:"legionnaire", ability:Gun, aps:1.5, ammo:25, range:60, damage:13),
|
||||||
/*10*/(key:"mig pilot", ability:Missile, ammo:5, range:60, damage:100, controls:Plane),
|
/*10*/(key:"mig pilot", ability:Missile, ammo:5, range:60, damage:100, controls:Plane),
|
||||||
|
|||||||
BIN
assets/models/projectiles/carrot.glb
Normal file
BIN
assets/models/projectiles/carrot.glb
Normal file
Binary file not shown.
199
src/abilities/curver.rs
Normal file
199
src/abilities/curver.rs
Normal file
@@ -0,0 +1,199 @@
|
|||||||
|
use crate::{
|
||||||
|
GameState,
|
||||||
|
abilities::TriggerCurver,
|
||||||
|
billboards::Billboard,
|
||||||
|
heads_database::HeadsDatabase,
|
||||||
|
hitpoints::Hit,
|
||||||
|
loading_assets::GameAssets,
|
||||||
|
physics_layers::GameLayer,
|
||||||
|
tb_entities::EnemySpawn,
|
||||||
|
utils::{auto_rotate::AutoRotation, global_observer, sprite_3d_animation::AnimationTimer},
|
||||||
|
};
|
||||||
|
use avian3d::prelude::*;
|
||||||
|
use bevy::{pbr::NotShadowCaster, prelude::*};
|
||||||
|
use bevy_sprite3d::{Sprite3dBuilder, Sprite3dParams};
|
||||||
|
use std::f32::consts::PI;
|
||||||
|
|
||||||
|
const MAX_SHOT_AGES: f32 = 15.;
|
||||||
|
|
||||||
|
#[derive(Component)]
|
||||||
|
struct CurverProjectile {
|
||||||
|
time: f32,
|
||||||
|
damage: u32,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Resource)]
|
||||||
|
struct ShotAssets {
|
||||||
|
image: Handle<Image>,
|
||||||
|
layout: Handle<TextureAtlasLayout>,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn plugin(app: &mut App) {
|
||||||
|
app.add_systems(OnEnter(GameState::Playing), setup);
|
||||||
|
app.add_systems(
|
||||||
|
Update,
|
||||||
|
(shot_collision, enemy_hit).run_if(in_state(GameState::Playing)),
|
||||||
|
);
|
||||||
|
app.add_systems(
|
||||||
|
FixedUpdate,
|
||||||
|
(update, timeout).run_if(in_state(GameState::Playing)),
|
||||||
|
);
|
||||||
|
|
||||||
|
global_observer!(app, on_trigger_missile);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn setup(mut commands: Commands, assets: Res<GameAssets>, mut sprite_params: Sprite3dParams) {
|
||||||
|
let layout = TextureAtlasLayout::from_grid(UVec2::splat(256), 7, 6, None, None);
|
||||||
|
let texture_atlas_layout = sprite_params.atlas_layouts.add(layout);
|
||||||
|
|
||||||
|
commands.insert_resource(ShotAssets {
|
||||||
|
image: assets.impact_atlas.clone(),
|
||||||
|
layout: texture_atlas_layout,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
fn on_trigger_missile(
|
||||||
|
trigger: Trigger<TriggerCurver>,
|
||||||
|
mut commands: Commands,
|
||||||
|
query_transform: Query<&Transform>,
|
||||||
|
time: Res<Time>,
|
||||||
|
heads_db: Res<HeadsDatabase>,
|
||||||
|
assets: Res<GameAssets>,
|
||||||
|
gltf_assets: Res<Assets<Gltf>>,
|
||||||
|
) {
|
||||||
|
let state = trigger.event().0;
|
||||||
|
|
||||||
|
let rotation = if let Some(target) = state.target {
|
||||||
|
let t = query_transform
|
||||||
|
.get(target)
|
||||||
|
.expect("target must have transform");
|
||||||
|
Transform::from_translation(state.pos)
|
||||||
|
.looking_at(t.translation, Vec3::Y)
|
||||||
|
.rotation
|
||||||
|
} else {
|
||||||
|
state.rot.mul_quat(Quat::from_rotation_y(PI))
|
||||||
|
};
|
||||||
|
|
||||||
|
let head = heads_db.head_stats(state.head);
|
||||||
|
|
||||||
|
let mut t = Transform::from_translation(state.pos).with_rotation(rotation);
|
||||||
|
t.translation += t.forward().as_vec3() * 2.0;
|
||||||
|
|
||||||
|
let mesh = assets.projectiles[format!("{}.glb", head.projectile).as_str()].clone();
|
||||||
|
let asset = gltf_assets.get(&mesh).unwrap();
|
||||||
|
|
||||||
|
commands.spawn((
|
||||||
|
Name::new("projectile-missle"),
|
||||||
|
CurverProjectile {
|
||||||
|
time: time.elapsed_secs(),
|
||||||
|
damage: head.damage,
|
||||||
|
},
|
||||||
|
Collider::capsule_endpoints(0.4, Vec3::new(0., 0., 2.), Vec3::new(0., 0., -2.)),
|
||||||
|
CollisionLayers::new(
|
||||||
|
LayerMask(GameLayer::Projectile.to_bits()),
|
||||||
|
LayerMask(state.target_layer.to_bits() | GameLayer::Level.to_bits()),
|
||||||
|
),
|
||||||
|
Sensor,
|
||||||
|
CollisionEventsEnabled,
|
||||||
|
Visibility::default(),
|
||||||
|
t,
|
||||||
|
children![(
|
||||||
|
Transform::from_rotation(Quat::from_rotation_x(PI / 2.).inverse()),
|
||||||
|
AutoRotation(Quat::from_rotation_x(0.4) * Quat::from_rotation_z(0.3)),
|
||||||
|
SceneRoot(asset.scenes[0].clone()),
|
||||||
|
),],
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
fn enemy_hit(
|
||||||
|
mut commands: Commands,
|
||||||
|
mut collision_event_reader: EventReader<CollisionStarted>,
|
||||||
|
query_shot: Query<&CurverProjectile>,
|
||||||
|
query_npc: Query<&EnemySpawn>,
|
||||||
|
) {
|
||||||
|
for CollisionStarted(e1, e2) in collision_event_reader.read() {
|
||||||
|
if !query_shot.contains(*e1) && !query_shot.contains(*e2) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if !query_npc.contains(*e1) && !query_npc.contains(*e2) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
let (enemy_entity, projectile) = if query_npc.contains(*e1) {
|
||||||
|
(*e1, query_shot.get(*e2))
|
||||||
|
} else {
|
||||||
|
(*e2, query_shot.get(*e1))
|
||||||
|
};
|
||||||
|
|
||||||
|
if let Ok(projectile) = projectile {
|
||||||
|
let damage = projectile.damage;
|
||||||
|
commands.entity(enemy_entity).trigger(Hit { damage });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn update(mut query: Query<&mut Transform, With<CurverProjectile>>) {
|
||||||
|
for mut transform in query.iter_mut() {
|
||||||
|
let forward = transform.forward();
|
||||||
|
transform.translation += forward * 0.5;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn timeout(mut commands: Commands, query: Query<(Entity, &CurverProjectile)>, time: Res<Time>) {
|
||||||
|
let current_time = time.elapsed_secs();
|
||||||
|
|
||||||
|
for (e, CurverProjectile { time, .. }) in query.iter() {
|
||||||
|
if current_time > time + MAX_SHOT_AGES {
|
||||||
|
commands.entity(e).despawn();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn shot_collision(
|
||||||
|
mut commands: Commands,
|
||||||
|
mut collision_event_reader: EventReader<CollisionStarted>,
|
||||||
|
query_shot: Query<&Transform, With<CurverProjectile>>,
|
||||||
|
assets: Res<ShotAssets>,
|
||||||
|
mut sprite_params: Sprite3dParams,
|
||||||
|
) {
|
||||||
|
for CollisionStarted(e1, e2) in collision_event_reader.read() {
|
||||||
|
if !query_shot.contains(*e1) && !query_shot.contains(*e2) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
let shot_entity = if query_shot.contains(*e1) { *e1 } else { *e2 };
|
||||||
|
|
||||||
|
let Ok(shot_pos) = query_shot.get(shot_entity).map(|t| t.translation) else {
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
|
||||||
|
if let Ok(mut entity) = commands.get_entity(shot_entity) {
|
||||||
|
entity.try_despawn();
|
||||||
|
} else {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
let texture_atlas = TextureAtlas {
|
||||||
|
layout: assets.layout.clone(),
|
||||||
|
index: 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
commands
|
||||||
|
.spawn(
|
||||||
|
Sprite3dBuilder {
|
||||||
|
image: assets.image.clone(),
|
||||||
|
pixels_per_metre: 128.,
|
||||||
|
alpha_mode: AlphaMode::Blend,
|
||||||
|
unlit: true,
|
||||||
|
..default()
|
||||||
|
}
|
||||||
|
.bundle_with_atlas(&mut sprite_params, texture_atlas),
|
||||||
|
)
|
||||||
|
.insert((
|
||||||
|
Billboard,
|
||||||
|
Transform::from_translation(shot_pos),
|
||||||
|
NotShadowCaster,
|
||||||
|
AnimationTimer::new(Timer::from_seconds(0.01, TimerMode::Repeating)),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
mod arrow;
|
mod arrow;
|
||||||
|
mod curver;
|
||||||
mod gun;
|
mod gun;
|
||||||
mod healing;
|
mod healing;
|
||||||
mod missile;
|
mod missile;
|
||||||
@@ -39,6 +40,7 @@ pub enum HeadAbility {
|
|||||||
Gun,
|
Gun,
|
||||||
Missile,
|
Missile,
|
||||||
Medic,
|
Medic,
|
||||||
|
Curver,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Reflect, Clone, Copy)]
|
#[derive(Debug, Reflect, Clone, Copy)]
|
||||||
@@ -79,6 +81,8 @@ pub struct TriggerArrow(pub TriggerData);
|
|||||||
pub struct TriggerThrow(pub TriggerData);
|
pub struct TriggerThrow(pub TriggerData);
|
||||||
#[derive(Event, Reflect)]
|
#[derive(Event, Reflect)]
|
||||||
pub struct TriggerMissile(pub TriggerData);
|
pub struct TriggerMissile(pub TriggerData);
|
||||||
|
#[derive(Event, Reflect)]
|
||||||
|
pub struct TriggerCurver(pub TriggerData);
|
||||||
|
|
||||||
#[derive(Resource, Default)]
|
#[derive(Resource, Default)]
|
||||||
pub struct TriggerStateRes {
|
pub struct TriggerStateRes {
|
||||||
@@ -100,6 +104,7 @@ pub fn plugin(app: &mut App) {
|
|||||||
app.add_plugins(arrow::plugin);
|
app.add_plugins(arrow::plugin);
|
||||||
app.add_plugins(missile::plugin);
|
app.add_plugins(missile::plugin);
|
||||||
app.add_plugins(healing::plugin);
|
app.add_plugins(healing::plugin);
|
||||||
|
app.add_plugins(curver::plugin);
|
||||||
|
|
||||||
app.add_systems(
|
app.add_systems(
|
||||||
Update,
|
Update,
|
||||||
@@ -175,6 +180,7 @@ fn update(
|
|||||||
HeadAbility::Gun => commands.trigger(TriggerGun(trigger_state)),
|
HeadAbility::Gun => commands.trigger(TriggerGun(trigger_state)),
|
||||||
HeadAbility::Missile => commands.trigger(TriggerMissile(trigger_state)),
|
HeadAbility::Missile => commands.trigger(TriggerMissile(trigger_state)),
|
||||||
HeadAbility::Arrow => commands.trigger(TriggerArrow(trigger_state)),
|
HeadAbility::Arrow => commands.trigger(TriggerArrow(trigger_state)),
|
||||||
|
HeadAbility::Curver => commands.trigger(TriggerCurver(trigger_state)),
|
||||||
_ => panic!("Unhandled head ability"),
|
_ => panic!("Unhandled head ability"),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ use crate::{
|
|||||||
loading_assets::GameAssets,
|
loading_assets::GameAssets,
|
||||||
physics_layers::GameLayer,
|
physics_layers::GameLayer,
|
||||||
sounds::PlaySound,
|
sounds::PlaySound,
|
||||||
utils::{global_observer, sprite_3d_animation::AnimationTimer},
|
utils::{auto_rotate::AutoRotation, global_observer, sprite_3d_animation::AnimationTimer},
|
||||||
};
|
};
|
||||||
use avian3d::prelude::*;
|
use avian3d::prelude::*;
|
||||||
use bevy::{pbr::NotShadowCaster, prelude::*};
|
use bevy::{pbr::NotShadowCaster, prelude::*};
|
||||||
@@ -21,10 +21,6 @@ struct ThrownProjectile {
|
|||||||
damage: u32,
|
damage: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Component, Reflect)]
|
|
||||||
#[reflect(Component)]
|
|
||||||
struct AutoRotation(Quat);
|
|
||||||
|
|
||||||
#[derive(Event, Debug)]
|
#[derive(Event, Debug)]
|
||||||
struct Explosion {
|
struct Explosion {
|
||||||
position: Vec3,
|
position: Vec3,
|
||||||
@@ -39,11 +35,8 @@ struct ShotAssets {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn plugin(app: &mut App) {
|
pub fn plugin(app: &mut App) {
|
||||||
app.register_type::<AutoRotation>();
|
|
||||||
|
|
||||||
app.add_systems(OnEnter(GameState::Playing), setup);
|
app.add_systems(OnEnter(GameState::Playing), setup);
|
||||||
app.add_systems(Update, shot_collision.run_if(in_state(GameState::Playing)));
|
app.add_systems(Update, shot_collision.run_if(in_state(GameState::Playing)));
|
||||||
app.add_systems(FixedUpdate, update_auto_rotation);
|
|
||||||
|
|
||||||
global_observer!(app, on_trigger_thrown);
|
global_observer!(app, on_trigger_thrown);
|
||||||
global_observer!(app, on_explosion);
|
global_observer!(app, on_explosion);
|
||||||
@@ -215,9 +208,3 @@ fn shot_collision(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_auto_rotation(mut query: Query<(&AutoRotation, &mut Transform)>) {
|
|
||||||
for (auto_rotation, mut transform) in query.iter_mut() {
|
|
||||||
transform.rotate_local(auto_rotation.0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -47,6 +47,8 @@ use loading_assets::AudioAssets;
|
|||||||
use std::io::{Read, Write};
|
use std::io::{Read, Write};
|
||||||
use utils::{billboards, sprite_3d_animation, squish_animation, trail};
|
use utils::{billboards, sprite_3d_animation, squish_animation, trail};
|
||||||
|
|
||||||
|
use crate::utils::auto_rotate;
|
||||||
|
|
||||||
#[derive(Resource, Reflect, Debug)]
|
#[derive(Resource, Reflect, Debug)]
|
||||||
#[reflect(Resource)]
|
#[reflect(Resource)]
|
||||||
struct DebugVisuals {
|
struct DebugVisuals {
|
||||||
@@ -168,6 +170,7 @@ fn main() {
|
|||||||
app.add_plugins(water::plugin);
|
app.add_plugins(water::plugin);
|
||||||
app.add_plugins(head_drop::plugin);
|
app.add_plugins(head_drop::plugin);
|
||||||
app.add_plugins(trail::plugin);
|
app.add_plugins(trail::plugin);
|
||||||
|
app.add_plugins(auto_rotate::plugin);
|
||||||
app.add_plugins(heal_effect::plugin);
|
app.add_plugins(heal_effect::plugin);
|
||||||
app.add_plugins(tb_entities::plugin);
|
app.add_plugins(tb_entities::plugin);
|
||||||
|
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ fn spawn(
|
|||||||
Player,
|
Player,
|
||||||
ActiveHead(0),
|
ActiveHead(0),
|
||||||
ActiveHeads::new([
|
ActiveHeads::new([
|
||||||
Some(HeadState::new(0, heads_db.as_ref())),
|
Some(HeadState::new(7, heads_db.as_ref())),
|
||||||
Some(HeadState::new(3, heads_db.as_ref())),
|
Some(HeadState::new(3, heads_db.as_ref())),
|
||||||
Some(HeadState::new(6, heads_db.as_ref())),
|
Some(HeadState::new(6, heads_db.as_ref())),
|
||||||
Some(HeadState::new(10, heads_db.as_ref())),
|
Some(HeadState::new(10, heads_db.as_ref())),
|
||||||
|
|||||||
17
src/utils/auto_rotate.rs
Normal file
17
src/utils/auto_rotate.rs
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
use bevy::prelude::*;
|
||||||
|
|
||||||
|
#[derive(Component, Reflect)]
|
||||||
|
#[reflect(Component)]
|
||||||
|
pub struct AutoRotation(pub Quat);
|
||||||
|
|
||||||
|
pub fn plugin(app: &mut App) {
|
||||||
|
app.register_type::<AutoRotation>();
|
||||||
|
|
||||||
|
app.add_systems(FixedUpdate, update_auto_rotation);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn update_auto_rotation(mut query: Query<(&AutoRotation, &mut Transform)>) {
|
||||||
|
for (auto_rotation, mut transform) in query.iter_mut() {
|
||||||
|
transform.rotate_local(auto_rotation.0);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
pub mod auto_rotate;
|
||||||
pub mod billboards;
|
pub mod billboards;
|
||||||
pub mod observers;
|
pub mod observers;
|
||||||
pub mod sprite_3d_animation;
|
pub mod sprite_3d_animation;
|
||||||
|
|||||||
Reference in New Issue
Block a user