@makefully/platypus 4.1.5 → 4.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +31 -0
- package/README.md +3 -3
- package/lib/platypus.js +1 -1
- package/package.json +7 -6
- package/src/AABB.js +685 -0
- package/src/ActionState.js +121 -0
- package/src/AssetManager.js +206 -0
- package/src/CollisionData.js +96 -0
- package/src/CollisionDataContainer.js +127 -0
- package/src/CollisionShape.js +315 -0
- package/src/Component.js +231 -0
- package/src/Data.js +64 -0
- package/src/DataMap.js +204 -0
- package/src/Entity.js +404 -0
- package/src/EntityLinker.js +113 -0
- package/src/EventHandler.js +115 -0
- package/src/EventHandlerList.js +251 -0
- package/src/Game.js +840 -0
- package/src/Gamepad.js +175 -0
- package/src/ID3CaptionPlayer.js +61 -0
- package/src/Messenger.js +365 -0
- package/src/PIXIAnimation.js +622 -0
- package/src/RandomSet.js +140 -0
- package/src/SFXPlayer.js +120 -0
- package/src/StateMap.js +252 -0
- package/src/Storage.js +152 -0
- package/src/TickerClient.js +48 -0
- package/src/TickerServer.js +23 -0
- package/src/TimeEvent.js +50 -0
- package/src/TimeEventList.js +100 -0
- package/src/VOPlayer.js +684 -0
- package/src/Vector.js +702 -0
- package/src/components/AIChaser.js +161 -0
- package/src/components/AIPacer.js +107 -0
- package/src/components/AudioMusic.js +151 -0
- package/src/components/AudioSFX.js +673 -0
- package/src/components/AudioVO.js +301 -0
- package/src/components/CollisionBasic.js +826 -0
- package/src/components/CollisionFilter.js +74 -0
- package/src/components/CollisionGroup.js +448 -0
- package/src/components/CollisionTiles.js +608 -0
- package/src/components/ComponentSwitcher.js +173 -0
- package/src/components/ControllerInput.js +65 -0
- package/src/components/Counter.js +165 -0
- package/src/components/EntityCamera.js +215 -0
- package/src/components/EntityContainer.js +549 -0
- package/src/components/EntityController.js +541 -0
- package/src/components/HandlerCamera.js +1052 -0
- package/src/components/HandlerCollision.js +1318 -0
- package/src/components/HandlerController.js +291 -0
- package/src/components/HandlerLogic.js +394 -0
- package/src/components/HandlerRender.js +217 -0
- package/src/components/Interactive.js +502 -0
- package/src/components/LevelBuilder.js +524 -0
- package/src/components/LogicAngularMovement.js +154 -0
- package/src/components/LogicAttachment.js +265 -0
- package/src/components/LogicButton.js +466 -0
- package/src/components/LogicCarrier.js +39 -0
- package/src/components/LogicDestroyMe.js +58 -0
- package/src/components/LogicDirectionalMovement.js +325 -0
- package/src/components/LogicDragDrop.js +371 -0
- package/src/components/LogicImpactLaunch.js +144 -0
- package/src/components/LogicPacingPlatform.js +64 -0
- package/src/components/LogicPortable.js +112 -0
- package/src/components/LogicPortal.js +115 -0
- package/src/components/LogicPushable.js +98 -0
- package/src/components/LogicRebounder.js +136 -0
- package/src/components/LogicRegionSpawner.js +139 -0
- package/src/components/LogicRotationalMovement.js +205 -0
- package/src/components/LogicSpawner.js +159 -0
- package/src/components/LogicStateMachine.js +382 -0
- package/src/components/LogicSwitch.js +77 -0
- package/src/components/LogicTeleportee.js +68 -0
- package/src/components/LogicTeleporter.js +93 -0
- package/src/components/LogicTimer.js +178 -0
- package/src/components/LogicWindUpRacer.js +179 -0
- package/src/components/Motion.js +371 -0
- package/src/components/Mover.js +566 -0
- package/src/components/Node.js +289 -0
- package/src/components/NodeMap.js +295 -0
- package/src/components/NodeResident.js +636 -0
- package/src/components/Orientation.js +697 -0
- package/src/components/RandomEvents.js +73 -0
- package/src/components/RelativePosition.js +204 -0
- package/src/components/RelayFamily.js +106 -0
- package/src/components/RelayGame.js +53 -0
- package/src/components/RelayLinker.js +94 -0
- package/src/components/RelayParent.js +57 -0
- package/src/components/RelaySelf.js +55 -0
- package/src/components/Render.js +178 -0
- package/src/components/RenderAnimator.js +275 -0
- package/src/components/RenderContainer.js +646 -0
- package/src/components/RenderDebug.js +319 -0
- package/src/components/RenderDestroyMe.js +59 -0
- package/src/components/RenderLottie.js +149 -0
- package/src/components/RenderProgress.js +120 -0
- package/src/components/RenderSpine.js +840 -0
- package/src/components/RenderSprite.js +527 -0
- package/src/components/RenderText.js +147 -0
- package/src/components/RenderTiles.js +1440 -0
- package/src/components/SceneChanger.js +128 -0
- package/src/components/TiledLoader.js +1459 -0
- package/src/components/Timeline.js +314 -0
- package/src/components/Tutorial.js +267 -0
- package/src/components/Tween.js +296 -0
- package/src/components/VoiceOver.js +373 -0
- package/src/components/XHR.js +129 -0
- package/src/components/index.js +79 -0
- package/src/factory.js +305 -0
- package/src/index.js +159 -0
- package/src/mixins/PIXI.Graphics.js +41 -0
- package/src/platypus.css +68 -0
- package/src/sayHello.js +50 -0
- package/src/shapes/Capsule.js +74 -0
- package/src/shapes/Circle.js +43 -0
- package/src/shapes/Ellipse.js +117 -0
- package/src/shapes/Point.js +191 -0
- package/src/shapes/Polygon.js +112 -0
- package/src/shapes/Polyline.js +97 -0
- package/src/shapes/Rectangle.js +78 -0
- package/src/shapes/RoundedRectangle.js +33 -0
- package/src/shapes/Segment.js +346 -0
- package/src/shapes/adjustedXY.js +19 -0
- package/src/shapes/castFromBox2D.js +92 -0
- package/src/shapes/castFromObject.js +53 -0
- package/src/shapes/castFromPixiGraphics.js +6 -0
- package/src/shapes/castFromPixiShape.js +89 -0
- package/src/shapes/castToBox2D.js +190 -0
- package/src/shapes/castToPixiGraphics.js +100 -0
- package/src/shapes/castToPixiShape.js +61 -0
- package/src/shapes/checkPointsMap.js +313 -0
- package/src/shapes/index.js +35 -0
- package/src/utils/array.js +73 -0
- package/src/utils/string.js +39 -0
- package/lib/243.platypus.mjs +0 -1
- package/lib/platypus.mjs +0 -1
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import createComponentClass from '../factory.js';
|
|
2
|
+
|
|
3
|
+
const
|
|
4
|
+
collidePos = function (state, event, collInfo) {
|
|
5
|
+
if (this.state.get(state)) {
|
|
6
|
+
this.trigger(event, collInfo);
|
|
7
|
+
}
|
|
8
|
+
},
|
|
9
|
+
collideNeg = function (state, event, collInfo) {
|
|
10
|
+
if (!this.state.get(state)) {
|
|
11
|
+
this.trigger(event, collInfo);
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export default createComponentClass(/** @lends platypus.components.CollisionFilter.prototype */{
|
|
16
|
+
id: 'CollisionFilter',
|
|
17
|
+
|
|
18
|
+
properties: {
|
|
19
|
+
/**
|
|
20
|
+
* One or more collision events for which to listen. For example, if the state property is set to "allergic":
|
|
21
|
+
*
|
|
22
|
+
{
|
|
23
|
+
"hitting-flowers": "sneeze",
|
|
24
|
+
// Listen for "hitting-flowers", and if the entity is "allergic", trigger a "sneeze" event.
|
|
25
|
+
|
|
26
|
+
"in-the-weeds": "cough"
|
|
27
|
+
// Another collision event that triggers "cough" if the entity is "allergic".
|
|
28
|
+
}
|
|
29
|
+
*
|
|
30
|
+
* @property collisions
|
|
31
|
+
* @type Object
|
|
32
|
+
* @default {}
|
|
33
|
+
*/
|
|
34
|
+
collisions: {},
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* The entity state that should cause the following list of collisions to trigger events. If this state is not true, no events are triggered. To trigger events on the inverse of a state, place "!" before the state such as "!allergic".
|
|
38
|
+
*
|
|
39
|
+
* @property state
|
|
40
|
+
* @type String
|
|
41
|
+
* @default ""
|
|
42
|
+
*/
|
|
43
|
+
state: ""
|
|
44
|
+
},
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* This component will listen for a particular collision message and, depending on a given entity.state attribute, retrigger the collision as another collision message.
|
|
48
|
+
*
|
|
49
|
+
* @memberof platypus.components
|
|
50
|
+
* @uses platypus.Component
|
|
51
|
+
* @constructs
|
|
52
|
+
*/
|
|
53
|
+
initialize: function () {
|
|
54
|
+
const
|
|
55
|
+
collisions = this.collisions;
|
|
56
|
+
|
|
57
|
+
if (collisions) {
|
|
58
|
+
const
|
|
59
|
+
{state, owner} = this,
|
|
60
|
+
negative = state[0] === '!',
|
|
61
|
+
resolveState = negative ? state.substring[1] : state,
|
|
62
|
+
resolveCollision = negative ? collideNeg : collidePos,
|
|
63
|
+
keys = Object.keys(collisions),
|
|
64
|
+
{length} = keys;
|
|
65
|
+
|
|
66
|
+
for (let i = 0; i < length; i++) {
|
|
67
|
+
const
|
|
68
|
+
key = keys[i];
|
|
69
|
+
|
|
70
|
+
this.addEventListener(key, resolveCollision.bind(owner, resolveState, collisions[key]));
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
});
|
|
@@ -0,0 +1,448 @@
|
|
|
1
|
+
import {arrayCache, greenSplice, union} from '../utils/array.js';
|
|
2
|
+
import AABB from '../AABB.js';
|
|
3
|
+
import DataMap from '../DataMap.js';
|
|
4
|
+
import Vector from '../Vector.js';
|
|
5
|
+
import createComponentClass from '../factory.js';
|
|
6
|
+
|
|
7
|
+
export default (function () {
|
|
8
|
+
return createComponentClass(/** @lends platypus.components.CollisionGroup.prototype */{
|
|
9
|
+
id: 'CollisionGroup',
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* This component groups other entities with this entity for collision checking. This is useful for carrying and moving platforms. It uses `EntityContainer` component messages if triggered to add to its collision list and also listens for explicit add/remove messages (useful in the absence of an `EntityContainer` component).
|
|
13
|
+
*
|
|
14
|
+
* @memberof platypus.components
|
|
15
|
+
* @uses platypus.Component
|
|
16
|
+
* @constructs
|
|
17
|
+
* @listens platypus.Entity#add-collision-entity
|
|
18
|
+
* @listens platypus.Entity#child-entity-added
|
|
19
|
+
* @listens platypus.Entity#child-entity-removed
|
|
20
|
+
* @listens platypus.Entity#relocate-entity
|
|
21
|
+
* @listens platypus.Entity#remove-collision-entity
|
|
22
|
+
*/
|
|
23
|
+
initialize: function () {
|
|
24
|
+
this.solidEntities = arrayCache.setUp();
|
|
25
|
+
|
|
26
|
+
// These are used as return values for methods, but are instantiated here for recycling later.
|
|
27
|
+
this.collisionTypes = arrayCache.setUp();
|
|
28
|
+
this.shapes = arrayCache.setUp();
|
|
29
|
+
this.prevShapes = arrayCache.setUp();
|
|
30
|
+
|
|
31
|
+
this.terrain = null;
|
|
32
|
+
this.aabb = AABB.setUp(this.owner.x, this.owner.y);
|
|
33
|
+
this.prevAABB = AABB.setUp(this.owner.x, this.owner.y);
|
|
34
|
+
this.filteredAABB = AABB.setUp();
|
|
35
|
+
|
|
36
|
+
Vector.assign(this.owner, 'position', 'x', 'y', 'z');
|
|
37
|
+
Vector.assign(this.owner, 'previousPosition', 'previousX', 'previousY', 'previousZ');
|
|
38
|
+
this.owner.previousX = this.owner.previousX || this.owner.x;
|
|
39
|
+
this.owner.previousY = this.owner.previousY || this.owner.y;
|
|
40
|
+
|
|
41
|
+
this.collisionGroup = this.owner.collisionGroup = {
|
|
42
|
+
getAllEntities: function () {
|
|
43
|
+
let count = 0;
|
|
44
|
+
|
|
45
|
+
for (let x = 0; x < this.solidEntities.length; x++) {
|
|
46
|
+
const
|
|
47
|
+
childEntity = this.solidEntities[x];
|
|
48
|
+
|
|
49
|
+
if ((childEntity !== this.owner) && childEntity.collisionGroup) {
|
|
50
|
+
count += childEntity.collisionGroup.getAllEntities();
|
|
51
|
+
} else {
|
|
52
|
+
count += 1;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return count;
|
|
57
|
+
}.bind(this),
|
|
58
|
+
getSize: function () {
|
|
59
|
+
return this.solidEntities.length;
|
|
60
|
+
}.bind(this),
|
|
61
|
+
getCollisionTypes: function () {
|
|
62
|
+
return this.getCollisionTypes();
|
|
63
|
+
}.bind(this),
|
|
64
|
+
getSolidCollisions: function () {
|
|
65
|
+
return this.getSolidCollisions();
|
|
66
|
+
}.bind(this),
|
|
67
|
+
getAABB: function (collisionType) {
|
|
68
|
+
return this.getAABB(collisionType);
|
|
69
|
+
}.bind(this),
|
|
70
|
+
getPreviousAABB: function (collisionType) {
|
|
71
|
+
return this.getPreviousAABB(collisionType);
|
|
72
|
+
}.bind(this),
|
|
73
|
+
getShapes: function (collisionType) {
|
|
74
|
+
return this.getShapes(collisionType);
|
|
75
|
+
}.bind(this),
|
|
76
|
+
getPrevShapes: function (collisionType) {
|
|
77
|
+
return this.getPrevShapes(collisionType);
|
|
78
|
+
}.bind(this),
|
|
79
|
+
prepareCollision: function (x, y) {
|
|
80
|
+
return this.prepareCollision(x, y);
|
|
81
|
+
}.bind(this),
|
|
82
|
+
relocateEntity: function (vector, collisionData) {
|
|
83
|
+
return this.relocateEntity(vector, collisionData);
|
|
84
|
+
}.bind(this),
|
|
85
|
+
movePreviousX: function (x) {
|
|
86
|
+
return this.movePreviousX(x);
|
|
87
|
+
}.bind(this),
|
|
88
|
+
getSolidEntities: function () {
|
|
89
|
+
return this.solidEntities;
|
|
90
|
+
}.bind(this),
|
|
91
|
+
jumpThrough: false //TODO: this introduces odd behavior - not sure how to resolve yet. - DDD
|
|
92
|
+
};
|
|
93
|
+
},
|
|
94
|
+
|
|
95
|
+
events: {
|
|
96
|
+
"child-entity-added": function (entity) {
|
|
97
|
+
this.addCollisionEntity(entity);
|
|
98
|
+
},
|
|
99
|
+
|
|
100
|
+
"add-collision-entity": function (entity) {
|
|
101
|
+
this.addCollisionEntity(entity);
|
|
102
|
+
},
|
|
103
|
+
|
|
104
|
+
"child-entity-removed": function (entity) {
|
|
105
|
+
this.removeCollisionEntity(entity);
|
|
106
|
+
},
|
|
107
|
+
|
|
108
|
+
"remove-collision-entity": function (entity) {
|
|
109
|
+
this.removeCollisionEntity(entity);
|
|
110
|
+
},
|
|
111
|
+
|
|
112
|
+
"relocate-entity": function () {
|
|
113
|
+
this.owner.previousPosition.setVector(this.owner.position);
|
|
114
|
+
this.updateAABB();
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
|
|
118
|
+
methods: {
|
|
119
|
+
addCollisionEntity: function (entity) {
|
|
120
|
+
const
|
|
121
|
+
{collisionTypes: types} = entity;
|
|
122
|
+
|
|
123
|
+
if (types) {
|
|
124
|
+
let i = types.length;
|
|
125
|
+
while (i--) {
|
|
126
|
+
if (entity.solidCollisionMap.get(types[i]).length && !entity.immobile) {
|
|
127
|
+
const
|
|
128
|
+
j = this.solidEntities.indexOf(entity);
|
|
129
|
+
|
|
130
|
+
if (j === -1) {
|
|
131
|
+
this.solidEntities[this.solidEntities.length] = entity;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
this.updateAABB();
|
|
136
|
+
}
|
|
137
|
+
},
|
|
138
|
+
|
|
139
|
+
removeCollisionEntity: function (entity) {
|
|
140
|
+
const
|
|
141
|
+
{collisionTypes: types} = entity;
|
|
142
|
+
|
|
143
|
+
if (types) {
|
|
144
|
+
let i = types.length;
|
|
145
|
+
while (i--) {
|
|
146
|
+
if (entity.solidCollisionMap.get(types[i]).length) {
|
|
147
|
+
const
|
|
148
|
+
j = this.solidEntities.indexOf(entity);
|
|
149
|
+
|
|
150
|
+
if (j >= 0) {
|
|
151
|
+
greenSplice(this.solidEntities, j);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
this.updateAABB();
|
|
156
|
+
}
|
|
157
|
+
},
|
|
158
|
+
|
|
159
|
+
getCollisionTypes: function () {
|
|
160
|
+
const
|
|
161
|
+
{collisionTypes, owner, solidEntities} = this;
|
|
162
|
+
let i = solidEntities.length;
|
|
163
|
+
|
|
164
|
+
collisionTypes.length = 0;
|
|
165
|
+
|
|
166
|
+
while (i--) {
|
|
167
|
+
const
|
|
168
|
+
childEntity = solidEntities[i];
|
|
169
|
+
|
|
170
|
+
if ((childEntity !== owner) && childEntity.collisionGroup) {
|
|
171
|
+
childEntity = childEntity.collisionGroup;
|
|
172
|
+
}
|
|
173
|
+
union(collisionTypes, childEntity.getCollisionTypes());
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
return collisionTypes;
|
|
177
|
+
},
|
|
178
|
+
|
|
179
|
+
getSolidCollisions: function () {
|
|
180
|
+
const
|
|
181
|
+
{owner, solidEntities} = this,
|
|
182
|
+
compiledList = DataMap.setUp();
|
|
183
|
+
|
|
184
|
+
for (let x = 0; x < solidEntities.length; x++) {
|
|
185
|
+
const
|
|
186
|
+
solidEntity = solidEntities[x],
|
|
187
|
+
{collisionGroup} = solidEntity,
|
|
188
|
+
useGC = (solidEntity !== owner) && collisionGroup,
|
|
189
|
+
childEntity = useGC ? collisionGroup : solidEntity,
|
|
190
|
+
entityList = childEntity.getSolidCollisions(),
|
|
191
|
+
keys = entityList.keys;
|
|
192
|
+
let i = keys.length;
|
|
193
|
+
|
|
194
|
+
while (i--) {
|
|
195
|
+
const
|
|
196
|
+
key = keys[i],
|
|
197
|
+
toList = compiledList.get(key) || compiledList.set(key, arrayCache.setUp()),
|
|
198
|
+
fromList = entityList.get(key);
|
|
199
|
+
|
|
200
|
+
union(toList, fromList);
|
|
201
|
+
|
|
202
|
+
if (useGC) {
|
|
203
|
+
fromList.recycle();
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
if (useGC) {
|
|
207
|
+
entityList.recycle();
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
return compiledList; // TODO: Track down where this is used and make sure the arrays are recycled. - DDD 2/1/2016
|
|
212
|
+
},
|
|
213
|
+
|
|
214
|
+
getAABB: function (collisionType) {
|
|
215
|
+
if (!collisionType) {
|
|
216
|
+
return this.aabb;
|
|
217
|
+
} else {
|
|
218
|
+
const
|
|
219
|
+
{filteredAABB, owner, solidEntities} = this;
|
|
220
|
+
let i = solidEntities.length;
|
|
221
|
+
|
|
222
|
+
filteredAABB.reset();
|
|
223
|
+
|
|
224
|
+
while (i--) {
|
|
225
|
+
const
|
|
226
|
+
solidEntity = solidEntities[i],
|
|
227
|
+
{collisionGroup} = solidEntity,
|
|
228
|
+
useGC = (solidEntity !== owner) && collisionGroup,
|
|
229
|
+
childEntity = useGC ? collisionGroup : solidEntity,
|
|
230
|
+
incAABB = childEntity.getAABB(collisionType);
|
|
231
|
+
|
|
232
|
+
if (incAABB) {
|
|
233
|
+
filteredAABB.include(incAABB);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
return filteredAABB;
|
|
237
|
+
}
|
|
238
|
+
},
|
|
239
|
+
|
|
240
|
+
getPreviousAABB: function (collisionType) {
|
|
241
|
+
if (!collisionType) {
|
|
242
|
+
return this.prevAABB;
|
|
243
|
+
} else {
|
|
244
|
+
const
|
|
245
|
+
{filteredAABB, owner, solidEntities} = this;
|
|
246
|
+
let i = solidEntities.length;
|
|
247
|
+
|
|
248
|
+
filteredAABB.reset();
|
|
249
|
+
|
|
250
|
+
while (i--) {
|
|
251
|
+
const
|
|
252
|
+
solidEntity = solidEntities[i],
|
|
253
|
+
{collisionGroup} = solidEntity,
|
|
254
|
+
useGC = (solidEntity !== owner) && collisionGroup,
|
|
255
|
+
childEntity = useGC ? collisionGroup : solidEntity,
|
|
256
|
+
incAABB = childEntity.getPreviousAABB(collisionType);
|
|
257
|
+
|
|
258
|
+
if (incAABB) {
|
|
259
|
+
filteredAABB.include(incAABB);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
return filteredAABB;
|
|
263
|
+
}
|
|
264
|
+
},
|
|
265
|
+
|
|
266
|
+
updateAABB: function () {
|
|
267
|
+
const
|
|
268
|
+
{aabb, owner, solidEntities} = this;
|
|
269
|
+
let i = solidEntities.length;
|
|
270
|
+
|
|
271
|
+
aabb.reset();
|
|
272
|
+
while (i--) {
|
|
273
|
+
const
|
|
274
|
+
entity = solidEntities[i];
|
|
275
|
+
|
|
276
|
+
aabb.include(((entity !== owner) && entity.getCollisionGroupAABB) ? entity.getCollisionGroupAABB() : entity.getAABB());
|
|
277
|
+
}
|
|
278
|
+
},
|
|
279
|
+
|
|
280
|
+
getShapes: function (collisionType) {
|
|
281
|
+
const
|
|
282
|
+
{owner, shapes, solidEntities} = this;
|
|
283
|
+
|
|
284
|
+
shapes.length = 0;
|
|
285
|
+
|
|
286
|
+
for (let i = 0; i < solidEntities.length; i++) {
|
|
287
|
+
const
|
|
288
|
+
solidEntity = solidEntities[i],
|
|
289
|
+
{collisionGroup} = solidEntity,
|
|
290
|
+
useGC = (solidEntity !== owner) && collisionGroup,
|
|
291
|
+
childEntity = useGC ? collisionGroup : solidEntity,
|
|
292
|
+
newShapes = childEntity.getShapes(collisionType);
|
|
293
|
+
|
|
294
|
+
if (newShapes) {
|
|
295
|
+
union(shapes, newShapes);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
return shapes;
|
|
299
|
+
},
|
|
300
|
+
|
|
301
|
+
getPrevShapes: function (collisionType) {
|
|
302
|
+
const
|
|
303
|
+
{owner, prevShapes: shapes, solidEntities} = this;
|
|
304
|
+
|
|
305
|
+
shapes.length = 0;
|
|
306
|
+
|
|
307
|
+
for (let i = 0; i < solidEntities.length; i++) {
|
|
308
|
+
const
|
|
309
|
+
solidEntity = solidEntities[i],
|
|
310
|
+
{collisionGroup} = solidEntity,
|
|
311
|
+
useGC = (solidEntity !== owner) && collisionGroup,
|
|
312
|
+
childEntity = useGC ? collisionGroup : solidEntity,
|
|
313
|
+
newShapes = childEntity.getPrevShapes(collisionType);
|
|
314
|
+
|
|
315
|
+
if (newShapes) {
|
|
316
|
+
union(shapes, newShapes);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
return shapes;
|
|
320
|
+
},
|
|
321
|
+
|
|
322
|
+
prepareCollision: function (x, y) {
|
|
323
|
+
const
|
|
324
|
+
{owner, solidEntities} = this;
|
|
325
|
+
|
|
326
|
+
for (let i = 0; i < solidEntities.length; i++) {
|
|
327
|
+
const
|
|
328
|
+
childEntity = solidEntities[i],
|
|
329
|
+
oX = owner.previousX - childEntity.previousX,
|
|
330
|
+
oY = owner.previousY - childEntity.previousY;
|
|
331
|
+
|
|
332
|
+
childEntity.saveDX = childEntity.x - childEntity.previousX;
|
|
333
|
+
childEntity.saveDY = childEntity.y - childEntity.previousY;
|
|
334
|
+
childEntity.saveOX = oX;
|
|
335
|
+
childEntity.saveOY = oY;
|
|
336
|
+
|
|
337
|
+
if ((childEntity !== owner) && childEntity.collisionGroup) {
|
|
338
|
+
childEntity.collisionGroup.prepareCollision(x - oX, y - oY);
|
|
339
|
+
} else {
|
|
340
|
+
childEntity.prepareCollision(x - oX, y - oY);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
},
|
|
344
|
+
|
|
345
|
+
movePreviousX: function (x) {
|
|
346
|
+
const
|
|
347
|
+
{owner, solidEntities} = this;
|
|
348
|
+
|
|
349
|
+
for (let i = 0; i < solidEntities.length; i++) {
|
|
350
|
+
const
|
|
351
|
+
childEntity = solidEntities[i],
|
|
352
|
+
offset = childEntity.saveOX;
|
|
353
|
+
|
|
354
|
+
if ((childEntity !== owner) && childEntity.collisionGroup) {
|
|
355
|
+
childEntity.collisionGroup.movePreviousX(x - offset);
|
|
356
|
+
} else {
|
|
357
|
+
childEntity.movePreviousX(x - offset);
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
},
|
|
361
|
+
|
|
362
|
+
relocateEntity: function (vector, collisionData) {
|
|
363
|
+
const
|
|
364
|
+
{owner, solidEntities} = this,
|
|
365
|
+
{xData, yData} = collisionData;
|
|
366
|
+
let x = xData.length,
|
|
367
|
+
y = yData.length;
|
|
368
|
+
|
|
369
|
+
owner.saveDX -= vector.x - owner.previousX;
|
|
370
|
+
owner.saveDY -= vector.y - owner.previousY;
|
|
371
|
+
|
|
372
|
+
while (x--) {
|
|
373
|
+
if (xData[x].thisShape.owner === owner) {
|
|
374
|
+
owner.saveDX = 0;
|
|
375
|
+
break;
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
while (y--) {
|
|
380
|
+
if (yData[y].thisShape.owner === owner) {
|
|
381
|
+
owner.saveDY = 0;
|
|
382
|
+
break;
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
for (let i = 0; i < solidEntities.length; i++) {
|
|
387
|
+
const
|
|
388
|
+
solidEntity = solidEntities[i],
|
|
389
|
+
{collisionGroup} = solidEntity,
|
|
390
|
+
useGC = (solidEntity !== owner) && collisionGroup,
|
|
391
|
+
childEntity = useGC ? collisionGroup : solidEntity,
|
|
392
|
+
v = Vector.setUp(vector.x - solidEntity.saveOX, vector.y - solidEntity.saveOY, childEntity.z);
|
|
393
|
+
|
|
394
|
+
childEntity.relocateEntity(v, collisionData);
|
|
395
|
+
v.recycle();
|
|
396
|
+
solidEntity.x += solidEntity.saveDX;
|
|
397
|
+
solidEntity.y += solidEntity.saveDY;
|
|
398
|
+
if (solidEntity !== owner) {
|
|
399
|
+
solidEntity.x += owner.saveDX;
|
|
400
|
+
solidEntity.y += owner.saveDY;
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
},
|
|
404
|
+
|
|
405
|
+
destroy: function () {
|
|
406
|
+
arrayCache.recycle(this.solidEntities);
|
|
407
|
+
arrayCache.recycle(this.collisionTypes);
|
|
408
|
+
arrayCache.recycle(this.shapes);
|
|
409
|
+
arrayCache.recycle(this.prevShapes);
|
|
410
|
+
this.aabb.recycle();
|
|
411
|
+
this.prevAABB.recycle();
|
|
412
|
+
this.filteredAABB.recycle();
|
|
413
|
+
}
|
|
414
|
+
},
|
|
415
|
+
|
|
416
|
+
publicMethods: {
|
|
417
|
+
/**
|
|
418
|
+
* Gets the bounding box of the group of entities.
|
|
419
|
+
*
|
|
420
|
+
* @method platypus.components.CollisionGroup#getCollisionGroupAABB
|
|
421
|
+
* @return platypus.AABB
|
|
422
|
+
*/
|
|
423
|
+
getCollisionGroupAABB: function () {
|
|
424
|
+
return this.getAABB();
|
|
425
|
+
},
|
|
426
|
+
|
|
427
|
+
/**
|
|
428
|
+
* Gets a list of all the entities in the world.
|
|
429
|
+
*
|
|
430
|
+
* @method platypus.components.CollisionGroup#getWorldEntities
|
|
431
|
+
* @return Array
|
|
432
|
+
*/
|
|
433
|
+
getWorldEntities: function () {
|
|
434
|
+
return this.owner.parent.getWorldEntities();
|
|
435
|
+
},
|
|
436
|
+
|
|
437
|
+
/**
|
|
438
|
+
* Gets the collision entity representing the world's terrain.
|
|
439
|
+
*
|
|
440
|
+
* @method platypus.components.CollisionGroup#getWorldTerrain
|
|
441
|
+
* @return platypus.Entity
|
|
442
|
+
*/
|
|
443
|
+
getWorldTerrain: function () {
|
|
444
|
+
return this.owner.parent.getWorldTerrain();
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
});
|
|
448
|
+
}());
|