@vpmedia/phaser 1.0.1 → 1.0.2

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 (107) hide show
  1. package/dist/phaser.cjs.LICENSE.txt +1 -1
  2. package/dist/phaser.js.LICENSE.txt +1 -1
  3. package/package.json +2 -3
  4. package/src/index.js +99 -0
  5. package/src/phaser/core/animation.js +355 -0
  6. package/src/phaser/core/animation_manager.js +238 -0
  7. package/src/phaser/core/animation_parser.js +130 -0
  8. package/src/phaser/core/array_set.js +108 -0
  9. package/src/phaser/core/cache.js +558 -0
  10. package/src/phaser/core/const.js +106 -0
  11. package/src/phaser/core/device.js +67 -0
  12. package/src/phaser/core/device_util.js +386 -0
  13. package/src/phaser/core/dom.js +207 -0
  14. package/src/phaser/core/event_manager.js +243 -0
  15. package/src/phaser/core/factory.js +74 -0
  16. package/src/phaser/core/frame.js +75 -0
  17. package/src/phaser/core/frame_data.js +84 -0
  18. package/src/phaser/core/frame_util.js +31 -0
  19. package/src/phaser/core/game.js +412 -0
  20. package/src/phaser/core/input.js +401 -0
  21. package/src/phaser/core/input_button.js +102 -0
  22. package/src/phaser/core/input_handler.js +687 -0
  23. package/src/phaser/core/input_mouse.js +289 -0
  24. package/src/phaser/core/input_mspointer.js +197 -0
  25. package/src/phaser/core/input_pointer.js +427 -0
  26. package/src/phaser/core/input_touch.js +157 -0
  27. package/src/phaser/core/loader.js +946 -0
  28. package/src/phaser/core/loader_parser.js +105 -0
  29. package/src/phaser/core/raf.js +46 -0
  30. package/src/phaser/core/raf_fb.js +75 -0
  31. package/src/phaser/core/raf_to.js +34 -0
  32. package/src/phaser/core/scale_manager.js +806 -0
  33. package/src/phaser/core/scene.js +66 -0
  34. package/src/phaser/core/scene_manager.js +310 -0
  35. package/src/phaser/core/signal.js +175 -0
  36. package/src/phaser/core/signal_binding.js +69 -0
  37. package/src/phaser/core/sound.js +538 -0
  38. package/src/phaser/core/sound_manager.js +365 -0
  39. package/src/phaser/core/stage.js +108 -0
  40. package/src/phaser/core/time.js +203 -0
  41. package/src/phaser/core/timer.js +276 -0
  42. package/src/phaser/core/timer_event.js +21 -0
  43. package/src/phaser/core/tween.js +329 -0
  44. package/src/phaser/core/tween_data.js +258 -0
  45. package/src/phaser/core/tween_easing.js +316 -0
  46. package/src/phaser/core/tween_manager.js +185 -0
  47. package/src/phaser/core/world.js +18 -0
  48. package/src/phaser/display/bitmap_text.js +322 -0
  49. package/src/phaser/display/button.js +194 -0
  50. package/src/phaser/display/canvas/buffer.js +36 -0
  51. package/src/phaser/display/canvas/graphics.js +227 -0
  52. package/src/phaser/display/canvas/masker.js +39 -0
  53. package/src/phaser/display/canvas/pool.js +121 -0
  54. package/src/phaser/display/canvas/renderer.js +123 -0
  55. package/src/phaser/display/canvas/tinter.js +141 -0
  56. package/src/phaser/display/canvas/util.js +151 -0
  57. package/src/phaser/display/display_object.js +597 -0
  58. package/src/phaser/display/graphics.js +723 -0
  59. package/src/phaser/display/graphics_data.js +27 -0
  60. package/src/phaser/display/graphics_data_util.js +14 -0
  61. package/src/phaser/display/group.js +227 -0
  62. package/src/phaser/display/image.js +288 -0
  63. package/src/phaser/display/sprite_batch.js +15 -0
  64. package/src/phaser/display/sprite_util.js +248 -0
  65. package/src/phaser/display/text.js +1089 -0
  66. package/src/phaser/display/webgl/abstract_filter.js +25 -0
  67. package/src/phaser/display/webgl/base_texture.js +68 -0
  68. package/src/phaser/display/webgl/blend_manager.js +35 -0
  69. package/src/phaser/display/webgl/earcut.js +647 -0
  70. package/src/phaser/display/webgl/earcut_node.js +28 -0
  71. package/src/phaser/display/webgl/fast_sprite_batch.js +242 -0
  72. package/src/phaser/display/webgl/filter_manager.js +46 -0
  73. package/src/phaser/display/webgl/filter_texture.js +61 -0
  74. package/src/phaser/display/webgl/graphics.js +618 -0
  75. package/src/phaser/display/webgl/graphics_data.js +42 -0
  76. package/src/phaser/display/webgl/mask_manager.js +36 -0
  77. package/src/phaser/display/webgl/render_texture.js +81 -0
  78. package/src/phaser/display/webgl/renderer.js +234 -0
  79. package/src/phaser/display/webgl/shader/complex.js +74 -0
  80. package/src/phaser/display/webgl/shader/fast.js +97 -0
  81. package/src/phaser/display/webgl/shader/normal.js +225 -0
  82. package/src/phaser/display/webgl/shader/primitive.js +72 -0
  83. package/src/phaser/display/webgl/shader/strip.js +77 -0
  84. package/src/phaser/display/webgl/shader_manager.js +89 -0
  85. package/src/phaser/display/webgl/sprite_batch.js +320 -0
  86. package/src/phaser/display/webgl/stencil_manager.js +170 -0
  87. package/src/phaser/display/webgl/texture.js +117 -0
  88. package/src/phaser/display/webgl/texture_util.js +32 -0
  89. package/src/phaser/display/webgl/util.js +74 -0
  90. package/src/phaser/geom/circle.js +186 -0
  91. package/src/phaser/geom/ellipse.js +65 -0
  92. package/src/phaser/geom/line.js +190 -0
  93. package/src/phaser/geom/matrix.js +147 -0
  94. package/src/phaser/geom/point.js +164 -0
  95. package/src/phaser/geom/polygon.js +141 -0
  96. package/src/phaser/geom/rectangle.js +306 -0
  97. package/src/phaser/geom/rounded_rectangle.js +36 -0
  98. package/src/phaser/geom/util/circle.js +115 -0
  99. package/src/phaser/geom/util/ellipse.js +30 -0
  100. package/src/phaser/geom/util/line.js +130 -0
  101. package/src/phaser/geom/util/matrix.js +48 -0
  102. package/src/phaser/geom/util/point.js +276 -0
  103. package/src/phaser/geom/util/polygon.js +24 -0
  104. package/src/phaser/geom/util/rectangle.js +212 -0
  105. package/src/phaser/geom/util/rounded_rectangle.js +28 -0
  106. package/src/phaser/util/math.js +279 -0
  107. package/src/phaser/util/string.js +26 -0
