Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Game Development

Reply
 
LinkBack Thread Tools Display Modes
Old 10-15-2011, 03:13 AM   #1 (permalink)
Registered Member
 
Join Date: Jan 2011
Posts: 80
Chris1979 is on a distinguished road
Default COCOS2D: How to make a blank location on a grid to stay neutral when matching bricks?

Hey guys!

I need your help with solving this issue.

I tried the COCOS2D forum a few weeks back but got no answer. I really hope that someone at this forum will be able to help me.

I have a grid (6x7). I have 41 bricks on it plus 1 blank position. I'm trying to make a "3 or more in a row" type of game.

The bricks can only move to the blank position.

The issue that I have is that the blank position is being included as a "matching brick" when the method below looks for matches. How do I make the blank position stay neutral instead of being included into the matching part?

I've tried with adding this if statement into the part where "none matched" bricks are being added into a new group but it fails to work. it either makes the game to crash, starts to match wrong bricks or nor matching happens at all.

Code:
if(blankPosition.x == currPosition.x && blankPosition.y ==
currPosition.y){
                                        continue; //Tried with break and return as well.
                                }
This is the looking for matches method:

Code:
-(void)checkGroups:(bool)firstTime{
        int curHGroup = 0;
        int curVGroup = 0;
        int lastGroup =-1;
        NSMutableArray * groupings = [[NSMutableArray alloc]init];

        for(int i =0; i< GRID_WIDTH ; i++)
        {
                for(int j =0; j< GRID_HEIGHT ; j++)
                {

                        Bricks * d = (Bricks *)grid[i][j];
                        d.disappearing = NO;
                        Bricks * l =nil;
                        Bricks * t =nil;

                        CGPoint currPosition = CGPointMake(i,j);

                        if(i>0)
                                l = (Bricks *)grid[i-1][j];
                        if(j>0)
                                t = (Bricks *)grid[i][j-1];

                        //IF there is a previous brick in the grid we compare the actual
one with that one. If they
                        //are of the same type we add it to that group.
                        //If not, we create a new horizontal group and add the brick to
that one.

                        if(l  && l.bricksType == d.bricksType)
                        {

                                [[groupings objectAtIndex:l.curHGroup] addObject:grid[i][j]];
                                grid[i][j].curHGroup = l.curHGroup;

                        }
                        else {

                                if(blankPosition.x == currPosition.x && blankPosition.y ==
currPosition.y){
                                        continue;
                                }
                                else{
                                curHGroup = lastGroup +1;
                                NSMutableSet * group = [[NSMutableSet alloc]init];
                                [groupings addObject:group];
                                [group release];
                                [[groupings objectAtIndex:curHGroup] addObject:grid[i][j]];
                                grid[i][j].curHGroup = curHGroup;
                                lastGroup = curHGroup;
                                }
                        }

                        //The same for grouping vertically

                        if(t &&  t.bricksType == d.bricksType)
                        {

                                [[groupings objectAtIndex:t.curVGroup] addObject:grid[i][j]];
                                grid[i][j].curVGroup = t.curVGroup;

                        }
                        else{

                                if(blankPosition.x == currPosition.x && blankPosition.y ==
currPosition.y){
                                        continue;
                                }
                                else{
                                curVGroup = lastGroup+1;
                                NSMutableSet * group2 = [[NSMutableSet alloc]init];
                                [groupings addObject:group2];
                                [group2 release];
                                [[groupings objectAtIndex:curVGroup] addObject:grid[i][j]];
                                grid[i][j].curVGroup = curVGroup;
                                lastGroup = curVGroup;
                                }
                        }
                }
        }

        BOOL moveBricks = NO;
        for (NSMutableSet * n in groupings)
        {
                if([n count]>=3)
                {
                        for(Bricks * c in n)
                        {
                                c.disappearing = YES;
                                moveBricks = YES;
                                [c.mySprite setOpacity:0];
                                [c.mySprite runAction:[CCFadeOut actionWithDuration:0.5]];
                        }
                }
        }

        //We are done with the groupings array, release it.
        [groupings release];

        if(moveBricks)
        {
                [self schedule:@selector(moveBricksDown) interval:0.5];

        }
        else
        {
                self.allowTouch = YES;
                CCLOG(@"self.allowTouch = YES");
        }
Thanks in advance!

***Update********

It seems that I was wrong. :S

The issue (as it seems after I had a revelation yesterday) isn't that the blank position is ACTING as matching brick BUT actually IS a brick but invisible and that's why it is causing this issue.

In other words....
...I wasn't able to create a empty space that was neutral. I created a empty space by removing the visibility of a specific brick without removing the attributes of the brick, which is causing it to still act as a brick.

I will create a new thread about it since this thread is totally wrong...

Last edited by Chris1979; 10-16-2011 at 01:12 AM.
Chris1979 is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 388
10 members and 378 guests
7twenty7, apatsufas, comicool, Creativ, Dalia, dansparrow, Duncan C, Murphy, pbart, Tomsky
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,676
Threads: 94,127
Posts: 402,916
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jleannex55
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 06:57 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0