by DST » Sat May 08, 2010 6:56 pm
Okay, so lets say for this example, that you have a playfield of 10 x 25 squares. That's 10 squares across, and 25 from top to bottom.
So a piece starts at the top, with the "follow mouse" command enabled (on createactor).
Then, on collision with another piece, change follow mouse to NONE_AXIS, and enable gravity and physical response on the piece. If you want it to stay in the column it was dropped in, make its x snap to the column x. Otherwise, let the piece physical response off the other ones until it stops moving, and snap it into the closest slot.
Then the piece reports itself to the array, an array of 5 dimensions. [250][5]. the 250 is the position in the array, and the five slots are 1. piece there or not, 2. x 3.y, 4. color of piece, 5. cloneindex of piece. Note that the xy slots are filled in at game start.
Then, when its finished moving, and its snapped into place, you run an array check. You wipe slots 1, 4, and 5 from every position in the array, and ask the pieces to fill in their data.
Then you simply run checks horizontally, vertically, (and diagonally if you wish), looking for 4 or more of the same color.
When found, you record all the slot[5]'s, run an Actor* loop to destroy each of those pieces. Or if you like, you can send a timer to the pieces, and have each of them check their cloneindex against your scored list, and destroy themselves. Then the pieces with holes under them fall, snap into their slots, and when they finish, you run another check. You keep doing this until every time a piece has locked into place.
None of this affects the piece being dropped....when a piece is let go, the timer starts for the next piece drop, whether more score checks are needed or not.
so lets say you drop a piece into slot 100 (in a 32 x 32 piece size). The x and y for this are 16, 346. (we snap the center of 32), and this is in the array from the start of the game. So we say, as the piece is falling,
int aa=round(x/32);
int bb=round(y/32);
int cc=aa+(bb*10); //cc is the slot that the jewel is closest to.
if(jewels[cc+10][0]==1{ //if there is a piece under this one (meaning it's landed finally)
if(abs(x-jewels[cc][1]<10 && abs(y-jewels[cc][2]<10){ //if the piece is within 10 pixels of slot center
x=jewels[cc][1];
y=jewels[cc][2]; //snap the jewel to the center of the slot.
}
}
Does this make sense?