parent
c9fd829788
commit
242aeef167
@ -0,0 +1,140 @@ |
|||||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||||
|
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
||||||
|
<ItemGroup Label="ProjectConfigurations"> |
||||||
|
<ProjectConfiguration Include="Debug|Win32"> |
||||||
|
<Configuration>Debug</Configuration> |
||||||
|
<Platform>Win32</Platform> |
||||||
|
</ProjectConfiguration> |
||||||
|
<ProjectConfiguration Include="Release|Win32"> |
||||||
|
<Configuration>Release</Configuration> |
||||||
|
<Platform>Win32</Platform> |
||||||
|
</ProjectConfiguration> |
||||||
|
<ProjectConfiguration Include="Debug|x64"> |
||||||
|
<Configuration>Debug</Configuration> |
||||||
|
<Platform>x64</Platform> |
||||||
|
</ProjectConfiguration> |
||||||
|
<ProjectConfiguration Include="Release|x64"> |
||||||
|
<Configuration>Release</Configuration> |
||||||
|
<Platform>x64</Platform> |
||||||
|
</ProjectConfiguration> |
||||||
|
</ItemGroup> |
||||||
|
<PropertyGroup Label="Globals"> |
||||||
|
<VCProjectVersion>16.0</VCProjectVersion> |
||||||
|
<Keyword>Win32Proj</Keyword> |
||||||
|
<ProjectGuid>{c421608b-8317-4954-89ab-212e3826c3bc}</ProjectGuid> |
||||||
|
<RootNamespace>Example</RootNamespace> |
||||||
|
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion> |
||||||
|
</PropertyGroup> |
||||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> |
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> |
||||||
|
<ConfigurationType>Application</ConfigurationType> |
||||||
|
<UseDebugLibraries>true</UseDebugLibraries> |
||||||
|
<PlatformToolset>v143</PlatformToolset> |
||||||
|
<CharacterSet>Unicode</CharacterSet> |
||||||
|
</PropertyGroup> |
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> |
||||||
|
<ConfigurationType>Application</ConfigurationType> |
||||||
|
<UseDebugLibraries>false</UseDebugLibraries> |
||||||
|
<PlatformToolset>v143</PlatformToolset> |
||||||
|
<WholeProgramOptimization>true</WholeProgramOptimization> |
||||||
|
<CharacterSet>Unicode</CharacterSet> |
||||||
|
</PropertyGroup> |
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> |
||||||
|
<ConfigurationType>Application</ConfigurationType> |
||||||
|
<UseDebugLibraries>true</UseDebugLibraries> |
||||||
|
<PlatformToolset>v143</PlatformToolset> |
||||||
|
<CharacterSet>Unicode</CharacterSet> |
||||||
|
</PropertyGroup> |
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> |
||||||
|
<ConfigurationType>Application</ConfigurationType> |
||||||
|
<UseDebugLibraries>false</UseDebugLibraries> |
||||||
|
<PlatformToolset>v143</PlatformToolset> |
||||||
|
<WholeProgramOptimization>true</WholeProgramOptimization> |
||||||
|
<CharacterSet>Unicode</CharacterSet> |
||||||
|
</PropertyGroup> |
||||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> |
||||||
|
<ImportGroup Label="ExtensionSettings"> |
||||||
|
</ImportGroup> |
||||||
|
<ImportGroup Label="Shared"> |
||||||
|
</ImportGroup> |
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> |
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> |
||||||
|
</ImportGroup> |
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> |
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> |
||||||
|
</ImportGroup> |
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> |
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> |
||||||
|
</ImportGroup> |
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> |
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> |
||||||
|
</ImportGroup> |
||||||
|
<PropertyGroup Label="UserMacros" /> |
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> |
||||||
|
<ClCompile> |
||||||
|
<WarningLevel>Level3</WarningLevel> |
||||||
|
<SDLCheck>true</SDLCheck> |
||||||
|
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> |
||||||
|
<ConformanceMode>true</ConformanceMode> |
||||||
|
</ClCompile> |
||||||
|
<Link> |
||||||
|
<SubSystem>Console</SubSystem> |
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation> |
||||||
|
</Link> |
||||||
|
</ItemDefinitionGroup> |
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> |
||||||
|
<ClCompile> |
||||||
|
<WarningLevel>Level3</WarningLevel> |
||||||
|
<FunctionLevelLinking>true</FunctionLevelLinking> |
||||||
|
<IntrinsicFunctions>true</IntrinsicFunctions> |
||||||
|
<SDLCheck>true</SDLCheck> |
||||||
|
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> |
||||||
|
<ConformanceMode>true</ConformanceMode> |
||||||
|
</ClCompile> |
||||||
|
<Link> |
||||||
|
<SubSystem>Console</SubSystem> |
||||||
|
<EnableCOMDATFolding>true</EnableCOMDATFolding> |
||||||
|
<OptimizeReferences>true</OptimizeReferences> |
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation> |
||||||
|
</Link> |
||||||
|
</ItemDefinitionGroup> |
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> |
||||||
|
<ClCompile> |
||||||
|
<WarningLevel>Level3</WarningLevel> |
||||||
|
<SDLCheck>true</SDLCheck> |
||||||
|
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> |
||||||
|
<ConformanceMode>true</ConformanceMode> |
||||||
|
<LanguageStandard>stdcpp17</LanguageStandard> |
||||||
|
</ClCompile> |
||||||
|
<Link> |
||||||
|
<SubSystem>Console</SubSystem> |
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation> |
||||||
|
</Link> |
||||||
|
</ItemDefinitionGroup> |
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> |
||||||
|
<ClCompile> |
||||||
|
<WarningLevel>Level3</WarningLevel> |
||||||
|
<FunctionLevelLinking>true</FunctionLevelLinking> |
||||||
|
<IntrinsicFunctions>true</IntrinsicFunctions> |
||||||
|
<SDLCheck>true</SDLCheck> |
||||||
|
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> |
||||||
|
<ConformanceMode>true</ConformanceMode> |
||||||
|
</ClCompile> |
||||||
|
<Link> |
||||||
|
<SubSystem>Console</SubSystem> |
||||||
|
<EnableCOMDATFolding>true</EnableCOMDATFolding> |
||||||
|
<OptimizeReferences>true</OptimizeReferences> |
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation> |
||||||
|
</Link> |
||||||
|
</ItemDefinitionGroup> |
||||||
|
<ItemGroup> |
||||||
|
<ClInclude Include="olcPixelGameEngine.h" /> |
||||||
|
<ClInclude Include="olcSoundWaveEngine.h" /> |
||||||
|
</ItemGroup> |
||||||
|
<ItemGroup> |
||||||
|
<ClCompile Include="main.cpp" /> |
||||||
|
</ItemGroup> |
||||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> |
||||||
|
<ImportGroup Label="ExtensionTargets"> |
||||||
|
</ImportGroup> |
||||||
|
</Project> |
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,137 @@ |
|||||||
|
#define OLC_PGE_APPLICATION |
||||||
|
#include "olcPixelGameEngine.h" |
||||||
|
#define OLC_SOUNDWAVE |
||||||
|
#include "olcSoundWaveEngine.h" |
||||||
|
|
||||||
|
using namespace olc; |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
enum SoundID { |
||||||
|
SONG, |
||||||
|
HERO, |
||||||
|
SIGG |
||||||
|
}; |
||||||
|
|
||||||
|
class Example : public olc::PixelGameEngine |
||||||
|
{ |
||||||
|
public: |
||||||
|
Example() |
||||||
|
{ |
||||||
|
sAppName = "Custom GameSound System based on olcSoundWaveEngine"; |
||||||
|
} |
||||||
|
sound::WaveEngine swe; |
||||||
|
sound::Wave song,hero,sigg; |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
struct GameSound { |
||||||
|
sound::PlayingWave sound; |
||||||
|
SoundID id; |
||||||
|
double duration; |
||||||
|
float playTime; |
||||||
|
bool paused = false; |
||||||
|
}; |
||||||
|
|
||||||
|
std::vector<GameSound>playingSounds; |
||||||
|
|
||||||
|
void PlayWaveform(SoundID id, sound::Wave* pWave, bool bLoop=false, double dSpeed=1.0) { |
||||||
|
sound::PlayingWave playing_sound = swe.PlayWaveform(pWave, bLoop, dSpeed); |
||||||
|
playingSounds.push_back({ playing_sound,id,playing_sound->dDuration }); |
||||||
|
} |
||||||
|
|
||||||
|
void PauseSound(GameSound& sound) { |
||||||
|
sound.paused = true; |
||||||
|
sound::WaveInstance& wi = *sound.sound; |
||||||
|
wi.bPaused = true; |
||||||
|
} |
||||||
|
|
||||||
|
void UnpauseSound(GameSound& sound) { |
||||||
|
sound.paused = false; |
||||||
|
sound::WaveInstance& wi = *sound.sound; |
||||||
|
wi.bPaused = false; |
||||||
|
} |
||||||
|
|
||||||
|
void StopSound(SoundID id) { |
||||||
|
for (std::vector<GameSound>::iterator it = playingSounds.begin(); it != playingSounds.end();) { |
||||||
|
GameSound& sound = *it; |
||||||
|
if (sound.id == id) { |
||||||
|
swe.StopWaveform(sound.sound); |
||||||
|
it=playingSounds.erase(it); |
||||||
|
if (it == playingSounds.end()) { |
||||||
|
break; |
||||||
|
} |
||||||
|
else { |
||||||
|
continue; |
||||||
|
} |
||||||
|
} |
||||||
|
++it; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public: |
||||||
|
bool OnUserCreate() override |
||||||
|
{ |
||||||
|
// Called once at the start, so create things here
|
||||||
|
//engine = &swe;
|
||||||
|
swe.InitialiseAudio(); |
||||||
|
song = sound::Wave("WeatherChannel.wav"); |
||||||
|
hero = sound::Wave("Hero.wav"); |
||||||
|
sigg = sound::Wave("Sigg.wav"); |
||||||
|
return true; |
||||||
|
} |
||||||
|
|
||||||
|
bool OnUserUpdate(float fElapsedTime) override |
||||||
|
{ |
||||||
|
if (GetKey(A).bPressed) { |
||||||
|
StopSound(SONG); |
||||||
|
PlayWaveform(SONG,&song,true); |
||||||
|
} |
||||||
|
if (GetKey(S).bPressed) { |
||||||
|
PlayWaveform(HERO, &hero, false); |
||||||
|
} |
||||||
|
if (GetKey(D).bPressed) { |
||||||
|
PlayWaveform(SIGG, &sigg, false); |
||||||
|
} |
||||||
|
if (GetKey(SPACE).bPressed) { |
||||||
|
StopSound(HERO); |
||||||
|
StopSound(SIGG); |
||||||
|
} |
||||||
|
if (GetKey(P).bPressed) { |
||||||
|
for (std::vector<GameSound>::iterator it = playingSounds.begin(); it != playingSounds.end(); ++it) { |
||||||
|
GameSound& sound = *it; |
||||||
|
PauseSound(sound); |
||||||
|
} |
||||||
|
} |
||||||
|
if (GetKey(U).bPressed) { |
||||||
|
for (std::vector<GameSound>::iterator it = playingSounds.begin(); it != playingSounds.end(); ++it) { |
||||||
|
GameSound& sound = *it; |
||||||
|
UnpauseSound(sound); |
||||||
|
} |
||||||
|
} |
||||||
|
for (std::vector<GameSound>::iterator it = playingSounds.begin(); it != playingSounds.end(); ++it) { |
||||||
|
GameSound& sound = *it; |
||||||
|
if (!sound.paused) { |
||||||
|
sound.playTime += fElapsedTime; |
||||||
|
if (sound.playTime > sound.duration) { |
||||||
|
it = playingSounds.erase(it); |
||||||
|
if (it == playingSounds.end()) { |
||||||
|
break; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
// called once per frame
|
||||||
|
return true; |
||||||
|
} |
||||||
|
}; |
||||||
|
|
||||||
|
|
||||||
|
int main() |
||||||
|
{ |
||||||
|
Example demo; |
||||||
|
if (demo.Construct(256, 240, 4, 4)) |
||||||
|
demo.Start(); |
||||||
|
|
||||||
|
return 0; |
||||||
|
} |
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
After Width: | Height: | Size: 11 KiB |
Loading…
Reference in new issue