Add AS1 files

master
John Montagu, the 4th Earl of Sandvich 2026-02-08 18:18:00 -08:00
parent 90ccaa3dac
commit 13f13a5abb
Signed by: sandvich
GPG Key ID: 9A39BE37E602B22D
6 changed files with 200 additions and 0 deletions

3
.gitignore vendored
View File

@ -1,2 +1,5 @@
# cmake build directory # cmake build directory
build/ build/
# clangd cache
.cache/

15
as1/CMakeLists.txt 100644
View File

@ -0,0 +1,15 @@
cmake_minimum_required(VERSION 3.18)
project(as1 CXX)
set(CMAKE_CXX_STANDARD 20)
# adding this option to make clangd work
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
add_subdirectory(../raylib-cpp raylib)
add_executable(as1 as1.cpp raygui.cpp)
target_link_libraries(as1 PUBLIC raylib raylib_cpp raygui)
configure_file(../assets/audio/ping.wav audio/ping.wav COPYONLY)
configure_file(../assets/audio/price-of-freedom.mp3 audio/price-of-freedom.mp3 COPYONLY)

0
as1/README.md 100644
View File

124
as1/VolumeControl.h 100755
View File

@ -0,0 +1,124 @@
/*******************************************************************************************
*
* VolumeControl v1.0.0 - Tool Description
*
* MODULE USAGE:
* #define GUI_VOLUMECONTROL_IMPLEMENTATION
* #include "gui_VolumeControl.h"
*
* INIT: GuiVolumeControlState state = InitGuiVolumeControl();
* DRAW: GuiVolumeControl(&state);
*
* LICENSE: Propietary License
*
* Copyright (c) 2022 Joshua Dahl. All Rights Reserved.
*
* Unauthorized copying of this file, via any medium is strictly prohibited
* This project is proprietary and confidential unless the owner allows
* usage in any other form by expresely written permission.
*
**********************************************************************************************/
#include "raylib.h"
// WARNING: raygui implementation is expected to be defined before including this header
// #undef RAYGUI_IMPLEMENTATION
#include "raygui.h"
#include <string.h> // Required for: strcpy()
#ifndef GUI_VOLUMECONTROL_H
#define GUI_VOLUMECONTROL_H
typedef struct {
// Define anchors
Vector2 anchor01; // ANCHOR ID:1
// Define controls variables
float SFXSliderValue; // Slider: SFXSlider
float MusicSliderValue; // Slider: MusicSlider
float DialogueSliderValue; // Slider: DialogueSlider
// Custom state variables (depend on development software)
// NOTE: This variables should be added manually if required
} GuiVolumeControlState;
#ifdef __cplusplus
extern "C" { // Prevents name mangling of functions
#endif
//----------------------------------------------------------------------------------
// Module Functions Declaration
//----------------------------------------------------------------------------------
GuiVolumeControlState InitGuiVolumeControl(void);
void GuiVolumeControl(GuiVolumeControlState *state);
// static void PingButton(); // Button: PingButton logic
#ifdef __cplusplus
}
#endif
#endif // GUI_VOLUMECONTROL_H
/***********************************************************************************
*
* GUI_VOLUMECONTROL IMPLEMENTATION
*
************************************************************************************/
#if defined(GUI_VOLUMECONTROL_IMPLEMENTATION)
#include "raygui.h"
//----------------------------------------------------------------------------------
// Module Functions Definition
//----------------------------------------------------------------------------------
GuiVolumeControlState InitGuiVolumeControl(void) {
GuiVolumeControlState state = { 0 };
// Init anchors
state.anchor01 = (Vector2){ 24, 24 }; // ANCHOR ID:1
// Initilize controls variables
state.SFXSliderValue = 0.0f; // Slider: SFXSlider
state.MusicSliderValue = 0.0f; // Slider: MusicSlider
state.DialogueSliderValue = 0.0f; // Slider: DialogueSlider
// Custom variables initialization
return state;
}
// Button: PingButton logic
// static void PingButton()
// {
// // TODO: Implement in outer file!
// }
void GuiVolumeControl(GuiVolumeControlState *state) {
// Const text
const char *VolumeGroupText = "Volume Controls"; // GROUPBOX: VolumeGroup
const char *SFXGroupText = "SFXVolume"; // GROUPBOX: SFXGroup
const char *SFXSliderText = ""; // SLIDER: SFXSlider
const char *MusicGroupText = "MusicVolume"; // GROUPBOX: MusicGroup
const char *MusicSliderText = ""; // SLIDER: MusicSlider
const char *DialogueGroupText = "DialogueVolume"; // GROUPBOX: DialogueGroup
const char *DialogueSliderText = ""; // SLIDER: DialogueSlider
const char *PingButtonText = "Ping"; // BUTTON: PingButton
// Draw controls
GuiGroupBox((Rectangle){ state->anchor01.x + 0, state->anchor01.y + 0, 256, 264 }, VolumeGroupText);
GuiGroupBox((Rectangle){ state->anchor01.x + 24, state->anchor01.y + 24, 208, 56 }, SFXGroupText);
GuiLabel((Rectangle){ 64, 64, 120, 24 }, TextFormat("%.0f%%", state->SFXSliderValue));
state->SFXSliderValue = GuiSlider((Rectangle){ state->anchor01.x + 72, state->anchor01.y + 40, 144, 24 }, SFXSliderText, NULL, state->SFXSliderValue, 0, 100);
GuiGroupBox((Rectangle){ state->anchor01.x + 24, state->anchor01.y + 104, 208, 56 }, MusicGroupText);
GuiLabel((Rectangle){ 64, 144, 120, 24 }, TextFormat("%.0f%%", state->MusicSliderValue));
state->MusicSliderValue = GuiSlider((Rectangle){ state->anchor01.x + 72, state->anchor01.y + 120, 144, 24 }, MusicSliderText, NULL, state->MusicSliderValue, 0, 100);
GuiGroupBox((Rectangle){ state->anchor01.x + 24, state->anchor01.y + 184, 208, 56 }, DialogueGroupText);
GuiLabel((Rectangle){ 64, 224, 120, 24 }, TextFormat("%.0f%%", state->DialogueSliderValue));
state->DialogueSliderValue = GuiSlider((Rectangle){ state->anchor01.x + 72, state->anchor01.y + 200, 144, 24 }, DialogueSliderText, NULL, state->DialogueSliderValue, 0, 100);
if (GuiButton((Rectangle){ 24, 304, 256, 24 }, PingButtonText)) PingButton();
}
#endif // GUI_VOLUMECONTROL_IMPLEMENTATION

56
as1/as1.cpp 100644
View File

@ -0,0 +1,56 @@
#include "AudioDevice.hpp"
#include "Color.hpp"
#include <raylib-cpp.hpp>
#include <iostream>
void PingButton() {
std::cout << "Ping!" << std::endl;
}
#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;
auto guiState = InitGuiVolumeControl();
raylib::Sound ping("audio/ping.wav");
raylib::Music music("audio/price-of-freedom.mp3");
music.Play();
// play ping sound when button is pressed
auto lambdaPingButton = [&ping]() {
ping.Play();
};
call_lambda(lambdaPingButton);
InitGuiVolumeControl();
while (!window.ShouldClose()) {
window.BeginDrawing();
window.ClearBackground(raylib::Color::RayWhite());
music.Update();
music.SetVolume(guiState.MusicSliderValue / 100.0f);
GuiVolumeControl(&guiState);
window.EndDrawing();
}
delete ping;
return 0;
}

2
as1/raygui.cpp 100644
View File

@ -0,0 +1,2 @@
#define RAYGUI_IMPLEMENTATION
#include "raygui.h"