Survive as long as you can defeating foes and striving for glory, but be careful... Make the wrong moves and things could become a lot more difficult.
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.
EarthboundBattleSim/main.cpp

98 lines
2.6 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);
}
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) {
FillRectDecal({pos.x+3,pos.y+3},{size.x-5,size.y-5},p);
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},p);
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 drawCheckerboardBox(const olc::vi2d &pos, const olc::vi2d &size, olc::Pixel p = olc::WHITE, olc::Pixel alternatingCol = olc::WHITE, const olc::vi2d &checkerboardSize = {3,3}, olc::Pixel p2 = olc::DARK_GREY, olc::Pixel p3 = olc::VERY_DARK_GREY) {
drawBox(pos,size,p,p2,p3);
for (int x=3;x<size.x;x+=checkerboardSize.x*2) {
for (int y=3;y<size.y;y+=checkerboardSize.y*2) {
if (x+checkerboardSize.x<size.x&&y+checkerboardSize.y<size.y) {
FillRectDecal({x+pos.x,y+pos.y},{checkerboardSize.x,checkerboardSize.y},alternatingCol);
}
}
}
}
void drawGame(){
drawBox({0,0},{128,48},olc::BLACK);
for (int i=0;i<partyMemberCount;i++) {
drawCheckerboardBox({(128-32*partyMemberCount)+i*64,160},{59,59},olc::Pixel(180,159,194),olc::Pixel(200,179,214),{6,6});
}
}
};
int main()
{
EarthboundBattleSim demo;
if (demo.Construct(256, 224, 4, 4))
demo.Start();
return 0;
}