-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOrbitalSurface.m
63 lines (43 loc) · 1.23 KB
/
OrbitalSurface.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
53
54
55
56
57
58
59
60
61
62
63
//
// OrbitalSurface.m
// GraceWorld
//
// Created by John Detloff on 4/27/13.
// Copyright (c) 2013 Uebie. All rights reserved.
//
#import "OrbitalSurface.h"
#import "OrbitalCoordinate.h"
@implementation OrbitalSurface {
SurfaceRelativeDirection _lastContactDirection;
}
- (id)initWithCoordA:(OrbitalCoordinate *)coordA coordB:(OrbitalCoordinate *)coordB {
self = [super init];
if (self) {
_coordA = coordA;
_coordB = coordB;
_lastContactDirection = SurfaceUntouched;
_collideFromBelow = YES;
_activated = YES;
}
return self;
}
#pragma mark -
- (BOOL)allowsCollision {
return _activated && !_isSensor;
}
#pragma mark -
- (void)contactBegan:(b2Contact *)contact {
// NO-op
}
- (void)contactEnded:(b2Contact *)contact {
if (!_isSensor) return;
_lastContactDirection = SurfaceUntouched;
}
- (void)boyMadeContactOnSide:(SurfaceRelativeDirection)relativeDirection {
if (!_isSensor) return;
if ((relativeDirection == SurfaceLeft && _lastContactDirection == SurfaceRight) || (relativeDirection == SurfaceRight && _lastContactDirection == SurfaceLeft)) {
self.sensorAction(YES);
}
_lastContactDirection = relativeDirection;
}
@end