So i have some simple code with a space invaders-esque design. I have implemented code that causes the score to start at 100 then loose 1 point when hit by a missile. I have 2 questions.
1, this code here
is the code for scoring, as you can see playerScore_value is set at 100, when the 'SpaceJunk' hits the ship it looses 1 point, all well and good
However as soon as the 'SpaceJunk' leaves the proximity of the player the health goes back up to 100! how can i prevent this? Also how do i make it so it take 5 off each time it hit, i.e. where i have
the "--" takes off one, is there a way where i can have "-5"?
Thanks
2,
My second question is to do with the spawning of the SpaceJunk itself, i have the being initialised on game start off screen and at a random X variable
How can i make it spawn over and over again, so there's multiple things coming down?
1, this code here
Code:
}
playerScore.text = [NSString stringWithFormat:@"%d",playerScore_value];
playerScore_value = 100;
if(CGRectIntersectsRect(SpaceJunk.frame,player.frame)) {
if(SpaceJunk.center.y > player.center.y) {
playerScore_value--;
}
}
if (playerScore_value < 100){
[playerScore setTextColor: [UIColor greenColor]];
}
if (playerScore_value < 50){
[playerScore setTextColor: [UIColor yellowColor]];
}
if (playerScore_value < 20){
[playerScore setTextColor: [UIColor redColor]];
}
if (playerScore_value < 5){
[playerScore setTextColor: [UIColor blackColor]];
}
}
is the code for scoring, as you can see playerScore_value is set at 100, when the 'SpaceJunk' hits the ship it looses 1 point, all well and good
However as soon as the 'SpaceJunk' leaves the proximity of the player the health goes back up to 100! how can i prevent this? Also how do i make it so it take 5 off each time it hit, i.e. where i have
Code:
playerScore_value--;
Thanks
2,
My second question is to do with the spawning of the SpaceJunk itself, i have the being initialised on game start off screen and at a random X variable
Code:
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, 0, 0, 0)];
SpaceJunk.animationDuration = 0.5;
SpaceJunk.contentMode = UIViewContentModeBottomLeft;
SpaceJunk.animationImages = SpaceJunkImages;
[SpaceJunk startAnimating];
[self.view addSubview:SpaceJunk];
How can i make it spawn over and over again, so there's multiple things coming down?