Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Game Development

Reply
 
LinkBack Thread Tools Display Modes
Old 03-13-2011, 10:07 PM   #1 (permalink)
Registered Member
 
Join Date: Mar 2011
Posts: 7
Doodl3 is on a distinguished road
Default Conditional powerups. Totally stuck!

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.
Doodl3 is offline   Reply With Quote
Old 03-14-2011, 12:14 AM   #2 (permalink)
Registered Member
iPhone Dev SDK Supporter
 
smasher's Avatar
 
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 3,858
smasher will become famous soon enough
Default

There's an easy way and a hard way.

The easy way is to use performSelector:withObject:afterDelay: to trigger another method two seconds after the powerup triggers.

Code:
- (IBAction)buttonClickedJetPack{
    if (JetPackCount >=1) {
        gravity = CGPointMake (0,-kGravity);
        JetPackCount -=1;
        [self performSelector:@selector(jetPackOff) withObject:nil afterDelay:2.0f];
}

-(void)jetPackOff{
        gravity = CGPointMake (0,kGravity);
}
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.
__________________

Free Games!
smasher is offline   Reply With Quote
Old 03-14-2011, 12:35 AM   #3 (permalink)
Registered Member
 
Join Date: Mar 2011
Posts: 7
Doodl3 is on a distinguished road
Default

Quote:
Originally Posted by smasher View Post
There's an easy way and a hard way.

The easy way is to use performSelector:withObject:afterDelay: to trigger another method two seconds after the powerup triggers.

Code:
- (IBAction)buttonClickedJetPack{
    if (JetPackCount >=1) {
        gravity = CGPointMake (0,-kGravity);
        JetPackCount -=1;
        [self performSelector:@selector(jetPackOff) withObject:nil afterDelay:2.0f];
}

-(void)jetPackOff{
        gravity = CGPointMake (0,kGravity);
}
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?

Last edited by Doodl3; 03-14-2011 at 01:03 AM.
Doodl3 is offline   Reply With Quote
Old 03-15-2011, 06:33 AM   #4 (permalink)
Registered Member
 
missing_no's Avatar
 
Join Date: Feb 2011
Posts: 41
missing_no is on a distinguished road
Default

Quote:
Originally Posted by Doodl3 View Post
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.
missing_no is offline   Reply With Quote
Reply

Bookmarks

Tags
game, gamelogic, newbie, stuck, timer

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 424
5 members and 419 guests
chemistry, hussain1982, Retouchable, skrew88, SLIC
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,679
Threads: 94,128
Posts: 402,921
Top Poster: BrianSlick (7,990)
Welcome to our newest member, xzoonxoom
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 08:14 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0