|
|
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
|
#1 (permalink) |
|
Junior Member
Join Date: Mar 2009
Posts: 1
|
I wanted to do something similar to the following thread:
8x8 Grid from Array - iPhone Dev SDK Forum 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:
You must Login or Register to view and contribute code! This is done to increase participation in helping one another out, if you have been helped please pass on the favor. 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];
}
|
|
|
|
![]() |
«
Previous Thread
|
Next Thread
»
| Thread Tools | |
| Display Modes | |
|
|
Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd. Search Engine Friendly URLs by vBSEO 3.3.0 RC1 |




Linear Mode
