Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #import "EasyView.h"
- #define kScoreToWin 5
- @implementation EasyView
- @synthesize image;
- @synthesize flakeImage;
- - (IBAction)easyClick {
- [self.parentViewController dismissModalViewControllerAnimated:NO];
- }
- // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- - (void)viewDidLoad
- {
- [super viewDidLoad];
- [[UIAccelerometer sharedAccelerometer] setUpdateInterval:(1/40.0)];
- [[UIAccelerometer sharedAccelerometer] setDelegate:self];
- // load our flake image we will use the same image over and over
- flakeImage = [UIImage imageNamed:@"ball.png"];
- // Make it invisible & add score
- }
- - (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];
- }
- - (IBAction)taptostart {
- start.hidden = YES;
- [NSTimer scheduledTimerWithTimeInterval:(3.9) target:self selector:@selector(onTimer) userInfo:nil repeats:YES];
- mainInt = 0;
- timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(countUp) userInfo:nil repeats:YES];
- }
- - (void)countUp {
- mainInt += 1;
- label.text = [NSString stringWithFormat:@"%i", mainInt];
- if (mainInt ==100) {
- }
- }
- // Timer event is called whenever the timer fires
- - (void)onTimer
- {
- image.center = CGPointMake(image.center.x+pos.x,ball.center.y+pos.y);
- if(CGRectIntersectsRect(image.frame,flakeImage.frame)) {
- ifimage.center.y < flakeImage.center.y) {
- pos.y = -pos.y;
- }
- }
- // build a view from our flake image
- UIImageView* flakeView = [[UIImageView alloc] initWithImage:flakeImage];
- // use the random() function to randomize up our flake attributes
- int startX = round(random() % 320);
- int endX = round(random() % 320);
- double scale = 1 / round(random() % 100) + 1.0;
- double speed = 1 / round(random() % 100) + 1.0;
- // set the flake start position
- flakeView.frame = CGRectMake(startX, -100.0, 25.0 * scale, 25.0 * scale);
- flakeView.alpha = 0.25;
- // put the flake in our main view
- [self.view addSubview:flakeView];
- [UIView beginAnimations:nil context:flakeView];
- // set up how fast the flake will fall
- [UIView setAnimationDuration:5 * speed];
- // set the postion where flake will move to
- flakeView.frame = CGRectMake(endX, 500.0, 25.0 * scale, 25.0 * scale);
- // set a stop callback so we can cleanup the flake when it reaches the
- // end of its animation
- [UIView setAnimationDidStopSelector:@selector(onAnimationComplete:finished:context:)];
- [UIView setAnimationDelegate:self];
- [UIView commitAnimations];
- }
- - (void)onAnimationComplete:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
- UIImageView *flakeView = context;
- [flakeView removeFromSuperview];
- // open the debug log and you will see that all flakes have a retain count
- // of 1 at this point so we know the release below will keep our memory
- // usage in check
- NSLog([NSString stringWithFormat:@"[flakeView retainCount] = %d", [flakeView retainCount]]);
- [flakeView release];
- }
- - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
- // Return YES for supported orientations
- return (interfaceOrientation == UIInterfaceOrientationPortrait);
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
- // Release anything that's not essential, such as cached data
- }
- - (void)dealloc {
- [super dealloc];
- [flakeImage release];
- [image release];
- }
- @end
Add Comment
Please, Sign In to add comment