melonjs 14.0.2 → 14.1.1

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 (219) hide show
  1. package/README.md +2 -0
  2. package/dist/melonjs.mjs/_virtual/_commonjsHelpers.js +10 -0
  3. package/dist/melonjs.mjs/_virtual/arraymultimap.js +10 -0
  4. package/dist/melonjs.mjs/_virtual/earcut.js +10 -0
  5. package/dist/melonjs.mjs/_virtual/howler.js +10 -0
  6. package/dist/melonjs.mjs/_virtual/index.js +10 -0
  7. package/dist/melonjs.mjs/_virtual/index2.js +10 -0
  8. package/dist/melonjs.mjs/_virtual/multimap.js +10 -0
  9. package/dist/melonjs.mjs/_virtual/setmultimap.js +10 -0
  10. package/dist/melonjs.mjs/application/application.js +238 -0
  11. package/dist/melonjs.mjs/audio/audio.js +536 -0
  12. package/dist/melonjs.mjs/camera/camera2d.js +731 -0
  13. package/dist/melonjs.mjs/entity/entity.js +247 -0
  14. package/dist/melonjs.mjs/game.js +29 -0
  15. package/dist/melonjs.mjs/geometries/ellipse.js +274 -0
  16. package/dist/melonjs.mjs/geometries/line.js +115 -0
  17. package/dist/melonjs.mjs/geometries/path2d.js +318 -0
  18. package/dist/melonjs.mjs/geometries/point.js +88 -0
  19. package/dist/melonjs.mjs/geometries/poly.js +498 -0
  20. package/dist/melonjs.mjs/geometries/rectangle.js +374 -0
  21. package/dist/melonjs.mjs/geometries/roundrect.js +167 -0
  22. package/dist/melonjs.mjs/index.js +248 -0
  23. package/dist/melonjs.mjs/input/gamepad.js +501 -0
  24. package/dist/melonjs.mjs/input/input.js +26 -0
  25. package/dist/melonjs.mjs/input/keyboard.js +470 -0
  26. package/dist/melonjs.mjs/input/pointer.js +393 -0
  27. package/dist/melonjs.mjs/input/pointerevent.js +818 -0
  28. package/dist/melonjs.mjs/lang/deprecated.js +157 -0
  29. package/dist/melonjs.mjs/level/level.js +297 -0
  30. package/dist/melonjs.mjs/level/tiled/TMXGroup.js +141 -0
  31. package/dist/melonjs.mjs/level/tiled/TMXLayer.js +446 -0
  32. package/dist/melonjs.mjs/level/tiled/TMXObject.js +355 -0
  33. package/dist/melonjs.mjs/level/tiled/TMXTile.js +193 -0
  34. package/dist/melonjs.mjs/level/tiled/TMXTileMap.js +636 -0
  35. package/dist/melonjs.mjs/level/tiled/TMXTileset.js +309 -0
  36. package/dist/melonjs.mjs/level/tiled/TMXTilesetGroup.js +81 -0
  37. package/dist/melonjs.mjs/level/tiled/TMXUtils.js +367 -0
  38. package/dist/melonjs.mjs/level/tiled/renderer/TMXHexagonalRenderer.js +504 -0
  39. package/dist/melonjs.mjs/level/tiled/renderer/TMXIsometricRenderer.js +218 -0
  40. package/dist/melonjs.mjs/level/tiled/renderer/TMXOrthogonalRenderer.js +155 -0
  41. package/dist/melonjs.mjs/level/tiled/renderer/TMXRenderer.js +124 -0
  42. package/dist/melonjs.mjs/level/tiled/renderer/TMXStaggeredRenderer.js +107 -0
  43. package/dist/melonjs.mjs/loader/loader.js +801 -0
  44. package/dist/melonjs.mjs/loader/loadingscreen.js +120 -0
  45. package/dist/melonjs.mjs/loader/melonjs_logo.png.js +11 -0
  46. package/dist/melonjs.mjs/math/color.js +616 -0
  47. package/dist/melonjs.mjs/math/math.js +218 -0
  48. package/dist/melonjs.mjs/math/matrix2.js +501 -0
  49. package/dist/melonjs.mjs/math/matrix3.js +679 -0
  50. package/dist/melonjs.mjs/math/observable_vector2.js +469 -0
  51. package/dist/melonjs.mjs/math/observable_vector3.js +559 -0
  52. package/dist/melonjs.mjs/math/vector2.js +526 -0
  53. package/dist/melonjs.mjs/math/vector3.js +567 -0
  54. package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/arraymultimap.js +73 -0
  55. package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/index.js +21 -0
  56. package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/multimap.js +324 -0
  57. package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/setmultimap.js +69 -0
  58. package/dist/melonjs.mjs/node_modules/earcut/src/earcut.js +691 -0
  59. package/dist/melonjs.mjs/node_modules/eventemitter3/index.js +350 -0
  60. package/dist/melonjs.mjs/node_modules/howler/dist/howler.js +3241 -0
  61. package/dist/melonjs.mjs/particles/emitter.js +265 -0
  62. package/dist/melonjs.mjs/particles/particle.js +186 -0
  63. package/dist/melonjs.mjs/particles/settings.js +319 -0
  64. package/dist/melonjs.mjs/physics/body.js +702 -0
  65. package/dist/melonjs.mjs/physics/bounds.js +459 -0
  66. package/dist/melonjs.mjs/physics/collision.js +132 -0
  67. package/dist/melonjs.mjs/physics/detector.js +194 -0
  68. package/dist/melonjs.mjs/physics/quadtree.js +394 -0
  69. package/dist/melonjs.mjs/physics/response.js +57 -0
  70. package/dist/melonjs.mjs/physics/sat.js +483 -0
  71. package/dist/melonjs.mjs/physics/world.js +219 -0
  72. package/dist/melonjs.mjs/plugin/plugin.js +141 -0
  73. package/dist/melonjs.mjs/renderable/collectable.js +60 -0
  74. package/dist/melonjs.mjs/renderable/colorlayer.js +78 -0
  75. package/dist/melonjs.mjs/renderable/container.js +1016 -0
  76. package/dist/melonjs.mjs/renderable/dragndrop.js +224 -0
  77. package/dist/melonjs.mjs/renderable/imagelayer.js +305 -0
  78. package/dist/melonjs.mjs/renderable/light2d.js +155 -0
  79. package/dist/melonjs.mjs/renderable/nineslicesprite.js +246 -0
  80. package/dist/melonjs.mjs/renderable/renderable.js +781 -0
  81. package/dist/melonjs.mjs/renderable/sprite.js +653 -0
  82. package/dist/melonjs.mjs/renderable/trigger.js +156 -0
  83. package/dist/melonjs.mjs/renderable/ui/uibaseelement.js +212 -0
  84. package/dist/melonjs.mjs/renderable/ui/uispriteelement.js +225 -0
  85. package/dist/melonjs.mjs/renderable/ui/uitextbutton.js +127 -0
  86. package/dist/melonjs.mjs/state/stage.js +236 -0
  87. package/dist/melonjs.mjs/state/state.js +596 -0
  88. package/dist/melonjs.mjs/system/device.js +909 -0
  89. package/dist/melonjs.mjs/system/dom.js +78 -0
  90. package/dist/melonjs.mjs/system/event.js +537 -0
  91. package/dist/melonjs.mjs/system/platform.js +41 -0
  92. package/dist/melonjs.mjs/system/pooling.js +209 -0
  93. package/dist/melonjs.mjs/system/save.js +157 -0
  94. package/dist/melonjs.mjs/system/timer.js +286 -0
  95. package/dist/melonjs.mjs/text/bitmaptext.js +363 -0
  96. package/dist/melonjs.mjs/text/bitmaptextdata.js +198 -0
  97. package/dist/melonjs.mjs/text/glyph.js +65 -0
  98. package/dist/melonjs.mjs/text/text.js +452 -0
  99. package/dist/melonjs.mjs/text/textmetrics.js +175 -0
  100. package/dist/melonjs.mjs/text/textstyle.js +23 -0
  101. package/dist/melonjs.mjs/tweens/easing.js +336 -0
  102. package/dist/melonjs.mjs/tweens/interpolation.js +112 -0
  103. package/dist/melonjs.mjs/tweens/tween.js +479 -0
  104. package/dist/melonjs.mjs/utils/agent.js +76 -0
  105. package/dist/melonjs.mjs/utils/array.js +63 -0
  106. package/dist/melonjs.mjs/utils/file.js +42 -0
  107. package/dist/melonjs.mjs/utils/function.js +70 -0
  108. package/dist/melonjs.mjs/utils/string.js +82 -0
  109. package/dist/melonjs.mjs/utils/utils.js +173 -0
  110. package/dist/melonjs.mjs/video/canvas/canvas_renderer.js +806 -0
  111. package/dist/melonjs.mjs/video/renderer.js +410 -0
  112. package/dist/melonjs.mjs/video/texture/atlas.js +519 -0
  113. package/dist/melonjs.mjs/video/texture/cache.js +143 -0
  114. package/dist/melonjs.mjs/video/texture/canvas_texture.js +144 -0
  115. package/dist/melonjs.mjs/video/video.js +462 -0
  116. package/dist/melonjs.mjs/video/webgl/buffer/vertex.js +142 -0
  117. package/dist/melonjs.mjs/video/webgl/glshader.js +167 -0
  118. package/dist/melonjs.mjs/video/webgl/shaders/primitive.frag.js +10 -0
  119. package/dist/melonjs.mjs/video/webgl/shaders/primitive.vert.js +10 -0
  120. package/dist/melonjs.mjs/video/webgl/shaders/quad.frag.js +10 -0
  121. package/dist/melonjs.mjs/video/webgl/shaders/quad.vert.js +10 -0
  122. package/dist/melonjs.mjs/video/webgl/utils/attributes.js +25 -0
  123. package/dist/melonjs.mjs/video/webgl/utils/precision.js +20 -0
  124. package/dist/melonjs.mjs/video/webgl/utils/program.js +67 -0
  125. package/dist/melonjs.mjs/video/webgl/utils/string.js +25 -0
  126. package/dist/melonjs.mjs/video/webgl/utils/uniforms.js +92 -0
  127. package/dist/melonjs.mjs/video/webgl/webgl_compositor.js +494 -0
  128. package/dist/melonjs.mjs/video/webgl/webgl_renderer.js +1035 -0
  129. package/dist/melonjs.module.d.ts +1298 -1359
  130. package/dist/melonjs.module.js +2072 -3520
  131. package/package.json +21 -16
  132. package/src/application/application.js +4 -5
  133. package/src/audio/audio.js +32 -32
  134. package/src/camera/camera2d.js +32 -33
  135. package/src/entity/entity.js +18 -19
  136. package/src/geometries/ellipse.js +17 -18
  137. package/src/geometries/line.js +6 -7
  138. package/src/geometries/path2d.js +33 -34
  139. package/src/geometries/point.js +1 -2
  140. package/src/geometries/poly.js +16 -18
  141. package/src/geometries/rectangle.js +19 -20
  142. package/src/geometries/roundrect.js +9 -10
  143. package/src/input/gamepad.js +15 -15
  144. package/src/input/keyboard.js +12 -12
  145. package/src/input/pointer.js +6 -6
  146. package/src/input/pointerevent.js +12 -12
  147. package/src/lang/deprecated.js +12 -12
  148. package/src/level/level.js +25 -25
  149. package/src/level/tiled/TMXLayer.js +23 -24
  150. package/src/level/tiled/TMXTile.js +6 -7
  151. package/src/level/tiled/TMXTileMap.js +8 -10
  152. package/src/level/tiled/TMXTileset.js +3 -4
  153. package/src/level/tiled/TMXTilesetGroup.js +1 -2
  154. package/src/level/tiled/TMXUtils.js +5 -5
  155. package/src/level/tiled/renderer/TMXHexagonalRenderer.js +3 -4
  156. package/src/level/tiled/renderer/TMXIsometricRenderer.js +3 -4
  157. package/src/level/tiled/renderer/TMXOrthogonalRenderer.js +2 -3
  158. package/src/level/tiled/renderer/TMXRenderer.js +20 -21
  159. package/src/level/tiled/renderer/TMXStaggeredRenderer.js +1 -2
  160. package/src/loader/loader.js +20 -20
  161. package/src/math/color.js +21 -22
  162. package/src/math/math.js +16 -16
  163. package/src/math/matrix2.js +17 -18
  164. package/src/math/matrix3.js +26 -27
  165. package/src/math/observable_vector2.js +15 -16
  166. package/src/math/observable_vector3.js +17 -18
  167. package/src/math/vector2.js +10 -11
  168. package/src/math/vector3.js +11 -12
  169. package/src/particles/emitter.js +7 -8
  170. package/src/particles/particle.js +3 -4
  171. package/src/physics/body.js +29 -30
  172. package/src/physics/bounds.js +10 -10
  173. package/src/physics/collision.js +2 -2
  174. package/src/physics/detector.js +6 -6
  175. package/src/physics/quadtree.js +18 -23
  176. package/src/physics/sat.js +31 -31
  177. package/src/physics/world.js +6 -7
  178. package/src/plugin/plugin.js +5 -5
  179. package/src/renderable/collectable.js +4 -6
  180. package/src/renderable/colorlayer.js +6 -8
  181. package/src/renderable/container.js +25 -27
  182. package/src/renderable/dragndrop.js +14 -14
  183. package/src/renderable/imagelayer.js +14 -15
  184. package/src/renderable/light2d.js +4 -5
  185. package/src/renderable/nineslicesprite.js +17 -18
  186. package/src/renderable/renderable.js +26 -28
  187. package/src/renderable/sprite.js +29 -30
  188. package/src/renderable/trigger.js +16 -17
  189. package/src/renderable/ui/uibaseelement.js +8 -9
  190. package/src/renderable/ui/uispriteelement.js +8 -8
  191. package/src/renderable/ui/uitextbutton.js +15 -15
  192. package/src/state/stage.js +8 -9
  193. package/src/state/state.js +17 -17
  194. package/src/system/device.js +11 -11
  195. package/src/system/event.js +10 -10
  196. package/src/system/pooling.js +9 -9
  197. package/src/system/save.js +2 -2
  198. package/src/system/timer.js +10 -10
  199. package/src/text/bitmaptext.js +19 -20
  200. package/src/text/bitmaptextdata.js +3 -4
  201. package/src/text/glyph.js +1 -2
  202. package/src/text/text.js +24 -25
  203. package/src/text/textmetrics.js +9 -10
  204. package/src/tweens/tween.js +20 -21
  205. package/src/utils/agent.js +5 -5
  206. package/src/utils/array.js +4 -4
  207. package/src/utils/file.js +2 -2
  208. package/src/utils/function.js +6 -6
  209. package/src/utils/string.js +5 -5
  210. package/src/utils/utils.js +4 -4
  211. package/src/video/canvas/canvas_renderer.js +72 -73
  212. package/src/video/renderer.js +27 -28
  213. package/src/video/texture/atlas.js +22 -22
  214. package/src/video/texture/canvas_texture.js +9 -9
  215. package/src/video/video.js +17 -17
  216. package/src/video/webgl/buffer/vertex.js +1 -2
  217. package/src/video/webgl/glshader.js +12 -12
  218. package/src/video/webgl/webgl_compositor.js +42 -43
  219. package/src/video/webgl/webgl_renderer.js +76 -77
