- Home /
Tetris style math game problem...
Hello everyone,
I am trying to create a tetris style puzzle game with math. Basically, blocks with numbers on them will fall, and as they collide (or trigger) with each other they will add that blocks value to their own, and vice versa. I am having an EXTREMELY difficult time doing so. All blocks have a raycast on the left and right side that can tell when a block is on the right or left side, I also set up a trigger box that extends out past the box to check when a box is triggering with it.
How can I go about creating this system? Is there an easy way?
Right now, when a block collides with another block the current block changes but the previous block stays the same. I need a way to stack blocks where once a block touched another block, they both become the same value: (first block value + current block value) and then apply that to the rest of the boxes that are touching it.
That might be really confusing.... any tips?
The chances of you getting help would increase noticeably if you posted the code you have currently.
Answer by haim96 · Feb 27, 2014 at 10:25 PM
if you asking me, you are doing it wrong. i think that tetris game should be managed by array that will handle the block position and type. you need to update the array with new positions and block types in every move cycle and check what ever you need to check.
Answer by Scumble373 · Mar 03, 2014 at 05:10 PM
Thanks man, that really got me on the right track. I started using an array like you said, and after many many hours of work I finally got the addition system working flawlessly. Here is the function I ended up using, in case anyone else if having a similar issue.
int addUp(int[,] array5, int xPos, int yPos)
{
int finalVal = 0;
//print(xPos);
//print(yPos);
//int j = 0;
bool allZerosR = false, allZerosL = false;
//is red block at bottom?
if (yPos != 19)
{
for (int i = yPos+1; i < 20; i++)
{
finalVal += array5[i, xPos];
}
}
//check the right sides until you
//reach a row of all 0's
while (allZerosR == false)
{
allZerosR = true;
//for loop #1 (right)
for (int j = xPos+1; j < 27; j++)
{
allZerosR = true;
//loop that goes through each
//block in a column
for (int k = 0; k < 20; k++)
{
finalVal += array5[k, j];
if (array5[k, j] != 0)
{
allZerosR = false;
}
}
//check if we found a column
//of 0's
if (allZerosR == true)
{
j = 28;
}
}
//allZerosR = true;
}
//check the left sides until you
//reach a row of all 0's
while (allZerosL == false)
{
allZerosL = true;
//for loop #2 (left)
for (int l = xPos-1; l > 0; l--)
{
allZerosL = true;
//loop that goes through each
//block in a column
for (int m = 0; m < 20; m++)
{
finalVal += array5[m, l];
if (array5[m, l] != 0)
{
allZerosL = false;
}
}
//check if we found a column
//of 0's
if (allZerosL == true)
{
l = 0;
}
}
//allZerosL = true;
}
print(finalVal);
return finalVal;
}