From 01b2832402eeff46055c3e8a6a3d63476dc694fd Mon Sep 17 00:00:00 2001 From: cool-mist Date: Thu, 15 Jan 2026 22:29:38 +0530 Subject: [PATCH] reduce volume, move buttons to the right --- src/game.rs | 26 ++++++++++++-------------- src/game/button.rs | 6 ++++-- src/game/constants.rs | 1 + src/game/sound.rs | 17 ++++++++++++++++- 4 files changed, 33 insertions(+), 17 deletions(-) create mode 100644 src/game/constants.rs diff --git a/src/game.rs b/src/game.rs index d2683f0..178097f 100644 --- a/src/game.rs +++ b/src/game.rs @@ -5,7 +5,7 @@ use std::{ use button::Button; use color::UiColor; -use macroquad::{audio, math, prelude::*, rand}; +use macroquad::{math, prelude::*, rand}; use shadow::draw_shadow; use sol_chess::{ board::{Board, BoardState}, @@ -19,6 +19,7 @@ pub mod color; pub mod shadow; pub mod sound; pub mod texture; +pub mod constants; pub struct MacroquadRandAdapter; impl RandomRange for MacroquadRandAdapter { @@ -428,24 +429,21 @@ impl Game { self.squares = rects; let btn_h = 0.08 * min_dimension; - let btn_w = board_width * 0.2; - + let btn_w = board_width * 0.20; let btn_y = board_width + board_y + 0.3 * self.square_width; - let btn_x_offset = 0.5 * (board_width / 2. - btn_w); + let btn_reset_x_offset = board_width / 2. + ((board_width / 4. - btn_w) / 2.); let reset_btn = Button::new( "Reset", - Rect::new(board_x + btn_x_offset, btn_y, btn_w, btn_h), + Rect::new(board_x + btn_reset_x_offset, btn_y, btn_w, btn_h), UiColor::Yellow, self.sounds.button.clone(), ); + + let btn_next_x_offset = + board_width / 2. + board_width / 4. + ((board_width / 4. - btn_w) / 2.); let mut next_btn = Button::new( "Next", - Rect::new( - board_x + (0.5 * board_width) + btn_x_offset, - btn_y, - btn_w, - btn_h, - ), + Rect::new(board_x + btn_next_x_offset, btn_y, btn_w, btn_h), UiColor::Green, self.sounds.button.clone(), ); @@ -607,9 +605,9 @@ impl Game { .get_mut(&ButtonAction::Next) .expect("Cannot find next button"); next_btn.is_active = true; - audio::play_sound_once(&self.sounds.win); + Sounds::play(&self.sounds.win); } else { - audio::play_sound_once(&self.sounds.loss); + Sounds::play(&self.sounds.loss); } return GameState::GameOver((x, y)); @@ -617,7 +615,7 @@ impl Game { self.reset_squares(); self.get(x, y).is_target = true; - audio::play_sound_once(&self.sounds.click); + Sounds::play(&self.sounds.click); return GameState::SelectSource(Some((x, y))); } diff --git a/src/game/button.rs b/src/game/button.rs index f2e7dd1..6fc09e5 100644 --- a/src/game/button.rs +++ b/src/game/button.rs @@ -1,4 +1,6 @@ -use macroquad::{audio::{self, Sound}, prelude::*}; +use macroquad::{audio::Sound, prelude::*}; + +use crate::game::sound::Sounds; use super::{color::UiColor, shadow::draw_shadow}; @@ -119,7 +121,7 @@ impl Button { if is_mouse_button_released(MouseButton::Left) { if c.overlaps_rect(&self.rect) { self.is_clicked = true; - audio::play_sound_once(&self.sound); + Sounds::play(&self.sound); self.is_down = false; return; } diff --git a/src/game/constants.rs b/src/game/constants.rs new file mode 100644 index 0000000..a2204fa --- /dev/null +++ b/src/game/constants.rs @@ -0,0 +1 @@ +pub(crate) const VOLUME: f32 = 0.3; // Between 0 and 1 diff --git a/src/game/sound.rs b/src/game/sound.rs index 40dd6d8..0e41af8 100644 --- a/src/game/sound.rs +++ b/src/game/sound.rs @@ -1,4 +1,7 @@ -use macroquad::audio::Sound; +use macroquad::audio::{self, Sound}; +use quad_snd::PlaySoundParams; + +use super::constants::VOLUME; pub struct Sounds { pub click: Sound, @@ -7,3 +10,15 @@ pub struct Sounds { pub button: Sound, pub mode: Sound, } + +impl Sounds { + pub fn play(sound: &Sound) { + audio::play_sound( + sound, + PlaySoundParams { + looped: false, + volume: VOLUME, + }, + ); + } +}