|
|
|
@ -19,11 +19,11 @@ bool Meteos::OnUserCreate() |
|
|
|
|
SPRITES["blocks_test.png"].Load("assets/blocks_test.png"); |
|
|
|
|
|
|
|
|
|
std::random_device rd; //Will be used to obtain a seed for the random number engine
|
|
|
|
|
gen=std::mt19937(0); //Standard mersenne_twister_engine seeded with rd()
|
|
|
|
|
gen=std::mt19937(rd()); //Standard mersenne_twister_engine seeded with rd()
|
|
|
|
|
randBlockPos=std::uniform_int_distribution<>(0, 9); |
|
|
|
|
coinFlip=std::uniform_int_distribution<>(0, 1); |
|
|
|
|
|
|
|
|
|
gameBoard=Board({10,14},0.04f,1.2f,-1.f,1.7f,2.0f,1.0f,{3,3,0,0,0,0,0,0,0,0},SPRITES["blocks_test.png"]); |
|
|
|
|
gameBoard=Board({10,14},0.04f,1.2f,-1.f,1.7f,2.0f,1.0f,{3,3,1,2,3,0,0,0,0,0},SPRITES["blocks_test.png"]); |
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
@ -418,25 +418,23 @@ void Meteos::updateGame(float fElapsedTime){ |
|
|
|
|
bool firstBlock=true; |
|
|
|
|
int baseBlockPos; |
|
|
|
|
for (BlockMatchingInfo&info:matchedBlockIDs) { |
|
|
|
|
Block*b; |
|
|
|
|
if (info.c!=-1){ |
|
|
|
|
b=&gameBoard.getBlockClumps()[info.c].getBlocks()[info.ind]; |
|
|
|
|
Block&b=gameBoard.getBlockClumps()[info.c].getBlocks()[info.ind]; |
|
|
|
|
if (firstBlock) { |
|
|
|
|
baseBlockPos=gameBoard.getBlockClumps()[info.c].getBlockPosition(*b).y; |
|
|
|
|
baseBlockPos=gameBoard.getBlockClumps()[info.c].getBlockPosition(b).y; |
|
|
|
|
c.y=baseBlockPos-1; |
|
|
|
|
firstBlock=false; |
|
|
|
|
} |
|
|
|
|
b.col=BlockColor::LAUNCHED; |
|
|
|
|
} else { |
|
|
|
|
b=&gameBoard.getBlocks(info.col)[info.ind]; |
|
|
|
|
Block&b=gameBoard.getBlocks(info.col)[info.ind]; |
|
|
|
|
if (firstBlock) { |
|
|
|
|
baseBlockPos=b->pos.y; |
|
|
|
|
baseBlockPos=b.pos.y; |
|
|
|
|
c.y=baseBlockPos-1; |
|
|
|
|
firstBlock=false; |
|
|
|
|
} |
|
|
|
|
b.col=BlockColor::LAUNCHED; |
|
|
|
|
} |
|
|
|
|
b->col=BlockColor::LAUNCHED; |
|
|
|
|
c.vspeed=gameBoard.launchSpd; |
|
|
|
|
c.launchTime=gameBoard.launchTime; |
|
|
|
|
} |
|
|
|
|
for (BlockMatchingInfo&info:matchedBlockIDs) { |
|
|
|
|
if (info.c!=-1){ |
|
|
|
@ -458,11 +456,14 @@ void Meteos::updateGame(float fElapsedTime){ |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
gameBoard.addClump(c); |
|
|
|
|
gameBoard.getBlockClumps()[gameBoard.getBlockClumps().size()-1].vspeed=gameBoard.launchSpd; |
|
|
|
|
gameBoard.getBlockClumps()[gameBoard.getBlockClumps().size()-1].launchTime=gameBoard.launchTime; |
|
|
|
|
} |
|
|
|
|
for (int i=0;i<gameBoard.getBlockClumps().size();i++){ //Resolve BlockClump movements.
|
|
|
|
|
BlockClump&c=gameBoard.getBlockClumps()[i]; |
|
|
|
|
for (int j=0;j<c.getBlocks().size();j++){ |
|
|
|
|
Block&b=c.getBlocks()[j]; |
|
|
|
|
b.addedToLaunchList=false; |
|
|
|
|
if (c.vspeed<0&&c.getBlockPosition(b).y<0||b.markedForRemoval){ |
|
|
|
|
c.removeBlock(j--); |
|
|
|
|
break; |
|
|
|
@ -484,6 +485,78 @@ void Meteos::updateGame(float fElapsedTime){ |
|
|
|
|
b.addedToLaunchList=false; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
//Invalidate the selected block if something is strange about it.
|
|
|
|
|
if (gameBoard.selectedBlock.col!=-1){ |
|
|
|
|
if (gameBoard.selectedBlock.c!=-1){ |
|
|
|
|
if (!(gameBoard.selectedBlock.c<gameBoard.getBlockClumps().size()&&gameBoard.selectedBlock.ind<gameBoard.getBlockClumps()[gameBoard.selectedBlock.c].getBlocks().size()&&gameBoard.getBlockClumps()[gameBoard.selectedBlock.c].getBlocks()[gameBoard.selectedBlock.ind].pos.x/12==gameBoard.selectedBlock.col)){ |
|
|
|
|
gameBoard.selectedBlock={-1}; |
|
|
|
|
goto invalidatedExit; |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
if (!(gameBoard.selectedBlock.ind<gameBoard.getBlocks(gameBoard.selectedBlock.col).size())){ |
|
|
|
|
gameBoard.selectedBlock={-1}; |
|
|
|
|
goto invalidatedExit; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
invalidatedExit: |
|
|
|
|
if (GetMouse(0).bHeld){ |
|
|
|
|
int mouseX=(GetMouseX()-gameBoard.drawOffset.x); |
|
|
|
|
int mouseY=(GetMouseY()-gameBoard.drawOffset.y); |
|
|
|
|
int mouseCol=mouseX/12; |
|
|
|
|
int mouseRow=mouseY/12; |
|
|
|
|
if (mouseCol>=0&&mouseCol<gameBoard.boardSize.x) { |
|
|
|
|
for (int y=0;y<gameBoard.getBlocks(mouseCol).size();y++){ |
|
|
|
|
Block&b=gameBoard.getBlocks(mouseCol)[y]; |
|
|
|
|
if (b.pos.y/12==mouseRow){ |
|
|
|
|
SelectedBlockData newData={mouseCol,y,-1}; |
|
|
|
|
if (gameBoard.selectedBlock.col!=-1&&mouseCol==gameBoard.selectedBlock.col){ |
|
|
|
|
//See if these two can be swapped.
|
|
|
|
|
Block&b1=gameBoard.getBlock(gameBoard.selectedBlock); |
|
|
|
|
Block&b2=gameBoard.getBlock(newData); |
|
|
|
|
int y1=(gameBoard.selectedBlock.c!=-1)?gameBoard.getBlockClumps()[gameBoard.selectedBlock.c].getBlockPosition(gameBoard.getBlockClumps()[gameBoard.selectedBlock.c].getBlocks()[gameBoard.selectedBlock.ind]).y:gameBoard.getBlocks(gameBoard.selectedBlock.col)[gameBoard.selectedBlock.ind].pos.y; |
|
|
|
|
int y2=(newData.c!=-1)?gameBoard.getBlockClumps()[newData.c].getBlockPosition(gameBoard.getBlockClumps()[newData.c].getBlocks()[newData.ind]).y:gameBoard.getBlocks(newData.col)[newData.ind].pos.y; |
|
|
|
|
if (b1.pos.x==b2.pos.x&&std::abs(y1-y2)<=12){ |
|
|
|
|
//Swap the two!
|
|
|
|
|
BlockColor tempCol=b1.col; |
|
|
|
|
b1.col=b2.col; |
|
|
|
|
b2.col=tempCol; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
gameBoard.selectedBlock=newData; |
|
|
|
|
goto found; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
for (int i=0;i<gameBoard.getBlockClumps().size();i++){ |
|
|
|
|
BlockClump&c=gameBoard.getBlockClumps()[i]; |
|
|
|
|
for (int j=0;j<c.getBlocks().size();j++){ |
|
|
|
|
Block&b=c.getBlocks()[j]; |
|
|
|
|
if (b.pos.x/12==mouseCol&&c.getBlockPosition(b).y<=mouseY&&c.getBlockPosition(b).y+12>=mouseY){ |
|
|
|
|
SelectedBlockData newData={mouseCol,j,i}; |
|
|
|
|
if (gameBoard.selectedBlock.col!=-1&&mouseCol==gameBoard.selectedBlock.col){ |
|
|
|
|
//See if these two can be swapped.
|
|
|
|
|
Block&b1=gameBoard.getBlock(gameBoard.selectedBlock); |
|
|
|
|
Block&b2=gameBoard.getBlock(newData); |
|
|
|
|
int y1=(gameBoard.selectedBlock.c!=-1)?gameBoard.getBlockClumps()[gameBoard.selectedBlock.c].getBlockPosition(gameBoard.getBlockClumps()[gameBoard.selectedBlock.c].getBlocks()[gameBoard.selectedBlock.ind]).y:gameBoard.getBlocks(gameBoard.selectedBlock.col)[gameBoard.selectedBlock.ind].pos.y; |
|
|
|
|
int y2=(newData.c!=-1)?gameBoard.getBlockClumps()[newData.c].getBlockPosition(gameBoard.getBlockClumps()[newData.c].getBlocks()[newData.ind]).y:gameBoard.getBlocks(newData.col)[newData.ind].pos.y; |
|
|
|
|
if (b1.pos.x==b2.pos.x&&std::abs(y1-y2)<=12){ |
|
|
|
|
//Swap the two!
|
|
|
|
|
BlockColor tempCol=b1.col; |
|
|
|
|
b1.col=b2.col; |
|
|
|
|
b2.col=tempCol; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
gameBoard.selectedBlock=newData; |
|
|
|
|
goto found; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
found:; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (GetMouse(0).bReleased){ |
|
|
|
|
gameBoard.selectedBlock={-1}; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void Meteos::drawGame(float fElapsedTime){ |
|
|
|
@ -501,13 +574,13 @@ void Meteos::drawGame(float fElapsedTime){ |
|
|
|
|
BlockClump&c=gameBoard.getBlockClumps()[i]; |
|
|
|
|
for (int j=0;j<c.getBlocks().size();j++){ |
|
|
|
|
Block&b=c.getBlocks()[j]; |
|
|
|
|
DrawPartialDecal(c.getBlockPosition(b)+gameBoard.drawOffset,gameBoard.tileset,{(float)(int)b.col*12,0},{12,12}); |
|
|
|
|
DrawPartialDecal(c.getBlockPosition(b)+gameBoard.drawOffset,gameBoard.tileset,{(float)(int)b.col*12,0},{12,12},{1,1},gameBoard.selectedBlock.col!=-1&&gameBoard.selectedBlock.ind==j&&gameBoard.selectedBlock.c==i?GREY:WHITE); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
for (int i=0;i<gameBoard.boardSize.x;i++){ |
|
|
|
|
for (int y=0;y<gameBoard.getBlocks(i).size();y++){ |
|
|
|
|
Block&b=gameBoard.getBlocks(i)[y]; |
|
|
|
|
DrawPartialDecal(b.pos+gameBoard.drawOffset,gameBoard.tileset,{(float)(int)b.col*12,0},{12,12}); |
|
|
|
|
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?GREY:WHITE); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|