forked from rolandoam/CCPhysics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCCPhysicsShape.h
executable file
·119 lines (102 loc) · 3.72 KB
/
CCPhysicsShape.h
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*
* CCPhysics for cocos2d - http://www.gamesforfood.com
*
* Copyright (c) 2010 Rolando Abarca M.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/
#import <Foundation/Foundation.h>
#import "cocos2d.h"
#define GRID_SIZE 32
typedef enum {
ShapeSquare = 1,
ShapeHalfSquare, // square of 16x16
ShapeRect_32x14, // rectangle of 32x14 (this is the Sperm)
ShapeRect_32x20, // rectangle of 32x20
ShapeCircle, // circle of 16px of radius
ShapeTR_L45, // right 45deg triangle
ShapeTR_R45, // left 45deg triangle
} CollisionShapeType;
extern CGPoint ShapeHalfWidths[];
enum {
kCollideNone = 0,
kCollideAxis,
kCollideOther
};
@interface CCPhysicsShape : CCNode {
// collision shape, should have an associated collision function
CollisionShapeType collisionType_;
// internal tile type (user data)
uint8_t tileType_;
// whether or not to inform our parent (CCNode) when we change our position
// this should be false for the dynamic object, since they inform on the
// integrate function
BOOL alertMovesToParent_;
// we use this to calculate velocity and verlet integration
CGPoint oldPos_;
// half widths. These are taken from the static list. Should not be
// modified by hand
CGPoint hw_;
}
@property (nonatomic,readonly) CollisionShapeType collisionType;
@property (nonatomic,readonly) CGPoint hw;
+ (CCPhysicsShape *)shapeWithCollisionType:(CollisionShapeType)collisionType;
- (id)initWithCollisionType:(CollisionShapeType)collisionType;
/*
* process collision
*
* we pass the collisionShape and the tile object, because when colliding
* with the world boundaries, collisionShape is 0 and object is nil, so
* we can't infer that from the object itself.
*
* This will call the specific calculation function for the shape type of
* the receiving object.
*/
- (void)collideWith:(CollisionShapeType)type object:(CCPhysicsShape *)obj projection:(CGPoint)p;
/*
* execute collision
*
* this is called after the projection and normal were calculated. This will change
* velocity according to the physics (adding friction and bounce)
*/
- (void)collisionWithWorldTile:(CCPhysicsShape *)tile projection:(CGPoint)proj normal:(CGPoint)d;
/*
* final collision callback
*
* this is called after the solver and after the execution. In case you need to do something
*/
- (void)collidedWithTile:(CCPhysicsShape *)tile;
@end
@interface CCPhysicsDynamicShape : CCPhysicsShape {
CGPoint gravity_;
}
+ (CCPhysicsDynamicShape *)shapeWithPosition:(CGPoint)pos;
- (id)initWithPosition:(CGPoint)pos;
/*
* verlet integration
*
* on static objects this do nothing. On dynamic objects it calculates the position
*/
- (void)integrate;
/*
* update what you need here, this is run just before integration
*/
- (void)update;
@end