@makefully/platypus 4.1.4 → 4.1.6
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 +20 -0
- package/README.md +4 -2
- package/lib/platypus.js +1 -1
- package/package.json +7 -2
- 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 +833 -0
- package/src/components/RenderSprite.js +527 -0
- package/src/components/RenderText.js +147 -0
- package/src/components/RenderTiles.js +1391 -0
- package/src/components/SceneChanger.js +128 -0
- package/src/components/TiledLoader.js +1451 -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
|
@@ -0,0 +1,566 @@
|
|
|
1
|
+
/* global platypus */
|
|
2
|
+
import {arrayCache, greenSplice} from '../utils/array.js';
|
|
3
|
+
import Vector from '../Vector.js';
|
|
4
|
+
import createComponentClass from '../factory.js';
|
|
5
|
+
|
|
6
|
+
const
|
|
7
|
+
tempVector = Vector.setUp(),
|
|
8
|
+
updateMax = function (delta, interim, goal, time) {
|
|
9
|
+
if (delta && (interim !== goal)) {
|
|
10
|
+
if (interim < goal) {
|
|
11
|
+
return Math.min(interim + delta * time, goal);
|
|
12
|
+
} else {
|
|
13
|
+
return Math.max(interim - delta * time, goal);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return interim;
|
|
18
|
+
},
|
|
19
|
+
clampNumber = function (v, d) {
|
|
20
|
+
const
|
|
21
|
+
mIn = this.maxMagnitudeInterim = updateMax(this.maxMagnitudeDelta, this.maxMagnitudeInterim, this.maxMagnitude, d);
|
|
22
|
+
|
|
23
|
+
if (v.magnitude() > mIn) {
|
|
24
|
+
v.normalize().multiply(mIn);
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
clampObject = function (v, d) {
|
|
28
|
+
const
|
|
29
|
+
max = this.maxMagnitude,
|
|
30
|
+
mD = this.maxMagnitudeDelta,
|
|
31
|
+
mIn = this.maxMagnitudeInterim;
|
|
32
|
+
|
|
33
|
+
mIn.up = updateMax(mD, mIn.up, max.up, d);
|
|
34
|
+
mIn.right = updateMax(mD, mIn.right, max.right, d);
|
|
35
|
+
mIn.down = updateMax(mD, mIn.down, max.down, d);
|
|
36
|
+
mIn.left = updateMax(mD, mIn.left, max.left, d);
|
|
37
|
+
|
|
38
|
+
if (v.x > 0) {
|
|
39
|
+
if (v.x > mIn.right) {
|
|
40
|
+
v.x = mIn.right;
|
|
41
|
+
}
|
|
42
|
+
} else if (v.x < 0) {
|
|
43
|
+
if (v.x < -mIn.left) {
|
|
44
|
+
v.x = -mIn.left;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (v.y > 0) {
|
|
49
|
+
if (v.y > mIn.down) {
|
|
50
|
+
v.y = mIn.down;
|
|
51
|
+
}
|
|
52
|
+
} else if (v.y < 0) {
|
|
53
|
+
if (v.y < -mIn.up) {
|
|
54
|
+
v.y = -mIn.up;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export default createComponentClass(/** @lends platypus.components.Mover.prototype */{
|
|
60
|
+
|
|
61
|
+
id: 'Mover',
|
|
62
|
+
|
|
63
|
+
properties: {
|
|
64
|
+
/** This is a normalized vector describing the direction the ground should face away from the entity.
|
|
65
|
+
*
|
|
66
|
+
* @property ground
|
|
67
|
+
* @type Array|Vector
|
|
68
|
+
* @default Vector(0, 1)
|
|
69
|
+
*/
|
|
70
|
+
ground: [0, 1]
|
|
71
|
+
},
|
|
72
|
+
|
|
73
|
+
publicProperties: {
|
|
74
|
+
/**
|
|
75
|
+
* A list of key/value pairs describing vectors or vector-like objects describing acceleration and velocity on the entity. See the ["Motion"]("Motion"%20Component.html) component for properties.
|
|
76
|
+
*
|
|
77
|
+
* @property movers
|
|
78
|
+
* @type Array
|
|
79
|
+
* @default []
|
|
80
|
+
*/
|
|
81
|
+
movers: [],
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* If specified, the property adds gravity motion to the entity.
|
|
85
|
+
*
|
|
86
|
+
* @property gravity
|
|
87
|
+
* @type number|Array|Vector
|
|
88
|
+
* @default: 0
|
|
89
|
+
*/
|
|
90
|
+
gravity: 0,
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* If specified, the property adds jumping motion to the entity.
|
|
94
|
+
*
|
|
95
|
+
* @property jump
|
|
96
|
+
* @type number|Array|Vector
|
|
97
|
+
* @default: 0
|
|
98
|
+
*/
|
|
99
|
+
jump: 0,
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* If specified, the property adds velocity to the entity.
|
|
103
|
+
*
|
|
104
|
+
* @property speed
|
|
105
|
+
* @type number|Array|Vector
|
|
106
|
+
* @default: 0
|
|
107
|
+
*/
|
|
108
|
+
speed: 0,
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* This property determines how quickly velocity is dampened when the entity is not in a "grounded" state. This should be a value between 1 (no motion) and 0 (no drag).
|
|
112
|
+
*
|
|
113
|
+
* @property drag
|
|
114
|
+
* @type number
|
|
115
|
+
* @default 0.01
|
|
116
|
+
*/
|
|
117
|
+
drag: 0.01,
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* This property determines how quickly velocity is dampened when the entity is in a "grounded" state. This should be a value between 1 (no motion) and 0 (no friction).
|
|
121
|
+
*
|
|
122
|
+
* @property friction
|
|
123
|
+
* @type number
|
|
124
|
+
* @default 0.06
|
|
125
|
+
*/
|
|
126
|
+
friction: 0.06,
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* This property determines the maximum amount of velocity this entity can maintain. This can be a number or an object describing maximum velocity in a particular direction. For example:
|
|
130
|
+
*
|
|
131
|
+
* {
|
|
132
|
+
* "up": 8,
|
|
133
|
+
* "right": 12,
|
|
134
|
+
* "down": 0.4,
|
|
135
|
+
* "left": 12
|
|
136
|
+
* }
|
|
137
|
+
*
|
|
138
|
+
* @property maxMagnitude
|
|
139
|
+
* @type number|Object
|
|
140
|
+
* @default Infinity
|
|
141
|
+
*/
|
|
142
|
+
maxMagnitude: Infinity,
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* This property determines the rate of change to new maximum amount of velocities.
|
|
146
|
+
*
|
|
147
|
+
* @property maxMagnitudeDelta
|
|
148
|
+
* @type number
|
|
149
|
+
* @default 0
|
|
150
|
+
*/
|
|
151
|
+
maxMagnitudeDelta: 0,
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* This property determines whether orientation changes should apply external velocities from pre-change momentum.
|
|
155
|
+
*
|
|
156
|
+
* @property reorientVelocities
|
|
157
|
+
* @type Boolean
|
|
158
|
+
* @default true
|
|
159
|
+
*/
|
|
160
|
+
reorientVelocities: true
|
|
161
|
+
},
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* This component handles entity motion via velocity and acceleration changes. This is useful for directional movement, gravity, bounce-back collision reactions, jumping, etc.
|
|
165
|
+
*
|
|
166
|
+
* @memberof platypus.components
|
|
167
|
+
* @uses platypus.Component
|
|
168
|
+
* @constructs
|
|
169
|
+
* @listens platypus.Entity#component-added
|
|
170
|
+
* @listens platypus.Entity#component-removed
|
|
171
|
+
* @listens platypus.Entity#handle-movement
|
|
172
|
+
* @listens platypus.Entity#handle-post-collision-logic
|
|
173
|
+
* @listens platypus.Entity#hit-solid
|
|
174
|
+
* @listens platypus.Entity#load
|
|
175
|
+
* @listens platypus.Entity#pause-movment
|
|
176
|
+
* @listens platypus.Entity#orientation-updated
|
|
177
|
+
* @listens platypus.Entity#set-mover
|
|
178
|
+
* @listens platypus.Entity#unpause-movment
|
|
179
|
+
*/
|
|
180
|
+
initialize: function () {
|
|
181
|
+
const
|
|
182
|
+
max = this.maxMagnitude,
|
|
183
|
+
{state} = this;
|
|
184
|
+
let maxMagnitude = Infinity;
|
|
185
|
+
|
|
186
|
+
Vector.assign(this.owner, 'position', 'x', 'y', 'z');
|
|
187
|
+
Vector.assign(this.owner, 'velocity', 'dx', 'dy', 'dz');
|
|
188
|
+
|
|
189
|
+
this.position = this.owner.position;
|
|
190
|
+
this.velocity = this.owner.velocity;
|
|
191
|
+
this.lastVelocity = Vector.setUp(this.velocity);
|
|
192
|
+
this.collision = null;
|
|
193
|
+
|
|
194
|
+
this.pause = false;
|
|
195
|
+
|
|
196
|
+
// Copy movers so we're not re-using mover definitions
|
|
197
|
+
this.moversCopy = this.movers;
|
|
198
|
+
this.movers = arrayCache.setUp();
|
|
199
|
+
|
|
200
|
+
this.velocityChanges = arrayCache.setUp();
|
|
201
|
+
this.velocityDirections = arrayCache.setUp();
|
|
202
|
+
|
|
203
|
+
this.ground = Vector.setUp(this.ground);
|
|
204
|
+
|
|
205
|
+
this.state = state;
|
|
206
|
+
state.set('grounded', false);
|
|
207
|
+
|
|
208
|
+
Object.defineProperty(this.owner, "maxMagnitude", {
|
|
209
|
+
get: function () {
|
|
210
|
+
return maxMagnitude;
|
|
211
|
+
},
|
|
212
|
+
set: function (max) {
|
|
213
|
+
if (typeof max === 'number') {
|
|
214
|
+
this.clamp = clampNumber;
|
|
215
|
+
maxMagnitude = max;
|
|
216
|
+
if (!this.maxMagnitudeDelta) {
|
|
217
|
+
this.maxMagnitudeInterim = max;
|
|
218
|
+
}
|
|
219
|
+
} else {
|
|
220
|
+
this.clamp = clampObject;
|
|
221
|
+
if (typeof maxMagnitude === 'number') {
|
|
222
|
+
maxMagnitude = {
|
|
223
|
+
up: maxMagnitude,
|
|
224
|
+
right: maxMagnitude,
|
|
225
|
+
down: maxMagnitude,
|
|
226
|
+
left: maxMagnitude
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
if (typeof max.up === 'number') {
|
|
230
|
+
maxMagnitude.up = max.up;
|
|
231
|
+
}
|
|
232
|
+
if (typeof max.right === 'number') {
|
|
233
|
+
maxMagnitude.right = max.right;
|
|
234
|
+
}
|
|
235
|
+
if (typeof max.down === 'number') {
|
|
236
|
+
maxMagnitude.down = max.down;
|
|
237
|
+
}
|
|
238
|
+
if (typeof max.left === 'number') {
|
|
239
|
+
maxMagnitude.left = max.left;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
if (typeof this.maxMagnitudeInterim === 'number') {
|
|
243
|
+
if (this.maxMagnitudeDelta) {
|
|
244
|
+
this.maxMagnitudeInterim = {
|
|
245
|
+
up: this.maxMagnitudeInterim,
|
|
246
|
+
right: this.maxMagnitudeInterim,
|
|
247
|
+
down: this.maxMagnitudeInterim,
|
|
248
|
+
left: this.maxMagnitudeInterim
|
|
249
|
+
};
|
|
250
|
+
} else {
|
|
251
|
+
this.maxMagnitudeInterim = {
|
|
252
|
+
up: maxMagnitude.up,
|
|
253
|
+
right: maxMagnitude.right,
|
|
254
|
+
down: maxMagnitude.down,
|
|
255
|
+
left: maxMagnitude.left
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
} else if (!this.maxMagnitudeDelta) {
|
|
259
|
+
this.maxMagnitudeInterim.up = maxMagnitude.up;
|
|
260
|
+
this.maxMagnitudeInterim.right = maxMagnitude.right;
|
|
261
|
+
this.maxMagnitudeInterim.down = maxMagnitude.down;
|
|
262
|
+
this.maxMagnitudeInterim.left = maxMagnitude.left;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}.bind(this)
|
|
266
|
+
});
|
|
267
|
+
this.maxMagnitudeInterim = 0;
|
|
268
|
+
this.maxMagnitude = max;
|
|
269
|
+
},
|
|
270
|
+
|
|
271
|
+
events: {
|
|
272
|
+
"component-added": function (component) {
|
|
273
|
+
if (component.type === 'Motion') {
|
|
274
|
+
this.movers.push(component);
|
|
275
|
+
}
|
|
276
|
+
},
|
|
277
|
+
|
|
278
|
+
"component-removed": function (component) {
|
|
279
|
+
if (component.type === 'Motion') {
|
|
280
|
+
let i = this.movers.indexOf(component);
|
|
281
|
+
if (i >= 0) {
|
|
282
|
+
greenSplice(this.movers, i);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
},
|
|
286
|
+
|
|
287
|
+
"load": function () {
|
|
288
|
+
const
|
|
289
|
+
movs = this.moversCopy;
|
|
290
|
+
|
|
291
|
+
delete this.moversCopy;
|
|
292
|
+
for (let i = 0; i < movs.length; i++) {
|
|
293
|
+
this.addMover(movs[i]);
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
this.externalForces = this.addMover({
|
|
297
|
+
velocity: [0, 0, 0],
|
|
298
|
+
orient: false
|
|
299
|
+
}).velocity;
|
|
300
|
+
|
|
301
|
+
// Set up speed property if supplied.
|
|
302
|
+
if (this.speed) {
|
|
303
|
+
if (!isNaN(this.speed)) {
|
|
304
|
+
this.speed = [this.speed, 0, 0];
|
|
305
|
+
}
|
|
306
|
+
this.speed = this.addMover({
|
|
307
|
+
velocity: this.speed,
|
|
308
|
+
controlState: "moving"
|
|
309
|
+
}).velocity;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
// Set up gravity property if supplied.
|
|
313
|
+
if (this.gravity) {
|
|
314
|
+
if (!isNaN(this.gravity)) {
|
|
315
|
+
this.gravity = [0, this.gravity, 0];
|
|
316
|
+
}
|
|
317
|
+
this.gravity = this.addMover({
|
|
318
|
+
acceleration: this.gravity,
|
|
319
|
+
orient: false,
|
|
320
|
+
aliases: {
|
|
321
|
+
"gravitate": "control-acceleration"
|
|
322
|
+
}
|
|
323
|
+
}).acceleration;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
// Set up jump property if supplied.
|
|
327
|
+
if (this.jump) {
|
|
328
|
+
if (!isNaN(this.jump)) {
|
|
329
|
+
this.jump = [0, this.jump, 0];
|
|
330
|
+
}
|
|
331
|
+
this.jump = this.addMover({
|
|
332
|
+
velocity: this.jump,
|
|
333
|
+
instant: true,
|
|
334
|
+
controlState: "grounded",
|
|
335
|
+
state: "jumping",
|
|
336
|
+
instantSuccess: "just-jumped",
|
|
337
|
+
instantDecay: 0.2,
|
|
338
|
+
aliases: {
|
|
339
|
+
"jump": "instant-motion"
|
|
340
|
+
}
|
|
341
|
+
}).instant;
|
|
342
|
+
}
|
|
343
|
+
},
|
|
344
|
+
|
|
345
|
+
"handle-movement": function ({delta}) {
|
|
346
|
+
const
|
|
347
|
+
{movers, position, state, velocity} = this,
|
|
348
|
+
vect = Vector.setUp();
|
|
349
|
+
let i = movers.length;
|
|
350
|
+
|
|
351
|
+
if (state.get('paused') || this.paused) {
|
|
352
|
+
return;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
if (!velocity.equals(this.lastVelocity, 2)) {
|
|
356
|
+
this.externalForces.addVector(velocity).subtractVector(this.lastVelocity);
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
velocity.setXYZ(0, 0, 0);
|
|
360
|
+
|
|
361
|
+
while (i--) {
|
|
362
|
+
const
|
|
363
|
+
m = movers[i].update(delta);
|
|
364
|
+
|
|
365
|
+
if (m) {
|
|
366
|
+
if (this.grounded) { // put this in here to match earlier behavior
|
|
367
|
+
if (movers[i].friction !== -1) {
|
|
368
|
+
m.multiply(1 - movers[i].friction);
|
|
369
|
+
} else {
|
|
370
|
+
m.multiply(1 - this.friction);
|
|
371
|
+
}
|
|
372
|
+
} else if (movers[i].drag !== -1) {
|
|
373
|
+
m.multiply(1 - movers[i].drag);
|
|
374
|
+
} else {
|
|
375
|
+
m.multiply(1 - this.drag);
|
|
376
|
+
}
|
|
377
|
+
velocity.add(m);
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
this.clamp(velocity, delta);
|
|
382
|
+
this.lastVelocity.setVector(velocity);
|
|
383
|
+
|
|
384
|
+
vect.set(velocity).multiply(delta);
|
|
385
|
+
position.add(vect);
|
|
386
|
+
vect.recycle();
|
|
387
|
+
|
|
388
|
+
state.set('grounded', this.grounded);
|
|
389
|
+
|
|
390
|
+
this.grounded = false;
|
|
391
|
+
},
|
|
392
|
+
|
|
393
|
+
/**
|
|
394
|
+
* On receiving this message, this component stops all velocities along the axis of the collision direction and sets "grounded" to `true` if colliding with the ground.
|
|
395
|
+
*
|
|
396
|
+
* @event platypus.Entity#hit-solid
|
|
397
|
+
* @param collisionInfo {Object}
|
|
398
|
+
* @param collisionInfo.direction {platypus.Vector} The direction of collision from the entity's position.
|
|
399
|
+
*/
|
|
400
|
+
"hit-solid": function ({direction, entity}) {
|
|
401
|
+
const
|
|
402
|
+
entityV = entity?.velocity,
|
|
403
|
+
vc = this.velocityChanges,
|
|
404
|
+
vd = this.velocityDirections,
|
|
405
|
+
i = vc.length;
|
|
406
|
+
let add = true,
|
|
407
|
+
s = 0;
|
|
408
|
+
|
|
409
|
+
if (direction.dot(this.ground) > 0) {
|
|
410
|
+
this.grounded = true;
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
s = this.velocity.scalarProjection(direction);
|
|
414
|
+
if (s > 0) {
|
|
415
|
+
if (entityV) {
|
|
416
|
+
const
|
|
417
|
+
e = Math.max(entityV.scalarProjection(direction), 0);
|
|
418
|
+
|
|
419
|
+
if (e < s) {
|
|
420
|
+
s = e;
|
|
421
|
+
} else {
|
|
422
|
+
s = 0;
|
|
423
|
+
}
|
|
424
|
+
} else {
|
|
425
|
+
s = 0;
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
while (i--) {
|
|
429
|
+
if ((s < vc[i]) && (vd[i].dot(direction) > 0)) {
|
|
430
|
+
vc[i] = s;
|
|
431
|
+
vd[i].setVector(direction);
|
|
432
|
+
add = false;
|
|
433
|
+
break;
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
if (add) {
|
|
438
|
+
vc.push(s);
|
|
439
|
+
vd.push(Vector.setUp(direction));
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
},
|
|
443
|
+
|
|
444
|
+
"handle-post-collision-logic": function () {
|
|
445
|
+
const
|
|
446
|
+
vc = this.velocityChanges,
|
|
447
|
+
i = vc.length;
|
|
448
|
+
|
|
449
|
+
if (i) {
|
|
450
|
+
const
|
|
451
|
+
ms = this.movers,
|
|
452
|
+
vd = this.velocityDirections,
|
|
453
|
+
v = tempVector,
|
|
454
|
+
soc = ms.filter(({stopOnCollision}) => stopOnCollision);
|
|
455
|
+
|
|
456
|
+
while (i--) {
|
|
457
|
+
let j = soc.length;
|
|
458
|
+
const
|
|
459
|
+
direction = vd[i],
|
|
460
|
+
s = vc[i],
|
|
461
|
+
sdi = s / j;
|
|
462
|
+
|
|
463
|
+
while (j--) {
|
|
464
|
+
const
|
|
465
|
+
m = soc[j];
|
|
466
|
+
|
|
467
|
+
v.setVector(direction).normalize().multiply(sdi - m.velocity.scalarProjection(direction));
|
|
468
|
+
m.velocity.add(v);
|
|
469
|
+
}
|
|
470
|
+
direction.recycle();
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
vc.length = 0;
|
|
474
|
+
vd.length = 0;
|
|
475
|
+
arrayCache.recycle(soc);
|
|
476
|
+
}
|
|
477
|
+
},
|
|
478
|
+
|
|
479
|
+
/**
|
|
480
|
+
* Update mover properties.
|
|
481
|
+
*
|
|
482
|
+
* @event platypus.Entity#set-mover
|
|
483
|
+
* @param mover {Object}
|
|
484
|
+
* @param [mover.maxMagnitude] {Number|Object} New maximums for magnitude.
|
|
485
|
+
* @param [mover.magnitude] {Number} Delta for the change in maximums.
|
|
486
|
+
*/
|
|
487
|
+
"set-mover": function (mover) {
|
|
488
|
+
if (typeof mover.maxMagnitudeDelta === 'number') {
|
|
489
|
+
this.maxMagnitudeDelta = mover.maxMagnitudeDelta;
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
if (mover.maxMagnitude) {
|
|
493
|
+
this.maxMagnitude = mover.maxMagnitude;
|
|
494
|
+
}
|
|
495
|
+
},
|
|
496
|
+
|
|
497
|
+
/**
|
|
498
|
+
* Stops all movement on the Entity.
|
|
499
|
+
*
|
|
500
|
+
* @event platypus.Entity#pause-movment
|
|
501
|
+
*/
|
|
502
|
+
"pause-movement": function () {
|
|
503
|
+
this.paused = true;
|
|
504
|
+
},
|
|
505
|
+
|
|
506
|
+
/**
|
|
507
|
+
* Unpauses all movement on the Entity.
|
|
508
|
+
*
|
|
509
|
+
* @event platypus.Entity#unpause-movment
|
|
510
|
+
*/
|
|
511
|
+
"unpause-movement": function () {
|
|
512
|
+
this.paused = false;
|
|
513
|
+
},
|
|
514
|
+
|
|
515
|
+
"orientation-updated": function (matrix) {
|
|
516
|
+
if (!this.reorientVelocities) {
|
|
517
|
+
this.lastVelocity.multiply(matrix);
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
},
|
|
521
|
+
|
|
522
|
+
methods: {
|
|
523
|
+
destroy: function () {
|
|
524
|
+
const
|
|
525
|
+
max = this.maxMagnitude;
|
|
526
|
+
|
|
527
|
+
for (let i = this.movers.length - 1; i >= 0; i--) {
|
|
528
|
+
this.removeMover(this.movers[i]);
|
|
529
|
+
}
|
|
530
|
+
arrayCache.recycle(this.movers);
|
|
531
|
+
|
|
532
|
+
this.ground.recycle();
|
|
533
|
+
this.lastVelocity.recycle();
|
|
534
|
+
arrayCache.recycle(this.velocityChanges);
|
|
535
|
+
arrayCache.recycle(this.velocityDirections);
|
|
536
|
+
|
|
537
|
+
delete this.owner.maxMagnitude; // remove property handlers
|
|
538
|
+
this.owner.maxMagnitude = max;
|
|
539
|
+
|
|
540
|
+
this.state = null;
|
|
541
|
+
}
|
|
542
|
+
},
|
|
543
|
+
|
|
544
|
+
publicMethods: {
|
|
545
|
+
/**
|
|
546
|
+
* This method adds a mover to the entity in the form of a ["Motion"]("Motion"%20Component.html) component definition.
|
|
547
|
+
*
|
|
548
|
+
* @method platypus.components.Mover#addMover
|
|
549
|
+
* @param mover {Object} For motion definition properties, see the ["Motion"]("Motion"%20Component.html) component.
|
|
550
|
+
* @return motion {Motion}
|
|
551
|
+
*/
|
|
552
|
+
addMover: function (mover) {
|
|
553
|
+
return this.owner.addComponent(new platypus.components.Motion(this.owner, mover));
|
|
554
|
+
},
|
|
555
|
+
|
|
556
|
+
/**
|
|
557
|
+
* This method removes a mover from the entity.
|
|
558
|
+
*
|
|
559
|
+
* @method platypus.components.Mover#removeMover
|
|
560
|
+
* @param motion {Motion}
|
|
561
|
+
*/
|
|
562
|
+
removeMover: function (m) {
|
|
563
|
+
this.owner.removeComponent(m);
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
});
|