reduce volume, move buttons to the right
This commit is contained in:
+12
-14
@@ -5,7 +5,7 @@ use std::{
|
|||||||
|
|
||||||
use button::Button;
|
use button::Button;
|
||||||
use color::UiColor;
|
use color::UiColor;
|
||||||
use macroquad::{audio, math, prelude::*, rand};
|
use macroquad::{math, prelude::*, rand};
|
||||||
use shadow::draw_shadow;
|
use shadow::draw_shadow;
|
||||||
use sol_chess::{
|
use sol_chess::{
|
||||||
board::{Board, BoardState},
|
board::{Board, BoardState},
|
||||||
@@ -19,6 +19,7 @@ pub mod color;
|
|||||||
pub mod shadow;
|
pub mod shadow;
|
||||||
pub mod sound;
|
pub mod sound;
|
||||||
pub mod texture;
|
pub mod texture;
|
||||||
|
pub mod constants;
|
||||||
|
|
||||||
pub struct MacroquadRandAdapter;
|
pub struct MacroquadRandAdapter;
|
||||||
impl RandomRange for MacroquadRandAdapter {
|
impl RandomRange for MacroquadRandAdapter {
|
||||||
@@ -428,24 +429,21 @@ impl Game {
|
|||||||
self.squares = rects;
|
self.squares = rects;
|
||||||
|
|
||||||
let btn_h = 0.08 * min_dimension;
|
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_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(
|
let reset_btn = Button::new(
|
||||||
"Reset",
|
"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,
|
UiColor::Yellow,
|
||||||
self.sounds.button.clone(),
|
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(
|
let mut next_btn = Button::new(
|
||||||
"Next",
|
"Next",
|
||||||
Rect::new(
|
Rect::new(board_x + btn_next_x_offset, btn_y, btn_w, btn_h),
|
||||||
board_x + (0.5 * board_width) + btn_x_offset,
|
|
||||||
btn_y,
|
|
||||||
btn_w,
|
|
||||||
btn_h,
|
|
||||||
),
|
|
||||||
UiColor::Green,
|
UiColor::Green,
|
||||||
self.sounds.button.clone(),
|
self.sounds.button.clone(),
|
||||||
);
|
);
|
||||||
@@ -607,9 +605,9 @@ impl Game {
|
|||||||
.get_mut(&ButtonAction::Next)
|
.get_mut(&ButtonAction::Next)
|
||||||
.expect("Cannot find next button");
|
.expect("Cannot find next button");
|
||||||
next_btn.is_active = true;
|
next_btn.is_active = true;
|
||||||
audio::play_sound_once(&self.sounds.win);
|
Sounds::play(&self.sounds.win);
|
||||||
} else {
|
} else {
|
||||||
audio::play_sound_once(&self.sounds.loss);
|
Sounds::play(&self.sounds.loss);
|
||||||
}
|
}
|
||||||
|
|
||||||
return GameState::GameOver((x, y));
|
return GameState::GameOver((x, y));
|
||||||
@@ -617,7 +615,7 @@ impl Game {
|
|||||||
|
|
||||||
self.reset_squares();
|
self.reset_squares();
|
||||||
self.get(x, y).is_target = true;
|
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)));
|
return GameState::SelectSource(Some((x, y)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+4
-2
@@ -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};
|
use super::{color::UiColor, shadow::draw_shadow};
|
||||||
|
|
||||||
@@ -119,7 +121,7 @@ impl Button {
|
|||||||
if is_mouse_button_released(MouseButton::Left) {
|
if is_mouse_button_released(MouseButton::Left) {
|
||||||
if c.overlaps_rect(&self.rect) {
|
if c.overlaps_rect(&self.rect) {
|
||||||
self.is_clicked = true;
|
self.is_clicked = true;
|
||||||
audio::play_sound_once(&self.sound);
|
Sounds::play(&self.sound);
|
||||||
self.is_down = false;
|
self.is_down = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
pub(crate) const VOLUME: f32 = 0.3; // Between 0 and 1
|
||||||
+16
-1
@@ -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 struct Sounds {
|
||||||
pub click: Sound,
|
pub click: Sound,
|
||||||
@@ -7,3 +10,15 @@ pub struct Sounds {
|
|||||||
pub button: Sound,
|
pub button: Sound,
|
||||||
pub mode: Sound,
|
pub mode: Sound,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Sounds {
|
||||||
|
pub fn play(sound: &Sound) {
|
||||||
|
audio::play_sound(
|
||||||
|
sound,
|
||||||
|
PlaySoundParams {
|
||||||
|
looped: false,
|
||||||
|
volume: VOLUME,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user