@@ -0,0 +1,164 @@
1
+ /**
2
+ * @author Andras Csizmadia <andras@vpmedia.hu>
3
+ * @author Richard Davey <rich@photonstorm.com>
4
+ * @copyright Copyright (c) 2018-present Richard Davey, Photon Storm Ltd., Andras Csizmadia <andras@vpmedia.hu> (www.vpmedia.hu)
5
+ */
6
+ import { distance, rotate, clone } from './util/point';
7
+ import { GEOM_POINT } from '../core/const';
8
+
9
+ export default class {
10
+
11
+ constructor(x = 0, y = 0) {
12
+ this.x = x;
13
+ this.y = y;
14
+ this.type = GEOM_POINT;
15
+ }
16
+
17
+ copyFrom(source) {
18
+ return this.setTo(source.x, source.y);
19
+ }
20
+
21
+ invert() {
22
+ return this.setTo(this.y, this.x);
23
+ }
24
+
25
+ setTo(x, y) {
26
+ this.x = x || 0;
27
+ this.y = y || ((y !== 0) ? this.x : 0);
28
+ return this;
29
+ }
30
+
31
+ set(x, y) {
32
+ // deprecated, use setTo(x, y)
33
+ this.x = x || 0;
34
+ this.y = y || ((y !== 0) ? this.x : 0);
35
+ return this;
36
+ }
37
+
38
+ add(x, y) {
39
+ this.x += x;
40
+ this.y += y;
41
+ return this;
42
+ }
43
+
44
+ subtract(x, y) {
45
+ this.x -= x;
46
+ this.y -= y;
47
+ return this;
48
+ }
49
+
50
+ multiply(x, y) {
51
+ this.x *= x;
52
+ this.y *= y;
53
+ return this;
54
+ }
55
+
56
+ divide(x, y) {
57
+ this.x /= x;
58
+ this.y /= y;
59
+ return this;
60
+ }
61
+
62
+ clampX(min, max) {
63
+ this.x = Math.max(min, Math.min(max, this.x));
64
+ return this;
65
+ }
66
+
67
+ clampY(min, max) {
68
+ this.y = Math.max(min, Math.min(max, this.y));
69
+ return this;
70
+ }
71
+
72
+ clamp(min, max) {
73
+ this.x = Math.max(min, Math.min(max, this.x));
74
+ this.y = Math.max(min, Math.min(max, this.y));
75
+ return this;
76
+ }
77
+
78
+ clone() {
79
+ return clone(this);
80
+ }
81
+
82
+ copyTo(dest) {
83
+ dest.x = this.x;
84
+ dest.y = this.y;
85
+ return dest;
86
+ }
87
+
88
+ distance(b) {
89
+ return distance(this, b);
90
+ }
91
+
92
+ equals(a) {
93
+ return (a.x === this.x && a.y === this.y);
94
+ }
95
+
96
+ angle(a, asDegrees = false) {
97
+ if (asDegrees) {
98
+ return (180 / Math.PI) * (Math.atan2(a.y - this.y, a.x - this.x));
99
+ }
100
+ return Math.atan2(a.y - this.y, a.x - this.x);
101
+ }
102
+
103
+ rotate(x, y, angle, asDegrees, dist) {
104
+ return rotate(this, x, y, angle, asDegrees, dist);
105
+ }
106
+
107
+ getMagnitude() {
108
+ return Math.sqrt((this.x * this.x) + (this.y * this.y));
109
+ }
110
+
111
+ getMagnitudeSq() {
112
+ return (this.x * this.x) + (this.y * this.y);
113
+ }
114
+
115
+ setMagnitude(magnitude) {
116
+ return this.normalize().multiply(magnitude, magnitude);
117
+ }
118
+
119
+ normalize() {
120
+ if (!this.isZero()) {
121
+ const m = this.getMagnitude();
122
+ this.x /= m;
123
+ this.y /= m;
124
+ }
125
+ return this;
126
+ }
127
+
128
+ isZero() {
129
+ return (this.x === 0 && this.y === 0);
130
+ }
131
+
132
+ dot(a) {
133
+ return ((this.x * a.x) + (this.y * a.y));
134
+ }
135
+
136
+ cross(a) {
137
+ return ((this.x * a.y) - (this.y * a.x));
138
+ }
139
+
140
+ perp() {
141
+ return this.setTo(-this.y, this.x);
142
+ }
143
+
144
+ rperp() {
145
+ return this.setTo(this.y, -this.x);
146
+ }
147
+
148
+ normalRightHand() {
149
+ return this.setTo(this.y * -1, this.x);
150
+ }
151
+
152
+ floor() {
153
+ return this.setTo(Math.floor(this.x), Math.floor(this.y));
154
+ }
155
+
156
+ ceil() {
157
+ return this.setTo(Math.ceil(this.x), Math.ceil(this.y));
158
+ }
159
+
160
+ toString() {
161
+ return '[{Point (x=' + this.x + ' y=' + this.y + ')}]';
162
+ }
163
+
164
+ }
@@ -0,0 +1,141 @@
1
+ /**
2
+ * @author Andras Csizmadia <andras@vpmedia.hu>
3
+ * @author Richard Davey <rich@photonstorm.com>
4
+ * @copyright Copyright (c) 2018-present Richard Davey, Photon Storm Ltd., Andras Csizmadia <andras@vpmedia.hu> (www.vpmedia.hu)
5
+ */
6
+ /* eslint-disable no-cond-assign, no-plusplus */
7
+ import Point from './point';
8
+ import { clone } from './util/polygon';
9
+ import { GEOM_POLYGON } from '../core/const';
10
+
11
+ export default class {
12
+
13
+ constructor(points = null) {
14
+ this.area = 0;
15
+ this._points = [];
16
+ this.closed = true;
17
+ this.flattened = false;
18
+ this.type = GEOM_POLYGON;
19
+ if (points) {
20
+ this.setTo(points);
21
+ }
22
+ }
23
+
24
+ toNumberArray(output = []) {
25
+ for (let i = 0; i < this._points.length; i += 1) {
26
+ if (typeof this._points[i] === 'number') {
27
+ output.push(this._points[i]);
28
+ output.push(this._points[i + 1]);
29
+ i += 1;
30
+ } else {
31
+ output.push(this._points[i].x);
32
+ output.push(this._points[i].y);
33
+ }
34
+ }
35
+ return output;
36
+ }
37
+
38
+ flatten() {
39
+ this._points = this.toNumberArray();
40
+ this.flattened = true;
41
+ return this;
42
+ }
43
+
44
+ clone() {
45
+ return clone(this);
46
+ }
47
+
48
+ contains(x, y) {
49
+ // Adapted from http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html by Jonas Raoni Soares Silva
50
+ let inside = false;
51
+ if (this.flattened) {
52
+ for (let i = -2, j = this._points.length - 2; (i += 2) < this._points.length; j = i) {
53
+ const ix = this._points[i];
54
+ const iy = this._points[i + 1];
55
+ const jx = this._points[j];
56
+ const jy = this._points[j + 1];
57
+ if (((iy <= y && y < jy) || (jy <= y && y < iy)) && (x < (jx - ix) * (y - iy) / (jy - iy) + ix)) {
58
+ inside = !inside;
59
+ }
60
+ }
61
+ } else {
62
+ for (let i = -1, j = this._points.length - 1; ++i < this._points.length; j = i) {
63
+ const ix = this._points[i].x;
64
+ const iy = this._points[i].y;
65
+ const jx = this._points[j].x;
66
+ const jy = this._points[j].y;
67
+ if (((iy <= y && y < jy) || (jy <= y && y < iy)) && (x < (jx - ix) * (y - iy) / (jy - iy) + ix)) {
68
+ inside = !inside;
69
+ }
70
+ }
71
+ }
72
+ return inside;
73
+ }
74
+
75
+ setTo(points) {
76
+ this.area = 0;
77
+ this._points = [];
78
+ if (points) {
79
+ // If points isn't an array, use arguments as the array
80
+ if (!Array.isArray(points)) {
81
+ console.error('[Polygon] setTo() error, input parameter is not an array', points);
82
+ }
83
+ /* if (!Array.isArray(points)) {
84
+ points = Array.prototype.slice.call(arguments);
85
+ } */
86
+ let y0 = Number.MAX_VALUE;
87
+ // Allows for mixed-type arguments
88
+ for (let i = 0, len = points.length; i < len; i += 1) {
89
+ let p;
90
+ if (typeof points[i] === 'number') {
91
+ p = new Point(points[i], points[i + 1]);
92
+ i += 1;
93
+ } else if (Array.isArray(points[i])) {
94
+ p = new Point(points[i][0], points[i][1]);
95
+ } else {
96
+ p = new Point(points[i].x, points[i].y);
97
+ }
98
+ this._points.push(p);
99
+ // Lowest boundary
100
+ if (p.y < y0) {
101
+ y0 = p.y;
102
+ }
103
+ }
104
+ this.calculateArea(y0);
105
+ }
106
+ return this;
107
+ }
108
+
109
+ calculateArea(y0) {
110
+ let p1;
111
+ let p2;
112
+ let avgHeight;
113
+ let width;
114
+ for (let i = 0, len = this._points.length; i < len; i += 1) {
115
+ p1 = this._points[i];
116
+ if (i === len - 1) {
117
+ p2 = this._points[0];
118
+ } else {
119
+ p2 = this._points[i + 1];
120
+ }
121
+ avgHeight = ((p1.y - y0) + (p2.y - y0)) / 2;
122
+ width = p1.x - p2.x;
123
+ this.area += avgHeight * width;
124
+ }
125
+ return this.area;
126
+ }
127
+
128
+ get points() {
129
+ return this._points;
130
+ }
131
+
132
+ set points(value) {
133
+ if (value !== null) {
134
+ this.setTo(value);
135
+ } else {
136
+ this.area = 0;
137
+ this._points = [];
138
+ }
139
+ }
140
+
141
+ }
@@ -0,0 +1,306 @@
1
+ /**
2
+ * @author Andras Csizmadia <andras@vpmedia.hu>
3
+ * @author Richard Davey <rich@photonstorm.com>
4
+ * @copyright Copyright (c) 2018-present Richard Davey, Photon Storm Ltd., Andras Csizmadia <andras@vpmedia.hu> (www.vpmedia.hu)
5
+ */
6
+ import Point from './point';
7
+ import { inflate, size, clone, contains, containsRect, equals, intersects, intersection, intersectsRaw, union } from './util/rectangle';
8
+ import { GEOM_RECTANGLE, TOP_LEFT, TOP_CENTER, TOP_RIGHT, LEFT_CENTER, CENTER, RIGHT_CENTER, BOTTOM_LEFT, BOTTOM_CENTER, BOTTOM_RIGHT } from '../core/const';
9
+
10
+ export default class {
11
+
12
+ constructor(x = 0, y = 0, width = 0, height = 0) {
13
+ this.x = x;
14
+ this.y = y;
15
+ this.width = width;
16
+ this.height = height;
17
+ this.type = GEOM_RECTANGLE;
18
+ }
19
+
20
+ offset(dx, dy) {
21
+ this.x += dx;
22
+ this.y += dy;
23
+ return this;
24
+ }
25
+
26
+ offsetPoint(point) {
27
+ return this.offset(point.x, point.y);
28
+ }
29
+
30
+ setTo(x, y, width, height) {
31
+ this.x = x;
32
+ this.y = y;
33
+ this.width = width;
34
+ this.height = height;
35
+ return this;
36
+ }
37
+
38
+ scale(x, y) {
39
+ if (y === undefined) { y = x; }
40
+ this.width *= x;
41
+ this.height *= y;
42
+ return this;
43
+ }
44
+
45
+ centerOn(x, y) {
46
+ this.centerX = x;
47
+ this.centerY = y;
48
+ return this;
49
+ }
50
+
51
+ floor() {
52
+ this.x = Math.floor(this.x);
53
+ this.y = Math.floor(this.y);
54
+ }
55
+
56
+ floorAll() {
57
+ this.x = Math.floor(this.x);
58
+ this.y = Math.floor(this.y);
59
+ this.width = Math.floor(this.width);
60
+ this.height = Math.floor(this.height);
61
+ }
62
+
63
+ ceil() {
64
+ this.x = Math.ceil(this.x);
65
+ this.y = Math.ceil(this.y);
66
+ }
67
+
68
+ ceilAll() {
69
+ this.x = Math.ceil(this.x);
70
+ this.y = Math.ceil(this.y);
71
+ this.width = Math.ceil(this.width);
72
+ this.height = Math.ceil(this.height);
73
+ }
74
+
75
+ copyFrom(source) {
76
+ return this.setTo(source.x, source.y, source.width, source.height);
77
+ }
78
+
79
+ copyTo(dest) {
80
+ dest.x = this.x;
81
+ dest.y = this.y;
82
+ dest.width = this.width;
83
+ dest.height = this.height;
84
+ return dest;
85
+ }
86
+
87
+ inflate(dx, dy) {
88
+ return inflate(this, dx, dy);
89
+ }
90
+
91
+ size(output) {
92
+ return size(this, output);
93
+ }
94
+
95
+ resize(width, height) {
96
+ this.width = width;
97
+ this.height = height;
98
+ return this;
99
+ }
100
+
101
+ clone(output) {
102
+ return clone(this, output);
103
+ }
104
+
105
+ contains(x, y) {
106
+ return contains(this, x, y);
107
+ }
108
+
109
+ containsRect(b) {
110
+ return containsRect(b, this);
111
+ }
112
+
113
+ equals(b) {
114
+ return equals(this, b);
115
+ }
116
+
117
+ intersection(b, out) {
118
+ return intersection(this, b, out);
119
+ }
120
+
121
+ intersects(b) {
122
+ return intersects(this, b);
123
+ }
124
+
125
+ intersectsRaw(left, right, top, bottom, tolerance) {
126
+ return intersectsRaw(this, left, right, top, bottom, tolerance);
127
+ }
128
+
129
+ union(b, out) {
130
+ return union(this, b, out);
131
+ }
132
+
133
+ random(output = null) {
134
+ const result = output || new Point();
135
+ result.x = this.randomX;
136
+ result.y = this.randomY;
137
+ return result;
138
+ }
139
+
140
+ getPoint(position, output = null) {
141
+ const result = output || new Point();
142
+ switch (position) {
143
+ case TOP_LEFT:
144
+ return result.set(this.x, this.y);
145
+ case TOP_CENTER:
146
+ return result.set(this.centerX, this.y);
147
+ case TOP_RIGHT:
148
+ return result.set(this.right, this.y);
149
+ case LEFT_CENTER:
150
+ return result.set(this.x, this.centerY);
151
+ case CENTER:
152
+ return result.set(this.centerX, this.centerY);
153
+ case RIGHT_CENTER:
154
+ return result.set(this.right, this.centerY);
155
+ case BOTTOM_LEFT:
156
+ return result.set(this.x, this.bottom);
157
+ case BOTTOM_CENTER:
158
+ return result.set(this.centerX, this.bottom);
159
+ case BOTTOM_RIGHT:
160
+ return result.set(this.right, this.bottom);
161
+ default:
162
+ return result.set(this.x, this.y);
163
+ }
164
+ }
165
+
166
+ toString() {
167
+ return '[{Rectangle (x=' + this.x + ' y=' + this.y + ' width=' + this.width + ' height=' + this.height + ' empty=' + this.empty + ')}]';
168
+ }
169
+
170
+ get halfWidth() {
171
+ return Math.round(this.width / 2);
172
+ }
173
+
174
+ get halfHeight() {
175
+ return Math.round(this.height / 2);
176
+ }
177
+
178
+ get top() {
179
+ return this.y;
180
+ }
181
+
182
+ set top(value) {
183
+ if (value >= this.bottom) {
184
+ this.height = 0;
185
+ this.y = value;
186
+ } else {
187
+ this.height = (this.bottom - value);
188
+ }
189
+ }
190
+
191
+ get topLeft() {
192
+ return new Point(this.x, this.y);
193
+ }
194
+
195
+ set topLeft(value) {
196
+ this.x = value.x;
197
+ this.y = value.y;
198
+ }
199
+
200
+ get topRight() {
201
+ return new Point(this.x + this.width, this.y);
202
+ }
203
+
204
+ set topRight(value) {
205
+ this.right = value.x;
206
+ this.y = value.y;
207
+ }
208
+
209
+ get bottom() {
210
+ return this.y + this.height;
211
+ }
212
+
213
+ set bottom(value) {
214
+ if (value <= this.y) {
215
+ this.height = 0;
216
+ } else {
217
+ this.height = value - this.y;
218
+ }
219
+ }
220
+
221
+ get bottomLeft() {
222
+ return new Point(this.x, this.bottom);
223
+ }
224
+
225
+ set bottomLeft(value) {
226
+ this.x = value.x;
227
+ this.bottom = value.y;
228
+ }
229
+
230
+ get bottomRight() {
231
+ return new Point(this.right, this.bottom);
232
+ }
233
+
234
+ set bottomRight(value) {
235
+ this.right = value.x;
236
+ this.bottom = value.y;
237
+ }
238
+
239
+ get left() {
240
+ return this.x;
241
+ }
242
+
243
+ set left(value) {
244
+ if (value >= this.right) {
245
+ this.width = 0;
246
+ } else {
247
+ this.width = this.right - value;
248
+ }
249
+ this.x = value;
250
+ }
251
+
252
+ get right() {
253
+ return this.x + this.width;
254
+ }
255
+
256
+ set right(value) {
257
+ if (value <= this.x) {
258
+ this.width = 0;
259
+ } else {
260
+ this.width = value - this.x;
261
+ }
262
+ }
263
+
264
+ get volume() {
265
+ return this.width * this.height;
266
+ }
267
+
268
+ get perimeter() {
269
+ return (this.width * 2) + (this.height * 2);
270
+ }
271
+
272
+ get centerX() {
273
+ return this.x + this.halfWidth;
274
+ }
275
+
276
+ set centerX(value) {
277
+ this.x = value - this.halfWidth;
278
+ }
279
+
280
+ get centerY() {
281
+ return this.y + this.halfHeight;
282
+ }
283
+
284
+ set centerY(value) {
285
+ this.y = value - this.halfHeight;
286
+ }
287
+
288
+ get randomX() {
289
+ return this.x + (Math.random() * this.width);
290
+ }
291
+
292
+ get randomY() {
293
+ return this.y + (Math.random() * this.height);
294
+ }
295
+
296
+ get empty() {
297
+ return !this.width || !this.height;
298
+ }
299
+
300
+ set empty(value) {
301
+ if (value === true) {
302
+ this.setTo(0, 0, 0, 0);
303
+ }
304
+ }
305
+
306
+ }
@@ -0,0 +1,36 @@
1
+ /**
2
+ * @author Andras Csizmadia <andras@vpmedia.hu>
3
+ * @author Richard Davey <rich@photonstorm.com>
4
+ * @copyright Copyright (c) 2018-present Richard Davey, Photon Storm Ltd., Andras Csizmadia <andras@vpmedia.hu> (www.vpmedia.hu)
5
+ */
6
+ import { clone } from './util/rounded_rectangle';
7
+ import { GEOM_ROUNDED_RECTANGLE } from '../core/const';
8
+
9
+ export default class {
10
+
11
+ constructor(x = 0, y = 0, width = 0, height = 0, radius = 20) {
12
+ this.x = x;
13
+ this.y = y;
14
+ this.width = width;
15
+ this.height = height;
16
+ this.radius = radius;
17
+ this.type = GEOM_ROUNDED_RECTANGLE;
18
+ }
19
+
20
+ contains(x, y) {
21
+ if (this.width <= 0 || this.height <= 0) {
22
+ return false;
23
+ }
24
+ if (x >= this.x && x <= this.x + this.width) {
25
+ if (y >= this.y && y <= this.y + this.height) {
26
+ return true;
27
+ }
28
+ }
29
+ return false;
30
+ }
31
+
32
+ clone() {
33
+ return clone(this);
34
+ }
35
+
36
+ }