// // timetornadoViewController.m // timetornado // // Created by MARK ARENZ on 9/20/09. // Copyright __MyCompanyName__ 2009. All rights reserved. // #import "timetornadoViewController.h" #import "timetornadoAppDelegate.h" #define kGameStatePaused 1 #define kgameStatePlayerTurn 2 #define kgameStatePlayerMoving 3 #define kgameStatePlayerMovingKnob 4 #define kgameStateInstructions 5 #define kGameStateOVER 6 #define kGameStateGameOverWaiting 7 #define kGameStateHSRMovingColumn 8 #define kGameStateHSR 8 #define kSlotMarginY 105.5 #define kSlotHeight 69.0 #define kItemSlideYMargin 2 #define kKnobXSnap 20 #define kKnobLeftMargin 110 #define kKnobRightMargin 220 #define kScoreCorrectAnswer 50 #define kScoreCorrectALLBonus 500 #define kGearZeroRot -1.049999 #define kGearRestRot 2.500010 #define kGearRestRot2 2.500010 #define kTimeStickRest 280 #define kHSRColumnYMax 1016 #define kHSRColumnYMin -489 #define RANDOM_SEED() srandom(time(NULL)) @implementation timetornadoViewController @synthesize foregroundL, foregroundR,instructions, hsrInitials, hintImg, hsrBG, hsrCol1, hsrCol2, hsrCol3, hsrBtnOK, hsrScoreDisp, dispNumHints, gameOver,dispBonus, timeStick, numHintsHL, gameOverTap, gameOverBG, gameOverBG2, gameLevel, gear1,gear2, gear3, buttonHint, buttonInstructions,bulb1,bulb2,bulb3,bulb4,bulb5,bulb6,bulb7,bulb8,bulb9,bulb10,item1,item2,item3,item4,item5,item1HL,item2HL,item3HL,item4HL,item5HL,resultAnmId,resultAnmOk, gameState, itemMovng, tsLocation,knob, playerScore, playerHealth, dispScore; @synthesize blackScreen, flickSoundID, swoosh1SoundID, swoosh2SoundID, lock1SoundID, lock2SoundID; // terminal command to convert wav file to caf // /usr/bin/afconvert -f caff -d LEI16 flickSound.wav flickSound.caf // freesound - ef626f59 /* // 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; } */ /* // Implement viewDidLoad to do additional setup after loading the view, typically from a nib. - (void)viewDidLoad { [super viewDidLoad]; } */ /* // Override to allow orientations other than the default portrait orientation. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { // Return YES for supported orientations return (interfaceOrientation == UIInterfaceOrientationPortrait); } */ -(void)displayNumHints{ if (numHints<=0){ dispNumHints.text=@""; } else { dispNumHints.text=[NSString stringWithFormat:@"%i",numHints]; } } -(void)loadInstructions{ instructions.hidden=NO; // instructions.alpha=0; instructions.center=CGPointMake(-320,240); [self.view bringSubviewToFront:instructions]; [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:.5]; [UIView setAnimationDelegate:self]; // instructions.alpha=1.0; instructions.center=CGPointMake(160,240); [UIView commitAnimations]; } -(void)unloadInstructionsComplete{ gameState=kgameStatePlayerTurn; instructions.hidden=YES; } -(void)unloadInstructions{ [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:.25]; [UIView setAnimationDelegate:self]; [UIView setAnimationDidStopSelector:@selector(unloadInstructionsComplete)]; instructions.center=CGPointMake(480,240); [UIView commitAnimations]; } -(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch=[touches anyObject]; CGPoint location=[touch locationInView:self.view]; if (gameState==kgameStatePlayerMoving){ [touchStart view].center=CGPointMake([touchStart view].center.x,location.y); } else if (gameState==kGameStateHSRMovingColumn){ if ([touchStart view]!=hsrBtnOK){ float distY=location.y-tsLocY; if ( (tsLocation.y+distY)kHSRColumnYMin ){ [touchStart view].center=CGPointMake([touchStart view].center.x,tsLocation.y+distY); } } } else if (gameState==kgameStatePlayerMovingKnob && [touchStart view]==knob && gameState==kgameStatePlayerMovingKnob){ CGFloat tmpX=location.x; if (tmpXkKnobRightMargin){tmpX=kKnobRightMargin;} knob.center=CGPointMake(tmpX, knob.center.y); } } -(BOOL)checkGuessItem:(UILabel *)myItem:(CGFloat)targetY{ if (myItem.center.y==targetY){ return YES; } else { return NO; } } -(void)displayScore{ dispScore.text=[NSString stringWithFormat:@"%i",playerScore]; } -(void)initRoundAnimDone{ gameState=kgameStatePlayerTurn; } -(void)initRoundAnim{ AudioServicesPlaySystemSound(swoosh1SoundID); [self.view bringSubviewToFront:foregroundL]; [self.view bringSubviewToFront:foregroundR]; [self.view bringSubviewToFront:timeStick]; UILabel *tmpImg=[itemsArray objectAtIndex:resultAnmId]; [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:.3]; [UIView setAnimationDelegate:self]; if (resultAnmId==4){ [UIView setAnimationDidStopSelector:@selector(initRoundAnimDone)]; } tmpImg.center=CGPointMake(160,tmpImg.center.y); [UIView commitAnimations]; resultAnmId++; } -(void)gameOverPart3{ hsrCol1.hidden=NO; hsrCol2.hidden=NO; hsrCol3.hidden=NO; hsrBG.hidden=NO; hsrBtnOK.hidden=NO; hsrScoreDisp.hidden=NO; hsrScoreDisp.text=[NSString stringWithFormat:@"%i",playerScore]; gameState=kGameStateHSR; [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:0.7]; [UIView setAnimationDelegate:self]; // [UIView setAnimationDidStopSelector:@selector(initGame)]; gameOverBG.center=CGPointMake(-320,240); gameOverBG2.center=CGPointMake(640,240); gameOver.alpha=0.0; [UIView commitAnimations]; } -(void)gameOverPart2{ // gameState=kGameStateGameOverWaiting; gameOver.hidden=NO; gameOver.alpha=0.0; gameOver.transform = CGAffineTransformScale(dispBonus.transform, 7.0, 1.0); [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:.3]; [UIView setAnimationDelegate:self]; // [UIView setAnimationDidStopSelector:@selector(gameOverPart3)]; gameOver.transform = CGAffineTransformIdentity; gameOver.alpha=1.0; [UIView commitAnimations]; [self performSelector:@selector(gameOverPart3) withObject:nil afterDelay:1.5]; } -(void)initRound{ // AudioServicesPlaySystemSound(flickSoundID); // clean up last round roundTicker=0; gameLevel++; item1.alpha=1.0; item2.alpha=1.0; item3.alpha=1.0; item4.alpha=1.0; item5.alpha=1.0; gearRot=kGearRestRot; gearRot2=kGearRestRot2; [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:1.0]; [UIView setAnimationDelegate:self]; CGAffineTransform transform = CGAffineTransformMakeRotation(kGearRestRot); gear1.transform=transform; CGAffineTransform transform2 = CGAffineTransformMakeRotation(kGearRestRot2); gear2.transform=transform2; gear3.transform=transform2; timeStick.center=CGPointMake(timeStick.center.x,kTimeStickRest); [UIView commitAnimations]; for (int i=0;i<=4;i++){ UIImageView *tmpImg=[itemsArrayHL objectAtIndex:i]; tmpImg.hidden=YES; UILabel *tmpLbl=[itemsArray objectAtIndex:i]; tmpLbl.center=CGPointMake(tmpLbl.center.x,(kSlotMarginY+i*kSlotHeight)); } BOOL Ok; resultAnmId=0; NSInteger maxID=[timeDBLabels count]; int numList[5]; int myRand; for (int i=0;i<=4;i++){ myRand = arc4random() % maxID; Ok=NO; while (Ok==NO){ Ok=YES; myRand = arc4random() % maxID; for (int j=0;j=(i+1)){ UIImageView *tmpImg=[bulbsArray objectAtIndex:i]; if (tmpImg.alpha==0){ [self displayHealthBulbOn:i]; } } else { if (tmpImg.alpha==1.0){ [self displayHealthBulbOff:i]; } } } } -(int )checkMyItem:(int )myID{ // replies // 0 = OK // 1 = up // 2 = down UILabel *myItem=[itemsArray objectAtIndex:myID]; // NSLog(@"CHECKING ITEM: %@",myItem.text); BOOL Ok=YES; if (myItem.center.y>kSlotMarginY){ CGFloat tmpY=myItem.center.y-kSlotHeight; for(int i=0;i<=4;i++){ UILabel *tmpItem=[itemsArray objectAtIndex:i]; if (tmpItem.center.y==tmpY){ // found item above... // NSLog(@"-------> ITEM ABOVE: %@",tmpItem.text); int compare1=currentHand[myID]; int compare2=currentHand[i]; if (compare2>=compare1){ Ok=NO; // NSLog(@"------------RESULT: UP"); return 1; } } } } if (myItem.center.y<(kSlotMarginY+4*kSlotHeight)){ CGFloat tmpY=myItem.center.y+kSlotHeight; for(int i=0;i<=4;i++){ UILabel *tmpItem=[itemsArray objectAtIndex:i]; if (tmpItem.center.y==tmpY){ // found item below... // NSLog(@"-------> ITEM BELOW: %@",tmpItem.text); int compare1=currentHand[myID]; int compare2=currentHand[i]; if (compare2<=compare1){ Ok=NO; // NSLog(@"------------RESULT: DOWN"); return 2; } } } } else { } // NSLog(@"------------RESULT: OK"); return 0; } -(void) displayBonus3{ dispBonus.hidden=YES; dispBonus.transform = CGAffineTransformIdentity; } -(void) displayBonus2{ [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:.3]; [UIView setAnimationDelegate:self]; [UIView setAnimationDidStopSelector:@selector(displayBonus3)]; dispBonus.transform = CGAffineTransformScale(dispBonus.transform, 10.0, 10.0); dispBonus.alpha=0.0; [UIView commitAnimations]; } -(void) displayBonus{ // NSLog(@"DISPLAY BONUS??"); dispBonus.hidden=NO; [self.view bringSubviewToFront:dispBonus]; dispBonus.transform = CGAffineTransformScale(dispBonus.transform, 0.1, 0.1); dispBonus.alpha=0.0; [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:.5]; [UIView setAnimationDelegate:self]; dispBonus.transform = CGAffineTransformScale(dispBonus.transform, 10.0, 10.0); dispBonus.alpha=1.0; [UIView commitAnimations]; [self performSelector:@selector(displayBonus2) withObject:nil afterDelay:1.0]; } -(void)afterAddHint{ numHintsHL.hidden=YES; } -(void)addHint{ numHints++; // numHintsHL.transform=CGAffineTransformIdentity; numHintsHL.transform = CGAffineTransformScale(dispBonus.transform, 0.5, 0.5); numHintsHL.alpha=1.0; numHintsHL.hidden=NO; [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:.3]; [UIView setAnimationDelegate:self]; [UIView setAnimationDidStopSelector:@selector(afterAddHint)]; numHintsHL.transform = CGAffineTransformScale(dispBonus.transform, 1.0,1.0); numHintsHL.alpha=0.0; [UIView commitAnimations]; [self displayNumHints]; } -(void)checkGuess{ BOOL Ok=YES; resultAnmId=0; for (int i=0;i<=4;i++){ UILabel *myTempLbl; myTempLbl=[itemsArray objectAtIndex:i]; // CGFloat targetY=kSlotMarginY+currentHand[i]*kSlotHeight; // if ([self checkGuessItem:[itemsArray objectAtIndex:i]:targetY]){ if ([self checkMyItem:i]==0){ // + score playerScore+=kScoreCorrectAnswer; // highlight at this spot UIImageView *tmpImg=[itemsArrayHL objectAtIndex:i]; tmpImg.image = [UIImage imageNamed:@"hl-right.png"]; CGFloat myDelay=0.1*i; hintThreshTicker++; if (hintThreshTicker>=5+gameLevel){ hintThreshTicker=0; if (numHints<10){ [self addHint]; } } [self performSelector:@selector(displayItemResult) withObject:nil afterDelay:myDelay]; } else{ // - health playerHealth--; [self displayHealth]; Ok=NO; UIImageView *tmpImg=[itemsArrayHL objectAtIndex:i]; tmpImg.image = [UIImage imageNamed:@"hl-wrong.png"]; CGFloat myDelay=0.1*i; [self performSelector:@selector(displayItemResult) withObject:nil afterDelay:myDelay]; } // delay this loop? } if (Ok==YES){ if (playerHealth<10){ playerHealth++; [self displayHealth]; } playerScore+=kScoreCorrectALLBonus; [self displayBonus]; [self displayScore]; } } -(void)itemSnappingComplete{ // [self checkGuess]; AudioServicesPlaySystemSound(flickSoundID); gameState=kgameStatePlayerTurn; } -(void)itemSnapToGrid:(UILabel *)myItem:(CGFloat)destY{ CGFloat myDestY=0; if (myItem.center.y>=destY && myItem.center.y<=tsLocation.y){ // +1 myDestY=myItem.center.y+kSlotHeight; } else if (myItem.center.y<=destY && myItem.center.y>=tsLocation.y){ // -1 myDestY=myItem.center.y-kSlotHeight; } else { } if (myDestY>0){ [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:0.3]; [UIView setAnimationDelegate:self]; // [UIView setAnimationDidStopSelector:@selector(itemSnappingComplete)]; myItem.center=CGPointMake(myItem.center.x,myDestY); [UIView commitAnimations]; } } -(void)knobReturned{ gameState=kgameStatePlayerTurn; } -(void)playerLockedIn{ gameState=99; [self checkGuess]; [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:1.5]; [UIView setAnimationDelegate:self]; knob.center=CGPointMake(kKnobRightMargin,knob.center.y); [UIView commitAnimations]; } -(void)hsrColSnappingComplete{ gameState=kGameStateHSR; } -(void)navToMainMenu2{ timetornadoAppDelegate *mainDelegate = [[UIApplication sharedApplication] delegate]; [mainDelegate fromGameToMenu]; } -(void)navToMainMenu{ // [window.viewController fromGametoMenu]; [self.view bringSubviewToFront:blackScreen]; blackScreen.hidden=0; blackScreen.alpha=0.0; [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:0.3]; [UIView setAnimationDelegate:self]; [UIView setAnimationDidStopSelector:@selector(navToMainMenu2)]; blackScreen.alpha=1.0; [UIView commitAnimations]; } -(void)registerScore:(int )pscore:(NSString *)intls{ int scoreFactor=arc4random()%50; int score2=scoreFactor*pscore; NSString *urlToAuthPage = [[NSString alloc] initWithFormat:@"&scr=%d&scrfactor=%d&scr2=%d&plyr=%@", pscore,scoreFactor,score2,intls]; // NSLog(urlToAuthPage); NSData *postData = [urlToAuthPage dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:NO]; // NSLog(@" -> %@", postData); NSString *postLength = [NSString stringWithFormat:@"%d",[urlToAuthPage length]]; NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease]; [request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://www.ridiculopathy.com/projects/flash/hs_save.php?gametext=timetornado"]]]; [request setHTTPMethod:@"POST"]; [request setValue:postLength forHTTPHeaderField:@"Content-Length"]; [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"]; [request setHTTPBody:postData]; NSURLConnection *conn = [[NSURLConnection alloc]initWithRequest:request delegate:self]; if (conn) { // NSLog(@"Connection Successful"); [self navToMainMenu]; } else { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error Connection" message:@"There was an error connecting" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil]; [alert show]; [alert release]; [self navToMainMenu]; } } -(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{ // UITouch *touch = [touches anyObject]; if (gameState==kgameStatePlayerMoving){ gameState=99; CGFloat destY; if ([touchStart view].center.y>((kSlotMarginY+4*kSlotHeight)-.5*kSlotHeight)){ destY=kSlotMarginY+4*kSlotHeight; } else if ([touchStart view].center.y>((kSlotMarginY+3*kSlotHeight)-.5*kSlotHeight)){ destY=kSlotMarginY+3*kSlotHeight; } else if ([touchStart view].center.y>((kSlotMarginY+2*kSlotHeight)-.5*kSlotHeight)){ destY=kSlotMarginY+2*kSlotHeight; } else if ([touchStart view].center.y>((kSlotMarginY+1*kSlotHeight)-.5*kSlotHeight)){ destY=kSlotMarginY+1*kSlotHeight; } else if ([touchStart view].center.y>((kSlotMarginY)-.5*kSlotHeight)){ destY=kSlotMarginY; } if (destY=670){ playerHealth--; if (playerHealth<1){ [self gameOver1]; } else { [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:0.25]; [UIView setAnimationDelegate:self]; timeStick.center=CGPointMake(timeStick.center.x,timeStick.center.y-200); [UIView commitAnimations]; } [self displayHealth]; } } } } -(void)initGame{ numHints=4; hintThreshTicker=0; [self displayNumHints]; gameOver.hidden=YES; gameOverBG.hidden=YES; gameOverBG2.hidden=YES; gameOverTap.hidden=YES; gameLevel=0; playerHealth=8; // for testing game-over + hsr playerHealth=8; [self displayHealth]; playerScore=0; dispScore.text=[NSString stringWithFormat:@"%i",playerScore]; itemsArray=[[NSMutableArray alloc] init]; [itemsArray addObject: item1]; [itemsArray addObject: item2]; [itemsArray addObject: item3]; [itemsArray addObject: item4]; [itemsArray addObject: item5]; for (int i=0;i<=4;i++){ UILabel *tmpLbl=[itemsArray objectAtIndex:i]; tmpLbl.center=CGPointMake(tmpLbl.center.x,((kSlotMarginY+i*kSlotHeight))); UIImageView *tmpImg=[itemsArrayHL objectAtIndex:i]; tmpImg.center=CGPointMake(tmpImg.center.x,((kSlotMarginY+i*kSlotHeight))); } [self initRound]; // itemsArray=[NSMutableArray arrayWithObjects: @"item","yLoc"]; // [itemsArray addObject: item1,item1.center.y, item1.center.y]; } -(void)restartGame{ [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:0.5]; [UIView setAnimationDelegate:self]; // [UIView setAnimationDidStopSelector:@selector(initGame)]; item1.alpha=0; item2.alpha=0; item3.alpha=0; item4.alpha=0; item5.alpha=0; item1HL.alpha=0; item2HL.alpha=0; item3HL.alpha=0; item4HL.alpha=0; item5HL.alpha=0; gameOver.alpha=0; gameOverTap.alpha=0; [UIView commitAnimations]; // [self performSelector:@selector(restartGameOpenDoors) withObject:nil afterDelay:0.7]; } -(void)hintFadedOut{ gameState=kgameStatePlayerTurn; hintImg.hidden=YES; } -(void)fadeoutHint{ [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:0.4]; [UIView setAnimationDelegate:self]; [UIView setAnimationDidStopSelector:@selector(hintFadedOut)]; hintImg.alpha=0.0; [UIView commitAnimations]; } -(void)doHint{ if (numHints>0){ numHints--; gameState=99; [self displayNumHints]; // do the hint thing... // assign randomly int myRand; myRand = arc4random() % 5; // NSLog(@"HINT RANDOM -> %i", myRand); int checkResult=[self checkMyItem:myRand]; // NSLog(@"CHECKING %i answer ... %i",myRand, checkResult); UILabel *myItem=[itemsArray objectAtIndex:myRand]; hintImg.center=CGPointMake(30,myItem.center.y); if (checkResult==0){ hintImg.image = [UIImage imageNamed:@"hint-check.png"]; } else if (checkResult==1){ hintImg.image = [UIImage imageNamed:@"hint-up.png"]; } else { hintImg.image = [UIImage imageNamed:@"hint-down.png"]; } hintImg.hidden=NO; hintImg.alpha=0; [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:0.4]; [UIView setAnimationDelegate:self]; hintImg.alpha=1.0; [UIView commitAnimations]; [self performSelector:@selector(fadeoutHint) withObject:nil afterDelay:2.0]; if (numHints<=0){ buttonHint.alpha=0.4; } } } -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ //NSLog(@"gamestate %i",gameState); touchStart=[[event allTouches] anyObject]; tsLocY=[touchStart locationInView:self.view].y; if (gameState==kgameStatePlayerTurn){ if ([touchStart view]==item1 ||[touchStart view]==item2 ||[touchStart view]==item3 ||[touchStart view]==item4 ||[touchStart view]==item5){ AudioServicesPlaySystemSound(flickSoundID); tsLocation=[touchStart view].center; [self.view bringSubviewToFront:[touchStart view]]; gameState=kgameStatePlayerMoving; } else if ([touchStart view]==knob){ gameState=kgameStatePlayerMovingKnob; } else if ([touchStart view]==buttonInstructions){ gameState=kgameStateInstructions; [self loadInstructions]; } else if ([touchStart view]==buttonHint){ [self doHint]; } } else if (gameState==kgameStateInstructions){ // unpause [self unloadInstructions]; } else if (gameState==kGameStateGameOverWaiting){ CGPoint location=[touchStart locationInView:self.view]; // NSLog(@"touch Y %f",location.y); if (location.y>gameOverTap.center.y){ [self restartGame]; } else { } } else if (gameState==kGameStateHSR){ touchStart=[[event allTouches] anyObject]; if ([touchStart view]==hsrCol1 || [touchStart view]==hsrCol2 || [touchStart view]==hsrCol3 ){ tsLocation=[touchStart view].center; gameState=kGameStateHSRMovingColumn; } else { // check for button OK press } } } -(void)processTimeDBString:(NSString *)myDate:(NSString *)myLabel{ [timeDBDates addObject: myDate]; [timeDBLabels addObject:myLabel]; // NSLog(@" %@ %@",myDate, myLabel); } -(void)initTimeDB{ timeDBLabels=[[NSMutableArray alloc] init]; timeDBDates=[[NSMutableArray alloc] init]; // NSMutableArray *currentHand = [NSMutableArray arrayWithCapacity:5]; // currentHand=[[NSMutableArray alloc] init]; // int currentHand[5]; NSString *filePath = [[NSBundle mainBundle] pathForResource:@"timeDBText" ofType:@"txt"]; if (filePath) { NSString *myText = [NSString stringWithContentsOfFile:filePath]; if (myText) { myText = [myText stringByReplacingOccurrencesOfString:@"\n" withString:@"\r"]; NSArray *timeDBLines=[myText componentsSeparatedByString:@"\r"]; //phraseResult = [timeDBLines objectAtIndex: 1]; //NSLog(@"word 0 %@",phraseResult); for (int i=0;i<=([timeDBLines count]-1);i++){ NSArray *timeDBBits=[[timeDBLines objectAtIndex: i] componentsSeparatedByString:@"|"]; // NSLog(@" --> %@",[timeDBBits objectAtIndex: 0]); [self processTimeDBString:[timeDBBits objectAtIndex: 0]:[timeDBBits objectAtIndex: 1]]; } } else { NSLog(@"OOPS! This won't work!"); } } /* [self processTimeDBString:@"0800-12-25":@"Charlemagne unified most of Europe"]; [self processTimeDBString:@"1295-01-01":@"Marco Polo returns from China"]; [self processTimeDBString:@"1492-10-12":@"Christopher Columbus sets sail"]; [self processTimeDBString:@"1517-10-31":@"Martin Luther nails list of greivances to church door"]; [self processTimeDBString:@"1687-01-01":@"Isaac Newton publishes his Principia"]; [self processTimeDBString:@"1776-07-04":@"Signing of the Declaration of Independence"]; [self processTimeDBString:@"2001-09-11":@"World Trade Center Towers Attacked"]; */ } -(void)viewDidLoad{ self.view.center=CGPointMake(160,250); NSString *tmpSoundPath = [[NSBundle mainBundle] pathForResource:@"flickSound" ofType:@"caf"]; CFURLRef tmpSoundURL = (CFURLRef ) [NSURL fileURLWithPath:tmpSoundPath]; AudioServicesCreateSystemSoundID (tmpSoundURL, & flickSoundID); tmpSoundPath = [[NSBundle mainBundle] pathForResource:@"swoosh1" ofType:@"caf"]; tmpSoundURL = (CFURLRef ) [NSURL fileURLWithPath:tmpSoundPath]; AudioServicesCreateSystemSoundID (tmpSoundURL, & swoosh1SoundID); tmpSoundPath = [[NSBundle mainBundle] pathForResource:@"swoosh2" ofType:@"caf"]; tmpSoundURL = (CFURLRef ) [NSURL fileURLWithPath:tmpSoundPath]; AudioServicesCreateSystemSoundID (tmpSoundURL, & swoosh2SoundID); tmpSoundPath = [[NSBundle mainBundle] pathForResource:@"lock" ofType:@"caf"]; tmpSoundURL = (CFURLRef ) [NSURL fileURLWithPath:tmpSoundPath]; AudioServicesCreateSystemSoundID (tmpSoundURL, & lock1SoundID); tmpSoundPath = [[NSBundle mainBundle] pathForResource:@"lock2" ofType:@"caf"]; tmpSoundURL = (CFURLRef ) [NSURL fileURLWithPath:tmpSoundPath]; AudioServicesCreateSystemSoundID (tmpSoundURL, & lock2SoundID); // NSLog(@"GAME VEIW CENTER Y= %f",self.view.center.y); hsrInitials=[NSString stringWithFormat:@"MMM"]; CGAffineTransform transform = CGAffineTransformMakeRotation(kGearRestRot); gear1.transform=transform; CGAffineTransform transform2 = CGAffineTransformMakeRotation(kGearRestRot2); gear2.transform=transform2; gear3.transform=transform2; timeStick.center=CGPointMake(timeStick.center.x,kTimeStickRest); // add knob knob=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"knob.png"]]; knob.frame=CGRectMake(0,0,76,64); [self.view addSubview:knob]; knob.userInteractionEnabled=YES; knob.center=CGPointMake(kKnobRightMargin,435); // highlights item1HL=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"hl-wrong.png"]]; item1HL.frame=CGRectMake(0,0,320,99); [self.view addSubview:item1HL]; item1HL.hidden=YES; item2HL=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"hl-wrong.png"]]; item2HL.frame=CGRectMake(0,0,320,99); [self.view addSubview:item2HL]; item2HL.hidden=YES; item3HL=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"hl-wrong.png"]]; item3HL.frame=CGRectMake(0,0,320,99); [self.view addSubview:item3HL]; item3HL.hidden=YES; item4HL=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"hl-wrong.png"]]; item4HL.frame=CGRectMake(0,0,320,99); [self.view addSubview:item4HL]; item4HL.hidden=YES; item5HL=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"hl-wrong.png"]]; item5HL.frame=CGRectMake(0,0,320,99); [self.view addSubview:item5HL]; item5HL.hidden=YES; // buttonInstructions=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"button-instructions.png"]]; // buttonInstructions.frame=CGRectMake(0,0,40,39); // buttonInstructions.center=CGPointMake(24,435); // [self.view addSubview:buttonInstructions]; buttonInstructions.userInteractionEnabled=YES; // buttonHint=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"button-hint.png"]]; // buttonHint.frame=CGRectMake(0,0,40,39); // buttonHint.center=CGPointMake(63,435); // [self.view addSubview:buttonHint]; buttonHint.userInteractionEnabled=YES; hsrBG=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"hsrBG.png"]]; hsrBG.frame=CGRectMake(0,0,320,480); [self.view addSubview:hsrBG]; hsrBG.hidden=YES; hsrBtnOK=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"hsrBtnOK.png"]]; hsrBtnOK.frame=CGRectMake(0,0,89,61); [self.view addSubview:hsrBtnOK]; hsrBtnOK.hidden=YES; hsrBtnOK.userInteractionEnabled=YES; hsrBtnOK.center=CGPointMake(160,390); hsrCol1=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"hsrCols.png"]]; hsrCol1.frame=CGRectMake(0,0,85,1647); [self.view addSubview:hsrCol1]; hsrCol1.hidden=YES; hsrCol1.userInteractionEnabled=YES; hsrCol2=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"hsrCols.png"]]; hsrCol2.frame=CGRectMake(0,0,85,1647); [self.view addSubview:hsrCol2]; hsrCol2.hidden=YES; hsrCol2.userInteractionEnabled=YES; hsrCol3=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"hsrCols.png"]]; hsrCol3.frame=CGRectMake(0,0,85,1647); [self.view addSubview:hsrCol3]; hsrCol3.hidden=YES; hsrCol3.userInteractionEnabled=YES; hsrCol1.center=CGPointMake(62,(13*60-489)); hsrCol2.center=CGPointMake(160,(13*60-489)); hsrCol3.center=CGPointMake(256,(13*60-489)); gameOverBG=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"gameOver-bg.png"]]; gameOverBG.frame=CGRectMake(0,0,160,480); [self.view addSubview:gameOverBG]; gameOverBG.hidden=YES; gameOverBG2=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"gameOver-bg2.png"]]; gameOverBG2.frame=CGRectMake(0,0,160,480); [self.view addSubview:gameOverBG2]; gameOverBG2.hidden=YES; gameOver=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"gameover.png"]]; gameOver.frame=CGRectMake(0,0,261,81); gameOver.center=CGPointMake(160,240); [self.view addSubview:gameOver]; gameOver.hidden=YES; gameOverTap=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"gameover3.png"]]; gameOverTap.frame=CGRectMake(0,0,320,89); gameOverTap.center=CGPointMake(160,360); [self.view addSubview:gameOverTap]; gameOverTap.hidden=YES; hintImg=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"hint-check.png"]]; hintImg.frame=CGRectMake(0,0,53,66); [self.view addSubview:hintImg]; hintImg.hidden=YES; dispBonus=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"dispBonus.png"]]; dispBonus.frame=CGRectMake(0,0,317,82); dispBonus.center=CGPointMake(160,240); [self.view addSubview:dispBonus]; dispBonus.hidden=YES; blackScreen=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"blackScreen.png"]]; blackScreen.frame=CGRectMake(0,0,320,480); blackScreen.center=CGPointMake(160,240); [self.view addSubview:blackScreen]; blackScreen.hidden=YES; numHintsHL=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"highlight1.png"]]; numHintsHL.frame=CGRectMake(0,0,87,87); numHintsHL.center=CGPointMake(85,420); [self.view addSubview:numHintsHL]; numHintsHL.hidden=YES; hsrScoreDisp.hidden=YES; foregroundL=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"tt-interface-fg-left.png"]]; foregroundL.frame=CGRectMake(0,0,11,334); foregroundL.center=CGPointMake(5,247); [self.view addSubview:foregroundL]; foregroundR=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"tt-interface-fg-right.png"]]; foregroundR.frame=CGRectMake(0,0,11,344); foregroundR.center=CGPointMake(315,242); [self.view addSubview:foregroundR]; timeStick=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"timestick.png"]]; timeStick.frame=CGRectMake(0,0,10,400); timeStick.center=CGPointMake(315,kTimeStickRest); [self.view addSubview:timeStick]; instructions=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"instructions.png"]]; instructions.frame=CGRectMake(0,0,320,480); [self.view addSubview:instructions]; instructions.hidden=YES; itemsArrayHL=[[NSMutableArray alloc] init]; [itemsArrayHL addObject: item1HL]; [itemsArrayHL addObject: item2HL]; [itemsArrayHL addObject: item3HL]; [itemsArrayHL addObject: item4HL]; [itemsArrayHL addObject: item5HL]; bulbsArray=[[NSMutableArray alloc] init]; bulbsArray=[[NSMutableArray alloc] init]; [bulbsArray addObject: bulb1]; [bulbsArray addObject: bulb2]; [bulbsArray addObject: bulb3]; [bulbsArray addObject: bulb4]; [bulbsArray addObject: bulb5]; [bulbsArray addObject: bulb6]; [bulbsArray addObject: bulb7]; [bulbsArray addObject: bulb8]; [bulbsArray addObject: bulb9]; [bulbsArray addObject: bulb10]; // load time database [self initTimeDB]; // init everything [self initGame]; [NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(gameLoop) userInfo:nil repeats:YES]; } - (void)viewDidUnload { // Release any retained subviews of the main view. // e.g. self.myOutlet = nil; } - (void)dealloc { [super dealloc]; } @end