Created
March 25, 2009 04:48
-
-
Save whoahbot/85291 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// TrollopsViewController.m | |
// Trollops | |
// | |
// Created by dph on 3/16/09. | |
// Copyright __MyCompanyName__ 2009. All rights reserved. | |
// | |
#import "TrollopsViewController.h" | |
#import "TrollopView.h" | |
#import <AVFoundation/AVFoundation.h> | |
@implementation TrollopsViewController | |
- (void)viewDidLoad { | |
[super viewDidLoad]; | |
[NSTimer scheduledTimerWithTimeInterval:1.0 / 30.0 target:self selector:@selector(paintTrollops) userInfo:nil repeats:YES]; | |
} | |
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { | |
Trollop * trollop; | |
UITouch *touch = [touches anyObject]; | |
currentTouch = [touch locationInView:self.view]; | |
trollop = [[Trollop alloc] init]; | |
trollop.position = currentTouch; | |
trollop.velocity = CGPointMake(4.0, 3.0); | |
trollop.radius = 20.0; | |
[(TrollopView *)self.view addTrollop:trollop]; | |
} | |
- (void) paintTrollops { | |
[(TrollopView *)self.view refresh]; | |
} | |
- (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]; | |
} | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// TrollopView.m | |
// Trollops | |
// | |
// Created by dph on 3/16/09. | |
// Copyright 2009 __MyCompanyName__. All rights reserved. | |
// | |
#import "TrollopView.h" | |
@implementation TrollopView | |
@synthesize trollops; | |
- (id)initWithFrame:(CGRect)frame { | |
if (self = [super initWithFrame:frame]) { | |
self.trollops = [[NSMutableArray alloc] init]; | |
// Initialization code | |
} | |
return self; | |
} | |
- (void)drawRect:(CGRect)rect { | |
Trollop *trollop; | |
for(trollop in trollops) { | |
CGContextRef context = UIGraphicsGetCurrentContext(); | |
CGContextSetStrokeColorWithColor(context, [UIColor orangeColor].CGColor); | |
CGContextSetLineWidth(context, 1.0); | |
CGContextAddEllipseInRect(context, [trollop getRect]); | |
CGContextStrokePath(context); | |
[trollop update]; | |
} | |
} | |
- (void)refresh { | |
[self setNeedsDisplay]; | |
} | |
- (void)addTrollop:(Trollop *) aTrollop { | |
Trollop * trollop; | |
[trollops addObject:aTrollop]; | |
} | |
- (void)dealloc { | |
[trollops release]; | |
[super dealloc]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment