Added score display

Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
master
sigonasr2 2 years ago
parent 9dc1ec3517
commit 581d0082b9
  1. BIN
      C++ProjectTemplate
  2. 13
      Meteos.h
  3. 66
      main.cpp

Binary file not shown.

@ -10,14 +10,27 @@ class Meteos : public olc::PixelGameEngine{
Meteos(){
sAppName="Meteos";
}
long frameTime=0;
const int BASE_SCORE = 60; //Cleared score is BASE_SCORE*combo.
const int MATCH_SCORE = 10; //Points earned when making a block match*combo.
const int BONUS_ATTACK_SCORE = 1000; //for every 10 blocks released at once, an extra 1000 BASE_SCORE is added.
float lastBlockLaunched=0.0f; //When enough time has passed, the attack is released to the opponent.
float blockLaunchWaitPeriod=3.0f;
int blocksInAttackQueue=0;
int accumulatedScore=0;
float lastBlockSpawn=0.0f;
float accumulatedTime=0.0f;
const float SCORE_DISPLAY_UPDATE_RATE=0.05f;
float lastScoreDisplayUpdate=0.0f;
std::uniform_int_distribution<> randBlockPos,coinFlip,comboOverlayOffset;
std::mt19937 gen;
Board gameBoard;
bool gameCanRun=true;
std::map<std::string,Renderable> SPRITES;
std::vector<ComboOverlay>comboDisplayList;
int score=0;
int displayTargetScore=0; //While technically the displayed score should be what the score actually is, if we're showing how many points we earn for a combo we want to delay adding it to our actual score display for flair and show a side bonus counter.
int displayScore=0;
bool OnUserCreate()override;
void updateGame(float fElapsedTime);
void handleInput();

@ -37,6 +37,7 @@ bool Meteos::OnUserUpdate(float fElapsedTime)
accumulatedTime+=fElapsedTime;
if (accumulatedTime>=1/60.0f) {
updateGame(1/60.0f);
frameTime++;
accumulatedTime=0;
}
handleInput();
@ -506,6 +507,8 @@ void Meteos::matchFlyingBlockClumps(){
c.vspeed=gameBoard.launchSpd[std::min(c.combo,(int)gameBoard.launchSpd.size()-1)]/(1+(c.getBlocks().size()*gameBoard.blockWeight));
c.launchTime=gameBoard.launchTime;
c.combo++;
score+=MATCH_SCORE*c.combo;
displayTargetScore+=MATCH_SCORE*c.combo;
vi2d randomOffset={comboOverlayOffset(gen),comboOverlayOffset(gen)};
comboDisplayList.push_back({c.getBlockPosition(gameBoard.getBlockClumps()[matchedBlockIDs[0].c].getBlocks()[matchedBlockIDs[0].ind])+randomOffset,c.combo});
//std::cout<<"Combo value is "<<c.combo<<std::endl;
@ -770,6 +773,8 @@ void Meteos::matchGroundedBlocks(){
gameBoard.getBlockClumps()[gameBoard.getBlockClumps().size()-1].vspeed=gameBoard.launchSpd[std::min(gameBoard.getBlockClumps()[gameBoard.getBlockClumps().size()-1].combo,(int)gameBoard.launchSpd.size()-1)]/(1+(gameBoard.getBlockClumps()[gameBoard.getBlockClumps().size()-1].getBlocks().size()*gameBoard.blockWeight));
gameBoard.getBlockClumps()[gameBoard.getBlockClumps().size()-1].launchTime=gameBoard.launchTime;
gameBoard.getBlockClumps()[gameBoard.getBlockClumps().size()-1].combo++;
score+=MATCH_SCORE*gameBoard.getBlockClumps()[gameBoard.getBlockClumps().size()-1].combo;
displayTargetScore+=MATCH_SCORE*gameBoard.getBlockClumps()[gameBoard.getBlockClumps().size()-1].combo;
vi2d randomOffset={comboOverlayOffset(gen),comboOverlayOffset(gen)};
comboDisplayList.push_back({baseBlockPos+randomOffset,gameBoard.getBlockClumps()[gameBoard.getBlockClumps().size()-1].combo});
//std::cout<<"Combo value is "<<gameBoard.getBlockClumps()[gameBoard.getBlockClumps().size()-1].combo<<std::endl;
@ -789,6 +794,16 @@ void Meteos::cleanupBlocks(){
Block&b=c.getBlocks()[j];
b.addedToLaunchList=false;
if (c.vspeed<0&&c.getBlockPosition(b).y<0||b.markedForRemoval){
if (c.vspeed<0&&c.getBlockPosition(b).y<0){
accumulatedScore+=BASE_SCORE*c.combo;
score+=BASE_SCORE*c.combo;
blocksInAttackQueue++;
lastBlockLaunched=0.0f;
if (blocksInAttackQueue%10==0){
accumulatedScore+=BONUS_ATTACK_SCORE;
score+=BONUS_ATTACK_SCORE;
}
}
std::cout<<"Removed block @"<<b.pos<<" from clump "<<i<<std::endl;
c.removeBlock(j);
}
@ -874,6 +889,50 @@ void Meteos::updateGame(float fElapsedTime){
handleWarningLevels(fElapsedTime);
validateSelectedBlock();
handleComboAnimations();
if (blocksInAttackQueue){
lastBlockLaunched+=fElapsedTime;
if (lastBlockLaunched>=blockLaunchWaitPeriod){
blocksInAttackQueue=0;
accumulatedScore=0;
displayTargetScore=score;
}
}
lastScoreDisplayUpdate+=fElapsedTime;
if (lastScoreDisplayUpdate>=SCORE_DISPLAY_UPDATE_RATE){
if (displayScore!=displayTargetScore){
int tempScore=displayTargetScore;
int tempDisplayScore=displayScore;
std::vector<int>targetScoreDigits;
std::vector<int>displayScoreDigits;
while (tempScore>0){
int digit=tempScore%10;
tempScore/=10;
targetScoreDigits.insert(targetScoreDigits.begin(),digit);
std::cout<<digit;
}
while (tempDisplayScore>0){
int digit=tempDisplayScore%10;
tempDisplayScore/=10;
displayScoreDigits.insert(displayScoreDigits.begin(),digit);
std::cout<<digit;
}
std::cout<<std::endl;
int marker=0;
while (marker<targetScoreDigits.size()||marker<displayScoreDigits.size()){
int targetScoreDigit=marker<targetScoreDigits.size()?targetScoreDigits[targetScoreDigits.size()-1-marker]:0;
int displayScoreDigit=marker<displayScoreDigits.size()?displayScoreDigits[displayScoreDigits.size()-1-marker]:0;
if (displayScoreDigit!=targetScoreDigit){
if (displayScoreDigit+1<10){
displayScore+=std::pow(10,marker);
} else {
displayScore-=std::pow(10,marker)*9;
}
}
marker++;
}
}
lastScoreDisplayUpdate=0;
}
}
void Meteos::drawGame(float fElapsedTime,bool debugView){
@ -911,6 +970,13 @@ void Meteos::drawGame(float fElapsedTime,bool debugView){
DrawStringPropDecal(c.pos+gameBoard.drawOffset+shadowOffset,"x"+std::to_string(c.combo),BLACK,{0.8,0.6});
DrawStringPropDecal(c.pos+gameBoard.drawOffset,"x"+std::to_string(c.combo),(c.lifetime%6>=3)?Pixel{207,103,0}:Pixel{255,255,255,180},{0.8,0.6});
}
DrawStringDecal(gameBoard.drawOffset+vi2d{-8,-16}+vi2d{1,1},std::to_string(displayScore),BLACK,{2,2});
DrawStringDecal(gameBoard.drawOffset+vi2d{-8,-16},std::to_string(displayScore),WHITE,{2,2});
if (accumulatedScore>0){
DrawStringDecal(gameBoard.drawOffset+vi2d{0,0}+vi2d{1,1},"+"+std::to_string(accumulatedScore),BLACK,{0.75,0.75});
DrawStringDecal(gameBoard.drawOffset+vi2d{0,0},"+"+std::to_string(accumulatedScore),frameTime%5>2?Pixel{224, 184, 148}:WHITE,{0.75,0.75});
}
}
int main()

Loading…
Cancel
Save