Okay, stacking blocks. You had this line in your moveBlocks method, to stop the blocks when they reach the bottom of the screen:
Code:
if (newCenter.y > 420) {
We want to change that to this, which will trigger if we're touching the bottom *or* our new method returns true:
Code:
if (newCenter.y > 420 || [self isTouchingStoppedBlock:block]) {
"isTouchingStoppedBlock" is a method we need to write. It will return true if the current block is touching a stopped block (meaning the new block should stop too).
Code:
-(bool) isTouchingStoppedBlock:(UIImageView*)block{
//create a new rectangle, based on the current block's frame
CGRect lowerFrame = block.frame;
//but slightly lower on the screen
// "10" should be a constant: how far a block moves in one frame
lowerFrame.origin.y = lowerFrame.origin.y+10;
//now check if this lower rectangle is touching any other stopped block.
//if it's touching a stopped block, we return true.
for (UIImageView* stoppedBlock in blockArray){
if( CGRectIntersectsRect(lowerFrame.fame, stoppedBlock.frame) )
return true;
}
return false;
}
I haven't compiled this code, so apologies for any typos. Let me know if it works.