Skip to content

Commit

Permalink
feat: Add super sonic effect (GFX + sound)
Browse files Browse the repository at this point in the history
  • Loading branch information
PraxTube committed Nov 4, 2023
1 parent 325b313 commit d205594
Show file tree
Hide file tree
Showing 9 changed files with 139 additions and 5 deletions.
7 changes: 7 additions & 0 deletions CREDITS.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ NOTE: Only a handful of sprites were used from this.

https://ansimuz.itch.io/explosion-animations-pack

#### Super Sonic Effect

https://bdragon1727.itch.io/free-smoke-fx-pixel-2

NOTE: Only a handful of sprites were used from this
(and rotated to work easier with the game).

### Audio

#### Sounds
Expand Down
Binary file added assets/gfx/super_sonic.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/sounds/super_sonic.ogg
Binary file not shown.
7 changes: 6 additions & 1 deletion src/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ pub struct GameAssets {
#[asset(texture_atlas(tile_size_x = 32.0, tile_size_y = 32.0, columns = 8, rows = 1))]
#[asset(path = "gfx/explosion.png")]
pub explosion: Handle<TextureAtlas>,
#[asset(texture_atlas(tile_size_x = 64.0, tile_size_y = 64.0, columns = 9, rows = 1))]
#[asset(path = "gfx/super_sonic.png")]
pub super_sonic: Handle<TextureAtlas>,

// MAP
#[asset(path = "map/background.png")]
Expand Down Expand Up @@ -75,7 +78,9 @@ pub struct GameAssets {
#[asset(path = "sounds/dodge.ogg")]
pub dodge_sound: Handle<AudioSource>,
#[asset(path = "sounds/dodge_refresh.ogg")]
pub dodge_refresh: Handle<AudioSource>,
pub dodge_refresh_sound: Handle<AudioSource>,
#[asset(path = "sounds/super_sonic.ogg")]
pub super_sonic_sound: Handle<AudioSource>,

#[asset(path = "sounds/round-start-sound.ogg")]
pub round_start_sound: Handle<AudioSource>,
Expand Down
2 changes: 1 addition & 1 deletion src/player/dodge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ pub fn tick_dodge_timers(

commands
.spawn(RollbackSound {
clip: assets.dodge_refresh.clone(),
clip: assets.dodge_refresh_sound.clone(),
start_frame: frame.0 as usize,
sub_key: player.handle,
volume: 0.35,
Expand Down
14 changes: 13 additions & 1 deletion src/player/effect/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
mod bullet;
pub mod damage;
pub mod trail;

mod bullet;
mod super_sonic;

use bevy::prelude::*;
use bevy_ggrs::GgrsSchedule;

Expand All @@ -25,6 +27,16 @@ impl Plugin for EffectPlugin {
.chain()
.run_if(in_state(GameState::InRollbackGame)),
)
.add_systems(
Update,
(
super_sonic::spawn_super_sonic_effects,
super_sonic::animate_super_sonic_effects,
super_sonic::despawn_super_sonic_effects,
)
.chain()
.run_if(in_state(GameState::InRollbackGame)),
)
.add_systems(
GgrsSchedule,
(
Expand Down
89 changes: 89 additions & 0 deletions src/player/effect/super_sonic.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
use std::time::Duration;

use bevy::core::FrameCount;
use bevy::prelude::*;
use bevy_ggrs::AddRollbackCommandExtension;

use crate::audio::RollbackSound;
use crate::misc::utils::quat_from_vec3;
use crate::network::ggrs_config::GGRS_FPS;
use crate::player::movement::ReachedMaxSpeed;
use crate::GameAssets;

#[derive(Component)]
pub struct SuperSonicAnimationTimer {
pub timer: Timer,
disabled: bool,
}

impl Default for SuperSonicAnimationTimer {
fn default() -> Self {
Self {
timer: Timer::from_seconds(0.075, TimerMode::Repeating),
disabled: false,
}
}
}

pub fn spawn_super_sonic_effects(
mut commands: Commands,
assets: Res<GameAssets>,
frame: Res<FrameCount>,
mut ev_reached_max_speed: EventReader<ReachedMaxSpeed>,
) {
for ev in &mut ev_reached_max_speed {
let transform = Transform::from_translation(ev.position)
.with_rotation(quat_from_vec3(ev.direction))
.with_scale(Vec3::splat(1.5));
let entity = commands
.spawn((
SuperSonicAnimationTimer::default(),
SpriteSheetBundle {
transform,
texture_atlas: assets.super_sonic.clone(),
..default()
},
))
.id();
commands
.spawn(RollbackSound {
clip: assets.super_sonic_sound.clone(),
start_frame: frame.0 as usize,
sub_key: entity.index() as usize,
..default()
})
.add_rollback();
}
}

pub fn animate_super_sonic_effects(
mut query: Query<(&mut SuperSonicAnimationTimer, &mut TextureAtlasSprite)>,
) {
for (mut timer, mut sprite) in &mut query {
if timer.disabled {
continue;
}

timer
.timer
.tick(Duration::from_secs_f32(1.0 / GGRS_FPS as f32));
if timer.timer.just_finished() {
if sprite.index == 8 {
timer.disabled = true;
} else {
sprite.index += 1;
}
}
}
}

pub fn despawn_super_sonic_effects(
mut commands: Commands,
query: Query<(Entity, &SuperSonicAnimationTimer)>,
) {
for (entity, timer) in &query {
if timer.disabled {
commands.entity(entity).despawn_recursive();
}
}
}
1 change: 1 addition & 0 deletions src/player/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ impl Plugin for PlayerPlugin {
),
)
.add_event::<health::PlayerTookDamage>()
.add_event::<movement::ReachedMaxSpeed>()
.init_resource::<PersistentPlayerStats>()
.add_plugins((shooting::ShootingPlugin, effect::EffectPlugin))
.add_systems(
Expand Down
24 changes: 22 additions & 2 deletions src/player/movement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ use crate::input;
use crate::network::GgrsConfig;
use crate::player::{Player, DELTA_SPEED, DELTA_STEERING, MIN_SPEED};

#[derive(Event)]
pub struct ReachedMaxSpeed {
pub position: Vec3,
pub direction: Vec3,
}

pub fn steer_players(
inputs: Res<PlayerInputs<GgrsConfig>>,
mut players: Query<(&mut Transform, &Player, &mut DebugTransform)>,
Expand All @@ -28,8 +34,12 @@ pub fn steer_players(
}
}

pub fn accelerate_players(inputs: Res<PlayerInputs<GgrsConfig>>, mut players: Query<&mut Player>) {
for mut player in &mut players {
pub fn accelerate_players(
inputs: Res<PlayerInputs<GgrsConfig>>,
mut players: Query<(&Transform, &mut Player)>,
mut ev_reached_max_speed: EventWriter<ReachedMaxSpeed>,
) {
for (transform, mut player) in &mut players {
let (input, _) = inputs[player.handle];

let accelerate_direction = input::accelerate_direction(input);
Expand All @@ -44,10 +54,20 @@ pub fn accelerate_players(inputs: Res<PlayerInputs<GgrsConfig>>, mut players: Qu
-DELTA_SPEED
};

let sub_sonic = player.current_speed != player.stats.max_speed;

player.current_speed += acceleration;
player.current_speed = player
.current_speed
.clamp(MIN_SPEED, player.stats.max_speed);

// We just reached max speed this frame, send event
if sub_sonic && player.current_speed == player.stats.max_speed {
ev_reached_max_speed.send(ReachedMaxSpeed {
position: transform.translation,
direction: transform.rotation.mul_vec3(Vec3::X),
});
}
}
}

Expand Down

0 comments on commit d205594

Please sign in to comment.