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.
192 lines
6.8 KiB
192 lines
6.8 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:
|
|
int frameCount=0;
|
|
float accumulatedTime=0;
|
|
const float UPDATE_RATE=1/60.0F;
|
|
char partyMemberCount=1;
|
|
olc::sound::WaveEngine engine;
|
|
olc::sound::Wave se1;
|
|
olc::Decal*rollingCounter;
|
|
|
|
char*player_name[4] = {"NESS","PAULA","JEFF","POO"};
|
|
int player_hp[4] = {120,74,105,96};
|
|
int player_pp[4] = {46,87,0,50};
|
|
int player_rollhp[4] = {player_hp[0],player_hp[1],player_hp[2],player_hp[3]};
|
|
int player_rollpp[4] = {player_pp[0],player_pp[1],player_pp[2],player_pp[3]};
|
|
int player_rollhp_display[4][3] = {{player_hp[0]%10,player_hp[0]/10%10,player_hp[0]/100%10},{player_hp[1]%10,player_hp[1]/10%10,player_hp[1]/100%10},{player_hp[2]%10,player_hp[2]/10%10,player_hp[2]/100%10},{player_hp[3]%10,player_hp[3]/10%10,player_hp[3]/100%10}};
|
|
int player_rollpp_display[4][3] = {{player_pp[0]%10,player_pp[0]/10%10,player_pp[0]/100%10},{player_pp[1]%10,player_pp[1]/10%10,player_pp[1]/100%10},{player_pp[2]%10,player_pp[2]/10%10,player_pp[2]/100%10},{player_pp[3]%10,player_pp[3]/10%10,player_pp[3]/100%10}};
|
|
int player_rollhp_counter[4][3] = {{0,0,0},{0,0,0},{0,0,0},{0,0,0}};
|
|
int player_rollpp_counter[4][3] = {{0,0,0},{0,0,0},{0,0,0},{0,0,0}};
|
|
|
|
|
|
bool OnUserCreate() override
|
|
{
|
|
SetPixelMode(olc::Pixel::ALPHA);
|
|
|
|
rollingCounter = new olc::Decal(new olc::Sprite("assets/rollingcounter.png"));
|
|
//ConsoleCaptureStdOut(true);
|
|
// Called once at the start, so create things here
|
|
engine.InitialiseAudio();
|
|
engine.SetOutputVolume(0.1f);
|
|
se1.LoadAudioWaveform("./assets/sample-9s.wav");
|
|
|
|
player_hp[0]=30;
|
|
//WriteEmscriptenFile("test","Test?\nThis has more\nthan two lines!");
|
|
|
|
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(){
|
|
frameCount++;
|
|
if (frameCount==180) {
|
|
std::vector<std::string> data = ReadEmscriptenFile("test");
|
|
for (int i=0;i<data.size();i++) {
|
|
cout << data[i] << "\n";
|
|
}
|
|
for (int i=0;i<data[0].length();i++) {
|
|
player_name[0][i]=data[0][i];
|
|
}
|
|
}
|
|
for (int i=0;i<partyMemberCount;i++) {
|
|
if (player_rollhp[i]>player_hp[i]) {
|
|
if (player_rollhp_counter[i][0]<=0) {
|
|
player_rollhp_display[i][0]--;
|
|
player_rollhp_counter[i][0]=13;
|
|
player_rollhp[i]--;
|
|
if (player_rollhp_display[i][0]<0) {
|
|
player_rollhp_display[i][0]=9;
|
|
player_rollhp_counter[i][0]=13;
|
|
player_rollhp_display[i][1]--;
|
|
player_rollhp_counter[i][1]=13;
|
|
if (player_rollhp_display[i][1]<0) {
|
|
player_rollhp_display[i][1]=9;
|
|
player_rollhp_counter[i][1]=13;
|
|
player_rollhp_display[i][2]--;
|
|
player_rollhp_counter[i][2]=13;
|
|
}
|
|
}
|
|
}
|
|
} else
|
|
if (player_rollhp[i]<player_hp[i]) {
|
|
|
|
} else {
|
|
player_rollhp_counter[i][0]=player_rollhp_counter[i][1]=player_rollhp_counter[i][2]=0;
|
|
}
|
|
if (player_rollhp_counter[i][0]>0) {
|
|
player_rollhp_counter[i][0]-=3;
|
|
}
|
|
if (player_rollhp_counter[i][1]>0) {
|
|
player_rollhp_counter[i][1]--;
|
|
}
|
|
if (player_rollhp_counter[i][2]>0) {
|
|
player_rollhp_counter[i][2]--;
|
|
}
|
|
}
|
|
}
|
|
|
|
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({(float)(pos.x+3),(float)(pos.y+3)},{(float)(size.x-5),(float)(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({(float)(x+pos.x),(float)(y+pos.y)},{(float)checkerboardSize.x,(float)checkerboardSize.y},alternatingCol);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void DrawRollingCounter(const olc::vi2d &pos,int val,int*rollcounter,int*rolloffset) {
|
|
FillRectDecal({(float)(pos.x+20),(float)(pos.y-3)},{30,13},olc::DARK_GREY);
|
|
FillRectDecal({(float)(pos.x+21),(float)(pos.y-2)},{28,11},olc::GREY);
|
|
DrawLineDecal({(float)(pos.x+30),(float)(pos.y-3)},{(float)(pos.x+30),(float)(pos.y+10)},olc::DARK_GREY);
|
|
DrawLineDecal({(float)(pos.x+40),(float)(pos.y-3)},{(float)(pos.x+40),(float)(pos.y+10)},olc::DARK_GREY);
|
|
DrawPartialDecal({(float)(pos.x+22),(float)(pos.y-1)},{7,9},rollingCounter,{0,(float)(rollcounter[2]*13+rolloffset[2])},{7,9});
|
|
DrawPartialDecal({(float)(pos.x+31),(float)(pos.y-1)},{7,9},rollingCounter,{0,(float)(rollcounter[1]*13+rolloffset[1])},{7,9});
|
|
DrawPartialDecal({(float)(pos.x+41),(float)(pos.y-1)},{7,9},rollingCounter,{0,(float)(rollcounter[0]*13+rolloffset[0])},{7,9});
|
|
}
|
|
|
|
void drawGame(){
|
|
drawBox({0,0},{128,48},olc::BLACK);
|
|
for (int i=0;i<partyMemberCount;i++) {
|
|
const olc::vi2d box = {(128-32*partyMemberCount)+i*64,160};
|
|
drawCheckerboardBox(box,{59,59},olc::Pixel(180,159,194),olc::Pixel(200,179,214),{6,6});
|
|
DrawStringDecal({(float)(box.x+6),(float)(box.y+6)},player_name[i],olc::BLACK);
|
|
const olc::vi2d hpTextPos = {box.x+5,box.y+25};
|
|
for (int x=-1;x<=1;x++) {
|
|
for (int y=-1;y<=1;y++) {
|
|
if (x!=0&&y!=0) {
|
|
DrawStringDecal({(float)(hpTextPos.x+x),(float)(hpTextPos.y+y)},"HP",olc::WHITE);
|
|
}
|
|
}
|
|
}
|
|
DrawStringDecal(hpTextPos,"HP",olc::BLACK);
|
|
DrawRollingCounter(hpTextPos,player_rollhp[i],player_rollhp_display[i],player_rollhp_counter[i]);
|
|
const olc::vi2d mpTextPos = {box.x+5,hpTextPos.y+17};
|
|
for (int x=-1;x<=1;x++) {
|
|
for (int y=-1;y<=1;y++) {
|
|
if (x!=0&&y!=0) {
|
|
DrawStringDecal({(float)(mpTextPos.x+x),(float)(mpTextPos.y+y)},"PP",olc::WHITE);
|
|
}
|
|
}
|
|
}
|
|
DrawStringDecal(mpTextPos,"PP",olc::BLACK);
|
|
DrawRollingCounter(mpTextPos,player_rollpp[i],player_rollpp_display[i],player_rollpp_counter[i]);
|
|
}
|
|
}
|
|
};
|
|
|
|
|
|
int main()
|
|
{
|
|
EarthboundBattleSim demo;
|
|
if (demo.Construct(256, 224, 4, 4))
|
|
demo.Start();
|
|
|
|
return 0;
|
|
} |