Include combo display numbers

Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
master
sigonasr2 2 years ago
parent fbfad3ab01
commit f0eb4b444e
  1. BIN
      C++ProjectTemplate
  2. 10
      ComboOverlay.h
  3. 2
      Meteos.h
  4. 45
      main.cpp

Binary file not shown.

@ -0,0 +1,10 @@
#include "pixelGameEngine.h"
class ComboOverlay{
public:
vf2d pos;
int combo;
int lifetime=0;
ComboOverlay(const vf2d pos,const int combo)
:pos(pos),combo(combo){}
};

@ -3,6 +3,7 @@
#include "pixelGameEngine.h" #include "pixelGameEngine.h"
#include "Board.h" #include "Board.h"
#include <random> #include <random>
#include "ComboOverlay.h"
class Meteos : public olc::PixelGameEngine{ class Meteos : public olc::PixelGameEngine{
public: public:
@ -16,6 +17,7 @@ class Meteos : public olc::PixelGameEngine{
Board gameBoard; Board gameBoard;
bool gameCanRun=true; bool gameCanRun=true;
std::map<std::string,Renderable> SPRITES; std::map<std::string,Renderable> SPRITES;
std::vector<ComboOverlay>comboDisplayList;
bool OnUserCreate()override; bool OnUserCreate()override;
void updateGame(float fElapsedTime); void updateGame(float fElapsedTime);
void handleInput(); void handleInput();

@ -288,7 +288,8 @@ void Meteos::updateGame(float fElapsedTime){
c.vspeed=gameBoard.launchSpd; c.vspeed=gameBoard.launchSpd;
c.launchTime=gameBoard.launchTime; c.launchTime=gameBoard.launchTime;
c.combo++; c.combo++;
std::cout<<"Combo value is "<<c.combo<<std::endl; comboDisplayList.push_back({c.getBlockPosition(c.getBlocks()[matchedBlockIDs[0]]),c.combo});
//std::cout<<"Combo value is "<<c.combo<<std::endl;
} }
} }
std::vector<BlockMatchingInfo>matchedBlockIDs; //Col followed by index std::vector<BlockMatchingInfo>matchedBlockIDs; //Col followed by index
@ -474,21 +475,21 @@ void Meteos::updateGame(float fElapsedTime){
if (matchedBlockIDs.size()>0) { if (matchedBlockIDs.size()>0) {
BlockClump c; BlockClump c;
bool firstBlock=true; bool firstBlock=true;
int baseBlockPos; vf2d baseBlockPos;
for (BlockMatchingInfo&info:matchedBlockIDs) { for (BlockMatchingInfo&info:matchedBlockIDs) {
if (info.c!=-1){ if (info.c!=-1){
Block&b=gameBoard.getBlockClumps()[info.c].getBlocks()[info.ind]; Block&b=gameBoard.getBlockClumps()[info.c].getBlocks()[info.ind];
if (firstBlock) { if (firstBlock) {
baseBlockPos=gameBoard.getBlockClumps()[info.c].getBlockPosition(b).y; baseBlockPos=gameBoard.getBlockClumps()[info.c].getBlockPosition(b);
c.y=baseBlockPos-1; c.y=baseBlockPos.y-1;
firstBlock=false; firstBlock=false;
} }
b.col=BlockColor::LAUNCHED; b.col=BlockColor::LAUNCHED;
} else { } else {
Block&b=gameBoard.getBlocks(info.col)[info.ind]; Block&b=gameBoard.getBlocks(info.col)[info.ind];
if (firstBlock) { if (firstBlock) {
baseBlockPos=b.pos.y; baseBlockPos=b.pos;
c.y=baseBlockPos-1; c.y=baseBlockPos.y-1;
firstBlock=false; firstBlock=false;
} }
b.col=BlockColor::LAUNCHED; b.col=BlockColor::LAUNCHED;
@ -502,12 +503,12 @@ void Meteos::updateGame(float fElapsedTime){
} }
for (int i=gameBoard.getBlockClumps()[info.c].getBlocks().size()-1;i>=0;i--) { for (int i=gameBoard.getBlockClumps()[info.c].getBlocks().size()-1;i>=0;i--) {
Block&b2=gameBoard.getBlockClumps()[info.c].getBlocks()[i]; Block&b2=gameBoard.getBlockClumps()[info.c].getBlocks()[i];
if ((int)fmod(std::abs(std::round(gameBoard.getBlockClumps()[info.c].getBlockPosition(b2).y)-std::round(baseBlockPos)),12)!=0){ if ((int)fmod(std::abs(std::round(gameBoard.getBlockClumps()[info.c].getBlockPosition(b2).y)-std::round(baseBlockPos.y)),12)!=0){
std::cout<<"Difference is not equal to 0! Value:"<<(int)fmod(std::abs(std::round(gameBoard.getBlockClumps()[info.c].getBlockPosition(b2).y)-std::round(baseBlockPos)),12)<<" "<<gameBoard.getBlockClumps()[info.c].getBlockPosition(b2).y<<"//"<<baseBlockPos<<std::endl; std::cout<<"Difference is not equal to 0! Value:"<<(int)fmod(std::abs(std::round(gameBoard.getBlockClumps()[info.c].getBlockPosition(b2).y)-std::round(baseBlockPos.y)),12)<<" "<<gameBoard.getBlockClumps()[info.c].getBlockPosition(b2).y<<"//"<<baseBlockPos.y<<std::endl;
assert(false); assert(false);
} }
c.addBlock(b2.pos.x/12,((int)gameBoard.getBlockClumps()[info.c].getBlockPosition(b2).y-(int)baseBlockPos)/12,b2.col); c.addBlock(b2.pos.x/12,((int)gameBoard.getBlockClumps()[info.c].getBlockPosition(b2).y-(int)baseBlockPos.y)/12,b2.col);
std::cout<<"Added block @"<<b2.pos.x/12<<((int)gameBoard.getBlockClumps()[info.c].getBlockPosition(b2).y-(int)baseBlockPos)/12<<std::endl; std::cout<<"Added block @"<<b2.pos.x/12<<((int)gameBoard.getBlockClumps()[info.c].getBlockPosition(b2).y-(int)baseBlockPos.y)/12<<std::endl;
gameBoard.getBlockClumps()[info.c].removeBlock(i); gameBoard.getBlockClumps()[info.c].removeBlock(i);
} }
} else { } else {
@ -519,12 +520,12 @@ void Meteos::updateGame(float fElapsedTime){
for (int i=gameBoard.getBlocks(info.col).size()-1;i>=0;i--){ for (int i=gameBoard.getBlocks(info.col).size()-1;i>=0;i--){
Block&b2=gameBoard.getBlocks(info.col)[i]; Block&b2=gameBoard.getBlocks(info.col)[i];
if (b2.pos.y<=yPos){ if (b2.pos.y<=yPos){
if ((int)fmod((int)b2.pos.y-(int)baseBlockPos,12)!=0){ if ((int)fmod((int)b2.pos.y-(int)baseBlockPos.y,12)!=0){
std::cout<<"Difference is not equal to 0! Value:"<<(int)fmod((int)b2.pos.y-(int)baseBlockPos,12)<<" "<<b2.pos.y<<"//"<<baseBlockPos<<std::endl; std::cout<<"Difference is not equal to 0! Value:"<<(int)fmod((int)b2.pos.y-(int)baseBlockPos.y,12)<<" "<<b2.pos.y<<"//"<<baseBlockPos.y<<std::endl;
assert(false); assert(false);
} }
c.addBlock(info.col,((int)b2.pos.y-(int)baseBlockPos)/12,b2.col); c.addBlock(info.col,((int)b2.pos.y-(int)baseBlockPos.y)/12,b2.col);
std::cout<<"Added block @"<<info.col<<((int)b2.pos.y-(int)baseBlockPos)/12<<std::endl; std::cout<<"Added block @"<<info.col<<((int)b2.pos.y-(int)baseBlockPos.y)/12<<std::endl;
//b2.markedForRemoval=true; //b2.markedForRemoval=true;
gameBoard.removeBlock(info.col,i); gameBoard.removeBlock(info.col,i);
} }
@ -535,7 +536,8 @@ void Meteos::updateGame(float fElapsedTime){
gameBoard.getBlockClumps()[gameBoard.getBlockClumps().size()-1].vspeed=gameBoard.launchSpd; gameBoard.getBlockClumps()[gameBoard.getBlockClumps().size()-1].vspeed=gameBoard.launchSpd;
gameBoard.getBlockClumps()[gameBoard.getBlockClumps().size()-1].launchTime=gameBoard.launchTime; gameBoard.getBlockClumps()[gameBoard.getBlockClumps().size()-1].launchTime=gameBoard.launchTime;
gameBoard.getBlockClumps()[gameBoard.getBlockClumps().size()-1].combo++; gameBoard.getBlockClumps()[gameBoard.getBlockClumps().size()-1].combo++;
std::cout<<"Combo value is "<<gameBoard.getBlockClumps()[gameBoard.getBlockClumps().size()-1].combo<<std::endl; comboDisplayList.push_back({baseBlockPos,gameBoard.getBlockClumps()[gameBoard.getBlockClumps().size()-1].combo});
//std::cout<<"Combo value is "<<gameBoard.getBlockClumps()[gameBoard.getBlockClumps().size()-1].combo<<std::endl;
} }
for (int i=gameBoard.getBlockClumps().size()-1;i>=0;i--){ //Resolve BlockClump movements. for (int i=gameBoard.getBlockClumps().size()-1;i>=0;i--){ //Resolve BlockClump movements.
BlockClump&c=gameBoard.getBlockClumps()[i]; BlockClump&c=gameBoard.getBlockClumps()[i];
@ -634,6 +636,13 @@ void Meteos::updateGame(float fElapsedTime){
found:; found:;
} }
} }
for (int i=comboDisplayList.size()-1;i>=0;i--){
ComboOverlay&c=comboDisplayList[i];
c.lifetime++;
if (c.lifetime>60){
comboDisplayList.erase(comboDisplayList.begin()+i);
}
}
} }
void Meteos::drawGame(float fElapsedTime,bool debugView){ void Meteos::drawGame(float fElapsedTime,bool debugView){
@ -662,6 +671,12 @@ void Meteos::drawGame(float fElapsedTime,bool debugView){
DrawPartialDecal(b.pos+gameBoard.drawOffset,gameBoard.tileset,{(float)(int)b.col*12,0},{12,12},{1,1},gameBoard.selectedBlock.col!=-1&&gameBoard.selectedBlock.c==-1&&gameBoard.selectedBlock.col==i&&gameBoard.selectedBlock.ind==y?Pixel(GREY.r,GREY.g,GREY.b,alpha):Pixel(WHITE.r,WHITE.g,WHITE.b,alpha)); DrawPartialDecal(b.pos+gameBoard.drawOffset,gameBoard.tileset,{(float)(int)b.col*12,0},{12,12},{1,1},gameBoard.selectedBlock.col!=-1&&gameBoard.selectedBlock.c==-1&&gameBoard.selectedBlock.col==i&&gameBoard.selectedBlock.ind==y?Pixel(GREY.r,GREY.g,GREY.b,alpha):Pixel(WHITE.r,WHITE.g,WHITE.b,alpha));
} }
} }
for (int i=0;i<comboDisplayList.size();i++){
ComboOverlay&c=comboDisplayList[i];
vi2d shadowOffset={1,1};
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});
}
} }
int main() int main()

Loading…
Cancel
Save