Plays sound, but only in emscripten for now. Something's wrong with ALSA

Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
master
sigonasr2 2 years ago
parent b7296f50a1
commit 92ab6d3a9c
  1. 4
      C++/scripts/web.sh
  2. BIN
      C++ProjectTemplate
  3. BIN
      C++ProjectTemplate.data
  4. 76
      C++ProjectTemplate.html
  5. 2
      C++ProjectTemplate.js
  6. BIN
      C++ProjectTemplate.wasm
  7. BIN
      assets/laserShoot.wav
  8. BIN
      assets/sample-9s.wav
  9. 71
      main.cpp
  10. 4
      sig
  11. 1780
      soundExtension.h

@ -1,9 +1,9 @@
#Compiles emscripten instance of this project for the web.
#C++
if [ -d "assets" ]; then
em++ -std=c++17 -O2 -s ALLOW_MEMORY_GROWTH=1 -s MAX_WEBGL_VERSION=2 -s MIN_WEBGL_VERSION=2 -s USE_LIBPNG=1 $(find . -type f -name "*.cpp") -o ${PROJECT_NAME}.html -I pixelGameEngine.h --preload-file ./assets
em++ -std=c++17 -O2 -s ALLOW_MEMORY_GROWTH=1 -s MAX_WEBGL_VERSION=2 -s MIN_WEBGL_VERSION=2 -s USE_SDL_MIXER=2 -s USE_LIBPNG=1 $(find . -type f -name "*.cpp") -o ${PROJECT_NAME}.html -I pixelGameEngine.h --preload-file ./assets
else
em++ -std=c++17 -O2 -s ALLOW_MEMORY_GROWTH=1 -s MAX_WEBGL_VERSION=2 -s MIN_WEBGL_VERSION=2 -s USE_LIBPNG=1 $(find . -type f -name "*.cpp") -o ${PROJECT_NAME}.html -I pixelGameEngine.h
em++ -std=c++17 -O2 -s ALLOW_MEMORY_GROWTH=1 -s MAX_WEBGL_VERSION=2 -s MIN_WEBGL_VERSION=2 -s USE_SDL_MIXER=2 -s USE_LIBPNG=1 $(find . -type f -name "*.cpp") -o ${PROJECT_NAME}.html -I pixelGameEngine.h
fi
cp buildtemplate.html ${PROJECT_NAME}.html

Binary file not shown.

Binary file not shown.

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

Binary file not shown.

Binary file not shown.

Binary file not shown.

@ -1,45 +1,88 @@
#define OLC_PGE_APPLICATION
#include "pixelGameEngine.h"
#define OLC_SOUNDWAVE
#include "soundExtension.h"
using namespace std;
class Example : public olc::PixelGameEngine
class EarthboundBattleSim : public olc::PixelGameEngine
{
public:
Example()
EarthboundBattleSim()
{
sAppName = "Example";
sAppName = "EarthboundBattleSim";
}
public:
float accumulatedTime=0;
const float UPDATE_RATE=1/60.0F;
char partyMemberCount=1;
olc::sound::WaveEngine engine;
olc::sound::Wave se1;
bool OnUserCreate() override
{
SetPixelMode(olc::Pixel::ALPHA);
ConsoleCaptureStdOut(true);
//ConsoleCaptureStdOut(true);
// Called once at the start, so create things here
for (int x = 0; x < ScreenWidth(); x++)
for (int y = 0; y < ScreenHeight(); y++)
Draw(x, y, olc::Pixel(rand() % 255, rand() % 255, rand()% 255));
for (int x=0;x<50;x++) {
for (int y=0;y<50;y++) {
Draw(x, y, olc::Pixel(255, 0, 0, 128));
}
}
engine.InitialiseAudio();
engine.SetOutputVolume(0.1f);
se1.LoadAudioWaveform("./assets/sample-9s.wav");
return true;
}
bool OnUserUpdate(float fElapsedTime) override
{
Clear(olc::BLACK);
accumulatedTime+=fElapsedTime;
while (accumulatedTime>=UPDATE_RATE) {
accumulatedTime-=UPDATE_RATE;
updateGame(); //DO NOT ADD THINGS HERE. USE updateGame()!
}
if (GetKey(olc::RIGHT).bPressed) {
partyMemberCount=min(partyMemberCount+1,4);
}
if (GetKey(olc::LEFT).bPressed) {
partyMemberCount=max(partyMemberCount-1,1);
}
if (GetMouse(0).bPressed) {
engine.PlayWaveform(&se1);
}
drawGame();
// called once per frame
return true;
}
void updateGame(){
}
void drawBox(const olc::vi2d &pos, const olc::vi2d &size, olc::Pixel p = olc::WHITE, olc::Pixel p2 = olc::DARK_GREY, olc::Pixel p3 = olc::VERY_DARK_GREY) {
DrawRect({pos.x,pos.y},size,p2);
DrawRect({pos.x+2,pos.y+2},{size.x-4,size.y-4},p3);
DrawRect({pos.x+1,pos.y+1},{size.x-2,size.y-2});
Draw({pos.x,pos.y},olc::BLACK);
Draw({pos.x+size.x,pos.y+size.y},olc::BLACK);
Draw({pos.x+size.x,pos.y},olc::BLACK);
Draw({pos.x,pos.y+size.y},olc::BLACK);
}
void drawGame(){
drawBox({0,0},{128,32});
for (int i=0;i<partyMemberCount;i++) {
drawBox({(128-32*partyMemberCount)+i*64,160},{64,64});
}
}
};
int main()
{
Example demo;
if (demo.Construct(256, 240, 4, 4))
EarthboundBattleSim demo;
if (demo.Construct(256, 224, 4, 4))
demo.Start();
return 0;

4
sig

@ -1,9 +1,9 @@
export AUTO_UPDATE=true
export AUTO_UPDATE=false
source utils/define.sh
define PROJECT_NAME "C++ProjectTemplate"
define CUSTOM_PARAMS "-lpng -lGL -lX11"
define CUSTOM_PARAMS "-lX11 -lGL -lpthread -lpng -lstdc++fs -lasound"
define LANGUAGE "C++"
source utils/main.sh

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save