Scrolling HP meters (down) implemented

Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
master
sigonasr2 2 years ago
parent 67453b3d89
commit 9ad2eba8eb
  1. BIN
      C++ProjectTemplate
  2. BIN
      assets/rollingcounter.png
  3. 85
      main.cpp

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 710 B

@ -20,16 +20,32 @@ public:
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;
return true;
}
@ -55,6 +71,41 @@ public:
}
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) {
@ -79,10 +130,42 @@ public:
}
}
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++) {
drawCheckerboardBox({(128-32*partyMemberCount)+i*64,160},{59,59},olc::Pixel(180,159,194),olc::Pixel(200,179,214),{6,6});
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]);
}
}
};

Loading…
Cancel
Save