Hi Everyone,
This's my first time creating an app and am having trouble understanding why I'm getting an "undeclared identifier 'PlaceTunnels' " message in my Game.m file when it comes to this code: -(void)PlaceTunnels
Here is the code from the two files:
I would greatly appreciate any kind of help. Thanks.
-Taleb
This's my first time creating an app and am having trouble understanding why I'm getting an "undeclared identifier 'PlaceTunnels' " message in my Game.m file when it comes to this code: -(void)PlaceTunnels
Here is the code from the two files:
Code:
// Game.h
#import <UIKit/UIKit.h>
int BirdFlight;
int RandomTopTunnelPosition;
int RandomBottomTunnelPosition;
int ScoreNumber;
NSInteger HighScoreNumber;
@interface Game : UIViewController
{
IBOutlet UIImageView *Bird;
IBOutlet UIButton *StartGame;
IBOutlet UIImageView *TunnelTop;
IBOutlet UIImageView *TunnelBottom;
IBOutlet UIImageView *Top;
IBOutlet UIImageView *Bottom;
IBOutlet UILabel *ScoreLabel;
NSTimer *BirdMovement;
NSTimer *TunnelMovement;
}
-(IBAction)StartGame:(id)sender;
-(void)TunnelMoving;
-(void)PlaceTunnels;
-(void)Score;
-(void)GameOver;
@end
Code:
// Game.m
#import "Game.h"
@interface Game ()
@end
@implementation Game
-(void)GameOver {
if (ScoreNumber > HighScoreNumber) {
[[NSUserDefaults standardUserDefaults] setInteger:ScoreNumber forKey:@"HighScoreSaved"];
}
[TunnelMovement invalidate];
[BirdMovement invalidate];
Exit.hidden = NO;
TunnelTop.hidden = YES;
TunnelBottom.hidden = YES;
Bird.hidden = YES;
}
-(void)Score {
ScoreNumber = ScoreNumber + 1;
ScoreLabel.text = [NSString stringWithFormat:@"%i", ScoreNumber];
}
-(IBAction)StartGame:(id)sender{
TunnelTop.hidden = NO;
TunnelBottom.hidden = NO;
StartGame.hidden = YES;
BirdMovement = [NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(BirdMoving) userInfo:nil repeats:YES];
[self PlaceTunnels];
TunnelMovement = [NSTimer scheduledTimerWithTimeInterval: 0.01 target:self selector:@selector(TunnelMoving) userInfo:nil repeats:YES];
}
-(void)TunnelMoving {
TunnelTop.center = CGPointMake(TunnelTop.center.x - 1, TunnelTop.center.y);
TunnelBottom.center = CGPointMake(TunnelBottom.center.x - 1, TunnelBottom.center.y);
if(TunnelTop.center.x < -28) {
[self PlaceTunnels];
if(TunnelTop.center.x == 30) {
[self Score];
}
if(CGRectIntersectsRect(Bird.frame, TunnelTop.frame)) {
[self GameOver];
}
if(CGRectIntersectsRect(Bird.frame, TunnelBottom.frame)) {
[self GameOver];
}
if(CGRectIntersectsRect(Bird.frame, Top.frame)) {
[self GameOver];
}
if(CGRectIntersectsRect(Bird.frame, Bottom.frame)) {
[self GameOver];
}
}
-(void)PlaceTunnels { // "Use of undeclared identifier 'PlaceTunnels'
RandomTopTunnelPosition = arc4random() %350;
RandomTopTunnelPosition = RandomTopTunnelPosition - 228;
RandomBottomTunnelPosition = RandomTopTunnelPosition + 655;
TunnelTop.center = CGPointMake(340, RandomTopTunnelPosition);
TunnelBottom.center = CGPointMake(340, RandomBottomTunnelPosition);
}
-(void)BirdMoving{
Bird.center = CGPointMake(Bird.center.x, Bird.center.y - BirdFlight);
BirdFlight = BirdFlight -5;
if( BirdFlight < -15) {
BirdFlight = -15;
}
if (BirdFlight > 0) {
Bird.image = [UIImage imageNamed:@"BirdUp.png"];
}
if (BirdFlight > 0) {
Bird.image = [UIImage imageNamed:@"BirdDown.png"];
}
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
BirdFlight = 30;
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
TunnelTop.hidden = YES;
TunnelBottom.hidden = YES;
Exit.hidden = YES;
ScoreNumber = 0;
HighScoreNumber = [[NSUserDefaults standardUserDefaults] integerForKey=@"HighScoreSaved"]
[super viewDidLoad];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
@end
I would greatly appreciate any kind of help. Thanks.
-Taleb
Last edited by a moderator: