Implement slider functionality
parent
11e3e60c3c
commit
44878dbafe
29
as1/as1.cpp
29
as1/as1.cpp
|
|
@ -1,25 +1,18 @@
|
|||
#include "AudioDevice.hpp"
|
||||
#include "Color.hpp"
|
||||
#include <raylib-cpp.hpp>
|
||||
#include <functional>
|
||||
#include <iostream>
|
||||
|
||||
static std::function<void()> pingButtonHandler;
|
||||
|
||||
void PingButton() {
|
||||
std::cout << "Ping!" << std::endl;
|
||||
pingButtonHandler();
|
||||
}
|
||||
|
||||
#define GUI_VOLUMECONTROL_IMPLEMENTATION
|
||||
#include "VolumeControl.h"
|
||||
|
||||
template<typename T>
|
||||
concept calls_with_no_arguments = requires(T a) {
|
||||
{ a() };
|
||||
};
|
||||
|
||||
template<typename TFunction>
|
||||
void call_lambda(TFunction func) {
|
||||
func();
|
||||
}
|
||||
|
||||
int main() {
|
||||
raylib::Window window(800, 600, "CS381 - Assignment 0");
|
||||
raylib::AudioDevice audio;
|
||||
|
|
@ -28,29 +21,35 @@ int main() {
|
|||
|
||||
raylib::Sound ping("audio/ping.wav");
|
||||
raylib::Music music("audio/price-of-freedom.mp3");
|
||||
raylib::Sound dialog("audio/crowd.wav");
|
||||
music.Play();
|
||||
dialog.Play();
|
||||
|
||||
// play ping sound when button is pressed
|
||||
auto lambdaPingButton = [&ping]() {
|
||||
ping.Play();
|
||||
};
|
||||
|
||||
call_lambda(lambdaPingButton);
|
||||
pingButtonHandler = lambdaPingButton;
|
||||
|
||||
InitGuiVolumeControl();
|
||||
|
||||
while (!window.ShouldClose()) {
|
||||
window.BeginDrawing();
|
||||
|
||||
GuiVolumeControl(&guiState);
|
||||
|
||||
window.ClearBackground(raylib::Color::RayWhite());
|
||||
|
||||
ping.SetVolume(guiState.SFXSliderValue / 100.0f);
|
||||
|
||||
music.Update();
|
||||
music.SetVolume(guiState.MusicSliderValue / 100.0f);
|
||||
GuiVolumeControl(&guiState);
|
||||
|
||||
dialog.SetVolume(guiState.DialogueSliderValue / 100.0f);
|
||||
|
||||
window.EndDrawing();
|
||||
}
|
||||
|
||||
delete ping;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue