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

181 lines
6.1 KiB

2 years ago
#define OLC_PGE_APPLICATION
#include "pixelGameEngine.h"
#define OLC_SOUNDWAVE
#include "soundExtension.h"
2 years ago
using namespace std;
class EarthboundBattleSim : public olc::PixelGameEngine
2 years ago
{
public:
EarthboundBattleSim()
2 years ago
{
sAppName = "EarthboundBattleSim";
2 years ago
}
public:
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}};
2 years ago
bool OnUserCreate() override
{
SetPixelMode(olc::Pixel::ALPHA);
rollingCounter = new olc::Decal(new olc::Sprite("assets/rollingcounter.png"));
//ConsoleCaptureStdOut(true);
2 years ago
// 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;
2 years ago
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();
2 years ago
// called once per frame
return true;
}
void updateGame(){
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({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 DrawRollingCounter(const olc::vi2d &pos,int val,int*rollcounter,int*rolloffset) {
FillRectDecal({pos.x+20,pos.y-3},{30,13},olc::DARK_GREY);
FillRectDecal({pos.x+21,pos.y-2},{28,11},olc::GREY);
DrawLineDecal({pos.x+30,pos.y-3},{pos.x+30,pos.y+10},olc::DARK_GREY);
DrawLineDecal({pos.x+40,pos.y-3},{pos.x+40,pos.y+10},olc::DARK_GREY);
DrawPartialDecal({pos.x+22,pos.y-1},{7,9},rollingCounter,{0,rollcounter[2]*13+rolloffset[2]},{7,9});
DrawPartialDecal({pos.x+31,pos.y-1},{7,9},rollingCounter,{0,rollcounter[1]*13+rolloffset[1]},{7,9});
DrawPartialDecal({pos.x+41,pos.y-1},{7,9},rollingCounter,{0,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({box.x+6,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({hpTextPos.x+x,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({mpTextPos.x+x,mpTextPos.y+y},"PP",olc::WHITE);
}
}
}
DrawStringDecal(mpTextPos,"PP",olc::BLACK);
DrawRollingCounter(mpTextPos,player_rollpp[i],player_rollpp_display[i],player_rollpp_counter[i]);
}
}
2 years ago
};
int main()
{
EarthboundBattleSim demo;
if (demo.Construct(256, 224, 4, 4))
2 years ago
demo.Start();
return 0;
}