pub struct ProceduralAudio { /* private fields */ }Expand description
Procedural audio generator for Pong.
Generates audio events based on game state changes. Events are returned as JSON to be executed by JavaScript’s Web Audio API.
§Example
use jugar_web::audio::ProceduralAudio;
let mut audio = ProceduralAudio::new();
audio.set_enabled(true);
// Trigger a paddle hit sound (hit_y, paddle_y, paddle_height)
audio.on_paddle_hit(300.0, 250.0, 100.0);
// Get events to send to JavaScript
let events = audio.take_events();
assert!(!events.is_empty());Implementations§
Source§impl ProceduralAudio
impl ProceduralAudio
Sourcepub fn set_volume(&mut self, volume: f32)
pub fn set_volume(&mut self, volume: f32)
Sets the master volume (0.0-1.0).
Sourcepub fn set_enabled(&mut self, enabled: bool)
pub fn set_enabled(&mut self, enabled: bool)
Enables or disables audio.
Sourcepub const fn is_enabled(&self) -> bool
pub const fn is_enabled(&self) -> bool
Returns whether audio is enabled.
Sourcepub fn on_paddle_hit(&mut self, hit_y: f32, paddle_y: f32, paddle_height: f32)
pub fn on_paddle_hit(&mut self, hit_y: f32, paddle_y: f32, paddle_height: f32)
Generates a paddle hit sound.
§Arguments
hit_y- Y position where ball hit the paddlepaddle_y- Center Y position of the paddlepaddle_height- Height of the paddle
Sourcepub fn on_wall_bounce(&mut self)
pub fn on_wall_bounce(&mut self)
Generates a wall bounce sound with optional velocity-based pitch variation.
Sourcepub fn on_wall_bounce_with_velocity(&mut self, ball_speed: f32, base_speed: f32)
pub fn on_wall_bounce_with_velocity(&mut self, ball_speed: f32, base_speed: f32)
Generates a wall bounce sound with velocity-based pitch.
§Arguments
ball_speed- Current ball speed (magnitude of velocity)base_speed- Reference speed for normal pitch
Sourcepub fn on_game_start(&mut self)
pub fn on_game_start(&mut self)
Generates a game start sound.
Sourcepub fn on_rally_milestone(&mut self, rally_count: u32)
pub fn on_rally_milestone(&mut self, rally_count: u32)
Generates a rally milestone sound.
Should be called when rally count reaches a milestone (5, 10, 15, etc.).
§Arguments
rally_count- Current rally count at the milestone
Sourcepub fn on_sound_toggle(&mut self, enabled: bool)
pub fn on_sound_toggle(&mut self, enabled: bool)
Generates a sound toggle confirmation sound.
Plays a brief confirmation when sound is enabled. This provides immediate feedback that audio is working.
Sourcepub fn take_events(&mut self) -> Vec<AudioEvent>
pub fn take_events(&mut self) -> Vec<AudioEvent>
Takes all pending audio events (clears the internal buffer).
§Returns
Vector of audio events to be played by JavaScript.
Sourcepub fn peek_events(&self) -> &[AudioEvent]
pub fn peek_events(&self) -> &[AudioEvent]
Returns pending events without clearing (for inspection).
Sourcepub fn clear_events(&mut self)
pub fn clear_events(&mut self)
Clears all pending events.
Sourcepub fn event_count(&self) -> usize
pub fn event_count(&self) -> usize
Returns the number of pending events.
Trait Implementations§
Source§impl Clone for ProceduralAudio
impl Clone for ProceduralAudio
Source§fn clone(&self) -> ProceduralAudio
fn clone(&self) -> ProceduralAudio
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ProceduralAudio
impl Debug for ProceduralAudio
Auto Trait Implementations§
impl Freeze for ProceduralAudio
impl RefUnwindSafe for ProceduralAudio
impl Send for ProceduralAudio
impl Sync for ProceduralAudio
impl Unpin for ProceduralAudio
impl UnwindSafe for ProceduralAudio
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more