littlejsengine 1.6.6 → 1.6.92
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 +51 -35
- package/build/littlejs.d.ts +71 -80
- package/build/littlejs.esm.js +162 -139
- package/build/littlejs.esm.min.js +1 -1
- package/build/littlejs.js +159 -129
- package/build/littlejs.min.js +1 -1
- package/build/littlejs.release.js +1942 -1907
- package/examples/breakout/game.js +5 -1
- package/examples/breakout/index.html +5 -5
- package/examples/breakoutTutorial/README.md +6 -6
- package/examples/breakoutTutorial/game.js +3 -0
- package/examples/breakoutTutorial/index.html +3 -3
- package/examples/electron/build.js +105 -0
- package/examples/electron/game.js +4 -2
- package/examples/electron/index.html +13 -2
- package/examples/electron/package.json +5 -3
- package/examples/empty/game.js +3 -1
- package/examples/empty/index.html +1 -1
- package/examples/js13k/build.bat +2 -0
- package/examples/js13k/build.js +110 -0
- package/examples/js13k/game.js +109 -0
- package/examples/js13k/index.html +18 -0
- package/examples/js13k/tiles.png +0 -0
- package/examples/module/game.js +9 -3
- package/examples/module/index.html +2 -2
- package/examples/particles/index.html +7 -13
- package/examples/platformer/game.js +5 -2
- package/examples/platformer/gameEffects.js +1 -2
- package/examples/platformer/gamePlayer.js +2 -2
- package/examples/platformer/index.html +8 -8
- package/examples/puzzle/game.js +5 -3
- package/examples/puzzle/index.html +4 -4
- package/examples/starter/build.bat +2 -78
- package/examples/starter/build.js +109 -0
- package/examples/starter/game.js +4 -1
- package/examples/starter/index.html +15 -18
- package/examples/stress/index.html +2 -4
- package/examples/typescript/build.bat +2 -14
- package/examples/typescript/build.js +31 -0
- package/examples/typescript/game.js +94 -89
- package/examples/typescript/game.ts +9 -3
- package/examples/typescript/index.html +2 -2
- package/package.json +2 -2
- package/src/engine.js +3 -3
- package/src/engineAudio.js +2 -2
- package/src/engineBuild.bat +2 -132
- package/src/engineBuild.js +143 -0
- package/src/engineDebug.js +4 -10
- package/src/engineDraw.js +12 -4
- package/src/engineExport.js +1 -8
- package/src/engineInput.js +1 -1
- package/src/engineObject.js +13 -11
- package/src/engineParticles.js +6 -6
- package/src/engineRelease.js +0 -1
- package/src/engineTileLayer.js +31 -18
- package/src/engineUtilities.js +74 -61
- package/examples/electron/build.bat +0 -52
package/src/engineTileLayer.js
CHANGED
|
@@ -67,12 +67,12 @@ function tileCollisionTest(pos, size=vec2(), object)
|
|
|
67
67
|
for (let x = minX; x < maxX; ++x)
|
|
68
68
|
{
|
|
69
69
|
const tileData = tileCollision[y*tileCollisionSize.x+x];
|
|
70
|
-
if (tileData && (!object || object.collideWithTile(tileData,
|
|
70
|
+
if (tileData && (!object || object.collideWithTile(tileData, vec2(x, y))))
|
|
71
71
|
return 1;
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
-
/** Return the center of tile if any that is hit (
|
|
75
|
+
/** Return the center of tile if any that is hit (does not return the exact intersection)
|
|
76
76
|
* @param {Vector2} posStart
|
|
77
77
|
* @param {Vector2} posEnd
|
|
78
78
|
* @param {EngineObject} [object]
|
|
@@ -81,28 +81,41 @@ function tileCollisionTest(pos, size=vec2(), object)
|
|
|
81
81
|
function tileCollisionRaycast(posStart, posEnd, object)
|
|
82
82
|
{
|
|
83
83
|
// test if a ray collides with tiles from start to end
|
|
84
|
-
// todo: a way to get the exact hit point, it must still
|
|
85
|
-
const
|
|
86
|
-
const
|
|
87
|
-
const
|
|
84
|
+
// todo: a way to get the exact hit point, it must still be inside the hit tile
|
|
85
|
+
const delta = posEnd.subtract(posStart);
|
|
86
|
+
const totalLength = delta.length();
|
|
87
|
+
const normalizedDelta = delta.normalize();
|
|
88
|
+
const unit = vec2(abs(1/normalizedDelta.x), abs(1/normalizedDelta.y));
|
|
89
|
+
const flooredPosStart = posStart.floor();
|
|
88
90
|
|
|
89
|
-
|
|
91
|
+
// setup iteration variables
|
|
92
|
+
let pos = flooredPosStart;
|
|
93
|
+
let xi = unit.x * (delta.x < 0 ? posStart.x - pos.x : pos.x - posStart.x + 1);
|
|
94
|
+
let yi = unit.y * (delta.y < 0 ? posStart.y - pos.y : pos.y - posStart.y + 1);
|
|
95
|
+
|
|
96
|
+
while (1)
|
|
90
97
|
{
|
|
91
|
-
|
|
92
|
-
|
|
98
|
+
// check for tile collision
|
|
99
|
+
const tileData = getTileCollisionData(pos);
|
|
100
|
+
if (tileData && (!object || object.collideWithTile(tileData, pos)))
|
|
93
101
|
{
|
|
94
|
-
debugRaycast && debugLine(posStart, posEnd, '#f00'
|
|
95
|
-
debugRaycast && debugPoint(
|
|
96
|
-
return
|
|
102
|
+
debugRaycast && debugLine(posStart, posEnd, '#f00', .02);
|
|
103
|
+
debugRaycast && debugPoint(pos.add(vec2(.5)), '#ff0');
|
|
104
|
+
return pos.add(vec2(.5));
|
|
97
105
|
}
|
|
98
106
|
|
|
99
|
-
//
|
|
100
|
-
if (
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
107
|
+
// check if past the end
|
|
108
|
+
if (xi > totalLength && yi > totalLength)
|
|
109
|
+
break;
|
|
110
|
+
|
|
111
|
+
// get coordinates of the next tile to check
|
|
112
|
+
if (xi > yi)
|
|
113
|
+
pos.y += sign(delta.y), yi += unit.y;
|
|
114
|
+
else
|
|
115
|
+
pos.x += sign(delta.x), xi += unit.x;
|
|
104
116
|
}
|
|
105
|
-
|
|
117
|
+
|
|
118
|
+
debugRaycast && debugLine(posStart, posEnd, '#00f', .02);
|
|
106
119
|
}
|
|
107
120
|
|
|
108
121
|
///////////////////////////////////////////////////////////////////////////////
|
package/src/engineUtilities.js
CHANGED
|
@@ -19,34 +19,34 @@ const PI = Math.PI;
|
|
|
19
19
|
* @param {Number} value
|
|
20
20
|
* @return {Number}
|
|
21
21
|
* @memberof Utilities */
|
|
22
|
-
function abs(
|
|
22
|
+
function abs(value) { return Math.abs(value); }
|
|
23
23
|
|
|
24
24
|
/** Returns lowest of two values passed in
|
|
25
25
|
* @param {Number} valueA
|
|
26
26
|
* @param {Number} valueB
|
|
27
27
|
* @return {Number}
|
|
28
28
|
* @memberof Utilities */
|
|
29
|
-
function min(
|
|
29
|
+
function min(valueA, valueB) { return Math.min(valueA, valueB); }
|
|
30
30
|
|
|
31
31
|
/** Returns highest of two values passed in
|
|
32
32
|
* @param {Number} valueA
|
|
33
33
|
* @param {Number} valueB
|
|
34
34
|
* @return {Number}
|
|
35
35
|
* @memberof Utilities */
|
|
36
|
-
function max(
|
|
36
|
+
function max(valueA, valueB) { return Math.max(valueA, valueB); }
|
|
37
37
|
|
|
38
38
|
/** Returns the sign of value passed in (also returns 1 if 0)
|
|
39
39
|
* @param {Number} value
|
|
40
40
|
* @return {Number}
|
|
41
41
|
* @memberof Utilities */
|
|
42
|
-
function sign(
|
|
42
|
+
function sign(value) { return Math.sign(value); }
|
|
43
43
|
|
|
44
44
|
/** Returns first parm modulo the second param, but adjusted so negative numbers work as expected
|
|
45
45
|
* @param {Number} dividend
|
|
46
46
|
* @param {Number} [divisor=1]
|
|
47
47
|
* @return {Number}
|
|
48
48
|
* @memberof Utilities */
|
|
49
|
-
function mod(
|
|
49
|
+
function mod(dividend, divisor=1) { return ((dividend % divisor) + divisor) % divisor; }
|
|
50
50
|
|
|
51
51
|
/** Clamps the value beween max and min
|
|
52
52
|
* @param {Number} value
|
|
@@ -54,8 +54,8 @@ function mod(a, b=1) { return ((a % b) + b) % b; }
|
|
|
54
54
|
* @param {Number} [max=1]
|
|
55
55
|
* @return {Number}
|
|
56
56
|
* @memberof Utilities */
|
|
57
|
-
function clamp(
|
|
58
|
-
{ return
|
|
57
|
+
function clamp(value, min=0, max=1)
|
|
58
|
+
{ return value < min ? min : value > max ? max : value; }
|
|
59
59
|
|
|
60
60
|
/** Returns what percentage the value is between max and min
|
|
61
61
|
* @param {Number} value
|
|
@@ -63,8 +63,8 @@ function clamp(v, min=0, max=1)
|
|
|
63
63
|
* @param {Number} [max=1]
|
|
64
64
|
* @return {Number}
|
|
65
65
|
* @memberof Utilities */
|
|
66
|
-
function percent(
|
|
67
|
-
{ return max-min ? clamp((
|
|
66
|
+
function percent(value, min=0, max=1)
|
|
67
|
+
{ return max-min ? clamp((value-min) / (max-min)) : 0; }
|
|
68
68
|
|
|
69
69
|
/** Linearly interpolates the percent value between max and min
|
|
70
70
|
* @param {Number} percent
|
|
@@ -72,29 +72,32 @@ function percent(v, min=0, max=1)
|
|
|
72
72
|
* @param {Number} [max=1]
|
|
73
73
|
* @return {Number}
|
|
74
74
|
* @memberof Utilities */
|
|
75
|
-
function lerp(
|
|
75
|
+
function lerp(percent, min=0, max=1){ return min + clamp(percent) * (max-min); }
|
|
76
76
|
|
|
77
77
|
/** Applies smoothstep function to the percentage value
|
|
78
|
-
* @param {Number}
|
|
78
|
+
* @param {Number} percent
|
|
79
79
|
* @return {Number}
|
|
80
80
|
* @memberof Utilities */
|
|
81
|
-
function smoothStep(
|
|
81
|
+
function smoothStep(percent) { return percent * percent * (3 - 2 * percent); }
|
|
82
82
|
|
|
83
83
|
/** Returns the nearest power of two not less then the value
|
|
84
84
|
* @param {Number} value
|
|
85
85
|
* @return {Number}
|
|
86
86
|
* @memberof Utilities */
|
|
87
|
-
function nearestPowerOfTwo(
|
|
87
|
+
function nearestPowerOfTwo(value) { return 2**Math.ceil(Math.log2(value)); }
|
|
88
88
|
|
|
89
89
|
/** Returns true if two axis aligned bounding boxes are overlapping
|
|
90
90
|
* @param {Vector2} pointA - Center of box A
|
|
91
91
|
* @param {Vector2} sizeA - Size of box A
|
|
92
92
|
* @param {Vector2} pointB - Center of box B
|
|
93
|
-
* @param {Vector2}
|
|
93
|
+
* @param {Vector2} sizeB - Size of box B
|
|
94
94
|
* @return {Boolean} - True if overlapping
|
|
95
95
|
* @memberof Utilities */
|
|
96
|
-
function isOverlapping(
|
|
97
|
-
{
|
|
96
|
+
function isOverlapping(pointA, sizeA, pointB, sizeB)
|
|
97
|
+
{
|
|
98
|
+
return abs(pointA.x - pointB.x)*2 < sizeA.x + sizeB.x
|
|
99
|
+
&& abs(pointA.y - pointB.y)*2 < sizeA.y + sizeB.y;
|
|
100
|
+
}
|
|
98
101
|
|
|
99
102
|
/** Returns an oscillating wave between 0 and amplitude with frequency of 1 Hz by default
|
|
100
103
|
* @param {Number} [frequency=1] - Frequency of the wave in Hz
|
|
@@ -121,14 +124,14 @@ function formatTime(t) { return (t/60|0) + ':' + (t%60<10?'0':'') + (t%60|0); }
|
|
|
121
124
|
* @param {Number} [valueB=0]
|
|
122
125
|
* @return {Number}
|
|
123
126
|
* @memberof Random */
|
|
124
|
-
function rand(
|
|
127
|
+
function rand(valueA=1, valueB=0) { return valueB + Math.random() * (valueA-valueB); }
|
|
125
128
|
|
|
126
129
|
/** Returns a floored random value the two values passed in
|
|
127
130
|
* @param {Number} [valueA=1]
|
|
128
131
|
* @param {Number} [valueB=0]
|
|
129
132
|
* @return {Number}
|
|
130
133
|
* @memberof Random */
|
|
131
|
-
function randInt(
|
|
134
|
+
function randInt(valueA=1, valueB=0) { return Math.floor(rand(valueA,valueB)); }
|
|
132
135
|
|
|
133
136
|
/** Randomly returns either -1 or 1
|
|
134
137
|
* @return {Number}
|
|
@@ -155,8 +158,11 @@ function randVector(length=1) { return new Vector2().setAngle(rand(2*PI), length
|
|
|
155
158
|
* @param {Boolean} [linear]
|
|
156
159
|
* @return {Color}
|
|
157
160
|
* @memberof Random */
|
|
158
|
-
function randColor(
|
|
159
|
-
{
|
|
161
|
+
function randColor(colorA=new Color, colorB=new Color(0,0,0,1), linear)
|
|
162
|
+
{
|
|
163
|
+
return linear ? colorA.lerp(colorB, rand()) :
|
|
164
|
+
new Color(rand(colorA.r,colorB.r), rand(colorA.g,colorB.g), rand(colorA.b,colorB.b), rand(colorA.a,colorB.a));
|
|
165
|
+
}
|
|
160
166
|
|
|
161
167
|
/** Seed used by the randSeeded function
|
|
162
168
|
* @type {Number}
|
|
@@ -174,13 +180,13 @@ function setRandSeed(seed) { randSeed = seed; }
|
|
|
174
180
|
* @param {Number} [valueB=0]
|
|
175
181
|
* @return {Number}
|
|
176
182
|
* @memberof Random */
|
|
177
|
-
function randSeeded(
|
|
183
|
+
function randSeeded(valueA=1, valueB=0)
|
|
178
184
|
{
|
|
179
185
|
// xorshift algorithm
|
|
180
186
|
randSeed ^= randSeed << 13;
|
|
181
187
|
randSeed ^= randSeed >>> 17;
|
|
182
188
|
randSeed ^= randSeed << 5;
|
|
183
|
-
return
|
|
189
|
+
return valueB + (valueA-valueB) * abs(randSeed % 1e9) / 1e9;
|
|
184
190
|
}
|
|
185
191
|
|
|
186
192
|
///////////////////////////////////////////////////////////////////////////////
|
|
@@ -202,7 +208,7 @@ function vec2(x=0, y)
|
|
|
202
208
|
|
|
203
209
|
/**
|
|
204
210
|
* Check if object is a valid Vector2
|
|
205
|
-
* @param {Vector2}
|
|
211
|
+
* @param {Vector2} v
|
|
206
212
|
* @return {Boolean}
|
|
207
213
|
* @memberof Utilities
|
|
208
214
|
*/
|
|
@@ -235,27 +241,27 @@ class Vector2
|
|
|
235
241
|
copy() { return new Vector2(this.x, this.y); }
|
|
236
242
|
|
|
237
243
|
/** Returns a copy of this vector plus the vector passed in
|
|
238
|
-
* @param {Vector2} vector
|
|
244
|
+
* @param {Vector2} v - other vector
|
|
239
245
|
* @return {Vector2} */
|
|
240
246
|
add(v) { ASSERT(isVector2(v)); return new Vector2(this.x + v.x, this.y + v.y); }
|
|
241
247
|
|
|
242
248
|
/** Returns a copy of this vector minus the vector passed in
|
|
243
|
-
* @param {Vector2} vector
|
|
249
|
+
* @param {Vector2} v - other vector
|
|
244
250
|
* @return {Vector2} */
|
|
245
251
|
subtract(v) { ASSERT(isVector2(v)); return new Vector2(this.x - v.x, this.y - v.y); }
|
|
246
252
|
|
|
247
253
|
/** Returns a copy of this vector times the vector passed in
|
|
248
|
-
* @param {Vector2} vector
|
|
254
|
+
* @param {Vector2} v - other vector
|
|
249
255
|
* @return {Vector2} */
|
|
250
256
|
multiply(v) { ASSERT(isVector2(v)); return new Vector2(this.x * v.x, this.y * v.y); }
|
|
251
257
|
|
|
252
258
|
/** Returns a copy of this vector divided by the vector passed in
|
|
253
|
-
* @param {Vector2} vector
|
|
259
|
+
* @param {Vector2} v - other vector
|
|
254
260
|
* @return {Vector2} */
|
|
255
261
|
divide(v) { ASSERT(isVector2(v)); return new Vector2(this.x / v.x, this.y / v.y); }
|
|
256
262
|
|
|
257
263
|
/** Returns a copy of this vector scaled by the vector passed in
|
|
258
|
-
* @param {Number} scale
|
|
264
|
+
* @param {Number} s - scale
|
|
259
265
|
* @return {Vector2} */
|
|
260
266
|
scale(s) { ASSERT(!isVector2(s)); return new Vector2(this.x * s, this.y * s); }
|
|
261
267
|
|
|
@@ -268,12 +274,12 @@ class Vector2
|
|
|
268
274
|
lengthSquared() { return this.x**2 + this.y**2; }
|
|
269
275
|
|
|
270
276
|
/** Returns the distance from this vector to vector passed in
|
|
271
|
-
* @param {Vector2} vector
|
|
277
|
+
* @param {Vector2} v - other vector
|
|
272
278
|
* @return {Number} */
|
|
273
279
|
distance(v) { return this.distanceSquared(v)**.5; }
|
|
274
280
|
|
|
275
281
|
/** Returns the distance squared from this vector to vector passed in
|
|
276
|
-
* @param {Vector2} vector
|
|
282
|
+
* @param {Vector2} v - other vector
|
|
277
283
|
* @return {Number} */
|
|
278
284
|
distanceSquared(v) { return (this.x - v.x)**2 + (this.y - v.y)**2; }
|
|
279
285
|
|
|
@@ -288,12 +294,12 @@ class Vector2
|
|
|
288
294
|
clampLength(length=1) { const l = this.length(); return l > length ? this.scale(length/l) : this; }
|
|
289
295
|
|
|
290
296
|
/** Returns the dot product of this and the vector passed in
|
|
291
|
-
* @param {Vector2} vector
|
|
297
|
+
* @param {Vector2} v - other vector
|
|
292
298
|
* @return {Number} */
|
|
293
299
|
dot(v) { ASSERT(isVector2(v)); return this.x*v.x + this.y*v.y; }
|
|
294
300
|
|
|
295
301
|
/** Returns the cross product of this and the vector passed in
|
|
296
|
-
* @param {Vector2} vector
|
|
302
|
+
* @param {Vector2} v - other vector
|
|
297
303
|
* @return {Number} */
|
|
298
304
|
cross(v) { ASSERT(isVector2(v)); return this.x*v.y - this.y*v.x; }
|
|
299
305
|
|
|
@@ -305,12 +311,17 @@ class Vector2
|
|
|
305
311
|
* @param {Number} [angle=0]
|
|
306
312
|
* @param {Number} [length=1]
|
|
307
313
|
* @return {Vector2} */
|
|
308
|
-
setAngle(
|
|
314
|
+
setAngle(angle=0, length=1)
|
|
315
|
+
{ this.x = length*Math.sin(angle); this.y = length*Math.cos(angle); return this; }
|
|
309
316
|
|
|
310
317
|
/** Returns copy of this vector rotated by the angle passed in
|
|
311
318
|
* @param {Number} angle
|
|
312
319
|
* @return {Vector2} */
|
|
313
|
-
rotate(
|
|
320
|
+
rotate(angle)
|
|
321
|
+
{
|
|
322
|
+
const c = Math.cos(angle), s = Math.sin(angle);
|
|
323
|
+
return new Vector2(this.x*c - this.y*s, this.x*s + this.y*c);
|
|
324
|
+
}
|
|
314
325
|
|
|
315
326
|
/** Returns the integer direction of this vector, corrosponding to multiples of 90 degree rotation (0-3)
|
|
316
327
|
* @return {Number} */
|
|
@@ -329,10 +340,11 @@ class Vector2
|
|
|
329
340
|
area() { return abs(this.x * this.y); }
|
|
330
341
|
|
|
331
342
|
/** Returns a new vector that is p percent between this and the vector passed in
|
|
332
|
-
* @param {Vector2} vector
|
|
343
|
+
* @param {Vector2} v - other vector
|
|
333
344
|
* @param {Number} percent
|
|
334
345
|
* @return {Vector2} */
|
|
335
|
-
lerp(v,
|
|
346
|
+
lerp(v, percent)
|
|
347
|
+
{ ASSERT(isVector2(v)); return this.add(v.subtract(this).scale(clamp(percent))); }
|
|
336
348
|
|
|
337
349
|
/** Returns true if this vector is within the bounds of an array size passed in
|
|
338
350
|
* @param {Vector2} arraySize
|
|
@@ -350,10 +362,10 @@ class Vector2
|
|
|
350
362
|
|
|
351
363
|
/**
|
|
352
364
|
* Create a color object with RGBA values
|
|
353
|
-
* @param {Number} [r=1]
|
|
354
|
-
* @param {Number} [g=1]
|
|
355
|
-
* @param {Number} [b=1]
|
|
356
|
-
* @param {Number} [a=1]
|
|
365
|
+
* @param {Number} [r=1] - red
|
|
366
|
+
* @param {Number} [g=1] - green
|
|
367
|
+
* @param {Number} [b=1] - blue
|
|
368
|
+
* @param {Number} [a=1] - alpha
|
|
357
369
|
* @return {Color}
|
|
358
370
|
* @memberof Utilities
|
|
359
371
|
*/
|
|
@@ -361,10 +373,10 @@ function rgb(r, g, b, a) { return new Color(r, g, b, a); }
|
|
|
361
373
|
|
|
362
374
|
/**
|
|
363
375
|
* Create a color object with HSLA values
|
|
364
|
-
* @param {Number} [h=0]
|
|
365
|
-
* @param {Number} [s=0]
|
|
366
|
-
* @param {Number} [l=1]
|
|
367
|
-
* @param {Number} [a=1]
|
|
376
|
+
* @param {Number} [h=0] - hue
|
|
377
|
+
* @param {Number} [s=0] - saturation
|
|
378
|
+
* @param {Number} [l=1] - lightness
|
|
379
|
+
* @param {Number} [a=1] - alpha
|
|
368
380
|
* @return {Color}
|
|
369
381
|
* @memberof Utilities
|
|
370
382
|
*/
|
|
@@ -381,11 +393,11 @@ function hsl(h, s, l, a) { return new Color().setHSLA(h, s, l, a); }
|
|
|
381
393
|
*/
|
|
382
394
|
class Color
|
|
383
395
|
{
|
|
384
|
-
/** Create a color with the components passed in, white by default
|
|
385
|
-
* @param {Number} [
|
|
386
|
-
* @param {Number} [
|
|
387
|
-
* @param {Number} [
|
|
388
|
-
* @param {Number} [
|
|
396
|
+
/** Create a color with the rgba components passed in, white by default
|
|
397
|
+
* @param {Number} [r=1] - red
|
|
398
|
+
* @param {Number} [g=1] - green
|
|
399
|
+
* @param {Number} [b=1] - blue
|
|
400
|
+
* @param {Number} [a=1] - alpha*/
|
|
389
401
|
constructor(r=1, g=1, b=1, a=1)
|
|
390
402
|
{
|
|
391
403
|
/** @property {Number} - Red */
|
|
@@ -403,22 +415,22 @@ class Color
|
|
|
403
415
|
copy() { return new Color(this.r, this.g, this.b, this.a); }
|
|
404
416
|
|
|
405
417
|
/** Returns a copy of this color plus the color passed in
|
|
406
|
-
* @param {Color} color
|
|
418
|
+
* @param {Color} c - other color
|
|
407
419
|
* @return {Color} */
|
|
408
420
|
add(c) { return new Color(this.r+c.r, this.g+c.g, this.b+c.b, this.a+c.a); }
|
|
409
421
|
|
|
410
422
|
/** Returns a copy of this color minus the color passed in
|
|
411
|
-
* @param {Color} color
|
|
423
|
+
* @param {Color} c - other color
|
|
412
424
|
* @return {Color} */
|
|
413
425
|
subtract(c) { return new Color(this.r-c.r, this.g-c.g, this.b-c.b, this.a-c.a); }
|
|
414
426
|
|
|
415
427
|
/** Returns a copy of this color times the color passed in
|
|
416
|
-
* @param {Color} color
|
|
428
|
+
* @param {Color} c - other color
|
|
417
429
|
* @return {Color} */
|
|
418
430
|
multiply(c) { return new Color(this.r*c.r, this.g*c.g, this.b*c.b, this.a*c.a); }
|
|
419
431
|
|
|
420
432
|
/** Returns a copy of this color divided by the color passed in
|
|
421
|
-
* @param {Color} color
|
|
433
|
+
* @param {Color} c - other color
|
|
422
434
|
* @return {Color} */
|
|
423
435
|
divide(c) { return new Color(this.r/c.r, this.g/c.g, this.b/c.b, this.a/c.a); }
|
|
424
436
|
|
|
@@ -426,23 +438,24 @@ class Color
|
|
|
426
438
|
* @param {Number} scale
|
|
427
439
|
* @param {Number} [alphaScale=scale]
|
|
428
440
|
* @return {Color} */
|
|
429
|
-
scale(
|
|
441
|
+
scale(scale, alphaScale=scale)
|
|
442
|
+
{ return new Color(this.r*scale, this.g*scale, this.b*scale, this.a*alphaScale); }
|
|
430
443
|
|
|
431
444
|
/** Returns a copy of this color clamped to the valid range between 0 and 1
|
|
432
445
|
* @return {Color} */
|
|
433
446
|
clamp() { return new Color(clamp(this.r), clamp(this.g), clamp(this.b), clamp(this.a)); }
|
|
434
447
|
|
|
435
448
|
/** Returns a new color that is p percent between this and the color passed in
|
|
436
|
-
* @param {Color} color
|
|
449
|
+
* @param {Color} c - other color
|
|
437
450
|
* @param {Number} percent
|
|
438
451
|
* @return {Color} */
|
|
439
|
-
lerp(c,
|
|
452
|
+
lerp(c, percent) { return this.add(c.subtract(this).scale(clamp(percent))); }
|
|
440
453
|
|
|
441
454
|
/** Sets this color given a hue, saturation, lightness, and alpha
|
|
442
|
-
* @param {Number} [
|
|
443
|
-
* @param {Number} [
|
|
444
|
-
* @param {Number} [
|
|
445
|
-
* @param {Number} [
|
|
455
|
+
* @param {Number} [h=0] - hue
|
|
456
|
+
* @param {Number} [s=0] - saturation
|
|
457
|
+
* @param {Number} [l=1] - lightness
|
|
458
|
+
* @param {Number} [a=1] - alpha
|
|
446
459
|
* @return {Color} */
|
|
447
460
|
setHSLA(h=0, s=0, l=1, a=1)
|
|
448
461
|
{
|
|
@@ -583,7 +596,7 @@ class Timer
|
|
|
583
596
|
|
|
584
597
|
/** Returns this timer expressed as a string
|
|
585
598
|
* @return {String} */
|
|
586
|
-
toString() { if (debug) { return this.
|
|
599
|
+
toString() { if (debug) { return this.isSet() ? Math.abs(this.get()) + ' seconds ' + (this.get()<0 ? 'before' : 'after' ) : 'unset'; }}
|
|
587
600
|
|
|
588
601
|
/** Get how long since elapsed, returns 0 if not set (returns negative if currently active)
|
|
589
602
|
* @return {Number} */
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
rem Simple build script for LittleJS by Frank Force
|
|
2
|
-
rem Minfies and combines index.html and index.js and zips the result
|
|
3
|
-
|
|
4
|
-
set NAME=game
|
|
5
|
-
set BUILD_FOLDER=build
|
|
6
|
-
set BUILD_FILENAME=index.js
|
|
7
|
-
|
|
8
|
-
rem remove old files
|
|
9
|
-
rmdir /s /q %BUILD_FOLDER%
|
|
10
|
-
mkdir %BUILD_FOLDER%
|
|
11
|
-
pushd %BUILD_FOLDER%
|
|
12
|
-
|
|
13
|
-
rem copy engine release build
|
|
14
|
-
type ..\..\..\build\littlejs.release.js >> %BUILD_FILENAME%
|
|
15
|
-
echo. >> %BUILD_FILENAME%
|
|
16
|
-
|
|
17
|
-
rem add your game's files to include here
|
|
18
|
-
type ..\game.js >> %BUILD_FILENAME%
|
|
19
|
-
echo. >> %BUILD_FILENAME%
|
|
20
|
-
|
|
21
|
-
rem copy images to build folder
|
|
22
|
-
copy ..\tiles.png tiles.png
|
|
23
|
-
|
|
24
|
-
rem minify code with uglify
|
|
25
|
-
call npx uglifyjs -o %BUILD_FILENAME% --compress --mangle -- %BUILD_FILENAME%
|
|
26
|
-
if %ERRORLEVEL% NEQ 0 (
|
|
27
|
-
pause
|
|
28
|
-
exit /b %ERRORLEVEL%
|
|
29
|
-
)
|
|
30
|
-
|
|
31
|
-
rem build the html, you can add html header and footers here
|
|
32
|
-
rem type ..\header.html >> index.html
|
|
33
|
-
echo ^<body^>^<script^> >> index.html
|
|
34
|
-
type %BUILD_FILENAME% >> index.html
|
|
35
|
-
echo ^</script^> >> index.html
|
|
36
|
-
|
|
37
|
-
rem delete intermediate files
|
|
38
|
-
del %BUILD_FILENAME%
|
|
39
|
-
|
|
40
|
-
rem copy elecron files to build folder
|
|
41
|
-
copy ..\electron.js electron.js
|
|
42
|
-
copy ..\package.json package.json
|
|
43
|
-
|
|
44
|
-
popd
|
|
45
|
-
|
|
46
|
-
rem build with electron
|
|
47
|
-
call npx electron-packager ./%BUILD_FOLDER% --overwrite
|
|
48
|
-
if %ERRORLEVEL% NEQ 0 (
|
|
49
|
-
pause
|
|
50
|
-
exit /b %ERRORLEVEL%
|
|
51
|
-
)
|
|
52
|
-
pause
|