@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.
Files changed (134) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/README.md +4 -2
  3. package/lib/platypus.js +1 -1
  4. package/package.json +7 -2
  5. package/src/AABB.js +685 -0
  6. package/src/ActionState.js +121 -0
  7. package/src/AssetManager.js +206 -0
  8. package/src/CollisionData.js +96 -0
  9. package/src/CollisionDataContainer.js +127 -0
  10. package/src/CollisionShape.js +315 -0
  11. package/src/Component.js +231 -0
  12. package/src/Data.js +64 -0
  13. package/src/DataMap.js +204 -0
  14. package/src/Entity.js +404 -0
  15. package/src/EntityLinker.js +113 -0
  16. package/src/EventHandler.js +115 -0
  17. package/src/EventHandlerList.js +251 -0
  18. package/src/Game.js +840 -0
  19. package/src/Gamepad.js +175 -0
  20. package/src/ID3CaptionPlayer.js +61 -0
  21. package/src/Messenger.js +365 -0
  22. package/src/PIXIAnimation.js +622 -0
  23. package/src/RandomSet.js +140 -0
  24. package/src/SFXPlayer.js +120 -0
  25. package/src/StateMap.js +252 -0
  26. package/src/Storage.js +152 -0
  27. package/src/TickerClient.js +48 -0
  28. package/src/TickerServer.js +23 -0
  29. package/src/TimeEvent.js +50 -0
  30. package/src/TimeEventList.js +100 -0
  31. package/src/VOPlayer.js +684 -0
  32. package/src/Vector.js +702 -0
  33. package/src/components/AIChaser.js +161 -0
  34. package/src/components/AIPacer.js +107 -0
  35. package/src/components/AudioMusic.js +151 -0
  36. package/src/components/AudioSFX.js +673 -0
  37. package/src/components/AudioVO.js +301 -0
  38. package/src/components/CollisionBasic.js +826 -0
  39. package/src/components/CollisionFilter.js +74 -0
  40. package/src/components/CollisionGroup.js +448 -0
  41. package/src/components/CollisionTiles.js +608 -0
  42. package/src/components/ComponentSwitcher.js +173 -0
  43. package/src/components/ControllerInput.js +65 -0
  44. package/src/components/Counter.js +165 -0
  45. package/src/components/EntityCamera.js +215 -0
  46. package/src/components/EntityContainer.js +549 -0
  47. package/src/components/EntityController.js +541 -0
  48. package/src/components/HandlerCamera.js +1052 -0
  49. package/src/components/HandlerCollision.js +1318 -0
  50. package/src/components/HandlerController.js +291 -0
  51. package/src/components/HandlerLogic.js +394 -0
  52. package/src/components/HandlerRender.js +217 -0
  53. package/src/components/Interactive.js +502 -0
  54. package/src/components/LevelBuilder.js +524 -0
  55. package/src/components/LogicAngularMovement.js +154 -0
  56. package/src/components/LogicAttachment.js +265 -0
  57. package/src/components/LogicButton.js +466 -0
  58. package/src/components/LogicCarrier.js +39 -0
  59. package/src/components/LogicDestroyMe.js +58 -0
  60. package/src/components/LogicDirectionalMovement.js +325 -0
  61. package/src/components/LogicDragDrop.js +371 -0
  62. package/src/components/LogicImpactLaunch.js +144 -0
  63. package/src/components/LogicPacingPlatform.js +64 -0
  64. package/src/components/LogicPortable.js +112 -0
  65. package/src/components/LogicPortal.js +115 -0
  66. package/src/components/LogicPushable.js +98 -0
  67. package/src/components/LogicRebounder.js +136 -0
  68. package/src/components/LogicRegionSpawner.js +139 -0
  69. package/src/components/LogicRotationalMovement.js +205 -0
  70. package/src/components/LogicSpawner.js +159 -0
  71. package/src/components/LogicStateMachine.js +382 -0
  72. package/src/components/LogicSwitch.js +77 -0
  73. package/src/components/LogicTeleportee.js +68 -0
  74. package/src/components/LogicTeleporter.js +93 -0
  75. package/src/components/LogicTimer.js +178 -0
  76. package/src/components/LogicWindUpRacer.js +179 -0
  77. package/src/components/Motion.js +371 -0
  78. package/src/components/Mover.js +566 -0
  79. package/src/components/Node.js +289 -0
  80. package/src/components/NodeMap.js +295 -0
  81. package/src/components/NodeResident.js +636 -0
  82. package/src/components/Orientation.js +697 -0
  83. package/src/components/RandomEvents.js +73 -0
  84. package/src/components/RelativePosition.js +204 -0
  85. package/src/components/RelayFamily.js +106 -0
  86. package/src/components/RelayGame.js +53 -0
  87. package/src/components/RelayLinker.js +94 -0
  88. package/src/components/RelayParent.js +57 -0
  89. package/src/components/RelaySelf.js +55 -0
  90. package/src/components/Render.js +178 -0
  91. package/src/components/RenderAnimator.js +275 -0
  92. package/src/components/RenderContainer.js +646 -0
  93. package/src/components/RenderDebug.js +319 -0
  94. package/src/components/RenderDestroyMe.js +59 -0
  95. package/src/components/RenderLottie.js +149 -0
  96. package/src/components/RenderProgress.js +120 -0
  97. package/src/components/RenderSpine.js +833 -0
  98. package/src/components/RenderSprite.js +527 -0
  99. package/src/components/RenderText.js +147 -0
  100. package/src/components/RenderTiles.js +1391 -0
  101. package/src/components/SceneChanger.js +128 -0
  102. package/src/components/TiledLoader.js +1451 -0
  103. package/src/components/Timeline.js +314 -0
  104. package/src/components/Tutorial.js +267 -0
  105. package/src/components/Tween.js +296 -0
  106. package/src/components/VoiceOver.js +373 -0
  107. package/src/components/XHR.js +129 -0
  108. package/src/components/index.js +79 -0
  109. package/src/factory.js +305 -0
  110. package/src/index.js +159 -0
  111. package/src/mixins/PIXI.Graphics.js +41 -0
  112. package/src/platypus.css +68 -0
  113. package/src/sayHello.js +50 -0
  114. package/src/shapes/Capsule.js +74 -0
  115. package/src/shapes/Circle.js +43 -0
  116. package/src/shapes/Ellipse.js +117 -0
  117. package/src/shapes/Point.js +191 -0
  118. package/src/shapes/Polygon.js +112 -0
  119. package/src/shapes/Polyline.js +97 -0
  120. package/src/shapes/Rectangle.js +78 -0
  121. package/src/shapes/RoundedRectangle.js +33 -0
  122. package/src/shapes/Segment.js +346 -0
  123. package/src/shapes/adjustedXY.js +19 -0
  124. package/src/shapes/castFromBox2D.js +92 -0
  125. package/src/shapes/castFromObject.js +53 -0
  126. package/src/shapes/castFromPixiGraphics.js +6 -0
  127. package/src/shapes/castFromPixiShape.js +89 -0
  128. package/src/shapes/castToBox2D.js +190 -0
  129. package/src/shapes/castToPixiGraphics.js +100 -0
  130. package/src/shapes/castToPixiShape.js +61 -0
  131. package/src/shapes/checkPointsMap.js +313 -0
  132. package/src/shapes/index.js +35 -0
  133. package/src/utils/array.js +73 -0
  134. package/src/utils/string.js +39 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@makefully/platypus",
