Skip to content

Commit

Permalink
update demo
Browse files Browse the repository at this point in the history
  • Loading branch information
Moros1138 committed Nov 18, 2023
1 parent f8ff226 commit 0052f0c
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions demo/demo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#define OLC_PGEX_MINIAUDIO
#include "olcPGEX_MiniAudio.h"

constexpr float thirtyFramesPerSecond = 1.0f / 30.f;

class Demo : public olc::PixelGameEngine
{
public:
Expand All @@ -23,24 +25,29 @@ class Demo : public olc::PixelGameEngine

return true;
}

bool OnUserUpdate(float fElapsedTime) override
{
fElapsedTime = (fElapsedTime > thirtyFramesPerSecond) ? thirtyFramesPerSecond : fElapsedTime;

if(GetKey(olc::K1).bPressed)
{
backgroundPlay = !backgroundPlay;
ma.SetBackgroundPlay(backgroundPlay);
}

if(GetKey(olc::S).bPressed)
{
ma.Play("assets/sounds/SampleA.wav");
}


if(GetKey(olc::SPACE).bPressed)
{
// Toggle takes a sample ID (int) and either starts playback or pauses playback
// depending on whether the sample is currently playing, or not.
ma.Toggle(song1);
}


if(GetKey(olc::MINUS).bHeld)
{
pan -= 1.0f * fElapsedTime;
Expand Down Expand Up @@ -110,7 +117,9 @@ class Demo : public olc::PixelGameEngine
"\n"
"Volume <" + std::to_string(volume) + "> Up, Down\n"
"\n"
"One-Off Sounds <" + std::to_string(ma.GetOneOffSounds().size()) + "> S", \
"One-Off Sounds <" + std::to_string(ma.GetOneOffSounds().size()) + "> S\n" \
"\n" \
"BackgroundPlay <" + ((backgroundPlay) ? "On": "Off") + "> K1\n",
olc::WHITE, {0.5f, 0.5f});

olc::vi2d center = (GetScreenSize() / 2);
Expand Down Expand Up @@ -146,6 +155,7 @@ class Demo : public olc::PixelGameEngine
float pitch = 1.0f;
float seek = 0.0f;
float volume = 1.0f;
bool backgroundPlay = false;

};

Expand Down

0 comments on commit 0052f0c

Please sign in to comment.