I have realised that the current code that I am using is causing the blocks to all fall to the bottom of the screen, whereas what I want is for the blocks to pile on top of themselves. I changes the code in the example smasher gave me to try to implement this, but it does not seem to have worked. The code I am currently using is posted below, but when built no blocks are created or animated down the screen.
Code:
- (void)viewDidLoad {
[super viewDidLoad];
self.gameState = kGameStatePaused;
blockVelocity = CGPointMake(kBlockSpeedX, kBlockSpeedY);
[NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(gameLoop) userInfo:nil repeats:YES];
[NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(blockCollision) userInfo:nil repeats:YES];
}
-(void)gameLoop {
if(gameState == kGameStateRunning) {
UIImage *blockImage = [UIImage imageNamed:@"block.png"];
block= [[UIImageView alloc] initWithImage: blockImage];
int x = arc4random()%320;
int y = -100;
block.center = CGPointMake (x,y);
block.center = CGPointMake(block.center.x + blockVelocity.x, block.center.y + blockVelocity.y);
[self.view addSubview: block];
[block release];
}}
-(void)blockCollision {
CGPoint newCenter = block.center;
if (newCenter.y > 420){
newCenter.y = 420;
UIImage *blockImage = [UIImage imageNamed:@"block.png"];
block= [[UIImageView alloc] initWithImage: blockImage];
int x = arc4random()%320;
int y = -100;
newCenter = CGPointMake (x,y);
[self.view addSubview: block];
[block release]; }
if (CGRectIntersectsRect(block.frame, block.frame)){
newCenter.y = -10;
UIImage *blockImage = [UIImage imageNamed:@"block.png"];
block= [[UIImageView alloc] initWithImage: blockImage];
int x = arc4random()%320;
int y = -100;
newCenter = CGPointMake (x,y);
[self.view addSubview: block];
[block release]; }
block.center = newCenter;
}
Again, any help would be much appreciated!!
Thanks
Cam