@@ -0,0 +1,247 @@
1
+ /*!
2
+ * melonJS Game Engine - v14.1.1
3
+ * http://www.melonjs.org
4
+ * melonjs is licensed under the MIT License.
5
+ * http://www.opensource.org/licenses/mit-license
6
+ * @copyright (C) 2011 - 2022 Olivier Biot (AltByte Pte Ltd)
7
+ */
8
+ import pool from '../system/pooling.js';
9
+ import Renderable from '../renderable/renderable.js';
10
+ import Sprite from '../renderable/sprite.js';
11
+ import Body from '../physics/body.js';
12
+
13
+ /**
14
+ * @classdesc
15
+ * a Generic Object Entity
16
+ * @augments Renderable
17
+ * @see Renderable
18
+ */
19
+ class Entity extends Renderable {
20
+ /**
21
+ * @param {number} x - the x coordinates of the entity object
22
+ * @param {number} y - the y coordinates of the entity object
23
+ * @param {object} settings - Entity properties, to be defined through Tiled or when calling the entity constructor
24
+ * <img src="images/object_properties.png"/>
25
+ * @param {number} settings.width - the physical width the entity takes up in game
26
+ * @param {number} settings.height - the physical height the entity takes up in game
27
+ * @param {string} [settings.name] - object entity name
28
+ * @param {string} [settings.id] - object unique IDs
29
+ * @param {Image|string} [settings.image] - resource name of a spritesheet to use for the entity renderable component
30
+ * @param {Vector2d} [settings.anchorPoint=0.0] - Entity anchor point
31
+ * @param {number} [settings.framewidth=settings.width] - width of a single frame in the given spritesheet
32
+ * @param {number} [settings.frameheight=settings.width] - height of a single frame in the given spritesheet
33
+ * @param {string} [settings.type] - object type
34
+ * @param {number} [settings.collisionMask] - Mask collision detection for this object
35
+ * @param {Rect[]|Polygon[]|Line[]|Ellipse[]} [settings.shapes] - the initial list of collision shapes (usually populated through Tiled)
36
+ */
37
+ constructor(x, y, settings) {
38
+
39
+ // ensure mandatory properties are defined
40
+ if ((typeof settings.width !== "number") || (typeof settings.height !== "number")) {
41
+ throw new Error("height and width properties are mandatory when passing settings parameters to an object entity");
42
+ }
43
+
44
+ // call the super constructor
45
+ super(x, y, settings.width, settings.height);
46
+
47
+ /**
48
+ * The array of renderable children of this entity.
49
+ * @ignore
50
+ */
51
+ this.children = [];
52
+
53
+ if (settings.image) {
54
+ // set the frame size to the given entity size, if not defined in settings
55
+ settings.framewidth = settings.framewidth || settings.width;
56
+ settings.frameheight = settings.frameheight || settings.height;
57
+ this.renderable = new Sprite(0, 0, settings);
58
+ }
59
+
60
+ // Update anchorPoint
61
+ if (settings.anchorPoint) {
62
+ this.anchorPoint.set(settings.anchorPoint.x, settings.anchorPoint.y);
63
+ } else {
64
+ // for backward compatibility
65
+ this.anchorPoint.set(0, 0);
66
+ }
67
+
68
+ // set the sprite name if specified
69
+ if (typeof (settings.name) === "string") {
70
+ this.name = settings.name;
71
+ }
72
+
73
+ /**
74
+ * object type (as defined in Tiled)
75
+ * @public
76
+ * @type {string}
77
+ * @name type
78
+ * @memberof Entity
79
+ */
80
+ this.type = settings.type || "";
81
+
82
+ /**
83
+ * object unique ID (as defined in Tiled)
84
+ * @public
85
+ * @type {number}
86
+ * @name id
87
+ * @memberof Entity
88
+ */
89
+ this.id = settings.id || "";
90
+
91
+ /**
92
+ * dead/living state of the entity<br>
93
+ * default value : true
94
+ * @public
95
+ * @type {boolean}
96
+ * @name alive
97
+ * @memberof Entity
98
+ */
99
+ this.alive = true;
100
+
101
+ /**
102
+ * the entity body object
103
+ * @public
104
+ * @member {Body}
105
+ * @name body
106
+ * @memberof Entity
107
+ */
108
+ // initialize the default body
109
+ if (typeof settings.shapes === "undefined") {
110
+ settings.shapes = pool.pull("Polygon", 0, 0, [
111
+ pool.pull("Vector2d", 0, 0),
112
+ pool.pull("Vector2d", this.width, 0),
113
+ pool.pull("Vector2d", this.width, this.height),
114
+ pool.pull("Vector2d", 0, this.height)
115
+ ]);
116
+ }
117
+ this.body = new Body(this, settings.shapes, this.onBodyUpdate.bind(this));
118
+
119
+ // resize the entity if required
120
+ if (this.width === 0 && this.height === 0) {
121
+ this.resize(this.body.getBounds().width, this.body.getBounds().height);
122
+ }
123
+
124
+ // set the collision mask and type (if defined)
125
+ this.body.setCollisionMask(settings.collisionMask);
126
+ this.body.setCollisionType(settings.collisionType);
127
+
128
+ // disable for entities
129
+ this.autoTransform = false;
130
+ }
131
+
132
+
133
+ /**
134
+ * The entity renderable component (can be any objects deriving from me.Renderable, like me.Sprite for example)
135
+ * @public
136
+ * @type {Renderable}
137
+ * @name renderable
138
+ * @memberof Entity
139
+ */
140
+
141
+ get renderable() {
142
+ return this.children[0];
143
+ }
144
+
145
+ set renderable(value) {
146
+ if (value instanceof Renderable) {
147
+ this.children[0] = value;
148
+ this.children[0].ancestor = this;
149
+ } else {
150
+ throw new Error(value + "should extend me.Renderable");
151
+ }
152
+ }
153
+
154
+ /** @ignore */
155
+ update(dt) {
156
+ if (this.renderable) {
157
+ this.isDirty |= this.renderable.update(dt);
158
+ }
159
+ return super.update(dt);
160
+ }
161
+
162
+ /**
163
+ * update the bounds position when the body is modified
164
+ * @ignore
165
+ * @name onBodyUpdate
166
+ * @memberof Entity
167
+ * @param {Body} body - the body whose bounds to update
168
+ */
169
+ onBodyUpdate(body) {
170
+ // update the entity bounds to include the body bounds
171
+ this.getBounds().addBounds(body.getBounds(), true);
172
+ // update the bounds pos
173
+ this.updateBoundsPos(this.pos.x, this.pos.y);
174
+ }
175
+
176
+ preDraw(renderer) {
177
+ renderer.save();
178
+
179
+ // translate to the entity position
180
+ renderer.translate(
181
+ this.pos.x + this.body.getBounds().x,
182
+ this.pos.y + this.body.getBounds().y
183
+ );
184
+
185
+ if (this.renderable instanceof Renderable) {
186
+ // draw the child renderable's anchorPoint at the entity's
187
+ // anchor point. the entity's anchor point is a scale from
188
+ // body position to body width/height
189
+ renderer.translate(
190
+ this.anchorPoint.x * this.body.getBounds().width,
191
+ this.anchorPoint.y * this.body.getBounds().height
192
+ );
193
+ }
194
+ }
195
+
196
+ /**
197
+ * draw this entity (automatically called by melonJS)
198
+ * @name draw
199
+ * @memberof Entity
200
+ * @protected
201
+ * @param {CanvasRenderer|WebGLRenderer} renderer - a renderer instance
202
+ * @param {Camera2d} [viewport] - the viewport to (re)draw
203
+ */
204
+ draw(renderer, viewport) {
205
+ var renderable = this.renderable;
206
+ if (renderable instanceof Renderable) {
207
+ // predraw (apply transforms)
208
+ renderable.preDraw(renderer);
209
+
210
+ // draw the object
211
+ renderable.draw(renderer, viewport);
212
+
213
+ // postdraw (clean-up);
214
+ renderable.postDraw(renderer);
215
+ }
216
+ }
217
+
218
+ /**
219
+ * Destroy function<br>
220
+ * @ignore
221
+ */
222
+ destroy() {
223
+ // free some property objects
224
+ if (this.renderable) {
225
+ this.renderable.destroy.apply(this.renderable, arguments);
226
+ this.children.splice(0, 1);
227
+ }
228
+
229
+ // call the parent destroy method
230
+ super.destroy(arguments);
231
+ }
232
+
233
+ /**
234
+ * onDeactivateEvent Notification function<br>
235
+ * Called by engine before deleting the object
236
+ * @name onDeactivateEvent
237
+ * @memberof Entity
238
+ */
239
+ onDeactivateEvent() {
240
+ if (this.renderable && this.renderable.onDeactivateEvent) {
241
+ this.renderable.onDeactivateEvent();
242
+ }
243
+ }
244
+
245
+ }
246
+
247
+ export { Entity as default };
@@ -0,0 +1,29 @@
1
+ /*!
2
+ * melonJS Game Engine - v14.1.1
3
+ * http://www.melonjs.org
4
+ * melonjs is licensed under the MIT License.
5
+ * http://www.opensource.org/licenses/mit-license
6
+ * @copyright (C) 2011 - 2022 Olivier Biot (AltByte Pte Ltd)
7
+ */
8
+ import { on, BOOT } from './system/event.js';
9
+ import Application from './application/application.js';
10
+
11
+ /**
12
+ * game is a default instance of a melonJS Application and represents your current game,
13
+ * it contains all the objects, tilemap layers, current viewport, collision map, etc...<br>
14
+ * @namespace game
15
+ * @see Application
16
+ */
17
+
18
+ // create a default melonJS application instance
19
+ let game = new Application();
20
+
21
+ // initialize the game manager on system boot
22
+ on(BOOT, () => {
23
+ // initialize the default game instance
24
+ game.init();
25
+ });
26
+
27
+ var game$1 = game;
28
+
29
+ export { game$1 as default };
@@ -0,0 +1,274 @@
1
+ /*!
2
+ * melonJS Game Engine - v14.1.1
3
+ * http://www.melonjs.org
4
+ * melonjs is licensed under the MIT License.
5
+ * http://www.opensource.org/licenses/mit-license
6
+ * @copyright (C) 2011 - 2022 Olivier Biot (AltByte Pte Ltd)
7
+ */
8
+ import pool from '../system/pooling.js';
9
+
10
+ /**
11
+ * @classdesc
12
+ * an ellipse Object
13
+ */
14
+ class Ellipse {
15
+ /**
16
+ * @param {number} x - the center x coordinate of the ellipse
17
+ * @param {number} y - the center y coordinate of the ellipse
18
+ * @param {number} w - width (diameter) of the ellipse
19
+ * @param {number} h - height (diameter) of the ellipse
20
+ */
21
+ constructor(x, y, w, h) {
22
+ /**
23
+ * the center coordinates of the ellipse
24
+ * @public
25
+ * @type {Vector2d}
26
+ * @name pos
27
+ * @memberof Ellipse
28
+ */
29
+ this.pos = pool.pull("Vector2d");
30
+
31
+ /**
32
+ * The bounding rectangle for this shape
33
+ * @private
34
+ */
35
+ this._bounds = undefined;
36
+
37
+ /**
38
+ * Maximum radius of the ellipse
39
+ * @public
40
+ * @type {number}
41
+ * @name radius
42
+ * @memberof Ellipse
43
+ */
44
+ this.radius = NaN;
45
+
46
+ /**
47
+ * Pre-scaled radius vector for ellipse
48
+ * @public
49
+ * @type {Vector2d}
50
+ * @name radiusV
51
+ * @memberof Ellipse
52
+ */
53
+ this.radiusV = pool.pull("Vector2d");
54
+
55
+ /**
56
+ * Radius squared, for pythagorean theorom
57
+ * @public
58
+ * @type {Vector2d}
59
+ * @name radiusSq
60
+ * @memberof Ellipse
61
+ */
62
+ this.radiusSq = pool.pull("Vector2d");
63
+
64
+ /**
65
+ * x/y scaling ratio for ellipse
66
+ * @public
67
+ * @type {Vector2d}
68
+ * @name ratio
69
+ * @memberof Ellipse
70
+ */
71
+ this.ratio = pool.pull("Vector2d");
72
+
73
+ // the shape type
74
+ this.shapeType = "Ellipse";
75
+ this.setShape(x, y, w, h);
76
+ }
77
+
78
+ /** @ignore */
79
+ onResetEvent(x, y, w, h) {
80
+ this.setShape(x, y, w, h);
81
+ }
82
+
83
+ /**
84
+ * set new value to the Ellipse shape
85
+ * @name setShape
86
+ * @memberof Ellipse
87
+ * @param {number} x - the center x coordinate of the ellipse
88
+ * @param {number} y - the center y coordinate of the ellipse
89
+ * @param {number} w - width (diameter) of the ellipse
90
+ * @param {number} h - height (diameter) of the ellipse
91
+ * @returns {Ellipse} this instance for objecf chaining
92
+ */
93
+ setShape(x, y, w, h) {
94
+ var hW = w / 2;
95
+ var hH = h / 2;
96
+
97
+ this.pos.set(x, y);
98
+ this.radius = Math.max(hW, hH);
99
+ this.ratio.set(hW / this.radius, hH / this.radius);
100
+ this.radiusV.set(this.radius, this.radius).scaleV(this.ratio);
101
+ var r = this.radius * this.radius;
102
+ this.radiusSq.set(r, r).scaleV(this.ratio);
103
+
104
+ // update the corresponding bounds
105
+ this.getBounds().setMinMax(x, y, x + w, x + h);
106
+ // elipse position is the center of the cirble, bounds position are top left
107
+ this.getBounds().translate(-this.radiusV.x, -this.radiusV.y);
108
+
109
+ return this;
110
+ }
111
+
112
+ /**
113
+ * Rotate this Ellipse (counter-clockwise) by the specified angle (in radians).
114
+ * @name rotate
115
+ * @memberof Ellipse
116
+ * @param {number} angle - The angle to rotate (in radians)
117
+ * @param {Vector2d|ObservableVector2d} [v] - an optional point to rotate around
118
+ * @returns {Ellipse} Reference to this object for method chaining
119
+ */
120
+ rotate(angle, v) {
121
+ // TODO : only works for circle
122
+ this.pos.rotate(angle, v);
123
+ this.getBounds().shift(this.pos);
124
+ this.getBounds().translate(-this.radiusV.x, -this.radiusV.y);
125
+ return this;
126
+ }
127
+
128
+ /**
129
+ * Scale this Ellipse by the specified scalar.
130
+ * @name scale
131
+ * @memberof Ellipse
132
+ * @param {number} x
133
+ * @param {number} [y=x]
134
+ * @returns {Ellipse} Reference to this object for method chaining
135
+ */
136
+ scale(x, y) {
137
+ y = typeof (y) !== "undefined" ? y : x;
138
+ return this.setShape(
139
+ this.pos.x,
140
+ this.pos.y,
141
+ this.radiusV.x * 2 * x,
142
+ this.radiusV.y * 2 * y
143
+ );
144
+ }
145
+
146
+ /**
147
+ * Scale this Ellipse by the specified vector.
148
+ * @name scale
149
+ * @memberof Ellipse
150
+ * @param {Vector2d} v
151
+ * @returns {Ellipse} Reference to this object for method chaining
152
+ */
153
+ scaleV(v) {
154
+ return this.scale(v.x, v.y);
155
+ }
156
+
157
+ /**
158
+ * apply the given transformation matrix to this ellipse
159
+ * @name transform
160
+ * @memberof Ellipse
161
+ * @param {Matrix2d} matrix - the transformation matrix
162
+ * @returns {Polygon} Reference to this object for method chaining
163
+ */
164
+ transform(matrix) { // eslint-disable-line no-unused-vars
165
+ // TODO
166
+ return this;
167
+ }
168
+
169
+ /**
170
+ * translate the circle/ellipse by the specified offset
171
+ * @name translate
172
+ * @memberof Ellipse
173
+ * @method
174
+ * @param {number} x - x offset
175
+ * @param {number} y - y offset
176
+ * @returns {Ellipse} this ellipse
177
+ */
178
+ /**
179
+ * translate the circle/ellipse by the specified vector
180
+ * @name translate
181
+ * @memberof Ellipse
182
+ * @param {Vector2d} v - vector offset
183
+ * @returns {Ellipse} this ellipse
184
+ */
185
+ translate() {
186
+ var _x, _y;
187
+
188
+ if (arguments.length === 2) {
189
+ // x, y
190
+ _x = arguments[0];
191
+ _y = arguments[1];
192
+ } else {
193
+ // vector
194
+ _x = arguments[0].x;
195
+ _y = arguments[0].y;
196
+ }
197
+
198
+ this.pos.x += _x;
199
+ this.pos.y += _y;
200
+ this.getBounds().translate(_x, _y);
201
+
202
+ return this;
203
+ }
204
+
205
+ /**
206
+ * check if this circle/ellipse contains the specified point
207
+ * @name contains
208
+ * @method
209
+ * @memberof Ellipse
210
+ * @param {Vector2d} point
211
+ * @returns {boolean} true if contains
212
+ */
213
+
214
+ /**
215
+ * check if this circle/ellipse contains the specified point
216
+ * @name contains
217
+ * @memberof Ellipse
218
+ * @param {number} x - x coordinate
219
+ * @param {number} y - y coordinate
220
+ * @returns {boolean} true if contains
221
+ */
222
+ contains() {
223
+ var _x, _y;
224
+
225
+ if (arguments.length === 2) {
226
+ // x, y
227
+ _x = arguments[0];
228
+ _y = arguments[1];
229
+ } else {
230
+ // vector
231
+ _x = arguments[0].x;
232
+ _y = arguments[0].y;
233
+ }
234
+
235
+ // Make position relative to object center point.
236
+ _x -= this.pos.x;
237
+ _y -= this.pos.y;
238
+ // Pythagorean theorem.
239
+ return (
240
+ ((_x * _x) / this.radiusSq.x) +
241
+ ((_y * _y) / this.radiusSq.y)
242
+ ) <= 1.0;
243
+ }
244
+
245
+ /**
246
+ * returns the bounding box for this shape, the smallest Rectangle object completely containing this shape.
247
+ * @name getBounds
248
+ * @memberof Ellipse
249
+ * @returns {Bounds} this shape bounding box Rectangle object
250
+ */
251
+ getBounds() {
252
+ if (typeof this._bounds === "undefined") {
253
+ this._bounds = pool.pull("Bounds");
254
+ }
255
+ return this._bounds;
256
+ }
257
+
258
+ /**
259
+ * clone this Ellipse
260
+ * @name clone
261
+ * @memberof Ellipse
262
+ * @returns {Ellipse} new Ellipse
263
+ */
264
+ clone() {
265
+ return new Ellipse(
266
+ this.pos.x,
267
+ this.pos.y,
268
+ this.radiusV.x * 2,
269
+ this.radiusV.y * 2
270
+ );
271
+ }
272
+ }
273
+
274
+ export { Ellipse as default };
@@ -0,0 +1,115 @@
1
+ /*!
2
+ * melonJS Game Engine - v14.1.1
3
+ * http://www.melonjs.org
4
+ * melonjs is licensed under the MIT License.
5
+ * http://www.opensource.org/licenses/mit-license
6
+ * @copyright (C) 2011 - 2022 Olivier Biot (AltByte Pte Ltd)
7
+ */
8
+ import pool from '../system/pooling.js';
9
+ import Polygon from './poly.js';
10
+
11
+ /**
12
+ * @classdesc
13
+ * a line segment Object
14
+ * @augments Polygon
15
+ * @param {number} x - origin point of the Line
16
+ * @param {number} y - origin point of the Line
17
+ * @param {Vector2d[]} points - array of vectors defining the Line
18
+ */
19
+
20
+ class Line extends Polygon {
21
+
22
+ /**
23
+ * Returns true if the Line contains the given point
24
+ * @name contains
25
+ * @memberof Line
26
+ * @method
27
+ * @param {Vector2d} point
28
+ * @returns {boolean} true if contains
29
+ */
30
+
31
+ /**
32
+ * Returns true if the Line contains the given point
33
+ * @name contains
34
+ * @memberof Line
35
+ * @param {number} x - x coordinate
36
+ * @param {number} y - y coordinate
37
+ * @returns {boolean} true if contains
38
+ */
39
+ contains() {
40
+ var _x, _y;
41
+
42
+ if (arguments.length === 2) {
43
+ // x, y
44
+ _x = arguments[0];
45
+ _y = arguments[1];
46
+ } else {
47
+ // vector
48
+ _x = arguments[0].x;
49
+ _y = arguments[0].y;
50
+ }
51
+
52
+ // translate the given coordinates,
53
+ // rather than creating temp translated vectors
54
+ _x -= this.pos.x; // Cx
55
+ _y -= this.pos.y; // Cy
56
+ var start = this.points[0]; // Ax/Ay
57
+ var end = this.points[1]; // Bx/By
58
+
59
+ //(Cy - Ay) * (Bx - Ax) = (By - Ay) * (Cx - Ax)
60
+ return (_y - start.y) * (end.x - start.x) === (end.y - start.y) * (_x - start.x);
61
+ }
62
+
63
+ /**
64
+ * Computes the calculated collision edges and normals.
65
+ * This **must** be called if the `points` array, `angle`, or `offset` is modified manually.
66
+ * @name recalc
67
+ * @memberof Line
68
+ * @returns {Line} this instance for objecf chaining
69
+ */
70
+ recalc() {
71
+ var edges = this.edges;
72
+ var normals = this.normals;
73
+ var indices = this.indices;
74
+
75
+ // Copy the original points array and apply the offset/angle
76
+ var points = this.points;
77
+
78
+ if (points.length !== 2) {
79
+ throw new Error("Requires exactly 2 points");
80
+ }
81
+
82
+ // Calculate the edges/normals
83
+ if (edges[0] === undefined) {
84
+ edges[0] = pool.pull("Vector2d");
85
+ }
86
+ edges[0].copy(points[1]).sub(points[0]);
87
+ if (normals[0] === undefined) {
88
+ normals[0] = pool.pull("Vector2d");
89
+ }
90
+ normals[0].copy(edges[0]).perp().normalize();
91
+
92
+ // do not do anything here, indices will be computed by
93
+ // toIndices if array is empty upon function call
94
+ indices.length = 0;
95
+
96
+ return this;
97
+ }
98
+
99
+ /**
100
+ * clone this line segment
101
+ * @name clone
102
+ * @memberof Line
103
+ * @returns {Line} new Line
104
+ */
105
+ clone() {
106
+ var copy = [];
107
+ this.points.forEach((point) => {
108
+ copy.push(point.clone());
109
+ });
110
+ return new Line(this.pos.x, this.pos.y, copy);
111
+ }
112
+
113
+ }
114
+
115
+ export { Line as default };