generated from sigonasr2/CPlusPlusProjectTemplate
Correcting bugs
Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
This commit is contained in:
parent
09ee429e0f
commit
2bb304ccec
Binary file not shown.
1
Meteos.h
1
Meteos.h
@ -17,6 +17,7 @@ class Meteos : public olc::PixelGameEngine{
|
||||
std::map<std::string,Renderable> SPRITES;
|
||||
bool OnUserCreate()override;
|
||||
void updateGame(float fElapsedTime);
|
||||
void handleInput();
|
||||
void drawGame(float fElapsedTime);
|
||||
bool OnUserUpdate(float fElapsedTime)override;
|
||||
};
|
||||
|
37
main.cpp
37
main.cpp
@ -35,10 +35,17 @@ bool Meteos::OnUserUpdate(float fElapsedTime)
|
||||
updateGame(1/60.0f);
|
||||
accumulatedTime=0;
|
||||
}
|
||||
handleInput();
|
||||
drawGame(fElapsedTime);
|
||||
return true;
|
||||
}
|
||||
|
||||
void Meteos::handleInput(){
|
||||
if (GetMouse(0).bReleased){
|
||||
gameBoard.selectedBlock={-1,-1,-1};
|
||||
}
|
||||
}
|
||||
|
||||
void Meteos::updateGame(float fElapsedTime){
|
||||
lastBlockSpawn+=fElapsedTime;
|
||||
if (lastBlockSpawn>=gameBoard.spawnRate){
|
||||
@ -65,29 +72,36 @@ void Meteos::updateGame(float fElapsedTime){
|
||||
if (c2.getBlockPosition(b2).x==c.getBlockPosition(b3).x&&
|
||||
c2.getBlockPosition(b2).y+12>=c.getBlockPosition(b3).y&&
|
||||
c2.getBlockPosition(b2).y<=c.getBlockPosition(b3).y+12) {
|
||||
|
||||
c.y=(int)c.y;
|
||||
c2.y=(int)c2.y;
|
||||
if (c2.getBlockPosition(b2).y>c.getBlockPosition(b3).y) {
|
||||
c.y-=12-(c2.getBlockPosition(b2).y-c.getBlockPosition(b3).y);
|
||||
c.y-=fmod(c.y-c2.y,12);
|
||||
if (fmod(c2.y-c.y,12)!=0){
|
||||
std::cout<<"Difference is not equal to 12!! Value:"<<c2.y-c.y<<std::endl;
|
||||
std::cout<<"Difference is not divisible by 12!! Value:"<<fmod(c2.y-c.y,12)<<","<<c2.y<<"//"<<c.y<<std::endl;
|
||||
assert(false);
|
||||
}
|
||||
} else {
|
||||
c2.y-=12-(c.getBlockPosition(b3).y-c2.getBlockPosition(b2).y);
|
||||
if (fmod(c2.y-c.y,12)!=0){
|
||||
std::cout<<"Difference is not equal to 12!! Value:"<<c.y-c2.y<<std::endl;
|
||||
c2.y-=fmod(c.y-c2.y,12);
|
||||
if (fmod(c.y-c2.y,12)!=0){
|
||||
std::cout<<"Difference is not divisible by 12!! Value:"<<fmod(c.y-c2.y,12)<<","<<c.y<<"//"<<c2.y<<std::endl;
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
float influence=(float)c.getBlocks().size()/(c.getBlocks().size()+c2.getBlocks().size());
|
||||
int blockCount=c.getBlocks().size();
|
||||
int blockCount2=c2.getBlocks().size();
|
||||
//Copy every block from one clump to the other
|
||||
for (int m=0;m<c2.getBlocks().size();m++) {
|
||||
Block&b4=c2.getBlocks()[m];
|
||||
bool exists=false;
|
||||
if (!exists){
|
||||
c.addBlock(b4.pos.x/12,(c2.getBlockPosition(b4).y-c.y)/12,b4.col);
|
||||
}
|
||||
if (blockCount+c2.getBlocks().size()!=c.getBlocks().size()) {
|
||||
std::cout<<"Block size is: "<<c.getBlocks().size()<<" but expected "<<blockCount+c2.getBlocks().size()<<std::endl;
|
||||
}
|
||||
if (blockCount+blockCount2!=c.getBlocks().size()) {
|
||||
std::cout<<"Block size is: "<<c.getBlocks().size()<<" but expected "<<blockCount+blockCount2<<std::endl;
|
||||
assert(false);
|
||||
}
|
||||
bool overlappingBlocks=false;
|
||||
@ -101,6 +115,9 @@ void Meteos::updateGame(float fElapsedTime){
|
||||
}
|
||||
}
|
||||
assert(!overlappingBlocks);
|
||||
if (overlappingBlocks){
|
||||
std::cout<<"Block b3 "<<b3.pos<<"!"<<std::endl;
|
||||
}
|
||||
if (c.vspeed>0) {
|
||||
c.vspeed/=4;
|
||||
}
|
||||
@ -109,6 +126,9 @@ void Meteos::updateGame(float fElapsedTime){
|
||||
}
|
||||
c.vspeed=c.vspeed*influence+c2.vspeed*(1-influence);
|
||||
c.sortBlocks();
|
||||
if (i>=j){
|
||||
i--;
|
||||
}
|
||||
gameBoard.removeClump(j--);
|
||||
goto nextClumpCollisionCheck;
|
||||
}
|
||||
@ -464,6 +484,7 @@ void Meteos::updateGame(float fElapsedTime){
|
||||
b2.markedForRemoval=true;
|
||||
}
|
||||
}
|
||||
b.markedForRemoval=true;
|
||||
} else {
|
||||
Block&b=gameBoard.getBlocks(info.col)[info.ind];
|
||||
for (Block&b2:gameBoard.getBlocks(b.pos.x/12)) {
|
||||
@ -472,6 +493,7 @@ void Meteos::updateGame(float fElapsedTime){
|
||||
b2.markedForRemoval=true;
|
||||
}
|
||||
}
|
||||
b.markedForRemoval=true;
|
||||
}
|
||||
}
|
||||
gameBoard.addClump(c);
|
||||
@ -573,9 +595,6 @@ void Meteos::updateGame(float fElapsedTime){
|
||||
found:;
|
||||
}
|
||||
}
|
||||
if (GetMouse(0).bReleased){
|
||||
gameBoard.selectedBlock={-1};
|
||||
}
|
||||
}
|
||||
|
||||
void Meteos::drawGame(float fElapsedTime){
|
||||
|
Loading…
x
Reference in New Issue
Block a user