3
- "version": "4.1.4",
3
+ "version": "4.1.6",
4
4
  "description": "2D tile-based HTML5 game engine with a component-based entity model",
5
5
  "license": "MIT",
6
6
  "contributors": [
@@ -8,13 +8,18 @@
8
8
  "Todd Lewis <todd.lewis@gopherwoodstudios.com> (https://github.com/GopherwoodTodd)"
9
9
  ],
10
10
  "main": "lib/platypus.js",
11
+ "module": "src/index.js",
11
12
  "exports": {
12
- ".": "./lib/platypus.js",
13
+ ".": {
14
+ "import": "./src/index.js",
15
+ "require": "./lib/platypus.js"
16
+ },
13
17
  "./platypus.css": "./lib/platypus.css",
14
18
  "./package.json": "./package.json"
15
19
  },
16
20
  "files": [
17
21
  "lib",
22
+ "src",
18
23
  "README.md",
19
24
  "CHANGELOG.md",
20
25
  "CONTRIBUTORS.md",
package/src/AABB.js ADDED
@@ -0,0 +1,685 @@
1
+ import recycle from 'recycle';
2
+
3
+ const
4
+ /**
5
+ * Defines an axis-aligned bounding box (AABB) used for collision checks,
6
+ * containment tests, and spatial calculations.
7
+ *
8
+ * The AABB stores both center-based coordinates (`x`, `y`, `width`,
9
+ * `height`) and edge-based coordinates (`left`, `top`, `right`, `bottom`)
10
+ * for fast access during collision operations.
11
+ *
12
+ * Position values (`x`, `y`) always represent the center of the rectangle.
13
+ *
14
+ * Mutation Semantics:
15
+ * - `move*` methods translate the AABB.
16
+ * - `setWidth` and `setHeight` resize around the center.
17
+ * - `setLeft`, `setRight`, `setTop`, and `setBottom` resize while
18
+ * preserving the opposite edge.
19
+ * - `setBounds` reconstructs the rectangle from explicit bounds.
20
+ *
21
+ * AABBs are mutable and recyclable. Instances should not be retained after
22
+ * calling `recycle`.
23
+ *
24
+ * @memberof platypus
25
+ * @class AABB
26
+ * @param x {number|platypus.AABB} The x position of the AABB center, or an
27
+ * existing AABB to copy.
28
+ * @param y {number} The y position of the AABB center.
29
+ * @param width {number} The width of the AABB.
30
+ * @param height {number} The height of the AABB.
31
+ * @return {platypus.AABB} Returns the instantiated AABB.
32
+ */
33
+ AABB = function (x, y, width, height) {
34
+ if (x instanceof AABB) {
35
+ this.set(x);
36
+ } else {
37
+ this.empty = true;
38
+ this.setAll(x, y, width, height);
39
+ }
40
+ },
41
+ proto = AABB.prototype;
42
+
43
+ /**
44
+ * Whether the AABB encloses a valid area.
45
+ *
46
+ * @property empty
47
+ * @type boolean
48
+ */
49
+
50
+ /**
51
+ * The x position of the AABB center.
52
+ *
53
+ * @property x
54
+ * @type number
55
+ */
56
+
57
+ /**
58
+ * The y position of the AABB center.
59
+ *
60
+ * @property y
61
+ * @type number
62
+ */
63
+
64
+ /**
65
+ * The width of the AABB.
66
+ *
67
+ * @property width
68
+ * @type number
69
+ */
70
+
71
+ /**
72
+ * The height of the AABB.
73
+ *
74
+ * @property height
75
+ * @type number
76
+ */
77
+
78
+ /**
79
+ * Half the width of the AABB.
80
+ *
81
+ * @property halfWidth
82
+ * @type number
83
+ */
84
+
85
+ /**
86
+ * Half the height of the AABB.
87
+ *
88
+ * @property halfHeight
89
+ * @type number
90
+ */
91
+
92
+ /**
93
+ * The left edge of the AABB.
94
+ *
95
+ * @property left
96
+ * @type number
97
+ */
98
+
99
+ /**
100
+ * The right edge of the AABB.
101
+ *
102
+ * @property right
103
+ * @type number
104
+ */
105
+
106
+ /**
107
+ * The top edge of the AABB.
108
+ *
109
+ * @property top
110
+ * @type number
111
+ */
112
+
113
+ /**
114
+ * The bottom edge of the AABB.
115
+ *
116
+ * @property bottom
117
+ * @type number
118
+ */
119
+
120
+ /**
121
+ * Sets all of the properties of the AABB.
122
+ *
123
+ * @method platypus.AABB#setAll
124
+ * @param x {number} The x position of the AABB center.
125
+ * @param y {number} The y position of the AABB center.
126
+ * @param width {number} The width of the AABB.
127
+ * @param height {number} The height of the AABB.
128
+ * @chainable
129
+ */
130
+ proto.setAll = function (x, y, width, height) {
131
+ this.empty = false;
132
+ this.x = x;
133
+ this.y = y;
134
+ this.resize(width, height);
135
+
136
+ return this;
137
+ };
138
+
139
+ /**
140
+ * Sets all four bounds of the AABB directly.
141
+ *
142
+ * Unlike edge mutators such as `setLeft` or `setTop`, this method completely
143
+ * reconstructs the rectangle from authoritative edge values.
144
+ *
145
+ * @method platypus.AABB#setBounds
146
+ * @param left {number} The left edge.
147
+ * @param top {number} The top edge.
148
+ * @param right {number} The right edge.
149
+ * @param bottom {number} The bottom edge.
150
+ * @chainable
151
+ */
152
+ proto.setBounds = function (left, top, right, bottom) {
153
+ this.empty = false;
154
+
155
+ this.left = left;
156
+ this.top = top;
157
+ this.right = right;
158
+ this.bottom = bottom;
159
+
160
+ this.width = right - left;
161
+ this.height = bottom - top;
162
+
163
+ this.halfWidth = this.width / 2;
164
+ this.halfHeight = this.height / 2;
165
+
166
+ this.x = left + this.halfWidth;
167
+ this.y = top + this.halfHeight;
168
+
169
+ return this;
170
+ };
171
+
172
+ /**
173
+ * Copies values from another AABB.
174
+ *
175
+ * @method platypus.AABB#set
176
+ * @param aabb {platypus.AABB} The AABB to copy values from.
177
+ * @chainable
178
+ */
179
+ proto.set = function (aabb) {
180
+ this.empty = aabb.empty;
181
+
182
+ this.x = aabb.x;
183
+ this.y = aabb.y;
184
+
185
+ this.width = aabb.width;
186
+ this.height = aabb.height;
187
+
188
+ this.halfWidth = aabb.halfWidth;
189
+ this.halfHeight = aabb.halfHeight;
190
+
191
+ this.left = aabb.left;
192
+ this.right = aabb.right;
193
+
194
+ this.top = aabb.top;
195
+ this.bottom = aabb.bottom;
196
+
197
+ return this;
198
+ };
199
+
200
+ /**
201
+ * Returns a string representation of the AABB.
202
+ *
203
+ * @method platypus.AABB#toString
204
+ * @return {string}
205
+ */
206
+ proto.toString = function () {
207
+ return '[AABB: ' + this.width + 'x' + this.height + ' (' + this.x + ', ' + this.y + ')]';
208
+ };
209
+
210
+ /**
211
+ * Marks the AABB as empty so it may be reused or recycled.
212
+ *
213
+ * Existing positional values are retained internally for performance reasons
214
+ * and should not be considered valid while `empty === true`.
215
+ *
216
+ * @method platypus.AABB#reset
217
+ * @chainable
218
+ */
219
+ proto.reset = function () {
220
+ this.empty = true;
221
+
222
+ return this;
223
+ };
224
+
225
+ /**
226
+ * Resizes the AABB around its center position.
227
+ *
228
+ * @method platypus.AABB#resize
229
+ * @param width {number} The new width.
230
+ * @param height {number} The new height.
231
+ * @chainable
232
+ */
233
+ proto.resize = function (width = 0, height = 0) {
234
+ this.setWidth(width);
235
+ this.setHeight(height);
236
+
237
+ return this;
238
+ };
239
+
240
+ /**
241
+ * Expands this AABB so that it encloses both its current area and the
242
+ * provided AABB.
243
+ *
244
+ * @method platypus.AABB#include
245
+ * @param aabb {platypus.AABB} The AABB to include.
246
+ * @chainable
247
+ */
248
+ proto.include = function (aabb) {
249
+ if (this.empty) {
250
+ this.set(aabb);
251
+ } else {
252
+ if (this.left > aabb.left) {
253
+ this.setLeft(aabb.left);
254
+ }
255
+
256
+ if (this.right < aabb.right) {
257
+ this.setRight(aabb.right);
258
+ }
259
+
260
+ if (this.top > aabb.top) {
261
+ this.setTop(aabb.top);
262
+ }
263
+
264
+ if (this.bottom < aabb.bottom) {
265
+ this.setBottom(aabb.bottom);
266
+ }
267
+ }
268
+
269
+ return this;
270
+ };
271
+
272
+ /**
273
+ * Expands this AABB so that it encloses the provided point or points.
274
+ *
275
+ * @method platypus.AABB#includeVector
276
+ * @param {...platypus.Vector} vectors The vectors to include.
277
+ * @chainable
278
+ */
279
+ proto.includeVector = function (...args) {
280
+ args.forEach(({x, y}) => {
281
+ if (this.empty) {
282
+ this.empty = false;
283
+
284
+ this.x = x;
285
+ this.y = y;
286
+
287
+ this.resize();
288
+ } else {
289
+ if (this.left > x) {
290
+ this.setLeft(x);
291
+ }
292
+
293
+ if (this.right < x) {
294
+ this.setRight(x);
295
+ }
296
+
297
+ if (this.top > y) {
298
+ this.setTop(y);
299
+ }
300
+
301
+ if (this.bottom < y) {
302
+ this.setBottom(y);
303
+ }
304
+ }
305
+ });
306
+
307
+ return this;
308
+ };
309
+
310
+ /**
311
+ * Moves the AABB to the specified location.
312
+ *
313
+ * @method platypus.AABB#move
314
+ * @param x {number} The new x position.
315
+ * @param y {number} The new y position.
316
+ * @chainable
317
+ */
318
+ proto.move = function (x, y) {
319
+ this.moveX(x);
320
+ this.moveY(y);
321
+
322
+ return this;
323
+ };
324
+
325
+ /**
326
+ * Moves the AABB horizontally.
327
+ *
328
+ * @method platypus.AABB#moveX
329
+ * @param x {number} The new x position.
330
+ * @chainable
331
+ */
332
+ proto.moveX = function (x) {
333
+ this.x = x;
334
+
335
+ this.left = x - this.halfWidth;
336
+ this.right = x + this.halfWidth;
337
+
338
+ return this;
339
+ };
340
+
341
+ /**
342
+ * Moves the AABB vertically.
343
+ *
344
+ * @method platypus.AABB#moveY
345
+ * @param y {number} The new y position.
346
+ * @chainable
347
+ */
348
+ proto.moveY = function (y) {
349
+ this.y = y;
350
+
351
+ this.top = y - this.halfHeight;
352
+ this.bottom = y + this.halfHeight;
353
+
354
+ return this;
355
+ };
356
+
357
+ /**
358
+ * Moves the AABB horizontally by a delta value.
359
+ *
360
+ * @method platypus.AABB#moveXBy
361
+ * @param deltaX {number} The change in x position.
362
+ * @chainable
363
+ */
364
+ proto.moveXBy = function (deltaX) {
365
+ return this.moveX(this.x + deltaX);
366
+ };
367
+
368
+ /**
369
+ * Moves the AABB vertically by a delta value.
370
+ *
371
+ * @method platypus.AABB#moveYBy
372
+ * @param deltaY {number} The change in y position.
373
+ * @chainable
374
+ */
375
+ proto.moveYBy = function (deltaY) {
376
+ return this.moveY(this.y + deltaY);
377
+ };
378
+
379
+ /**
380
+ * Sets the width of the AABB while preserving its center position.
381
+ *
382
+ * @method platypus.AABB#setWidth
383
+ * @param width {number} The new width.
384
+ * @chainable
385
+ */
386
+ proto.setWidth = function (width) {
387
+ const hw = width / 2;
388
+
389
+ this.width = width;
390
+ this.halfWidth = hw;
391
+
392
+ if (typeof this.x === 'number') {
393
+ this.left = this.x - hw;
394
+ this.right = this.x + hw;
395
+ } else {
396
+ this.empty = true;
397
+ }
398
+
399
+ return this;
400
+ };
401
+
402
+ /**
403
+ * Sets the height of the AABB while preserving its center position.
404
+ *
405
+ * @method platypus.AABB#setHeight
406
+ * @param height {number} The new height.
407
+ * @chainable
408
+ */
409
+ proto.setHeight = function (height) {
410
+ const hh = height / 2;
411
+
412
+ this.height = height;
413
+ this.halfHeight = hh;
414
+
415
+ if (typeof this.y === 'number') {
416
+ this.top = this.y - hh;
417
+ this.bottom = this.y + hh;
418
+ } else {
419
+ this.empty = true;
420
+ }
421
+
422
+ return this;
423
+ };
424
+
425
+ /**
426
+ * Sets the left edge of the AABB while preserving the right edge.
427
+ *
428
+ * This operation resizes the AABB horizontally.
429
+ *
430
+ * @method platypus.AABB#setLeft
431
+ * @param left {number} The new left edge.
432
+ * @chainable
433
+ */
434
+ proto.setLeft = function (left) {
435
+ const
436
+ width = this.right - left,
437
+ hw = width / 2;
438
+
439
+ this.left = left;
440
+
441
+ this.width = width;
442
+ this.halfWidth = hw;
443
+
444
+ this.x = left + hw;
445
+
446
+ return this;
447
+ };
448
+
449
+ /**
450
+ * Sets the right edge of the AABB while preserving the left edge.
451
+ *
452
+ * This operation resizes the AABB horizontally.
453
+ *
454
+ * @method platypus.AABB#setRight
455
+ * @param right {number} The new right edge.
456
+ * @chainable
457
+ */
458
+ proto.setRight = function (right) {
459
+ const
460
+ width = right - this.left,
461
+ hw = width / 2;
462
+
463
+ this.right = right;
464
+
465
+ this.width = width;
466
+ this.halfWidth = hw;
467
+
468
+ this.x = this.left + hw;
469
+
470
+ return this;
471
+ };
472
+
473
+ /**
474
+ * Sets the top edge of the AABB while preserving the bottom edge.
475
+ *
476
+ * This operation resizes the AABB vertically.
477
+ *
478
+ * @method platypus.AABB#setTop
479
+ * @param top {number} The new top edge.
480
+ * @chainable
481
+ */
482
+ proto.setTop = function (top) {
483
+ const
484
+ height = this.bottom - top,
485
+ hh = height / 2;
486
+
487
+ this.top = top;
488
+
489
+ this.height = height;
490
+ this.halfHeight = hh;
491
+
492
+ this.y = top + hh;
493
+
494
+ return this;
495
+ };
496
+
497
+ /**
498
+ * Sets the bottom edge of the AABB while preserving the top edge.
499
+ *
500
+ * This operation resizes the AABB vertically.
501
+ *
502
+ * @method platypus.AABB#setBottom
503
+ * @param bottom {number} The new bottom edge.
504
+ * @chainable
505
+ */
506
+ proto.setBottom = function (bottom) {
507
+ const
508
+ height = bottom - this.top,
509
+ hh = height / 2;
510
+
511
+ this.bottom = bottom;
512
+
513
+ this.height = height;
514
+ this.halfHeight = hh;
515
+
516
+ this.y = this.top + hh;
517
+
518
+ return this;
519
+ };
520
+
521
+ /**
522
+ * Returns whether this AABB matches another AABB exactly.
523
+ *
524
+ * @method platypus.AABB#equals
525
+ * @param aabb {platypus.AABB} The AABB to compare against.
526
+ * @return {boolean}
527
+ */
528
+ proto.equals = function (aabb) {
529
+ return !this.empty &&
530
+ !aabb.empty &&
531
+ (this.left === aabb.left) &&
532
+ (this.top === aabb.top) &&
533
+ (this.right === aabb.right) &&
534
+ (this.bottom === aabb.bottom);
535
+ };
536
+
537
+ /**
538
+ * Returns whether this AABB completely contains another AABB.
539
+ *
540
+ * @method platypus.AABB#contains
541
+ * @param aabb {platypus.AABB} The AABB to test.
542
+ * @return {boolean}
543
+ */
544
+ proto.contains = function (aabb) {
545
+ return (aabb.top >= this.top) &&
546
+ (aabb.bottom <= this.bottom) &&
547
+ (aabb.left >= this.left) &&
548
+ (aabb.right <= this.right);
549
+ };
550
+
551
+ /**
552
+ * Returns whether this AABB contains the provided vector.
553
+ *
554
+ * @method platypus.AABB#containsVector
555
+ * @param vector {platypus.Vector} The vector to test.
556
+ * @return {boolean}
557
+ */
558
+ proto.containsVector = function (vector) {
559
+ return this.containsPoint(vector.x, vector.y);
560
+ };
561
+
562
+ /**
563
+ * Returns whether this AABB contains the provided point.
564
+ *
565
+ * Edge-touching counts as containment.
566
+ *
567
+ * @method platypus.AABB#containsPoint
568
+ * @param x {number} The x coordinate.
569
+ * @param y {number} The y coordinate.
570
+ * @return {boolean}
571
+ */
572
+ proto.containsPoint = function (x, y) {
573
+ return (y >= this.top) &&
574
+ (y <= this.bottom) &&
575
+ (x >= this.left) &&
576
+ (x <= this.right);
577
+ };
578
+
579
+ /**
580
+ * Returns whether this AABB overlaps another AABB.
581
+ *
582
+ * Edge-touching does not count as a collision.
583
+ *
584
+ * @method platypus.AABB#collides
585
+ * @param aabb {platypus.AABB} The AABB to test.
586
+ * @return {boolean}
587
+ */
588
+ proto.collides = function (aabb) {
589
+ return (aabb.bottom > this.top) &&
590
+ (aabb.top < this.bottom) &&
591
+ (aabb.right > this.left) &&
592
+ (aabb.left < this.right);
593
+ };
594
+
595
+ /**
596
+ * Returns whether this AABB overlaps the provided point.
597
+ *
598
+ * Edge-touching does not count as collision.
599
+ *
600
+ * @method platypus.AABB#collidesPoint
601
+ * @param x {number} The x coordinate.
602
+ * @param y {number} The y coordinate.
603
+ * @return {boolean}
604
+ */
605
+ proto.collidesPoint = function (x, y) {
606
+ return (y > this.top) &&
607
+ (y < this.bottom) &&
608
+ (x > this.left) &&
609
+ (x < this.right);
610
+ };
611
+
612
+ /**
613
+ * Returns whether this AABB intersects another AABB.
614
+ *
615
+ * Edge-touching counts as an intersection.
616
+ *
617
+ * @method platypus.AABB#intersects
618
+ * @param aabb {platypus.AABB} The AABB to test.
619
+ * @return {boolean}
620
+ */
621
+ proto.intersects = function (aabb) {
622
+ return (aabb.bottom >= this.top) &&
623
+ (aabb.top <= this.bottom) &&
624
+ (aabb.right >= this.left) &&
625
+ (aabb.left <= this.right);
626
+ };
627
+
628
+ /**
629
+ * Returns a new AABB representing the overlapping area between two AABBs.
630
+ *
631
+ * If no overlap exists, an empty AABB is returned.
632
+ *
633
+ * The returned AABB is pooled and should be recycled when no longer needed.
634
+ *
635
+ * @method platypus.AABB#getIntersection
636
+ * @param aabb {platypus.AABB} The AABB to intersect against.
637
+ * @return {platypus.AABB}
638
+ */
639
+ proto.getIntersection = function (aabb) {
640
+ return this.intersects(aabb) ? AABB.setUp().setBounds(
641
+ Math.max(this.left, aabb.left),
642
+ Math.max(this.top, aabb.top),
643
+ Math.min(this.right, aabb.right),
644
+ Math.min(this.bottom, aabb.bottom)
645
+ ) : AABB.setUp();
646
+ };
647
+
648
+ /**
649
+ * Returns the overlapping area between two AABBs.
650
+ *
651
+ * Returns `0` if no overlap exists.
652
+ *
653
+ * @method platypus.AABB#getIntersectionArea
654
+ * @param aabb {platypus.AABB} The AABB to intersect against.
655
+ * @return {number}
656
+ */
657
+ proto.getIntersectionArea = function (aabb) {
658
+ return this.intersects(aabb) ? (
659
+ (Math.min(this.bottom, aabb.bottom) - Math.max(this.top, aabb.top)) *
660
+ (Math.min(this.right, aabb.right) - Math.max(this.left, aabb.left))
661
+ ) : 0;
662
+ };
663
+
664
+ /**
665
+ * Returns an AABB from cache or creates a new one if none are available.
666
+ *
667
+ * @method platypus.AABB.setUp
668
+ * @return {platypus.AABB}
669
+ */
670
+
671
+ /**
672
+ * Returns an AABB to the cache.
673
+ *
674
+ * @method platypus.AABB.recycle
675
+ * @param {platypus.AABB} aabb The AABB to recycle.
676
+ */
677
+
678
+ /**
679
+ * Relinquishes properties of the AABB and recycles it.
680
+ *
681
+ * @method platypus.AABB#recycle
682
+ */
683
+ recycle.add(AABB, 'AABB', AABB, null, true);
684
+
685
+ export default AABB;