project_files/HedgewarsMobile/Classes/GameConfigViewController.m
branchios-revival
changeset 11206 2e80c9861818
parent 11162 715849bf6458
child 11215 51cc7ec00c2d
equal deleted inserted replaced
11205:9fd7b8d3cf4d 11206:2e80c9861818
   230 }
   230 }
   231 
   231 
   232 -(void) loadNiceHogs {
   232 -(void) loadNiceHogs {
   233     @autoreleasepool {
   233     @autoreleasepool {
   234     
   234     
   235     srand(time(NULL));
       
   236     NSString *filePath = [[NSString alloc] initWithFormat:@"%@/Hedgehog/Idle.png",GRAPHICS_DIRECTORY()];
   235     NSString *filePath = [[NSString alloc] initWithFormat:@"%@/Hedgehog/Idle.png",GRAPHICS_DIRECTORY()];
   237     UIImage *hogSprite = [[UIImage alloc] initWithContentsOfFile:filePath];
   236     UIImage *hogSprite = [[UIImage alloc] initWithContentsOfFile:filePath];
   238     [filePath release];
   237     [filePath release];
   239 
   238 
   240     NSArray *hatArray = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:HATS_DIRECTORY() error:NULL];
   239     NSArray *hatArray = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:HATS_DIRECTORY() error:NULL];
   243 
   242 
   244     if (self.imgContainer != nil)
   243     if (self.imgContainer != nil)
   245         [self.imgContainer removeFromSuperview];
   244         [self.imgContainer removeFromSuperview];
   246 
   245 
   247     self.imgContainer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 40)];
   246     self.imgContainer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 40)];
   248     NSInteger numberOfHogs = 1 + random() % 20;
   247     NSInteger numberOfHogs = 1 + arc4random_uniform(20);
   249     DLog(@"Drawing %ld nice hedgehogs", (long)numberOfHogs);
   248     DLog(@"Drawing %ld nice hedgehogs", (long)numberOfHogs);
   250     for (int i = 0; i < numberOfHogs; i++) {
   249     for (int i = 0; i < numberOfHogs; i++) {
   251         NSString *hat = [hatArray objectAtIndex:random()%numberOfHats];
   250         NSString *hat = [hatArray objectAtIndex:arc4random_uniform((int)numberOfHats)];
   252 
   251 
   253         NSString *hatFile = [[NSString alloc] initWithFormat:@"%@/%@", HATS_DIRECTORY(), hat];
   252         NSString *hatFile = [[NSString alloc] initWithFormat:@"%@/%@", HATS_DIRECTORY(), hat];
   254         UIImage *hatSprite = [[UIImage alloc] initWithContentsOfFile:hatFile];
   253         UIImage *hatSprite = [[UIImage alloc] initWithContentsOfFile:hatFile];
   255         NSMutableArray *animation = [[NSMutableArray alloc] initWithCapacity:animationFrames];
   254         NSMutableArray *animation = [[NSMutableArray alloc] initWithCapacity:animationFrames];
   256         for (int j = 0; j < animationFrames; j++) {
   255         for (int j = 0; j < animationFrames; j++) {
   267         UIImageView *hog = [[UIImageView alloc] initWithImage:[animation objectAtIndex:0]];
   266         UIImageView *hog = [[UIImageView alloc] initWithImage:[animation objectAtIndex:0]];
   268         hog.animationImages = animation;
   267         hog.animationImages = animation;
   269         hog.animationDuration = 3;
   268         hog.animationDuration = 3;
   270         [animation release];
   269         [animation release];
   271 
   270 
   272         int x = 20*i+random()%128;
   271         int x = 20*i+arc4random_uniform(128);
   273         if (x > 320 - 32)
   272         if (x > 320 - 32)
   274             x = i*random()%32;
   273             x = i*arc4random_uniform(32);
   275         hog.frame = CGRectMake(x, 25, hog.frame.size.width, hog.frame.size.height);
   274         hog.frame = CGRectMake(x, 25, hog.frame.size.width, hog.frame.size.height);
   276         [self.imgContainer addSubview:hog];
   275         [self.imgContainer addSubview:hog];
   277         [hog startAnimating];
   276         [hog startAnimating];
   278         [hog release];
   277         [hog release];
   279     }
   278     }