Alrighty so a very helpful guy helped me out with randomly generating an object but at the moment its just sitting still, i need it to move down the screen on the Y axis upon spawn of the object.
Thanks for your help
Code:
#define kSpeedY 7
#define kSpeedX 0
#define kScoreToWin 10
@implementation Space_AdventureViewController
@synthesize player,player_score,computer_score,gameState,tapToBegin;
@synthesize velocity;
/*
// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
// Custom initialization
}
return self;
}
*/
- (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,player.center.y);
player.center = xLocation;
}
-(void) gameLoop {
}
-(void)reset:(BOOL) newGame {
self.gameState = kGameStatePaused;
SpaceJunk.center = self.view.center;
if(newGame) {
if(computer_score_value > player_score_value) {
tapToBegin.text = @"You Died, The Earth Is Doomed";
} else {
tapToBegin.text = @"You Survived the Onslaught";
}
computer_score_value = 0;
player_score_value = 0;
} else {
tapToBegin.text = @"Tap To Begin";
}
player_score.text = [NSString stringWithFormat:@"%d",player_score_value];
computer_score.text = [NSString stringWithFormat:@"%d",computer_score_value];
}
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
self.gameState = kGameStatePaused;
[NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(gameLoop) userInfo:nil repeats:YES];
velocity = CGPointMake(kSpeedX, kSpeedX);
//HERE IS THE SPRITES ANIMATION AND SPAWN INFO
//*
//*
int randomX = arc4random() % 320 + 1;
SpaceJunkImages = [[NSArray alloc] initWithObjects: [UIImage imageNamed:@"flash1.png"], [UIImage imageNamed:@"flash3.png"], [UIImage imageNamed:@"flash4.png"], [UIImage imageNamed:@"flash5.png"], [UIImage imageNamed:@"flash2.png"], nil];
SpaceJunk = [[UIImageView alloc] initWithFrame: CGRectMake (randomX, 20, 30, 30)];
SpaceJunk.animationDuration = 0.5;
SpaceJunk.contentMode = UIViewContentModeBottomLeft;
SpaceJunk.animationImages = SpaceJunkImages;
[SpaceJunk startAnimating];
[self.view addSubview:SpaceJunk];
//*
//*
}
/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
// Release anything that's not essential, such as cached data
}
- (void)dealloc {
[super dealloc];
[player release];
[player_score release];
[computer_score release];
[tapToBegin release];
}
Thanks for your help