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,318 @@
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 { TAU } from '../math/math.js';
10
+ import '../node_modules/earcut/src/earcut.js';
11
+ import { e as earcut } from '../_virtual/earcut.js';
12
+
13
+ /**
14
+ * @classdesc
15
+ * a simplified path2d implementation, supporting only one path
16
+ */
17
+ class Path2D {
18
+ constructor() {
19
+ /**
20
+ * the points defining the current path
21
+ * @public
22
+ * @type {Vector2d[]}
23
+ * @name points
24
+ * @memberof Path2D#
25
+ */
26
+ this.points = [];
27
+
28
+ /**
29
+ * space between interpolated points for quadratic and bezier curve approx. in pixels.
30
+ * @public
31
+ * @type {number}
32
+ * @name arcResolution
33
+ * @default 5
34
+ * @memberof Path2D#
35
+ */
36
+ this.arcResolution = 5;
37
+
38
+ /* @ignore */
39
+ this.vertices = [];
40
+ }
41
+
42
+ /**
43
+ * begin a new path
44
+ * @name beginPath
45
+ * @memberof Path2D
46
+ */
47
+ beginPath() {
48
+ // empty the cache and recycle all vectors
49
+ this.points.forEach((point) => {
50
+ pool.push(point);
51
+ });
52
+ this.points.length = 0;
53
+ }
54
+
55
+ /**
56
+ * causes the point of the pen to move back to the start of the current path.
57
+ * It tries to draw a straight line from the current point to the start.
58
+ * If the shape has already been closed or has only one point, this function does nothing.
59
+ * @name closePath
60
+ * @memberof Path2D
61
+ */
62
+ closePath() {
63
+ var points = this.points;
64
+ if (points.length > 1 && !points[points.length-1].equals(points[0])) {
65
+ points.push(pool.pull("Vector2d", points[0].x, points[0].y));
66
+ }
67
+ }
68
+
69
+ /**
70
+ * triangulate the shape defined by this path into an array of triangles
71
+ * @name triangulatePath
72
+ * @memberof Path2D
73
+ * @returns {Vector2d[]}
74
+ */
75
+ triangulatePath() {
76
+ var i = 0;
77
+ var points = this.points;
78
+ var vertices = this.vertices;
79
+ var indices = earcut.exports(points.flatMap(p => [p.x, p.y]));
80
+
81
+ // calculate all vertices
82
+ for (i = 0; i < indices.length; i++ ) {
83
+ if (typeof vertices[i] === "undefined") {
84
+ // increase cache buffer if necessary
85
+ vertices[i] = pool.pull("Vector2d");
86
+ }
87
+ vertices[i].set(points[indices[i]].x, points[indices[i]].y);
88
+ }
89
+
90
+ // recycle overhead from a previous triangulation
91
+ while (vertices.length > indices.length) {
92
+ pool.push(vertices[vertices.length-1]);
93
+ vertices.length -= 1;
94
+ }
95
+
96
+ return vertices;
97
+ }
98
+
99
+ /**
100
+ * moves the starting point of the current path to the (x, y) coordinates.
101
+ * @name moveTo
102
+ * @memberof Path2D
103
+ * @param {number} x - the x-axis (horizontal) coordinate of the point.
104
+ * @param {number} y - the y-axis (vertical) coordinate of the point.
105
+ */
106
+ moveTo(x, y) {
107
+ this.points.push(pool.pull("Vector2d", x, y));
108
+ }
109
+
110
+ /**
111
+ * connects the last point in the current patch to the (x, y) coordinates with a straight line.
112
+ * @name lineTo
113
+ * @memberof Path2D
114
+ * @param {number} x - the x-axis coordinate of the line's end point.
115
+ * @param {number} y - the y-axis coordinate of the line's end point.
116
+ */
117
+ lineTo(x, y) {
118
+ this.points.push(pool.pull("Vector2d", x, y));
119
+ }
120
+
121
+ /**
122
+ * adds an arc to the current path which is centered at (x, y) position with the given radius,
123
+ * starting at startAngle and ending at endAngle going in the given direction by counterclockwise (defaulting to clockwise).
124
+ * @name arc
125
+ * @memberof Path2D
126
+ * @param {number} x - the horizontal coordinate of the arc's center.
127
+ * @param {number} y - the vertical coordinate of the arc's center.
128
+ * @param {number} radius - the arc's radius. Must be positive.
129
+ * @param {number} startAngle - the angle at which the arc starts in radians, measured from the positive x-axis.
130
+ * @param {number} endAngle - the angle at which the arc ends in radians, measured from the positive x-axis.
131
+ * @param {boolean} [anticlockwise=false] - an optional boolean value. If true, draws the arc counter-clockwise between the start and end angles.
132
+ */
133
+ arc(x, y, radius, startAngle, endAngle, anticlockwise = false) {
134
+ var points = this.points;
135
+ // based on from https://github.com/karellodewijk/canvas-webgl/blob/master/canvas-webgl.js
136
+ //bring angles all in [0, 2*PI] range
137
+ if (startAngle === endAngle) return;
138
+ var fullCircle = anticlockwise ? Math.abs(startAngle-endAngle) >= (TAU) : Math.abs(endAngle-startAngle) >= (TAU);
139
+
140
+ startAngle = startAngle % (TAU);
141
+ endAngle = endAngle % (TAU);
142
+
143
+ if (startAngle < 0) startAngle += TAU;
144
+ if (endAngle < 0) endAngle += TAU;
145
+
146
+ if (startAngle >= endAngle) {
147
+ endAngle+= TAU;
148
+ }
149
+
150
+ var diff = endAngle - startAngle;
151
+ var direction = 1;
152
+ if (anticlockwise) {
153
+ direction = -1;
154
+ diff = TAU - diff;
155
+ }
156
+
157
+ if (fullCircle) diff = TAU;
158
+
159
+ var length = diff * radius;
160
+ var nr_of_interpolation_points = length / this.arcResolution;
161
+ var dangle = diff / nr_of_interpolation_points;
162
+
163
+ var angle = startAngle;
164
+ for (var j = 0; j < nr_of_interpolation_points; j++) {
165
+ points.push(pool.pull("Vector2d", x + radius * Math.cos(angle), y + radius * Math.sin(angle)));
166
+ angle += direction * dangle;
167
+ }
168
+ points.push(pool.pull("Vector2d", x + radius * Math.cos(endAngle), y + radius * Math.sin(endAngle)));
169
+ }
170
+
171
+ /**
172
+ * adds a circular arc to the path with the given control points and radius, connected to the previous point by a straight line.
173
+ * @name arcTo
174
+ * @memberof Path2D
175
+ * @param {number} x1 - the x-axis coordinate of the first control point.
176
+ * @param {number} y1 - the y-axis coordinate of the first control point.
177
+ * @param {number} x2 - the x-axis coordinate of the second control point.
178
+ * @param {number} y2 - the y-axis coordinate of the second control point.
179
+ * @param {number} radius - the arc's radius. Must be positive.
180
+ */
181
+ arcTo(x1, y1, x2, y2, radius) {
182
+ var points = this.points;
183
+ // based on from https://github.com/karellodewijk/canvas-webgl/blob/master/canvas-webgl.js
184
+ var x0 = points[points.length-1].x, y0 = points[points.length-1].y;
185
+
186
+ //a = -incoming vector, b = outgoing vector to x1, y1
187
+ var a = [x0 - x1, y0 - y1];
188
+ var b = [x2 - x1, y2 - y1];
189
+
190
+ //normalize
191
+ var l_a = Math.sqrt(Math.pow(a[0], 2) + Math.pow(a[1], 2));
192
+ var l_b = Math.sqrt(Math.pow(b[0], 2) + Math.pow(b[1], 2));
193
+ a[0] /= l_a; a[1] /= l_a; b[0] /= l_b; b[1] /= l_b;
194
+ var angle = Math.atan2(a[1], a[0]) - Math.atan2(b[1], b[0]);
195
+
196
+ //work out tangent points using tan(θ) = opposite / adjacent; angle/2 because hypotenuse is the bisection of a,b
197
+ var tan_angle_div2 = Math.tan(angle/2);
198
+ var adj_l = (radius/tan_angle_div2);
199
+
200
+ var tangent_point1 = [x1 + a[0] * adj_l, y1 + a[1] * adj_l];
201
+ var tangent_point2 = [x1 + b[0] * adj_l, y1 + b[1] * adj_l];
202
+
203
+ points.push(pool.pull("Vector2d", tangent_point1[0], tangent_point1[1]));
204
+
205
+ var bisec = [(a[0] + b[0]) / 2.0, (a[1] + b[1]) / 2.0];
206
+ var bisec_l = Math.sqrt(Math.pow(bisec[0], 2) + Math.pow(bisec[1], 2));
207
+ bisec[0] /= bisec_l; bisec[1] /= bisec_l;
208
+
209
+ var hyp_l = Math.sqrt(Math.pow(radius, 2) + Math.pow(adj_l, 2));
210
+ var center = [x1 + hyp_l * bisec[0], y1 + hyp_l * bisec[1]];
211
+
212
+ var startAngle = Math.atan2(tangent_point1[1] - center[1], tangent_point1[0] - center[0]);
213
+ var endAngle = Math.atan2(tangent_point2[1] - center[1], tangent_point2[0] - center[0]);
214
+
215
+ this.arc(center[0], center[1], radius, startAngle, endAngle);
216
+ }
217
+
218
+ /**
219
+ * adds an elliptical arc to the path which is centered at (x, y) position with the radii radiusX and radiusY
220
+ * starting at startAngle and ending at endAngle going in the given direction by counterclockwise.
221
+ * @name ellipse
222
+ * @memberof Path2D
223
+ * @param {number} x - the x-axis (horizontal) coordinate of the ellipse's center.
224
+ * @param {number} y - the y-axis (vertical) coordinate of the ellipse's center.
225
+ * @param {number} radiusX - the ellipse's major-axis radius. Must be non-negative.
226
+ * @param {number} radiusY - the ellipse's minor-axis radius. Must be non-negative.
227
+ * @param {number} rotation - the rotation of the ellipse, expressed in radians.
228
+ * @param {number} startAngle - the angle at which the ellipse starts, measured clockwise from the positive x-axis and expressed in radians.
229
+ * @param {number} endAngle - the angle at which the ellipse ends, measured clockwise from the positive x-axis and expressed in radians.
230
+ * @param {boolean} [anticlockwise=false] - an optional boolean value which, if true, draws the ellipse counterclockwise (anticlockwise).
231
+ */
232
+ ellipse(x, y, radiusX, radiusY, rotation, startAngle, endAngle, anticlockwise = false) {
233
+ var points = this.points;
234
+ // based on from https://github.com/karellodewijk/canvas-webgl/blob/master/canvas-webgl.js
235
+ if (startAngle === endAngle) return;
236
+ var fullCircle = anticlockwise ? Math.abs(startAngle-endAngle) >= (TAU) : Math.abs(endAngle-startAngle) >= (TAU);
237
+
238
+ //bring angles all in [0, 2*PI] range
239
+ startAngle = startAngle % (TAU);
240
+ endAngle = endAngle % (TAU);
241
+ if (startAngle < 0) startAngle += TAU;
242
+ if (endAngle < 0) endAngle += TAU;
243
+
244
+ if (startAngle>=endAngle) {
245
+ endAngle += TAU;
246
+ }
247
+
248
+ var diff = endAngle - startAngle;
249
+
250
+ var direction = 1;
251
+ if (anticlockwise) {
252
+ direction = -1;
253
+ diff = TAU - diff;
254
+ }
255
+
256
+ if (fullCircle) diff = TAU;
257
+
258
+ var length = (diff * radiusX + diff * radiusY) / 2;
259
+ var nr_of_interpolation_points = length / this.arcResolution;
260
+ var dangle = diff / nr_of_interpolation_points;
261
+
262
+ var angle = startAngle;
263
+ var cos_rotation = Math.cos(rotation);
264
+ var sin_rotation = Math.sin(rotation);
265
+ for (var j = 0; j < nr_of_interpolation_points; j++) {
266
+ var _x1 = radiusX * Math.cos(angle);
267
+ var _y1 = radiusY * Math.sin(angle);
268
+ var _x2 = x + _x1 * cos_rotation - _y1 * sin_rotation;
269
+ var _y2 = y + _x1 * sin_rotation + _y1 * cos_rotation;
270
+ points.push(pool.pull("Vector2d", _x2, _y2));
271
+ angle += direction * dangle;
272
+ }
273
+ //var x1 = radiusX * Math.cos(endAngle);
274
+ //var y1 = radiusY * Math.sin(endAngle);
275
+ //points.push(pool.pull("Vector2d", x + x1 * cos_rotation - y1 * sin_rotation, y + x1 * sin_rotation + y1 * cos_rotation));
276
+ }
277
+
278
+ /**
279
+ * creates a path for a rectangle at position (x, y) with a size that is determined by width and height.
280
+ * @name rect
281
+ * @memberof Path2D
282
+ * @param {number} x - the x-axis coordinate of the rectangle's starting point.
283
+ * @param {number} y - the y-axis coordinate of the rectangle's starting point.
284
+ * @param {number} width - the rectangle's width. Positive values are to the right, and negative to the left.
285
+ * @param {number} height - the rectangle's height. Positive values are down, and negative are up.
286
+ */
287
+ rect(x, y, width, height) {
288
+ this.moveTo(x, y);
289
+ this.lineTo(x + width, y);
290
+ this.lineTo(x + width, y + height);
291
+ this.lineTo(x, y + height);
292
+ this.lineTo(x, y);
293
+ }
294
+
295
+ /**
296
+ * adds an rounded rectangle to the current path.
297
+ * @name roundRect
298
+ * @memberof Path2D
299
+ * @param {number} x - the x-axis coordinate of the rectangle's starting point.
300
+ * @param {number} y - the y-axis coordinate of the rectangle's starting point.
301
+ * @param {number} width - the rectangle's width. Positive values are to the right, and negative to the left.
302
+ * @param {number} height - the rectangle's height. Positive values are down, and negative are up.
303
+ * @param {number} radius - the arc's radius to draw the borders. Must be positive.
304
+ */
305
+ roundRect(x, y, width, height, radius) {
306
+ this.moveTo(x + radius, y);
307
+ this.lineTo(x + width - radius, y);
308
+ this.arcTo(x + width, y, x + width, y + radius, radius);
309
+ this.lineTo(x + width, y + height - radius);
310
+ this.arcTo(x + width, y + height, x + width - radius, y + height, radius);
311
+ this.lineTo(x + radius, y + height);
312
+ this.arcTo(x, y + height, x, y + height - radius, radius);
313
+ this.lineTo(x, y + radius);
314
+ this.arcTo(x, y, x + radius, y, radius);
315
+ }
316
+ }
317
+
318
+ export { Path2D as default };
@@ -0,0 +1,88 @@
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
+ /**
9
+ * @classdesc
10
+ * represents a point in a 2d space
11
+ */
12
+ class Point {
13
+ constructor(x = 0, y = 0) {
14
+ /**
15
+ * the position of the point on the horizontal axis
16
+ * @public
17
+ * @type {Number}
18
+ * @default 0
19
+ */
20
+ this.x = x;
21
+
22
+ /**
23
+ * the position of the point on the vertical axis
24
+ * @public
25
+ * @type {Number}
26
+ * @default 0
27
+ */
28
+ this.y = y;
29
+ }
30
+
31
+ /** @ignore */
32
+ onResetEvent(x = 0, y = 0) {
33
+ this.set(x, y);
34
+ }
35
+
36
+ /**
37
+ * set the Point x and y properties to the given values
38
+ * @param {number} x
39
+ * @param {number} y
40
+ * @returns {Point} Reference to this object for method chaining
41
+ */
42
+ set(x = 0, y = 0) {
43
+ this.x = x;
44
+ this.y = y;
45
+ return this;
46
+ }
47
+
48
+ /**
49
+ * return true if the two points are the same
50
+ * @name equals
51
+ * @memberof Point
52
+ * @method
53
+ * @param {Point} point
54
+ * @returns {boolean}
55
+ */
56
+ /**
57
+ * return true if this point is equal to the given values
58
+ * @name equals
59
+ * @memberof Point
60
+ * @param {number} x
61
+ * @param {number} y
62
+ * @returns {boolean}
63
+ */
64
+ equals() {
65
+ var _x, _y;
66
+ if (arguments.length === 2) {
67
+ // x, y
68
+ _x = arguments[0];
69
+ _y = arguments[1];
70
+ } else {
71
+ // point
72
+ _x = arguments[0].x;
73
+ _y = arguments[0].y;
74
+ }
75
+ return ((this.x === _x) && (this.y === _y));
76
+ }
77
+
78
+ /**
79
+ * clone this Point
80
+ * @name clone
81
+ * @returns {Point} new Point
82
+ */
83
+ clone() {
84
+ return new Point(this.x, this.y);
85
+ }
86
+ }
87
+
88
+ export { Point as default };