Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #import "EasyView.h"
- @implementation EasyView
- @synthesize start,image,ball,ball2,ball3;
- - (void)ontimer {
- ball.center = CGPointMake(ball.center.x+pos.x,ball.center.y+pos.y);
- if (ball.center.x > 320 || ball.center.x < 0)
- pos.x = -pos.x;
- if (ball.center.y > 460 || ball.center.y < 0)
- pos.y = -pos.y;
- ball2.center = CGPointMake(ball2.center.x+pos2.x,ball2.center.y+pos2.y);
- if (ball2.center.x > 320 || ball2.center.x < 0)
- pos2.x = -pos2.x;
- if (ball2.center.y > 460 || ball2.center.y < 0)
- pos2.y = -pos2.y;
- ball3.center = CGPointMake(ball3.center.x+pos3.x,ball3.center.y+pos3.y);
- if (ball3.center.x > 320 || ball3.center.x < 0)
- pos3.x = -pos3.x;
- if (ball3.center.y > 460 || ball3.center.y < 0)
- pos3.y = -pos3.y;
- if(CGRectIntersectsRect(ball.frame, image.frame)) {
- 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];
- [alert show];
- [alert release];
- }
- else {
- [self.parentViewController dismissModalViewControllerAnimated:NO];
- }
- }
- - (void)countUp {
- mainInt += 1;
- mainLabel.text = [NSString stringWithFormat:@"%i", mainInt];
- if (mainInt == 5) {
- imaball.hidden = NO;
- }
- else {
- if (mainInt == 9) {
- imaball2.hidden = NO;
- }
- }
- }
- - (IBAction)tapStart {
- start.hidden = YES;
- /*
- ball.center = CGPointMake(ball.center.x+pos.x,ball.center.y+pos.y);
- if (ball.center.x > 320 || ball.center.x < 0)
- pos.x = -pos.x;
- if (ball.center.y > 460 || ball.center.y < 0)
- pos.y = -pos.y;
- ball2.center = CGPointMake(ball2.center.x+pos2.x,ball2.center.y+pos2.y);
- if (ball2.center.x > 320 || ball2.center.x < 0)
- pos2.x = -pos2.x;
- if (ball2.center.y > 460 || ball2.center.y < 0)
- pos2.y = -pos2.y;
- ball3.center = CGPointMake(ball3.center.x+pos3.x,ball3.center.y+pos3.y);
- if (ball3.center.x > 320 || ball3.center.x < 0)
- pos3.x = -pos3.x;
- if (ball3.center.y > 460 || ball3.center.y < 0)
- pos3.y = -pos3.y;
- */
- //pos = CGPointMake(5.0,7.0);
- [NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector (ontimer) userInfo:nil repeats:YES];
- //pos2 = CGPointMake(5.0,7.0);
- [NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector (ontimer) userInfo:nil repeats:YES];
- //pos3 = CGPointMake(5.0,7.0);
- [NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector (ontimer) userInfo:nil repeats:YES];
- counter = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector (countUp) userInfo:nil repeats:YES];
- mainInt = 0;
- }
- // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.//
- - (void)viewDidLoad
- {
- [super viewDidLoad];
- pos = CGPointMake(5.0,7.0);
- pos2 = CGPointMake(5.0,7.0);
- pos3 = CGPointMake(5.0,7.0);
- [[UIAccelerometer sharedAccelerometer] setUpdateInterval:(1/40.0)];
- [[UIAccelerometer sharedAccelerometer] setDelegate:self];
- image = [[UIView alloc] initWithFrame:CGRectMake(110, 180, 100, 100)];
- imaball.hidden = YES;
- imaball2.hidden = YES;
- }
- - (void)moveBoxWithX:(float)xAmount andY:(float)yAmount
- {
- CGPoint boxCenter = image.center;
- boxCenter.x += xAmount;
- boxCenter.y += yAmount;
- if (boxCenter.x < 50.0)
- boxCenter.x = 50.0;
- if (boxCenter.x > 270.0)
- boxCenter.x = 270.0;
- if (boxCenter.y < 50.0)
- boxCenter.y = 50.0;
- if (boxCenter.y > 410.0)
- boxCenter.y = 410.0;
- image.center = boxCenter;
- }
- - (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration
- {
- float sensitivity = 25.0f;
- float xDistance = acceleration.x *sensitivity;
- float yDistance = acceleration.y *-sensitivity;
- [self moveBoxWithX:xDistance andY:yDistance];
- }
- - (void)dealloc {
- [image release];
- image = nil;
- [super dealloc];
- }
- -(IBAction)easyClick {
- [self.parentViewController dismissModalViewControllerAnimated:NO];
- }
- @end
Add Comment
Please, Sign In to add comment