melonjs 14.0.2 → 14.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/dist/melonjs.mjs/_virtual/_commonjsHelpers.js +10 -0
- package/dist/melonjs.mjs/_virtual/arraymultimap.js +10 -0
- package/dist/melonjs.mjs/_virtual/earcut.js +10 -0
- package/dist/melonjs.mjs/_virtual/howler.js +10 -0
- package/dist/melonjs.mjs/_virtual/index.js +10 -0
- package/dist/melonjs.mjs/_virtual/index2.js +10 -0
- package/dist/melonjs.mjs/_virtual/multimap.js +10 -0
- package/dist/melonjs.mjs/_virtual/setmultimap.js +10 -0
- package/dist/melonjs.mjs/application/application.js +240 -0
- package/dist/melonjs.mjs/audio/audio.js +536 -0
- package/dist/melonjs.mjs/camera/camera2d.js +732 -0
- package/dist/melonjs.mjs/entity/entity.js +248 -0
- package/dist/melonjs.mjs/game.js +29 -0
- package/dist/melonjs.mjs/geometries/ellipse.js +275 -0
- package/dist/melonjs.mjs/geometries/line.js +116 -0
- package/dist/melonjs.mjs/geometries/path2d.js +319 -0
- package/dist/melonjs.mjs/geometries/point.js +89 -0
- package/dist/melonjs.mjs/geometries/poly.js +500 -0
- package/dist/melonjs.mjs/geometries/rectangle.js +375 -0
- package/dist/melonjs.mjs/geometries/roundrect.js +168 -0
- package/dist/melonjs.mjs/index.js +248 -0
- package/dist/melonjs.mjs/input/gamepad.js +501 -0
- package/dist/melonjs.mjs/input/input.js +26 -0
- package/dist/melonjs.mjs/input/keyboard.js +470 -0
- package/dist/melonjs.mjs/input/pointer.js +393 -0
- package/dist/melonjs.mjs/input/pointerevent.js +818 -0
- package/dist/melonjs.mjs/lang/deprecated.js +157 -0
- package/dist/melonjs.mjs/level/level.js +297 -0
- package/dist/melonjs.mjs/level/tiled/TMXGroup.js +141 -0
- package/dist/melonjs.mjs/level/tiled/TMXLayer.js +448 -0
- package/dist/melonjs.mjs/level/tiled/TMXObject.js +355 -0
- package/dist/melonjs.mjs/level/tiled/TMXTile.js +194 -0
- package/dist/melonjs.mjs/level/tiled/TMXTileMap.js +639 -0
- package/dist/melonjs.mjs/level/tiled/TMXTileset.js +311 -0
- package/dist/melonjs.mjs/level/tiled/TMXTilesetGroup.js +83 -0
- package/dist/melonjs.mjs/level/tiled/TMXUtils.js +367 -0
- package/dist/melonjs.mjs/level/tiled/renderer/TMXHexagonalRenderer.js +506 -0
- package/dist/melonjs.mjs/level/tiled/renderer/TMXIsometricRenderer.js +220 -0
- package/dist/melonjs.mjs/level/tiled/renderer/TMXOrthogonalRenderer.js +157 -0
- package/dist/melonjs.mjs/level/tiled/renderer/TMXRenderer.js +125 -0
- package/dist/melonjs.mjs/level/tiled/renderer/TMXStaggeredRenderer.js +109 -0
- package/dist/melonjs.mjs/loader/loader.js +801 -0
- package/dist/melonjs.mjs/loader/loadingscreen.js +120 -0
- package/dist/melonjs.mjs/loader/melonjs_logo.png.js +11 -0
- package/dist/melonjs.mjs/math/color.js +618 -0
- package/dist/melonjs.mjs/math/math.js +218 -0
- package/dist/melonjs.mjs/math/matrix2.js +503 -0
- package/dist/melonjs.mjs/math/matrix3.js +681 -0
- package/dist/melonjs.mjs/math/observable_vector2.js +471 -0
- package/dist/melonjs.mjs/math/observable_vector3.js +561 -0
- package/dist/melonjs.mjs/math/vector2.js +528 -0
- package/dist/melonjs.mjs/math/vector3.js +569 -0
- package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/arraymultimap.js +73 -0
- package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/index.js +21 -0
- package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/multimap.js +324 -0
- package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/setmultimap.js +69 -0
- package/dist/melonjs.mjs/node_modules/earcut/src/earcut.js +691 -0
- package/dist/melonjs.mjs/node_modules/eventemitter3/index.js +350 -0
- package/dist/melonjs.mjs/node_modules/howler/dist/howler.js +3241 -0
- package/dist/melonjs.mjs/particles/emitter.js +267 -0
- package/dist/melonjs.mjs/particles/particle.js +188 -0
- package/dist/melonjs.mjs/particles/settings.js +319 -0
- package/dist/melonjs.mjs/physics/body.js +704 -0
- package/dist/melonjs.mjs/physics/bounds.js +460 -0
- package/dist/melonjs.mjs/physics/collision.js +132 -0
- package/dist/melonjs.mjs/physics/detector.js +194 -0
- package/dist/melonjs.mjs/physics/quadtree.js +391 -0
- package/dist/melonjs.mjs/physics/response.js +57 -0
- package/dist/melonjs.mjs/physics/sat.js +483 -0
- package/dist/melonjs.mjs/physics/world.js +221 -0
- package/dist/melonjs.mjs/plugin/plugin.js +141 -0
- package/dist/melonjs.mjs/renderable/collectable.js +62 -0
- package/dist/melonjs.mjs/renderable/colorlayer.js +80 -0
- package/dist/melonjs.mjs/renderable/container.js +1018 -0
- package/dist/melonjs.mjs/renderable/dragndrop.js +224 -0
- package/dist/melonjs.mjs/renderable/imagelayer.js +306 -0
- package/dist/melonjs.mjs/renderable/light2d.js +156 -0
- package/dist/melonjs.mjs/renderable/nineslicesprite.js +247 -0
- package/dist/melonjs.mjs/renderable/renderable.js +783 -0
- package/dist/melonjs.mjs/renderable/sprite.js +654 -0
- package/dist/melonjs.mjs/renderable/trigger.js +157 -0
- package/dist/melonjs.mjs/renderable/ui/uibaseelement.js +213 -0
- package/dist/melonjs.mjs/renderable/ui/uispriteelement.js +226 -0
- package/dist/melonjs.mjs/renderable/ui/uitextbutton.js +128 -0
- package/dist/melonjs.mjs/state/stage.js +237 -0
- package/dist/melonjs.mjs/state/state.js +596 -0
- package/dist/melonjs.mjs/system/device.js +909 -0
- package/dist/melonjs.mjs/system/dom.js +78 -0
- package/dist/melonjs.mjs/system/event.js +537 -0
- package/dist/melonjs.mjs/system/platform.js +41 -0
- package/dist/melonjs.mjs/system/pooling.js +209 -0
- package/dist/melonjs.mjs/system/save.js +157 -0
- package/dist/melonjs.mjs/system/timer.js +286 -0
- package/dist/melonjs.mjs/text/bitmaptext.js +364 -0
- package/dist/melonjs.mjs/text/bitmaptextdata.js +199 -0
- package/dist/melonjs.mjs/text/glyph.js +66 -0
- package/dist/melonjs.mjs/text/text.js +453 -0
- package/dist/melonjs.mjs/text/textmetrics.js +176 -0
- package/dist/melonjs.mjs/text/textstyle.js +23 -0
- package/dist/melonjs.mjs/tweens/easing.js +336 -0
- package/dist/melonjs.mjs/tweens/interpolation.js +112 -0
- package/dist/melonjs.mjs/tweens/tween.js +480 -0
- package/dist/melonjs.mjs/utils/agent.js +76 -0
- package/dist/melonjs.mjs/utils/array.js +63 -0
- package/dist/melonjs.mjs/utils/file.js +42 -0
- package/dist/melonjs.mjs/utils/function.js +70 -0
- package/dist/melonjs.mjs/utils/string.js +82 -0
- package/dist/melonjs.mjs/utils/utils.js +173 -0
- package/dist/melonjs.mjs/video/canvas/canvas_renderer.js +807 -0
- package/dist/melonjs.mjs/video/renderer.js +411 -0
- package/dist/melonjs.mjs/video/texture/atlas.js +519 -0
- package/dist/melonjs.mjs/video/texture/cache.js +143 -0
- package/dist/melonjs.mjs/video/texture/canvas_texture.js +144 -0
- package/dist/melonjs.mjs/video/video.js +462 -0
- package/dist/melonjs.mjs/video/webgl/buffer/vertex.js +143 -0
- package/dist/melonjs.mjs/video/webgl/glshader.js +168 -0
- package/dist/melonjs.mjs/video/webgl/shaders/primitive.frag.js +10 -0
- package/dist/melonjs.mjs/video/webgl/shaders/primitive.vert.js +10 -0
- package/dist/melonjs.mjs/video/webgl/shaders/quad.frag.js +10 -0
- package/dist/melonjs.mjs/video/webgl/shaders/quad.vert.js +10 -0
- package/dist/melonjs.mjs/video/webgl/utils/attributes.js +25 -0
- package/dist/melonjs.mjs/video/webgl/utils/precision.js +20 -0
- package/dist/melonjs.mjs/video/webgl/utils/program.js +67 -0
- package/dist/melonjs.mjs/video/webgl/utils/string.js +25 -0
- package/dist/melonjs.mjs/video/webgl/utils/uniforms.js +92 -0
- package/dist/melonjs.mjs/video/webgl/webgl_compositor.js +495 -0
- package/dist/melonjs.mjs/video/webgl/webgl_renderer.js +1036 -0
- package/dist/melonjs.module.d.ts +1163 -1163
- package/dist/melonjs.module.js +1903 -3274
- package/package.json +22 -17
- package/src/application/application.js +3 -3
- package/src/audio/audio.js +32 -32
- package/src/camera/camera2d.js +31 -31
- package/src/entity/entity.js +17 -17
- package/src/geometries/ellipse.js +16 -16
- package/src/geometries/line.js +5 -5
- package/src/geometries/path2d.js +32 -32
- package/src/geometries/poly.js +15 -15
- package/src/geometries/rectangle.js +18 -18
- package/src/geometries/roundrect.js +8 -8
- package/src/input/gamepad.js +15 -15
- package/src/input/keyboard.js +12 -12
- package/src/input/pointer.js +6 -6
- package/src/input/pointerevent.js +12 -12
- package/src/lang/deprecated.js +12 -12
- package/src/level/level.js +25 -25
- package/src/level/tiled/TMXLayer.js +22 -22
- package/src/level/tiled/TMXTile.js +5 -5
- package/src/level/tiled/TMXTileMap.js +6 -6
- package/src/level/tiled/TMXTileset.js +2 -2
- package/src/level/tiled/TMXUtils.js +5 -5
- package/src/level/tiled/renderer/TMXHexagonalRenderer.js +2 -2
- package/src/level/tiled/renderer/TMXIsometricRenderer.js +2 -2
- package/src/level/tiled/renderer/TMXOrthogonalRenderer.js +1 -1
- package/src/level/tiled/renderer/TMXRenderer.js +19 -19
- package/src/loader/loader.js +20 -20
- package/src/math/color.js +20 -20
- package/src/math/math.js +16 -16
- package/src/math/matrix2.js +16 -16
- package/src/math/matrix3.js +25 -25
- package/src/math/observable_vector2.js +14 -14
- package/src/math/observable_vector3.js +16 -16
- package/src/math/vector2.js +9 -9
- package/src/math/vector3.js +10 -10
- package/src/particles/emitter.js +6 -6
- package/src/particles/particle.js +2 -2
- package/src/physics/body.js +28 -28
- package/src/physics/bounds.js +8 -8
- package/src/physics/collision.js +2 -2
- package/src/physics/detector.js +6 -6
- package/src/physics/quadtree.js +11 -11
- package/src/physics/sat.js +31 -31
- package/src/physics/world.js +5 -5
- package/src/plugin/plugin.js +5 -5
- package/src/renderable/collectable.js +3 -3
- package/src/renderable/colorlayer.js +5 -5
- package/src/renderable/container.js +21 -21
- package/src/renderable/dragndrop.js +14 -14
- package/src/renderable/imagelayer.js +13 -13
- package/src/renderable/light2d.js +3 -3
- package/src/renderable/nineslicesprite.js +16 -16
- package/src/renderable/renderable.js +23 -23
- package/src/renderable/sprite.js +28 -28
- package/src/renderable/trigger.js +15 -15
- package/src/renderable/ui/uibaseelement.js +7 -7
- package/src/renderable/ui/uispriteelement.js +6 -6
- package/src/renderable/ui/uitextbutton.js +13 -13
- package/src/state/stage.js +7 -7
- package/src/state/state.js +17 -17
- package/src/system/device.js +11 -11
- package/src/system/event.js +10 -10
- package/src/system/pooling.js +9 -9
- package/src/system/save.js +2 -2
- package/src/system/timer.js +10 -10
- package/src/text/bitmaptext.js +18 -18
- package/src/text/bitmaptextdata.js +2 -2
- package/src/text/text.js +23 -23
- package/src/text/textmetrics.js +8 -8
- package/src/tweens/tween.js +19 -19
- package/src/utils/agent.js +5 -5
- package/src/utils/array.js +4 -4
- package/src/utils/file.js +2 -2
- package/src/utils/function.js +6 -6
- package/src/utils/string.js +5 -5
- package/src/utils/utils.js +4 -4
- package/src/video/canvas/canvas_renderer.js +70 -70
- package/src/video/renderer.js +26 -26
- package/src/video/texture/atlas.js +22 -22
- package/src/video/texture/canvas_texture.js +9 -9
- package/src/video/video.js +17 -17
- package/src/video/webgl/glshader.js +10 -10
- package/src/video/webgl/webgl_compositor.js +41 -41
- package/src/video/webgl/webgl_renderer.js +75 -75
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* melonJS Game Engine - v14.1.0
|
|
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
|
+
var Entity$1 = Entity;
|
|
247
|
+
|
|
248
|
+
export { Entity$1 as default };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* melonJS Game Engine - v14.1.0
|
|
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,275 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* melonJS Game Engine - v14.1.0
|
|
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
|
+
var Ellipse$1 = Ellipse;
|
|
274
|
+
|
|
275
|
+
export { Ellipse$1 as default };
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* melonJS Game Engine - v14.1.0
|
|
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
|
+
var Line$1 = Line;
|
|
115
|
+
|
|
116
|
+
export { Line$1 as default };
|