littlejsengine 1.6.0 → 1.6.4
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 +133 -33
- package/build/littlejs.d.ts +13 -5
- package/build/littlejs.esm.js +106 -95
- package/build/littlejs.esm.min.js +1 -1
- package/build/littlejs.js +98 -93
- package/build/littlejs.min.js +1 -1
- package/build/littlejs.release.js +91 -91
- package/examples/breakout/game.js +5 -0
- package/examples/breakout/gameObjects.js +41 -48
- package/examples/breakout/index.html +3 -3
- package/examples/breakoutTutorial/README.md +514 -0
- package/examples/breakoutTutorial/game.js +181 -0
- package/examples/breakoutTutorial/images/1.png +0 -0
- package/examples/breakoutTutorial/images/10.png +0 -0
- package/examples/breakoutTutorial/images/11.png +0 -0
- package/examples/breakoutTutorial/images/2.png +0 -0
- package/examples/breakoutTutorial/images/3.png +0 -0
- package/examples/breakoutTutorial/images/4.png +0 -0
- package/examples/breakoutTutorial/images/5.png +0 -0
- package/examples/breakoutTutorial/images/6.png +0 -0
- package/examples/breakoutTutorial/images/7.png +0 -0
- package/examples/breakoutTutorial/images/8.png +0 -0
- package/examples/breakoutTutorial/images/9.png +0 -0
- package/examples/breakoutTutorial/index.html +10 -0
- package/examples/empty/game.js +10 -0
- package/examples/module/index.html +1 -1
- package/examples/particles/index.html +1 -1
- package/examples/platformer/gameLevel.js +1 -1
- package/examples/platformer/gamePlayer.js +1 -1
- package/examples/platformer/index.html +6 -6
- package/examples/puzzle/index.html +2 -2
- package/examples/starter/build.bat +3 -2
- package/examples/starter/game.js +9 -9
- package/examples/starter/index.html +13 -13
- package/examples/stress/index.html +1 -1
- package/examples/typescript/game.js +89 -89
- package/examples/typescript/game.ts +10 -10
- package/examples/typescript/index.html +1 -1
- package/package.json +3 -3
- package/src/engine.js +1 -2
- package/src/engineAudio.js +11 -11
- package/src/engineBuild.bat +3 -1
- package/src/engineDebug.js +8 -2
- package/src/engineDraw.js +19 -15
- package/src/engineExport.js +8 -2
- package/src/engineInput.js +51 -55
- package/src/engineObject.js +4 -4
- package/src/engineRelease.js +1 -0
- package/src/engineUtilities.js +4 -4
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
// import module
|
|
8
8
|
import * as LittleJS from '../../build/littlejs.esm.js';
|
|
9
|
-
const {
|
|
9
|
+
const {Color, vec2} = LittleJS;
|
|
10
10
|
|
|
11
11
|
// sound effects
|
|
12
12
|
const sound_click = new LittleJS.Sound([1,.5]);
|
|
@@ -16,7 +16,7 @@ const medal_example = new LittleJS.Medal(0, 'Example Medal', 'Welcome to LittleJ
|
|
|
16
16
|
LittleJS.medalsInit('Hello World');
|
|
17
17
|
|
|
18
18
|
// game variables
|
|
19
|
-
let
|
|
19
|
+
let particleEmitter: LittleJS.ParticleEmitter;
|
|
20
20
|
|
|
21
21
|
///////////////////////////////////////////////////////////////////////////////
|
|
22
22
|
function gameInit()
|
|
@@ -55,7 +55,7 @@ function gameInit()
|
|
|
55
55
|
|
|
56
56
|
// create particle emitter
|
|
57
57
|
const center = LittleJS.tileCollisionSize.scale(.5).add(vec2(0,9));
|
|
58
|
-
|
|
58
|
+
particleEmitter = new LittleJS.ParticleEmitter(
|
|
59
59
|
center, 0, // emitPos, emitAngle
|
|
60
60
|
1, 0, 500, Math.PI, // emitSize, emitTime, emitRate, emiteCone
|
|
61
61
|
0, vec2(16), // tileIndex, tileSize
|
|
@@ -65,8 +65,8 @@ function gameInit()
|
|
|
65
65
|
.99, 1, 1, Math.PI, // damping, angleDamping, gravityScale, cone
|
|
66
66
|
.05, .5, true, true // fadeRate, randomness, collide, additive
|
|
67
67
|
);
|
|
68
|
-
|
|
69
|
-
|
|
68
|
+
particleEmitter.elasticity = .3; // bounce when it collides
|
|
69
|
+
particleEmitter.trailScale = 2; // stretch in direction of motion
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
///////////////////////////////////////////////////////////////////////////////
|
|
@@ -78,10 +78,10 @@ function gameUpdate()
|
|
|
78
78
|
sound_click.play(LittleJS.mousePos);
|
|
79
79
|
|
|
80
80
|
// change particle color and set to fade out
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
81
|
+
particleEmitter.colorStartA = new Color;
|
|
82
|
+
particleEmitter.colorStartB = LittleJS.randColor();
|
|
83
|
+
particleEmitter.colorEndA = particleEmitter.colorStartA.scale(1,0);
|
|
84
|
+
particleEmitter.colorEndB = particleEmitter.colorStartB.scale(1,0);
|
|
85
85
|
|
|
86
86
|
// unlock medals
|
|
87
87
|
medal_example.unlock();
|
|
@@ -89,7 +89,7 @@ function gameUpdate()
|
|
|
89
89
|
|
|
90
90
|
// move particles to mouse location if on screen
|
|
91
91
|
if (LittleJS.mousePosScreen.x)
|
|
92
|
-
|
|
92
|
+
particleEmitter.pos = LittleJS.mousePos;
|
|
93
93
|
}
|
|
94
94
|
|
|
95
95
|
///////////////////////////////////////////////////////////////////////////////
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "littlejsengine",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.4",
|
|
4
4
|
"description": "LittleJS - Tiny and Fast HTML5 Game Engine",
|
|
5
5
|
"main": "engine/engine.all.module.js",
|
|
6
6
|
"repository": {
|
|
@@ -26,10 +26,10 @@
|
|
|
26
26
|
"build": "cd src && engineBuild.bat"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"ect-bin": "~1.4.1",
|
|
30
29
|
"google-closure-compiler": "~20230502.0.0",
|
|
31
30
|
"roadroller": "~2.1.0",
|
|
31
|
+
"uglify-js": "~3.17.4",
|
|
32
32
|
"typescript": "~5.1.6",
|
|
33
|
-
"
|
|
33
|
+
"ect-bin": "~1.4.1"
|
|
34
34
|
}
|
|
35
35
|
}
|
package/src/engine.js
CHANGED
|
@@ -34,7 +34,7 @@ const engineName = 'LittleJS';
|
|
|
34
34
|
* @type {String}
|
|
35
35
|
* @default
|
|
36
36
|
* @memberof Engine */
|
|
37
|
-
const engineVersion = '1.6.
|
|
37
|
+
const engineVersion = '1.6.4';
|
|
38
38
|
|
|
39
39
|
/** Frames per second to update objects
|
|
40
40
|
* @type {Number}
|
|
@@ -125,7 +125,6 @@ function engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRender
|
|
|
125
125
|
(glCanvas||mainCanvas).style = mainCanvas.style = overlayCanvas.style = styleCanvas;
|
|
126
126
|
|
|
127
127
|
gameInit();
|
|
128
|
-
touchGamepadCreate();
|
|
129
128
|
engineUpdate();
|
|
130
129
|
};
|
|
131
130
|
|
package/src/engineAudio.js
CHANGED
|
@@ -270,7 +270,7 @@ function playSamples(sampleChannels, volume=1, rate=1, pan=0, loop=0)
|
|
|
270
270
|
}
|
|
271
271
|
|
|
272
272
|
///////////////////////////////////////////////////////////////////////////////
|
|
273
|
-
// ZzFXMicro - Zuper Zmall Zound Zynth - v1.
|
|
273
|
+
// ZzFXMicro - Zuper Zmall Zound Zynth - v1.2.0 by Frank Force
|
|
274
274
|
|
|
275
275
|
/** Generate and play a ZzFX sound
|
|
276
276
|
* <br>
|
|
@@ -296,11 +296,11 @@ function zzfxG
|
|
|
296
296
|
bitCrush = 0, delay = 0, sustainVolume = 1, decay = 0, tremolo = 0
|
|
297
297
|
)
|
|
298
298
|
{
|
|
299
|
-
//
|
|
299
|
+
// locals
|
|
300
300
|
let PI2 = PI*2, startSlide = slide *= 500 * PI2 / zzfxR / zzfxR, b=[],
|
|
301
301
|
startFrequency = frequency *= (1 + randomness*rand(-1,1)) * PI2 / zzfxR,
|
|
302
|
-
t=0, tm=0, i=0, j=1, r=0, c=0, s=0, f, length
|
|
303
|
-
|
|
302
|
+
t=0, tm=0, i=0, j=1, r=0, c=0, s=0, f, length
|
|
303
|
+
|
|
304
304
|
// scale by sample rate
|
|
305
305
|
attack = attack * zzfxR + 9; // minimum attack to prevent pop
|
|
306
306
|
decay *= zzfxR;
|
|
@@ -350,18 +350,18 @@ function zzfxG
|
|
|
350
350
|
Math.cos(modulation*tm++); // modulation
|
|
351
351
|
t += f - f*noise*(1 - (Math.sin(i)+1)*1e9%2); // noise
|
|
352
352
|
|
|
353
|
-
if (j && ++j > pitchJumpTime)
|
|
353
|
+
if (j && ++j > pitchJumpTime) // pitch jump
|
|
354
354
|
{
|
|
355
|
-
frequency += pitchJump;
|
|
356
|
-
startFrequency += pitchJump;
|
|
357
|
-
j = 0;
|
|
355
|
+
frequency += pitchJump; // apply pitch jump
|
|
356
|
+
startFrequency += pitchJump; // also apply to start
|
|
357
|
+
j = 0; // reset pitch jump time
|
|
358
358
|
}
|
|
359
359
|
|
|
360
360
|
if (repeatTime && !(++r % repeatTime)) // repeat
|
|
361
361
|
{
|
|
362
|
-
frequency = startFrequency;
|
|
363
|
-
slide = startSlide;
|
|
364
|
-
j
|
|
362
|
+
frequency = startFrequency; // reset frequency
|
|
363
|
+
slide = startSlide; // reset slide
|
|
364
|
+
j ||= 1; // reset pitch jump time
|
|
365
365
|
}
|
|
366
366
|
}
|
|
367
367
|
|
package/src/engineBuild.bat
CHANGED
|
@@ -7,7 +7,8 @@ rem --- BUILD ENGINE DEBUG ---
|
|
|
7
7
|
set BUILD_FOLDER=build
|
|
8
8
|
set ENGINE_NAME=littlejs
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
pushd ..
|
|
11
|
+
|
|
11
12
|
rem remove old files
|
|
12
13
|
rmdir /s /q %BUILD_FOLDER%
|
|
13
14
|
mkdir %BUILD_FOLDER%
|
|
@@ -127,4 +128,5 @@ if %ERRORLEVEL% NEQ 0 (
|
|
|
127
128
|
exit /b %ERRORLEVEL%
|
|
128
129
|
)
|
|
129
130
|
|
|
131
|
+
popd
|
|
130
132
|
popd
|
package/src/engineDebug.js
CHANGED
|
@@ -45,6 +45,12 @@ let showWatermark = 1;
|
|
|
45
45
|
* @memberof Debug */
|
|
46
46
|
let godMode = 0;
|
|
47
47
|
|
|
48
|
+
/** Key code used to toggle debug mode, Esc by default
|
|
49
|
+
* @type {Boolean}
|
|
50
|
+
* @default
|
|
51
|
+
* @memberof Debug */
|
|
52
|
+
let debugKey = 27;
|
|
53
|
+
|
|
48
54
|
// Engine internal variables not exposed to documentation
|
|
49
55
|
let debugPrimitives = [], debugOverlay = 0, debugPhysics = 0, debugRaycast = 0,
|
|
50
56
|
debugParticles = 0, debugGamepads = 0, debugMedals = 0, debugTakeScreenshot, downloadLink;
|
|
@@ -166,7 +172,7 @@ const debugUpdate = ()=>
|
|
|
166
172
|
if (!debug)
|
|
167
173
|
return;
|
|
168
174
|
|
|
169
|
-
if (keyWasPressed(
|
|
175
|
+
if (keyWasPressed(debugKey)) // Esc
|
|
170
176
|
debugOverlay = !debugOverlay;
|
|
171
177
|
if (debugOverlay)
|
|
172
178
|
{
|
|
@@ -351,7 +357,7 @@ const debugRender = ()=>
|
|
|
351
357
|
overlayContext.fillText('Time: ' + formatTime(time), x, y += h);
|
|
352
358
|
overlayContext.fillText('---------', x, y += h);
|
|
353
359
|
overlayContext.fillStyle = '#f00';
|
|
354
|
-
overlayContext.fillText('
|
|
360
|
+
overlayContext.fillText('ESC: Debug Overlay', x, y += h);
|
|
355
361
|
overlayContext.fillStyle = debugPhysics ? '#f00' : '#fff';
|
|
356
362
|
overlayContext.fillText('1: Debug Physics', x, y += h);
|
|
357
363
|
overlayContext.fillStyle = debugParticles ? '#f00' : '#fff';
|
package/src/engineDraw.js
CHANGED
|
@@ -226,6 +226,23 @@ function setBlendMode(additive, useWebGL=glEnable)
|
|
|
226
226
|
mainContext.globalCompositeOperation = additive ? 'lighter' : 'source-over';
|
|
227
227
|
}
|
|
228
228
|
|
|
229
|
+
/** Draw text on overlay canvas in world space
|
|
230
|
+
* Automatically splits new lines into rows
|
|
231
|
+
* @param {String} text
|
|
232
|
+
* @param {Vector2} pos
|
|
233
|
+
* @param {Number} [size=1]
|
|
234
|
+
* @param {Color} [color=Color()]
|
|
235
|
+
* @param {Number} [lineWidth=0]
|
|
236
|
+
* @param {Color} [lineColor=Color(0,0,0)]
|
|
237
|
+
* @param {String} [textAlign='center']
|
|
238
|
+
* @param {String} [font=fontDefault]
|
|
239
|
+
* @param {CanvasRenderingContext2D} [context=overlayContext]
|
|
240
|
+
* @memberof Draw */
|
|
241
|
+
function drawText(text, pos, size=1, color, lineWidth=0, lineColor, textAlign, font, context)
|
|
242
|
+
{
|
|
243
|
+
drawTextScreen(text, worldToScreen(pos), size*cameraScale, color, lineWidth*cameraScale, lineColor, textAlign, font, context);
|
|
244
|
+
}
|
|
245
|
+
|
|
229
246
|
/** Draw text on overlay canvas in screen space
|
|
230
247
|
* Automatically splits new lines into rows
|
|
231
248
|
* @param {String} text
|
|
@@ -235,6 +252,8 @@ function setBlendMode(additive, useWebGL=glEnable)
|
|
|
235
252
|
* @param {Number} [lineWidth=0]
|
|
236
253
|
* @param {Color} [lineColor=Color(0,0,0)]
|
|
237
254
|
* @param {String} [textAlign='center']
|
|
255
|
+
* @param {String} [font=fontDefault]
|
|
256
|
+
* @param {CanvasRenderingContext2D} [context=overlayContext]
|
|
238
257
|
* @memberof Draw */
|
|
239
258
|
function drawTextScreen(text, pos, size=1, color=new Color, lineWidth=0, lineColor=new Color(0,0,0), textAlign='center', font=fontDefault, context=overlayContext)
|
|
240
259
|
{
|
|
@@ -255,21 +274,6 @@ function drawTextScreen(text, pos, size=1, color=new Color, lineWidth=0, lineCol
|
|
|
255
274
|
});
|
|
256
275
|
}
|
|
257
276
|
|
|
258
|
-
/** Draw text on overlay canvas in world space
|
|
259
|
-
* Automatically splits new lines into rows
|
|
260
|
-
* @param {String} text
|
|
261
|
-
* @param {Vector2} pos
|
|
262
|
-
* @param {Number} [size=1]
|
|
263
|
-
* @param {Color} [color=Color()]
|
|
264
|
-
* @param {Number} [lineWidth=0]
|
|
265
|
-
* @param {Color} [lineColor=Color(0,0,0)]
|
|
266
|
-
* @param {String} [textAlign='center']
|
|
267
|
-
* @memberof Draw */
|
|
268
|
-
function drawText(text, pos, size=1, color, lineWidth=0, lineColor, textAlign, font)
|
|
269
|
-
{
|
|
270
|
-
drawTextScreen(text, worldToScreen(pos), size*cameraScale, color, lineWidth*cameraScale, lineColor, textAlign, font, mainContext);
|
|
271
|
-
}
|
|
272
|
-
|
|
273
277
|
///////////////////////////////////////////////////////////////////////////////
|
|
274
278
|
|
|
275
279
|
let engineFontImage;
|
package/src/engineExport.js
CHANGED
|
@@ -196,6 +196,11 @@ const setShowWatermark = (show)=> showWatermark = show;
|
|
|
196
196
|
* @memberof Debug */
|
|
197
197
|
const setGodMode = (enable)=> godMode = enable;
|
|
198
198
|
|
|
199
|
+
/** Set key code used to toggle debug mode, Esc by default
|
|
200
|
+
* @param {Number} key
|
|
201
|
+
* @memberof Debug */
|
|
202
|
+
const setDebugKey = (key)=> debugKey = key;
|
|
203
|
+
|
|
199
204
|
export {
|
|
200
205
|
// Setters for global variables
|
|
201
206
|
setCameraPos,
|
|
@@ -236,6 +241,7 @@ export {
|
|
|
236
241
|
setMedalsPreventUnlock,
|
|
237
242
|
setShowWatermark,
|
|
238
243
|
setGodMode,
|
|
244
|
+
setDebugKey,
|
|
239
245
|
|
|
240
246
|
// Settings
|
|
241
247
|
canvasMaxSize,
|
|
@@ -322,8 +328,8 @@ export {
|
|
|
322
328
|
Color,
|
|
323
329
|
Timer,
|
|
324
330
|
vec2,
|
|
325
|
-
|
|
326
|
-
|
|
331
|
+
rgb,
|
|
332
|
+
hsl,
|
|
327
333
|
|
|
328
334
|
// Base
|
|
329
335
|
EngineObject,
|
package/src/engineInput.js
CHANGED
|
@@ -292,6 +292,9 @@ if (isTouchDevice)
|
|
|
292
292
|
return true;
|
|
293
293
|
}
|
|
294
294
|
|
|
295
|
+
// try to create touch game pad
|
|
296
|
+
touchGamepadEnable && touchGamepadCreate();
|
|
297
|
+
|
|
295
298
|
return ontouchstart(e);
|
|
296
299
|
}
|
|
297
300
|
}
|
|
@@ -305,76 +308,69 @@ let touchGamepadTimer = new Timer, touchGamepadButtons, touchGamepadStick;
|
|
|
305
308
|
// create the touch gamepad, called automatically by the engine
|
|
306
309
|
function touchGamepadCreate()
|
|
307
310
|
{
|
|
308
|
-
if (!touchGamepadEnable || !isTouchDevice)
|
|
309
|
-
return;
|
|
310
|
-
|
|
311
311
|
// touch input internal variables
|
|
312
312
|
touchGamepadButtons = [];
|
|
313
313
|
touchGamepadStick = vec2();
|
|
314
314
|
|
|
315
|
-
|
|
316
|
-
ontouchstart = (e)=>
|
|
315
|
+
let touchHandler = ontouchstart;
|
|
316
|
+
ontouchstart = ontouchmove = ontouchend = (e)=>
|
|
317
317
|
{
|
|
318
|
-
//
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
318
|
+
// clear touch gamepad input
|
|
319
|
+
touchGamepadStick = vec2();
|
|
320
|
+
touchGamepadButtons = [];
|
|
321
|
+
|
|
322
|
+
const touching = e.touches.length;
|
|
323
|
+
if (touching)
|
|
322
324
|
{
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
touchGamepadButtons = [];
|
|
326
|
-
|
|
327
|
-
const touching = e.touches.length;
|
|
328
|
-
if (touching)
|
|
325
|
+
touchGamepadTimer.set();
|
|
326
|
+
if (paused)
|
|
329
327
|
{
|
|
330
|
-
//
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
if (paused)
|
|
335
|
-
{
|
|
336
|
-
// touch anywhere to press start when paused
|
|
337
|
-
touchGamepadButtons[9] = 1;
|
|
338
|
-
return;
|
|
339
|
-
}
|
|
328
|
+
// touch anywhere to press start when paused
|
|
329
|
+
touchGamepadButtons[9] = 1;
|
|
330
|
+
return;
|
|
340
331
|
}
|
|
332
|
+
}
|
|
341
333
|
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
334
|
+
// get center of left and right sides
|
|
335
|
+
const stickCenter = vec2(touchGamepadSize, mainCanvasSize.y-touchGamepadSize);
|
|
336
|
+
const buttonCenter = mainCanvasSize.subtract(vec2(touchGamepadSize, touchGamepadSize));
|
|
337
|
+
const startCenter = mainCanvasSize.scale(.5);
|
|
346
338
|
|
|
347
|
-
|
|
348
|
-
|
|
339
|
+
// check each touch point
|
|
340
|
+
for (const touch of e.touches)
|
|
341
|
+
{
|
|
342
|
+
const touchPos = mouseToScreen(vec2(touch.clientX, touch.clientY));
|
|
343
|
+
if (touchPos.distance(stickCenter) < touchGamepadSize)
|
|
349
344
|
{
|
|
350
|
-
|
|
351
|
-
if (
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
if (touchGamepadAnalog)
|
|
355
|
-
touchGamepadStick = touchPos.subtract(stickCenter).scale(2/touchGamepadSize).clampLength();
|
|
356
|
-
else
|
|
357
|
-
{
|
|
358
|
-
// 8 way dpad
|
|
359
|
-
const angle = touchPos.subtract(stickCenter).angle();
|
|
360
|
-
touchGamepadStick.setAngle((angle * 4 / PI + 8.5 | 0) * PI / 4);
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
else if (touchPos.distance(buttonCenter) < touchGamepadSize)
|
|
364
|
-
{
|
|
365
|
-
// virtual face buttons
|
|
366
|
-
const button = touchPos.subtract(buttonCenter).direction();
|
|
367
|
-
touchGamepadButtons[button] = 1;
|
|
368
|
-
}
|
|
369
|
-
else if (touchPos.distance(startCenter) < touchGamepadSize)
|
|
345
|
+
// virtual analog stick
|
|
346
|
+
if (touchGamepadAnalog)
|
|
347
|
+
touchGamepadStick = touchPos.subtract(stickCenter).scale(2/touchGamepadSize).clampLength();
|
|
348
|
+
else
|
|
370
349
|
{
|
|
371
|
-
//
|
|
372
|
-
|
|
350
|
+
// 8 way dpad
|
|
351
|
+
const angle = touchPos.subtract(stickCenter).angle();
|
|
352
|
+
touchGamepadStick.setAngle((angle * 4 / PI + 8.5 | 0) * PI / 4);
|
|
373
353
|
}
|
|
374
354
|
}
|
|
355
|
+
else if (touchPos.distance(buttonCenter) < touchGamepadSize)
|
|
356
|
+
{
|
|
357
|
+
// virtual face buttons
|
|
358
|
+
const button = touchPos.subtract(buttonCenter).direction();
|
|
359
|
+
touchGamepadButtons[button] = 1;
|
|
360
|
+
}
|
|
361
|
+
else if (touchPos.distance(startCenter) < touchGamepadSize)
|
|
362
|
+
{
|
|
363
|
+
// virtual start button in center
|
|
364
|
+
touchGamepadButtons[9] = 1;
|
|
365
|
+
}
|
|
375
366
|
}
|
|
376
367
|
|
|
377
|
-
|
|
368
|
+
// call default touch handler and set to using gamepad
|
|
369
|
+
touchHandler(e);
|
|
370
|
+
isUsingGamepad = 1;
|
|
371
|
+
|
|
372
|
+
// must return true so the document will get focus
|
|
373
|
+
return true;
|
|
378
374
|
}
|
|
379
375
|
}
|
|
380
376
|
|
|
@@ -400,7 +396,7 @@ function touchGamepadRender()
|
|
|
400
396
|
overlayContext.beginPath();
|
|
401
397
|
|
|
402
398
|
const leftCenter = vec2(touchGamepadSize, mainCanvasSize.y-touchGamepadSize);
|
|
403
|
-
if (touchGamepadAnalog)
|
|
399
|
+
if (touchGamepadAnalog) // draw circle shaped gamepad
|
|
404
400
|
{
|
|
405
401
|
overlayContext.arc(leftCenter.x, leftCenter.y, touchGamepadSize/2, 0, 9);
|
|
406
402
|
overlayContext.fill();
|
package/src/engineObject.js
CHANGED
|
@@ -112,6 +112,7 @@ class EngineObject
|
|
|
112
112
|
this.velocity.y += gravity * this.gravityScale;
|
|
113
113
|
this.pos.x += this.velocity.x *= this.damping;
|
|
114
114
|
this.pos.y += this.velocity.y *= this.damping;
|
|
115
|
+
this.angle += this.angleVelocity *= this.angleDamping;
|
|
115
116
|
|
|
116
117
|
// physics sanity checks
|
|
117
118
|
ASSERT(this.angleDamping >= 0 && this.angleDamping <= 1);
|
|
@@ -168,6 +169,7 @@ class EngineObject
|
|
|
168
169
|
const smallStepUp = (oldPos.y - o.pos.y)*2 > sizeBoth.y + gravity; // prefer to push up if small delta
|
|
169
170
|
const isBlockedX = abs(oldPos.y - o.pos.y)*2 < sizeBoth.y;
|
|
170
171
|
const isBlockedY = abs(oldPos.x - o.pos.x)*2 < sizeBoth.x;
|
|
172
|
+
const elasticity = max(this.elasticity, o.elasticity);
|
|
171
173
|
|
|
172
174
|
if (smallStepUp | isBlockedY | !isBlockedX) // resolve y collision
|
|
173
175
|
{
|
|
@@ -180,7 +182,7 @@ class EngineObject
|
|
|
180
182
|
this.groundObject = o;
|
|
181
183
|
|
|
182
184
|
// bounce if other object is fixed or grounded
|
|
183
|
-
this.velocity.y *= -
|
|
185
|
+
this.velocity.y *= -elasticity;
|
|
184
186
|
}
|
|
185
187
|
else if (o.mass)
|
|
186
188
|
{
|
|
@@ -194,7 +196,6 @@ class EngineObject
|
|
|
194
196
|
+ this.velocity.y * 2 * this.mass / (this.mass + o.mass);
|
|
195
197
|
|
|
196
198
|
// lerp betwen elastic or inelastic based on elasticity
|
|
197
|
-
const elasticity = max(this.elasticity, o.elasticity);
|
|
198
199
|
this.velocity.y = lerp(elasticity, inelastic, elastic0);
|
|
199
200
|
o.velocity.y = lerp(elasticity, inelastic, elastic1);
|
|
200
201
|
}
|
|
@@ -215,12 +216,11 @@ class EngineObject
|
|
|
215
216
|
+ this.velocity.x * 2 * this.mass / (this.mass + o.mass);
|
|
216
217
|
|
|
217
218
|
// lerp betwen elastic or inelastic based on elasticity
|
|
218
|
-
const elasticity = max(this.elasticity, o.elasticity);
|
|
219
219
|
this.velocity.x = lerp(elasticity, inelastic, elastic0);
|
|
220
220
|
o.velocity.x = lerp(elasticity, inelastic, elastic1);
|
|
221
221
|
}
|
|
222
222
|
else // bounce if other object is fixed
|
|
223
|
-
this.velocity.x *= -
|
|
223
|
+
this.velocity.x *= -elasticity;
|
|
224
224
|
}
|
|
225
225
|
debugOverlay && debugPhysics && debugAABB(this.pos, this.size, o.pos, o.size, '#f0f');
|
|
226
226
|
}
|
package/src/engineRelease.js
CHANGED
package/src/engineUtilities.js
CHANGED
|
@@ -348,7 +348,7 @@ class Vector2
|
|
|
348
348
|
* @return {Color}
|
|
349
349
|
* @memberof Utilities
|
|
350
350
|
*/
|
|
351
|
-
const
|
|
351
|
+
const rgb = (r, g, b, a)=> new Color(r, g, b, a);
|
|
352
352
|
|
|
353
353
|
/**
|
|
354
354
|
* Create a color object with HSLA values
|
|
@@ -359,7 +359,7 @@ const colorRGBA = (r, g, b, a)=> new Color(r, g, b, a);
|
|
|
359
359
|
* @return {Color}
|
|
360
360
|
* @memberof Utilities
|
|
361
361
|
*/
|
|
362
|
-
const
|
|
362
|
+
const hsl = (h, s, l, a)=> new Color().setHSLA(h, s, l, a);
|
|
363
363
|
|
|
364
364
|
/**
|
|
365
365
|
* Color object (red, green, blue, alpha) with some helpful functions
|
|
@@ -367,8 +367,8 @@ const colorHSLA = (h, s, l, a)=> new Color().setHSLA(h, s, l, a);
|
|
|
367
367
|
* let a = new Color; // white
|
|
368
368
|
* let b = new Color(1, 0, 0); // red
|
|
369
369
|
* let c = new Color(0, 0, 0, 0); // transparent black
|
|
370
|
-
* let d =
|
|
371
|
-
* let e =
|
|
370
|
+
* let d = RGB(0, 0, 1); // blue using rgb color
|
|
371
|
+
* let e = HSL(.3, 1, .5); // green using hsl color
|
|
372
372
|
*/
|
|
373
373
|
class Color
|
|
374
374
|
{
|