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 03-25-2011, 01:00 AM   #1 (permalink)
Registered Member
 
Join Date: Jan 2011
Posts: 80
Chris1979 is on a distinguished road
Default brick on a grid moves twice instead of once due to a blankposition on the grid

Hey guys!

# = grid
O = bricks

########
#OOOOOO#
#OOOOOO#
#OOOOOO#
#OOOOOO#
#OOOOOO#
#OOOOO #
########

I´m creating a puzzle game where I have several, randomly picked bricks on a 6x6 grid. The thing is that I wanted the space at X=5 and Y=5 to be empty from the beginning, in other words instead of filling the grid with 36 bricks, I would have 35 bricks on it and 1 blank space. The reason for that is that the bricks would only be able to move on the grid if they are located next to it. (similar to a picture slide game)

The thing is that the brick located at X=4 Y=5 acts very strangely due to this. it moves twice instead of once.

I´ve located the problem to this part
Code:
if( blankPosition.x == orgPosition.x && blankPosition.y == orgPosition.y ){
				continue; 
			}
which you see in the code below. This part is the part that creates the empty space on the grid. Everything seems to work fine when I remove it from the equation but as soon as I enable it again, the brick located at X = 4 Y =5 starts to act as the brick that should have been at X = 5 Y = 5 (if the empty space wasn´t there) is "inside" it and starts to move twice instead of once upon touch.

can anyone help me solve this?

Code:
-(void)createbricks{
	
	//Level 1, 6 types of bricks
	brickTypes[0] = @"Ch'en.png"; 
	brickTypes[1] = @"K'ank'in.png"; 
	brickTypes[2] = @"K'ayab'.png"; 
	brickTypes[3] = @"kej.png";
	brickTypes[4] = @"kumk'u.png";
	brickTypes[5] = @"mak.png";
	
	
	LianTop[0] = @"lian.png";
	
	//empty spot in the bottom right corner of the grid
	blankPosition = CGPointMake(5, 5);
	
	int Bx = blankPosition.x;
	int By = blankPosition.y;
	
	NSLog(@"CreateBricks, blankPosition.x = Bx: %d", Bx);
	NSLog(@"CreateBricks, blankPosition.y = By: %d", By);
	
	
	for (int y = 0; y < BRICKHEIGHT; y++)
	{
		for (int x = 0; x < BRICKWIDTH; x++) 
		{
			
			CGPoint orgPosition = CGPointMake(x,y);
			
			if( blankPosition.x == orgPosition.x && blankPosition.y == orgPosition.y ){
				continue; 
			}
			
			UIImage *image = [UIImage imageNamed: brickTypes [rand() % 6]];
			grid[x][y] = [[[UIImageView alloc] initWithImage:image] autorelease];
			CGRect newFrame = grid[x][y].frame; 
			newFrame.origin = CGPointMake((x * 48)+52, (y * 49)+7);
			grid[x][y].frame = newFrame; 
			
			[self.view addSubview:grid[x][y]];

		}
		
	}	
}
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: 428
6 members and 422 guests
chemistry, Emy, hussain1982, Retouchable, skrew88, SLIC
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,679
Threads: 94,128
Posts: 402,922
Top Poster: BrianSlick (7,990)
Welcome to our newest member, xzoonxoom
Powered by vBadvanced CMPS v3.1.0

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