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

View Single Post
Old 02-07-2010, 04:10 AM   #35 (permalink)
iPhoneDevelopment
Banned
 
Join Date: Dec 2009
Posts: 61
iPhoneDevelopment is on a distinguished road
Default

Cool, thanks. All I need to do now is the collision between the character and the blocks, and make a high score system.

So far the high scores, I have got this code in my main view controller:
Code:
-(void)viewDidLoad {
        ....
	highscore_value = 0; }

-(void)moveBlocks {
        ...
        if (character.center.y > 550) {
			GameOverViewController *viewController =           [[GameOverViewController alloc]    initWithNibName:@"GameOverViewController" bundle:nil];
			viewController.delegate = self;
			[self presentModalViewController:viewController animated:YES];
			[viewController release];
			[self reset];
		} }

-(void)reset {
	self.gameState = kGameStatePaused;
	NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
	if (score_value > highscore_value) {
		[prefs setInteger:score_value forKey:@"highscore"];}	
	score_value = 0;
	character.center = CGPointMake(180, 450);
        //TODO: reset blocks
}
And this in my GameOverViewController:
Code:
- (void)viewDidLoad {
    [super viewDidLoad];
	
	NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
	NSInteger highscore_value = [prefs integerForKey:@"highscore"];
	highScore.text = [NSString stringWithFormat:@"%d", highscore_value]; }
Basically what I want is the score_value from my main view controller to be saved to NSUserDefaults as highscore_value if it is larger than the one already saved there, and then be shown in my GameOverViewController in the highscore label, but at the moment the highscore label updates to the highest score of the previous games, not the one that has just ended. Any advice?

Thanks,

Cam

Last edited by iPhoneDevelopment; 02-07-2010 at 07:20 AM.
iPhoneDevelopment is offline   Reply With Quote
 

» Advertisements
» Online Users: 490
8 members and 482 guests
Domele, GHuebner, iekei, manop_cs, Newbie123, nguyenhieu129, RockBaby, Thompson22
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,446
Threads: 94,031
Posts: 402,605
Top Poster: BrianSlick (7,978)
Welcome to our newest member, larueta13
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 10:36 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.