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

View Single Post
Old 03-17-2009, 07:16 PM   #1 (permalink)
fulvio
Registered Member
 
Join Date: Mar 2009
Posts: 42
fulvio is on a distinguished road
Default 8x8 Grid from Array

I wanted to do something similar to the following thread:
http://www.iphonedevsdk.com/forum/ip...id-images.html

I'm not actually sure how best to explain this. Basically I'm in the process of creating an Arkanoid clone type game where there are several bricks on the screen. A ball bounces around the screen bumping off walls and when it finally collides with the paddle (controlled by the user) it changes velocity and eventually hits one of the bricks that appears above. So far this portion of the game has been completed.

I have 9 different colored images/bricks named (yellow.png, red.png, blue.png, etc).

What I wanted to do for each level is change the position of the bricks depending on the following (as an example of one of the levels) might be the following:

brickArray *brickLevel1 = {
{0,0,0,0,0,0,0,0},
{1,1,0,0,0,0,1,1},
{1,0,1,0,0,1,0,1},
{1,0,2,0,0,2,0,1},
{1,0,2,0,0,2,0,1},
{1,0,1,0,0,1,0,1},
{1,1,0,0,0,0,1,1},
{1,1,3,1,1,3,1,1}
};

The following is a representation of an 8x8 grid of bricks.

The "x" will be replaced with a number (as seen above) and then the number will be associated with a unique colored brick. The numbers range from 1 - 9.

[x] [x] [x] [x] [x] [x] [x] [x]
[x] [x] [x] [x] [x] [x] [x] [x]
[x] [x] [x] [x] [x] [x] [x] [x]
[x] [x] [x] [x] [x] [x] [x] [x]
[x] [x] [x] [x] [x] [x] [x] [x]
[x] [x] [x] [x] [x] [x] [x] [x]
[x] [x] [x] [x] [x] [x] [x] [x]
[x] [x] [x] [x] [x] [x] [x] [x]

I am wanting to loop through this array and dynamically fill the correct image in its place depending on the brickLevel1 array?

The following is the current loop I'm using to display an 8x8 grid with just ONE color, because that's all I'm capable of doing at the moment. I wasn't sure how to implement my idea properly and loop through and render each image in its correct place.

Code:

Code:
	int x = 0, y = 0, brick_width = 39, brick_height = 23;
	for (int i=0; i < 64; i++)
	{
		x = (brick_width+1)*floor(i%8);
		y = (brick_height+1)*floor(i/8);

		brick = (UIImageView *)[brickArray objectAtIndex:i];
		brick = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"yellow.png", i]]];
		brick.transform = CGAffineTransformMakeTranslation(x, y);
		
		if (CGRectIntersectsRect(ball.frame, brick.frame))
			ballVelocity.y = -ballVelocity.y;

		[self.view addSubview:brick];
	}
I hope some of what I'm trying to achieve makes sense. If anyone could lead me in the right direction that would be greatly appreciated.
fulvio is offline   Reply With Quote
 

» Advertisements
» Online Users: 460
17 members and 443 guests
apatsufas, baja_yu, buggen, chenpo, ChrisYates, Feldspar, HowEver, ilmman, IphoneSdk, jeroenkeij, jNoxx, RobTaku, rraagg, swelsh, taylor202, Trickphotostudios, v1n2e7t
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,635
Threads: 94,098
Posts: 402,804
Top Poster: BrianSlick (7,990)
Welcome to our newest member, sadevb61
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 09:48 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.