Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
bevy = "0.17.0-rc.2"
bevy = "0.17.2"
fastrand = "2.1.1" # ref: https://github.com/bevyengine/bevy/pull/3992
bevy_hanabi = "0.17"

[workspace]
resolver ="2"
Expand Down
Binary file added assets/Fox.glb
Binary file not shown.
Binary file added assets/circle.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/cloud.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/ramp.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion src/game/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use bevy::prelude::*;
//use bevy_hanabi::prelude::HanabiPlugin; <-- TODO: Add this back in
use bevy_hanabi::prelude::HanabiPlugin;

mod ai;
pub use ai::AiPlugin;
Expand Down Expand Up @@ -69,6 +69,7 @@ impl Plugin for GamePlugin {
CollisionPlugin,
LevelPlugin,
DespawnerPlugin,
HanabiPlugin,
VfxPlugin,
ActorPlugin,
)); // currently for cleaning up entities
Expand Down
94 changes: 89 additions & 5 deletions src/game/vfx/mod.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,32 @@
use std::f32::consts::PI;

use crate::constants::CAMERA_FAR;
use bevy::prelude::*;
use std::time::Duration;

use bevy::prelude::*;
use bevy_hanabi::prelude::*;
use bevy_hanabi::Gradient as HanabiGradient;
use fastrand;

use crate::constants::CAMERA_FAR;

use super::components::*;
use super::events::*;

const EXPLOSION_PARTICLE_LIFETIME: f32 = 0.6;
const EXPLOSION_SPAWN_COUNT: f32 = 160.0;
const EXPLOSION_RADIUS: f32 = 6.0;
const EXPLOSION_BASE_SPEED: f32 = 42.0;

#[derive(Resource, Clone)]
struct ExplosionEffectHandle(pub Handle<EffectAsset>);

pub struct VfxPlugin;

impl Plugin for VfxPlugin {
fn build(&self, app: &mut App) {
app.add_message::<CameraShakeEvent>()
.add_message::<ExplosionEvent>()
.add_systems(Update, shake_camera);
.add_systems(Startup, setup_explosion_effect)
.add_systems(Update, (shake_camera, on_explosion_event));
}
}

Expand Down Expand Up @@ -55,9 +66,82 @@ fn shake_camera(
fn on_explosion_event(
mut events: MessageReader<ExplosionEvent>,
mut commands: Commands,
asset_server: Res<AssetServer>,
effect: Res<ExplosionEffectHandle>,
) {
if events.is_empty() {
return;
}

for event in events.read() {
let lifetime = event
.lifetime
.max(EXPLOSION_PARTICLE_LIFETIME)
.max(f32::EPSILON);

commands.spawn((
ParticleEffect::new(effect.0.clone()),
EffectProperties::default(),
Transform::from_translation(event.position),
GlobalTransform::default(),
TimedDespawn {
timer: Timer::from_seconds(lifetime, TimerMode::Once),
},
Name::new("ExplosionVfx"),
));
}
}

fn setup_explosion_effect(mut commands: Commands, mut effects: ResMut<Assets<EffectAsset>>) {
let mut color_gradient = HanabiGradient::<Vec4>::new();
color_gradient.add_key(0.0, Vec4::new(2.5, 1.4, 0.4, 1.0));
color_gradient.add_key(0.15, Vec4::new(1.8, 0.6, 0.1, 0.9));
color_gradient.add_key(0.45, Vec4::new(0.9, 0.2, 0.05, 0.5));
color_gradient.add_key(1.0, Vec4::ZERO);

let mut size_gradient = HanabiGradient::<Vec3>::new();
size_gradient.add_key(0.0, Vec3::splat(0.4));
size_gradient.add_key(0.3, Vec3::splat(0.8));
size_gradient.add_key(1.0, Vec3::splat(0.05));

let writer = ExprWriter::new();

let init_position = SetPositionSphereModifier {
center: writer.lit(Vec3::ZERO).expr(),
radius: writer.lit(EXPLOSION_RADIUS).expr(),
dimension: ShapeDimension::Surface,
};
let init_velocity = SetVelocitySphereModifier {
center: writer.lit(Vec3::ZERO).expr(),
speed: writer.lit(EXPLOSION_BASE_SPEED).expr(),
};
let init_age = SetAttributeModifier::new(Attribute::AGE, writer.lit(0.).expr());
let init_lifetime = SetAttributeModifier::new(
Attribute::LIFETIME,
writer.lit(EXPLOSION_PARTICLE_LIFETIME).expr(),
);
let drag = LinearDragModifier::new(writer.lit(8.0).expr());

let effect = EffectAsset::new(
512,
SpawnerSettings::once(EXPLOSION_SPAWN_COUNT.into()),
writer.finish(),
)
.with_name("Explosion")
.init(init_position)
.init(init_velocity)
.init(init_age)
.init(init_lifetime)
.update(drag)
.render(ColorOverLifetimeModifier {
gradient: color_gradient,
blend: ColorBlendMode::Add,
mask: ColorBlendMask::RGBA,
})
.render(SizeOverLifetimeModifier {
gradient: size_gradient,
screen_space_size: false,
});

let handle = effects.add(effect);
commands.insert_resource(ExplosionEffectHandle(handle));
}
5 changes: 4 additions & 1 deletion src/game/weapon/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use bevy::{light::{NotShadowCaster, NotShadowReceiver}, prelude::*};
use bevy::{
light::{NotShadowCaster, NotShadowReceiver},
prelude::*,
};

use super::super::AppState;
use super::actor::bullet::*;
Expand Down
5 changes: 1 addition & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@ fn main() {
.add_plugins(DefaultPlugins.set(WindowPlugin {
primary_window: Some(Window {
title: "StarRust".to_string(),
resolution: WindowResolution::new(
SCREEN_WIDTH as u32,
SCREEN_HEIGHT as u32,
),
resolution: WindowResolution::new(SCREEN_WIDTH as u32, SCREEN_HEIGHT as u32),
..default()
}),
..default()
Expand Down
Loading