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