Guest User

Untitled

a guest
Jul 21st, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.07 KB | None | 0 0
  1. #import "EasyView.h"
  2. #define kScoreToWin 5
  3.  
  4. @implementation EasyView
  5. @synthesize image;
  6. @synthesize flakeImage;
  7.  
  8. - (IBAction)easyClick {
  9. [self.parentViewController dismissModalViewControllerAnimated:NO];
  10.  
  11. }
  12.  
  13. // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
  14. - (void)viewDidLoad
  15. {
  16. [super viewDidLoad];
  17.  
  18. [[UIAccelerometer sharedAccelerometer] setUpdateInterval:(1/40.0)];
  19. [[UIAccelerometer sharedAccelerometer] setDelegate:self];
  20.  
  21. // load our flake image we will use the same image over and over
  22. flakeImage = [UIImage imageNamed:@"ball.png"];
  23.  
  24. // Make it invisible & add score
  25.  
  26.  
  27. }
  28.  
  29. - (void)moveBoxWithX:(float)xAmount andY:(float)yAmount
  30. {
  31. CGPoint boxCenter = image.center;
  32.  
  33. boxCenter.x += xAmount;
  34. boxCenter.y += yAmount;
  35.  
  36. if (boxCenter.x < 50.0)
  37. boxCenter.x = 50.0;
  38. if (boxCenter.x > 270.0)
  39. boxCenter.x = 270.0;
  40.  
  41. if (boxCenter.y < 50.0)
  42. boxCenter.y = 50.0;
  43. if (boxCenter.y > 410.0)
  44. boxCenter.y = 410.0;
  45.  
  46. image.center = boxCenter;
  47. }
  48.  
  49. - (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration
  50. {
  51. float sensitivity = 25.0f;
  52. float xDistance = acceleration.x *sensitivity;
  53. float yDistance = acceleration.y *-sensitivity;
  54.  
  55. [self moveBoxWithX:xDistance andY:yDistance];
  56. }
  57.  
  58. - (IBAction)taptostart {
  59.  
  60. start.hidden = YES;
  61. [NSTimer scheduledTimerWithTimeInterval:(3.9) target:self selector:@selector(onTimer) userInfo:nil repeats:YES];
  62.  
  63. mainInt = 0;
  64. timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(countUp) userInfo:nil repeats:YES];
  65.  
  66. }
  67.  
  68. - (void)countUp {
  69.  
  70. mainInt += 1;
  71. label.text = [NSString stringWithFormat:@"%i", mainInt];
  72.  
  73. if (mainInt ==100) {
  74.  
  75. }
  76. }
  77.  
  78.  
  79. // Timer event is called whenever the timer fires
  80. - (void)onTimer
  81. {
  82. image.center = CGPointMake(image.center.x+pos.x,ball.center.y+pos.y);
  83.  
  84. if(CGRectIntersectsRect(image.frame,flakeImage.frame)) {
  85. ifimage.center.y < flakeImage.center.y) {
  86. pos.y = -pos.y;
  87. }
  88.  
  89.  
  90. }
  91. // build a view from our flake image
  92. UIImageView* flakeView = [[UIImageView alloc] initWithImage:flakeImage];
  93.  
  94. // use the random() function to randomize up our flake attributes
  95. int startX = round(random() % 320);
  96. int endX = round(random() % 320);
  97. double scale = 1 / round(random() % 100) + 1.0;
  98. double speed = 1 / round(random() % 100) + 1.0;
  99.  
  100. // set the flake start position
  101. flakeView.frame = CGRectMake(startX, -100.0, 25.0 * scale, 25.0 * scale);
  102. flakeView.alpha = 0.25;
  103.  
  104. // put the flake in our main view
  105. [self.view addSubview:flakeView];
  106.  
  107. [UIView beginAnimations:nil context:flakeView];
  108. // set up how fast the flake will fall
  109. [UIView setAnimationDuration:5 * speed];
  110.  
  111. // set the postion where flake will move to
  112. flakeView.frame = CGRectMake(endX, 500.0, 25.0 * scale, 25.0 * scale);
  113.  
  114. // set a stop callback so we can cleanup the flake when it reaches the
  115. // end of its animation
  116. [UIView setAnimationDidStopSelector:@selector(onAnimationComplete:finished:context:)];
  117. [UIView setAnimationDelegate:self];
  118. [UIView commitAnimations];
  119.  
  120. }
  121.  
  122. - (void)onAnimationComplete:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
  123.  
  124. UIImageView *flakeView = context;
  125. [flakeView removeFromSuperview];
  126. // open the debug log and you will see that all flakes have a retain count
  127. // of 1 at this point so we know the release below will keep our memory
  128. // usage in check
  129. NSLog([NSString stringWithFormat:@"[flakeView retainCount] = %d", [flakeView retainCount]]);
  130. [flakeView release];
  131.  
  132.  
  133. }
  134.  
  135. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
  136. // Return YES for supported orientations
  137. return (interfaceOrientation == UIInterfaceOrientationPortrait);
  138. }
  139.  
  140.  
  141. - (void)didReceiveMemoryWarning {
  142. [super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
  143. // Release anything that's not essential, such as cached data
  144. }
  145.  
  146. - (void)dealloc {
  147. [super dealloc];
  148. [flakeImage release];
  149. [image release];
  150. }
  151.  
  152. @end
Add Comment
Please, Sign In to add comment