Guest User

Untitled

a guest
Jul 22nd, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.08 KB | None | 0 0
  1. #import "EasyView.h"
  2.  
  3. @implementation EasyView
  4. @synthesize start,image,ball,ball2,ball3;
  5.  
  6. - (void)ontimer {
  7.  
  8. ball.center = CGPointMake(ball.center.x+pos.x,ball.center.y+pos.y);
  9.  
  10. if (ball.center.x > 320 || ball.center.x < 0)
  11. pos.x = -pos.x;
  12. if (ball.center.y > 460 || ball.center.y < 0)
  13. pos.y = -pos.y;
  14.  
  15.  
  16. ball2.center = CGPointMake(ball2.center.x+pos2.x,ball2.center.y+pos2.y);
  17.  
  18. if (ball2.center.x > 320 || ball2.center.x < 0)
  19. pos2.x = -pos2.x;
  20. if (ball2.center.y > 460 || ball2.center.y < 0)
  21. pos2.y = -pos2.y;
  22.  
  23. ball3.center = CGPointMake(ball3.center.x+pos3.x,ball3.center.y+pos3.y);
  24.  
  25. if (ball3.center.x > 320 || ball3.center.x < 0)
  26. pos3.x = -pos3.x;
  27. if (ball3.center.y > 460 || ball3.center.y < 0)
  28. pos3.y = -pos3.y;
  29.  
  30. if(CGRectIntersectsRect(ball.frame, image.frame)) {
  31. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"You Lost!" message:@"Sorry but the thunder ball touched your cloud,better luck next time!" delegate:self cancelButtonTitle:@"Dismiss" otherButtonTitles:nil];
  32. [alert show];
  33. [alert release];
  34. }
  35.  
  36. else {
  37. [self.parentViewController dismissModalViewControllerAnimated:NO];
  38. }
  39.  
  40.  
  41. }
  42.  
  43. - (void)countUp {
  44.  
  45. mainInt += 1;
  46. mainLabel.text = [NSString stringWithFormat:@"%i", mainInt];
  47.  
  48. if (mainInt == 5) {
  49. imaball.hidden = NO;
  50.  
  51. }
  52. else {
  53. if (mainInt == 9) {
  54. imaball2.hidden = NO;
  55.  
  56. }
  57. }
  58.  
  59. }
  60.  
  61.  
  62. - (IBAction)tapStart {
  63. start.hidden = YES;
  64.  
  65. /*
  66. ball.center = CGPointMake(ball.center.x+pos.x,ball.center.y+pos.y);
  67.  
  68. if (ball.center.x > 320 || ball.center.x < 0)
  69. pos.x = -pos.x;
  70. if (ball.center.y > 460 || ball.center.y < 0)
  71. pos.y = -pos.y;
  72.  
  73.  
  74. ball2.center = CGPointMake(ball2.center.x+pos2.x,ball2.center.y+pos2.y);
  75.  
  76. if (ball2.center.x > 320 || ball2.center.x < 0)
  77. pos2.x = -pos2.x;
  78. if (ball2.center.y > 460 || ball2.center.y < 0)
  79. pos2.y = -pos2.y;
  80.  
  81. ball3.center = CGPointMake(ball3.center.x+pos3.x,ball3.center.y+pos3.y);
  82.  
  83. if (ball3.center.x > 320 || ball3.center.x < 0)
  84. pos3.x = -pos3.x;
  85. if (ball3.center.y > 460 || ball3.center.y < 0)
  86. pos3.y = -pos3.y;
  87.  
  88.  
  89. */
  90. //pos = CGPointMake(5.0,7.0);
  91.  
  92. [NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector (ontimer) userInfo:nil repeats:YES];
  93.  
  94. //pos2 = CGPointMake(5.0,7.0);
  95.  
  96. [NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector (ontimer) userInfo:nil repeats:YES];
  97.  
  98. //pos3 = CGPointMake(5.0,7.0);
  99.  
  100. [NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector (ontimer) userInfo:nil repeats:YES];
  101.  
  102. counter = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector (countUp) userInfo:nil repeats:YES];
  103. mainInt = 0;
  104.  
  105.  
  106.  
  107. }
  108.  
  109.  
  110.  
  111. // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.//
  112. - (void)viewDidLoad
  113. {
  114. [super viewDidLoad];
  115.  
  116. pos = CGPointMake(5.0,7.0);
  117.  
  118. pos2 = CGPointMake(5.0,7.0);
  119.  
  120. pos3 = CGPointMake(5.0,7.0);
  121.  
  122.  
  123. [[UIAccelerometer sharedAccelerometer] setUpdateInterval:(1/40.0)];
  124. [[UIAccelerometer sharedAccelerometer] setDelegate:self];
  125.  
  126. image = [[UIView alloc] initWithFrame:CGRectMake(110, 180, 100, 100)];
  127.  
  128. imaball.hidden = YES;
  129. imaball2.hidden = YES;
  130.  
  131.  
  132.  
  133.  
  134. }
  135.  
  136.  
  137. - (void)moveBoxWithX:(float)xAmount andY:(float)yAmount
  138. {
  139. CGPoint boxCenter = image.center;
  140.  
  141. boxCenter.x += xAmount;
  142. boxCenter.y += yAmount;
  143.  
  144. if (boxCenter.x < 50.0)
  145. boxCenter.x = 50.0;
  146. if (boxCenter.x > 270.0)
  147. boxCenter.x = 270.0;
  148.  
  149. if (boxCenter.y < 50.0)
  150. boxCenter.y = 50.0;
  151. if (boxCenter.y > 410.0)
  152. boxCenter.y = 410.0;
  153.  
  154. image.center = boxCenter;
  155. }
  156.  
  157.  
  158.  
  159. - (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration
  160. {
  161. float sensitivity = 25.0f;
  162. float xDistance = acceleration.x *sensitivity;
  163. float yDistance = acceleration.y *-sensitivity;
  164.  
  165. [self moveBoxWithX:xDistance andY:yDistance];
  166. }
  167.  
  168. - (void)dealloc {
  169. [image release];
  170. image = nil;
  171. [super dealloc];
  172. }
  173.  
  174. -(IBAction)easyClick {
  175. [self.parentViewController dismissModalViewControllerAnimated:NO];
  176.  
  177. }
  178.  
  179. @end
Add Comment
Please, Sign In to add comment