generated from sigonasr2/CPlusPlusProjectTemplate
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
89 lines
1.9 KiB
89 lines
1.9 KiB
#define OLC_PGE_APPLICATION
|
|
#include "pixelGameEngine.h"
|
|
#define OLC_SOUNDWAVE
|
|
#include "soundExtension.h"
|
|
|
|
using namespace std;
|
|
|
|
class EarthboundBattleSim : public olc::PixelGameEngine
|
|
{
|
|
public:
|
|
EarthboundBattleSim()
|
|
{
|
|
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);
|
|
// Called once at the start, so create things here
|
|
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()
|
|
{
|
|
EarthboundBattleSim demo;
|
|
if (demo.Construct(256, 224, 4, 4))
|
|
demo.Start();
|
|
|
|
return 0;
|
|
} |