Does this look righto to you then?
Code:
-(void)createFirstBlock{
if (blockArray==nil){
blockArray = [[NSMutableArray alloc] init]; }
UIImage *blockImage = [UIImage imageNamed:@"block.png"];
UIImageView *block;
for (int i = 0; i< 1; i++){
block = [[UIImageView alloc] initWithImage: blockImage];
int x = arc4random()%320;
int y = -500;
block.center = CGPointMake (x,y);
[self.view addSubview: block];
[blockArray addObject: block];
[block release];
}
}
-(void)addOneBlock {
UIImage *blockImage = [UIImage imageNamed:@"block.png"];
UIImageView *block;
block= [[UIImageView alloc] initWithImage: blockImage];
//pick a position *above* the top of the screen
int x = arc4random()%320;
int y = -500; // place at top of the screen
block.center = CGPointMake (x,y);
[self.view addSubview: block];
[blockArray addObject: block];
[block release];
}
-(void)moveBlocks {
if(gameState == kGameStateRunning) {
for (UIImageView *block in blockArray) {
//move new center down
CGPoint newCenter = block.center;
newCenter.y = newCenter.y +10;
if (newCenter.y > 420) {
if (stoppedBlocks==nil){
stoppedBlocks = [[NSMutableArray alloc] init]; }
newCenter.y = newCenter.y -10;
[stoppedBlocks addObject: block];
[self addOneBlock];
continue;
[blockArray removeObjectsInArray: stoppedBlocks];
}
block.center = newCenter; }
}
else {
if (showPlay.hidden) {
showPlay.hidden = NO;}
if (showInstructions.hidden) {
showInstructions.hidden = NO;}
if (showOpenfeint.hidden) {
showOpenfeint.hidden = NO;}
}
}