227 [GameInterfaceBridge registerCallingController:self]; |
222 [GameInterfaceBridge registerCallingController:self]; |
228 [GameInterfaceBridge startLocalGame:gameDictionary]; |
223 [GameInterfaceBridge startLocalGame:gameDictionary]; |
229 [gameDictionary release]; |
224 [gameDictionary release]; |
230 } |
225 } |
231 |
226 |
232 -(void) loadNiceHogs { |
227 -(void) loadNiceHogs |
233 @autoreleasepool { |
228 { |
|
229 @autoreleasepool |
|
230 { |
234 |
231 |
235 NSString *filePath = [[NSString alloc] initWithFormat:@"%@/Hedgehog/Idle.png",GRAPHICS_DIRECTORY()]; |
232 NSString *filePath = [[NSString alloc] initWithFormat:@"%@/Hedgehog/Idle.png",GRAPHICS_DIRECTORY()]; |
236 UIImage *hogSprite = [[UIImage alloc] initWithContentsOfFile:filePath]; |
233 UIImage *hogSprite = [[UIImage alloc] initWithContentsOfFile:filePath]; |
237 [filePath release]; |
234 [filePath release]; |
238 |
235 |
239 NSArray *hatArray = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:HATS_DIRECTORY() error:NULL]; |
236 NSArray *hatArray = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:HATS_DIRECTORY() error:NULL]; |
240 NSUInteger numberOfHats = [hatArray count]; |
237 NSUInteger numberOfHats = [hatArray count]; |
241 int animationFrames = IS_VERY_POWERFUL([HWUtils modelType]) ? 16 : 1; |
238 int animationFrames = IS_VERY_POWERFUL([HWUtils modelType]) ? 16 : 1; |
242 |
239 |
243 if (self.imgContainer != nil) |
240 self.imgContainer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 40)]; |
244 [self.imgContainer removeFromSuperview]; |
241 NSInteger numberOfHogs = 1 + arc4random_uniform(15); |
245 |
242 DLog(@"Drawing %ld nice hedgehogs", (long)numberOfHogs); |
246 self.imgContainer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 40)]; |
243 for (int i = 0; i < numberOfHogs; i++) { |
247 NSInteger numberOfHogs = 1 + arc4random_uniform(15); |
244 NSString *hat = [hatArray objectAtIndex:arc4random_uniform((int)numberOfHats)]; |
248 DLog(@"Drawing %ld nice hedgehogs", (long)numberOfHogs); |
245 |
249 for (int i = 0; i < numberOfHogs; i++) { |
246 NSString *hatFile = [[NSString alloc] initWithFormat:@"%@/%@", HATS_DIRECTORY(), hat]; |
250 NSString *hat = [hatArray objectAtIndex:arc4random_uniform((int)numberOfHats)]; |
247 UIImage *hatSprite = [[UIImage alloc] initWithContentsOfFile:hatFile]; |
251 |
248 NSMutableArray *animation = [[NSMutableArray alloc] initWithCapacity:animationFrames]; |
252 NSString *hatFile = [[NSString alloc] initWithFormat:@"%@/%@", HATS_DIRECTORY(), hat]; |
249 for (int j = 0; j < animationFrames; j++) { |
253 UIImage *hatSprite = [[UIImage alloc] initWithContentsOfFile:hatFile]; |
250 int x = ((j*32)/(int)hatSprite.size.height)*32; |
254 NSMutableArray *animation = [[NSMutableArray alloc] initWithCapacity:animationFrames]; |
251 int y = (j*32)%(int)hatSprite.size.height; |
255 for (int j = 0; j < animationFrames; j++) { |
252 UIImage *hatSpriteFrame = [hatSprite cutAt:CGRectMake(x, y, 32, 32)]; |
256 int x = ((j*32)/(int)hatSprite.size.height)*32; |
253 UIImage *hogSpriteFrame = [hogSprite cutAt:CGRectMake(x, y, 32, 32)]; |
257 int y = (j*32)%(int)hatSprite.size.height; |
254 UIImage *hogWithHat = [hogSpriteFrame mergeWith:hatSpriteFrame atPoint:CGPointMake(0, 5)]; |
258 UIImage *hatSpriteFrame = [hatSprite cutAt:CGRectMake(x, y, 32, 32)]; |
255 [animation addObject:hogWithHat]; |
259 UIImage *hogSpriteFrame = [hogSprite cutAt:CGRectMake(x, y, 32, 32)]; |
256 } |
260 UIImage *hogWithHat = [hogSpriteFrame mergeWith:hatSpriteFrame atPoint:CGPointMake(0, 5)]; |
257 [hatSprite release]; |
261 [animation addObject:hogWithHat]; |
258 [hatFile release]; |
|
259 |
|
260 UIImageView *hog = [[UIImageView alloc] initWithImage:[animation objectAtIndex:0]]; |
|
261 hog.animationImages = animation; |
|
262 hog.animationDuration = 3; |
|
263 [animation release]; |
|
264 |
|
265 int x = 20*i+arc4random_uniform(128); |
|
266 while (x > 320 - 32) |
|
267 x = i*arc4random_uniform(32); |
|
268 |
|
269 hog.frame = CGRectMake(x, 25, hog.frame.size.width, hog.frame.size.height); |
|
270 [self.imgContainer addSubview:hog]; |
|
271 [hog startAnimating]; |
|
272 [hog release]; |
262 } |
273 } |
263 [hatSprite release]; |
274 [hogSprite release]; |
264 [hatFile release]; |
|
265 |
|
266 UIImageView *hog = [[UIImageView alloc] initWithImage:[animation objectAtIndex:0]]; |
|
267 hog.animationImages = animation; |
|
268 hog.animationDuration = 3; |
|
269 [animation release]; |
|
270 |
|
271 int x = 20*i+arc4random_uniform(128); |
|
272 while (x > 320 - 32) |
|
273 x = i*arc4random_uniform(32); |
|
274 |
275 |
275 hog.frame = CGRectMake(x, 25, hog.frame.size.width, hog.frame.size.height); |
276 dispatch_async(dispatch_get_main_queue(), ^{ |
276 [self.imgContainer addSubview:hog]; |
277 |
277 [hog startAnimating]; |
278 [self.view addSubview:self.imgContainer]; |
278 [hog release]; |
279 |
279 } |
280 // don't place the nice hogs if there is no space for them |
280 |
281 if ((self.interfaceOrientation == UIInterfaceOrientationPortrait || |
281 // don't place the nice hogs if there is no space for them |
282 self.interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)) |
282 if ((self.interfaceOrientation == UIInterfaceOrientationPortrait || |
283 self.imgContainer.alpha = 0; |
283 self.interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)) |
284 |
284 self.imgContainer.alpha = 0; |
285 self.isDrawingNiceHogs = NO; |
285 |
286 }); |
286 [self.view addSubview:self.imgContainer]; |
287 } |
287 [hogSprite release]; |
288 } |
288 |
289 |
289 } |
290 - (void)clearImgContainer |
|
291 { |
|
292 for (UIView *oneView in [self.imgContainer subviews]) |
|
293 { |
|
294 if ([oneView isMemberOfClass:[UIImageView class]]) |
|
295 { |
|
296 UIImageView *anImageView = (UIImageView *)oneView; |
|
297 [anImageView removeFromSuperview]; |
|
298 } |
|
299 } |
|
300 |
|
301 [self.imgContainer removeFromSuperview]; |
|
302 self.imgContainer = nil; |
290 } |
303 } |
291 |
304 |
292 -(void) viewDidLoad { |
305 -(void) viewDidLoad { |
293 self.view.backgroundColor = [UIColor blackColor]; |
306 self.view.backgroundColor = [UIColor blackColor]; |
294 |
307 |