Greetings!
I'm having an issue with removing objects from superview if they are from the same type. It's a grid 6 x 6 with lets say 3 different types of objects and what I'm trying to accomplish is on touch all neighbour objects from same type to disappear.
Code:
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch* touch = [touches anyObject];
CGPoint touchXY = [touch locationInView:self.view];
touchedX = (touchXY.x+startX)/CELL_XSIZE;
touchedY = (touchXY.y+startY)/CELL_YSIZE;
originValue=myCells[touchedY][touchedX];
memset(myCellsTmp, sizeof(myCellsTmp), 0);
int x,y;
for (y=0; y<GRID_HEIGHT; y++) {
for (x=0; x<GRID_WIDTH; x++) {
myCellsTmp[y][x] = 0;
if (myCells[y][x] == originValue) {
myCellsTmp[y][x]=1;
if (myCellsTmp[y][x] == 1 && (y>0 && myCellsTmp[y-1][x] == 1) || (y<5 && myCellsTmp[y+1][x] == 1) || (x>0 && myCellsTmp[y][x-1]==1) || (x<5 && myCellsTmp[y][x+1]==1)) {
[myCellsImages[y][x] removeFromSuperview];
}
}
}
}
}
myCells is int [6][6] array that serves as a map. Object from type 1 is 1..type 2 - 2 ...ect
int myCellsTmp[6][6] is all 0 and what I'm doing there is all items from type same as the touched one turn into 1s.
myCellsImages contains the png's which the grid is loading and uses myCells as a map to that.
I believe that my second if is the reason I get messy results. I know there should be something more in it cause now it removes gems from same type but not necessarily being neighbours of the touched one.
Any help?
p.s. needless to say I'm new to programming