Okay, as a quick insight on what im doing and what id like to do ill quickly explain. So, i have made on my game that when the score is increased by 5000 at a time a scoreincrement counter Adds one to an NSInteger JetPackCount . Now i have made a button method that if the JetPackCount is >=1 meaning if the user has scored 5000+ , the use of a jetpack button is available. The button method looks something like this.
- (IBAction)buttonClickedJetPack{
if (JetPackCount >=1) {
gravity = CGPointMake (0,-kGravity);
JetPackCount -=1;
//Kgravity is the #defined y velocity that pulls the user downwards, or if turned to negative propells the user upwards.
}
}
now, my question is. How could i make it so that the gravity is only negative for 2 seconds. so that when 2 seconds has passed since the button is pressed the gravity will return to positive, pulling the user downwards. Any help is greatly apreciated! Thanks in advance.
The harder method would be to keep an array of Powerup objects, with a subclass of Powerup class for each kind of powerup. When you start the powerup you'd call [powerup begin] and add it to the array. Then every second you'd set powerup.countdown-=1 for each active powerup; and when the coutdown hits zero you'd call [powerup end] and remove it from the array.
The second method is more complicated, but it keeps track of the current state in a way that's easy to save to a savegame file, etc.
The harder method would be to keep an array of Powerup objects, with a subclass of Powerup class for each kind of powerup. When you start the powerup you'd call [powerup begin] and add it to the array. Then every second you'd set powerup.countdown-=1 for each active powerup; and when the coutdown hits zero you'd call [powerup end] and remove it from the array.
The second method is more complicated, but it keeps track of the current state in a way that's easy to save to a savegame file, etc.
Works perfectly . Your my hero.
Another question, If anyone would like to help. This one has me stumped but then again, i'm a total newbie. so a tiny bit on insight on what i'm doing first of all. With the jetpack working thanks to smasher, i can successfully propell my ball upwards on the screen. This is all fine and dandy but, I have the gam set in a way that as the ball passes 3/4 of the screen as you move upwards jumping on bricks, the bricks that fall down below the screen are repositioned at the top, with code looking like this.
Code:
if (ball.center.y < (self.view.bounds.size.height/4)) {
float difference = (self.view.bounds.size.height/4) - ball.center.y;
score += (int)difference;
NSString *nssScore = [NSString stringWithFormat:@"%i", score];
lblScore.text = nssScore;
ScoreIncrement += (int)difference;
ball.center = CGPointMake(ball.center.x, ball.center.y + difference);
platform1.center = CGPointMake(platform1.center.x, platform1.center.y + difference);
platform2.center = CGPointMake(platform2.center.x, platform2.center.y + difference);
platform3.center = CGPointMake(platform3.center.x, platform3.center.y + difference);
platform4.center = CGPointMake(platform4.center.x, platform4.center.y + difference);
platform5.center = CGPointMake(platform5.center.x, platform5.center.y + difference);
float viewWidth = self.view.bounds.size.width;
float fViewWidthMinusPlatformWidth = viewWidth - 55.0f;
int iViewWidthMinusPlatformWidth = (int)fViewWidthMinusPlatformWidth;
// If the platforms move off the screen, then reset them at a random spot at the top
if (platform1.center.y >= (self.view.bounds.size.height + 8)) {
float x = random() % iViewWidthMinusPlatformWidth;
x = x + 22.5f;
float y = (random() % 20)-8;
platform1.center = CGPointMake(x,y);
platform1Veloctiy.y = 0;
}
if (platform2.center.y >= (self.view.bounds.size.height + 8)) {
float x = random() % iViewWidthMinusPlatformWidth;
x = x + 22.5f;
float y = (random() % 20)-8;
platform2.center = CGPointMake(x,y);
platform2Veloctiy.y = 0;
}
if (platform3.center.y >= (self.view.bounds.size.height + 8)) {
float x = random() % iViewWidthMinusPlatformWidth;
x = x + 22.5f;
float y = (random() % 20)-8;
platform3.center = CGPointMake(x,y);
platform3Veloctiy.y = 0;
}
if (platform4.center.y >= (self.view.bounds.size.height + 8)) {
float x = random() % iViewWidthMinusPlatformWidth;
x = x + 22.5f;
float y = (random() % 20)-8;
platform4.center = CGPointMake(x,y);
platform4Veloctiy.y = 0;
}
if (platform5.center.y >= (self.view.bounds.size.height + 8)) {
float x = random() % iViewWidthMinusPlatformWidth;
x = x + 22.5f;
float y = (random() % 20)-8;
platform5.center = CGPointMake(x,y);
platform5Veloctiy.y = 0;
}
}
Now the problem is, as you use the jetpack and are propelled towards the top of the self.view.bounds.height the platforms seem to group together at the top of the screen, so when your jetpack turns off you have nothing to land on. Sorry if my question is unclear, so i will quickly try to recap . My problem is as you move upwards quickly the bricks stack on top of eachother and group up at the very top of the screen for some reason, making it impossible to not fall and die because there is no platforms to land on. Any suggestions? or samples?
Okay, as a quick insight on what im doing and what id like to do ill quickly explain. So, i have made on my game that when the score is increased by 5000 at a time a scoreincrement counter Adds one to an NSInteger JetPackCount . Now i have made a button method that if the JetPackCount is >=1 meaning if the user has scored 5000+ , the use of a jetpack button is available. The button method looks something like this.
- (IBAction)buttonClickedJetPack{
if (JetPackCount >=1) {
gravity = CGPointMake (0,-kGravity);
JetPackCount -=1;
//Kgravity is the #defined y velocity that pulls the user downwards, or if turned to negative propells the user upwards.
}
}
now, my question is. How could i make it so that the gravity is only negative for 2 seconds. so that when 2 seconds has passed since the button is pressed the gravity will return to positive, pulling the user downwards. Any help is greatly apreciated! Thanks in advance.
I hope you are adding/subtracting the kGravity parameter to a speed parameter or something...other wise you won't get the parabolic trajectory. (edit) I just read some of the discussion above oops
Last edited by missing_no; 03-15-2011 at 06:38 AM.