-
Notifications
You must be signed in to change notification settings - Fork 0
/
ObjectInstance.m
52 lines (43 loc) · 1.29 KB
/
ObjectInstance.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//
// ObjectInstance.m
// hiddenObjectTest
//
// Created by Jonathan Langens on 28/03/15.
// Copyright (c) 2015 Jonathan Langens. All rights reserved.
//
#import "ObjectInstance.h"
@implementation ObjectInstance
-(BOOL) collidesWithRect:(CGRect) otherRect
{
bool xbounded = false;
if(self.rect.origin.x > otherRect.origin.x &&
self.rect.origin.x < (otherRect.origin.x + otherRect.size.width))
{
xbounded = true;
}
if(((self.rect.origin.x + self.rect.size.width) > otherRect.origin.x) &&
(self.rect.origin.x + self.rect.size.width) < (otherRect.size.width + otherRect.origin.x))
{
xbounded = true;
}
bool ybounded = false;
if(self.rect.origin.y > otherRect.origin.y &&
self.rect.origin.y < (otherRect.origin.y + otherRect.size.height))
{
ybounded = true;
}
if(((self.rect.origin.y + self.rect.size.height) > otherRect.origin.y) &&
(self.rect.origin.y + self.rect.size.height) < (otherRect.size.height + otherRect.origin.y))
{
ybounded = true;
}
return xbounded && ybounded;
}
-(instancetype) initWithRect:(CGRect) rect andImageName:(NSString*) name
{
self = [super init];
self.rect = rect;
self.imageName = name;
return self;
}
@end