Hello,
First off, I'm new here (as you may be able to tell!) so I'm sorry if this is the wrong section...
I have a problem and was wondering if you could help me: I'm following a tutorial at the moment, which involves building a simple Pong-style game. I've followed it letter for letter (apart form the fact I have changed the names of a few objects etc.), but have come across a problem - it's an error that reads: "Expected identifier or '(' before 'if'.
Do you have a solution to the problem, or know of a way in which I could solve it? I'm really eager to become familiar with the SDK, so I'd love to know what the problem is too. Thanks in advance! (the problem line is highlighted in
red) (the tutorial is
here, if needed)
Code:
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
self.gameState = kGameStatePaused;
pucVelocity = CGPointMake(kPucSpeedX,KPucSpeedY);
[NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(gameLoop) userInfo:nil repeats:YES];
}
-(void) gameLoop {
if(gameState == kGameStateRunning) {
puc.center = CGPointMake(puc.center.x + pucVelocity.x , puc.center.y + pucVelocity.y);
if(puc.center.x > self.view.bounds.size.width || puc.center.x < 0) {
pucVelocity.x = -pucVelocity.x;
}
if(puc.center.y > self.view.bounds.size.height || puc.center.y < 0) {
pucVelocity.y = -pucVelocity.y;
}
} else {
if (tapToBegin.hidden) {
tapToBegin.hidden = NO;
}
}
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
if (gameState == kGameStatePaused) {
tapToBegin.hidden = YES;
gameState = kGameStateRunning;
} else if(gameState == kGameStateRunning) {
[self touchesMoved:touches withEvent:event];
}
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
CGPoint location = [touch locationInView:touch.view];
CGPoint xLocation = CGPointMake(location.x,paddleblue.center.y);
paddleblue.center = xLocation;
}
if (CGRectIntersectsRect(puc.frame,paddleblue.frame)) {
if(puc.center.y < paddleblue.center.y) {
pucVelocity.y = -pucVelocity.y;
NSLog(@"%f %f",puc.center,paddlegreen.center);
}
}
if (CGRectIntersectsRect(puc.frame,paddlegreen.frame)) {
if(puc.center.y > paddlegreen.center.y) {
pucVelocity.y = -pucVelocity.y;
}
}
//AI
if (puc.center.y <= self.view.center.y) {
if(puc.center.x < paddlegreen.center.x) {
CGPoint compLocation = CGPointMake(paddlegreen.center.x - kCompMoveSpeed, paddlegreen.center.y);
paddlegreen.center = compLocation;
}
if(puc.center.x > paddlegreen.center.x) {
CGPoint compLocation = CGPoint(paddlegreen.center.x + kCompMoveSpeed, paddlegreen.center.y);
paddlegreen.center = compLocation;
}
}