littlejsengine 1.2.3 → 1.3.3
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 +4 -3
- package/build.bat +6 -6
- package/buildSetup.bat +7 -0
- package/docs/Audio.html +2268 -0
- package/docs/Color.html +3376 -0
- package/docs/Debug.html +2933 -0
- package/docs/Draw.html +4480 -0
- package/docs/EngineObject.html +4734 -0
- package/docs/FontImage.html +1055 -0
- package/docs/Input.html +2806 -0
- package/docs/Medal.html +1007 -0
- package/docs/Medals.html +628 -0
- package/docs/Music.html +584 -0
- package/docs/Newgrounds.html +1399 -0
- package/docs/Particle.html +4825 -0
- package/docs/ParticleEmitter.html +8099 -0
- package/docs/Random.html +1774 -0
- package/docs/Settings.html +3140 -0
- package/docs/Sound.html +1249 -0
- package/docs/TileCollision.html +1409 -0
- package/docs/TileLayer.html +7310 -0
- package/docs/TileLayerData.html +1052 -0
- package/docs/Timer.html +1295 -0
- package/docs/Utilities.html +3278 -0
- package/docs/Vector2.html +4266 -0
- package/docs/WebGL.html +2307 -0
- package/docs/engine.js.html +443 -0
- package/docs/engineAudio.js.html +627 -0
- package/docs/engineDebug.js.html +554 -0
- package/docs/engineDraw.js.html +539 -0
- package/docs/engineInput.js.html +571 -0
- package/docs/engineMedals.js.html +460 -0
- package/docs/engineObject.js.html +533 -0
- package/docs/engineParticles.js.html +443 -0
- package/docs/engineSettings.js.html +381 -0
- package/docs/engineTileLayer.js.html +503 -0
- package/docs/engineUtilities.js.html +700 -0
- package/docs/engineWebGL.js.html +511 -0
- package/docs/fonts/MavenPro-Regular.ttf +0 -0
- package/docs/fonts/Montserrat-Regular.ttf +0 -0
- package/docs/fonts/Muli-Black.ttf +0 -0
- package/docs/fonts/OFL-hind.txt +93 -0
- package/docs/fonts/OFL-montserrat.txt +93 -0
- package/docs/global.html +1771 -0
- package/docs/index.css +6 -0
- package/docs/index.html +267 -0
- package/docs/scripts/fix-code-block.js +53 -0
- package/docs/scripts/fix-navbar.js +25 -0
- package/docs/scripts/linenumber.js +25 -0
- package/docs/scripts/misc.js +217 -0
- package/docs/scripts/resize.js +85 -0
- package/docs/scripts/search.js +83 -0
- package/docs/scripts/third-party/Apache-License-2.0.txt +202 -0
- package/docs/scripts/third-party/fuse.js +9 -0
- package/docs/scripts/third-party/lang-css.js +2 -0
- package/docs/scripts/third-party/prettify.js +28 -0
- package/docs/static/favicon.png +0 -0
- package/docs/static/index.css +4 -0
- package/docs/styles/clean-jsdoc-theme-base.css +393 -0
- package/docs/styles/clean-jsdoc-theme-dark.css +324 -0
- package/docs/styles/clean-jsdoc-theme-light.css +319 -0
- package/docs/styles/reset.css +346 -0
- package/docs/styles/third-party/ionicons.min.css +11 -0
- package/docs/styles/third-party/prettify-jsdoc.css +111 -0
- package/docs/styles/third-party/prettify-tomorrow.css +5 -0
- package/engine/engine.all.js +171 -67
- package/engine/engine.all.min.js +1 -1
- package/engine/engine.all.release.js +162 -53
- package/engine/engine.js +3 -3
- package/engine/engineAudio.js +5 -7
- package/engine/engineBuild.bat +3 -4
- package/engine/engineDebug.js +9 -14
- package/engine/engineDraw.js +32 -13
- package/engine/engineInput.js +5 -1
- package/engine/engineMedals.js +5 -2
- package/engine/engineObject.js +24 -5
- package/engine/engineParticles.js +2 -2
- package/engine/engineSettings.js +5 -0
- package/engine/engineTileLayer.js +11 -10
- package/engine/engineUtilities.js +67 -7
- package/engine/engineWebGL.js +3 -3
- package/engine/index.d.ts +57 -18
- package/examples/breakout/index.html +3 -3
- package/examples/particles/index.html +366 -0
- package/examples/particles/tiles.png +0 -0
- package/examples/platformer/gameEffects.js +6 -6
- package/examples/platformer/index.html +6 -6
- package/examples/puzzle/game.js +4 -2
- package/examples/puzzle/index.html +2 -2
- package/examples/stress/index.html +1 -1
- package/game.js +3 -14
- package/index.html +13 -13
- package/package.json +1 -1
- package/engine/engineBuildSetup.bat +0 -7
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
<html><head><meta charset=utf-8>
|
|
2
|
+
<meta name=viewport content=width=device-width,height=device-height,initial-scale=1,maximum-scale=1>
|
|
3
|
+
<meta name=apple-mobile-web-app-capable content=yes>
|
|
4
|
+
<meta name=mobile-web-app-capable content=yes>
|
|
5
|
+
<link rel=icon type=image/png href=favicon.png>
|
|
6
|
+
<style>
|
|
7
|
+
input
|
|
8
|
+
{
|
|
9
|
+
width:99px;
|
|
10
|
+
}
|
|
11
|
+
button
|
|
12
|
+
{
|
|
13
|
+
margin:1px;
|
|
14
|
+
}
|
|
15
|
+
</style>
|
|
16
|
+
</head><body>
|
|
17
|
+
|
|
18
|
+
<script src=../../engine/engineDebug.js?108></script>
|
|
19
|
+
<script src=../../engine/engineUtilities.js?108></script>
|
|
20
|
+
<script src=../../engine/engineSettings.js?108></script>
|
|
21
|
+
<script src=../../engine/engineObject.js?108></script>
|
|
22
|
+
<script src=../../engine/engineDraw.js?108></script>
|
|
23
|
+
<script src=../../engine/engineInput.js?108></script>
|
|
24
|
+
<script src=../../engine/engineAudio.js?108></script>
|
|
25
|
+
<script src=../../engine/engineTileLayer.js?108></script>
|
|
26
|
+
<script src=../../engine/engineParticles.js?108></script>
|
|
27
|
+
<script src=../../engine/engineMedals.js?108></script>
|
|
28
|
+
<script src=../../engine/engineWebGL.js?108></script>
|
|
29
|
+
<script src=../../engine/engine.js?108></script>
|
|
30
|
+
<script>
|
|
31
|
+
|
|
32
|
+
'use strict';
|
|
33
|
+
|
|
34
|
+
let particleEditor = 0, particleSystem, particleSystemDiv, particleSystemCode;
|
|
35
|
+
let inputExpand;
|
|
36
|
+
let restartTimer = new Timer();
|
|
37
|
+
const storagePrefix = 'particles_';
|
|
38
|
+
|
|
39
|
+
const particleSettings = [];
|
|
40
|
+
function addSetting(name, type, min, max, step, description)
|
|
41
|
+
{
|
|
42
|
+
particleSettings.push({name, type:type||'number', min, max, step, description});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
addSetting('emitSize', '', 0, 1e9, .1, 'World space size of the emitter');
|
|
46
|
+
addSetting('emitTime', '', 0, 1e9, .1, 'How long to stay alive (0 is forever)');
|
|
47
|
+
addSetting('emitRate', '', 0, 1e9, 1, 'How many particles per second to spawn, does not emit if 0');
|
|
48
|
+
addSetting('emitConeAngle', '', 0, 1e9, .01,'Local angle to apply velocity to particles from emitter');
|
|
49
|
+
addSetting('tileIndex', '', -1, 1e9, 1, 'Tile to use to render object (-1 is untextured)');
|
|
50
|
+
addSetting('tileSizeX', '', 0, 1e9, 1, 'X Size of texture tile in source pixelss');
|
|
51
|
+
addSetting('tileSizeY', '', 0, 1e9, 1, 'Y Size of texture tile in source pixelss');
|
|
52
|
+
addSetting('colorStartA', 'color',0,0,0, 'Color at start of life 1');
|
|
53
|
+
addSetting('colorStartB', 'color',0,0,0, 'Color at start of life 2');
|
|
54
|
+
addSetting('colorEndA', 'color',0,0,0, 'Color at end of life 1');
|
|
55
|
+
addSetting('colorEndB', 'color',0,0,0, 'Color at end of life 2');
|
|
56
|
+
addSetting('colorAlphaStartA', 'alpha', 0, 1, .01, 'Alpha at start of life 1');
|
|
57
|
+
addSetting('colorAlphaStartB', 'alpha', 0, 1, .01, 'Alpha at start of life 2');
|
|
58
|
+
addSetting('colorAlphaEndA', 'alpha', 0, 1, .01, 'Alpha at end of life 1');
|
|
59
|
+
addSetting('colorAlphaEndB', 'alpha', 0, 1, .01, 'Alpha at end of life 2');
|
|
60
|
+
addSetting('particleTime', '', 0, 1e9, .1, 'How long particles live');
|
|
61
|
+
addSetting('sizeStart', '', 0, 1e9, .01,'How big are particles at start');
|
|
62
|
+
addSetting('sizeEnd', '', 0, 1e9, .01,'How big are particles at end');
|
|
63
|
+
addSetting('speed', '', 0, 1e9, .01,'How fast are particles when spawned');
|
|
64
|
+
addSetting('angleSpeed', '', 0, 1e9, .01,'How fast are particles rotating');
|
|
65
|
+
addSetting('damping', '', 0, 1, .01,'How much to dampen particle speed');
|
|
66
|
+
addSetting('angleDamping', '', 0, 1, .01,'How much to dampen particle angular speed');
|
|
67
|
+
addSetting('gravityScale', '', -1e9, 1e9, .1, 'How much does gravity effect particles');
|
|
68
|
+
addSetting('particleConeAngle','', 0, 1e9, .1, 'Cone for start particle angle');
|
|
69
|
+
addSetting('fadeRate', '', 0, 1, .01,'How quickly particles fade in percent of life');
|
|
70
|
+
addSetting('randomness', '', 0, 1, .01,'Apply extra randomness percent');
|
|
71
|
+
addSetting('collideTiles', 'checkbox',0,0,0, 'Do particles collide against tiles?');
|
|
72
|
+
addSetting('additive', 'checkbox',0,0,0, 'Should particles use addtive blend?');
|
|
73
|
+
addSetting('randomColorLinear','checkbox',0,0,0, 'Should color be randomized linearly?');
|
|
74
|
+
|
|
75
|
+
function makeEmitter()
|
|
76
|
+
{
|
|
77
|
+
particleSystem = new ParticleEmitter(cameraPos);
|
|
78
|
+
particleSystem.emitConeAngle =
|
|
79
|
+
particleSystem.particleConeAngle = 3.14;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
83
|
+
function gameInit()
|
|
84
|
+
{
|
|
85
|
+
makeEmitter();
|
|
86
|
+
gravity = -.01;
|
|
87
|
+
cameraScale = 50;
|
|
88
|
+
|
|
89
|
+
const div = particleSystemDiv = document.createElement('div');
|
|
90
|
+
div.innerHTML = '<big><b>LittleJS Particle Tool';
|
|
91
|
+
div.style = 'position:absolute;top:10;left:10;color:#fff';
|
|
92
|
+
document.body.appendChild(div);
|
|
93
|
+
|
|
94
|
+
for (const setting of particleSettings)
|
|
95
|
+
{
|
|
96
|
+
const input = setting.input = document.createElement('input');
|
|
97
|
+
const name = setting.name;
|
|
98
|
+
input.type = setting.type == 'alpha' ? 'number' : setting.type;
|
|
99
|
+
input.title = setting.description;
|
|
100
|
+
input.oninput = (e)=> updateParticles(setting.type == 'checkbox');
|
|
101
|
+
input.onblur = (e)=> updateParticles(1);
|
|
102
|
+
if (setting.min !== undefined)
|
|
103
|
+
input.min = setting.min;
|
|
104
|
+
if (setting.max !== undefined)
|
|
105
|
+
input.max = setting.max;
|
|
106
|
+
if (setting.step !== undefined)
|
|
107
|
+
input.step = setting.step;
|
|
108
|
+
if (name == 'emitConeAngle' || name == 'particleConeAngle')
|
|
109
|
+
particleSystem[name] = 3.14; // simplify pi
|
|
110
|
+
|
|
111
|
+
div.appendChild(document.createElement('br'));
|
|
112
|
+
div.appendChild(input);
|
|
113
|
+
div.appendChild(document.createTextNode(' ' + name));
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
div.appendChild(document.createElement('br'));
|
|
117
|
+
div.appendChild(document.createElement('br'));
|
|
118
|
+
|
|
119
|
+
{
|
|
120
|
+
const button = document.createElement('button')
|
|
121
|
+
div.appendChild(button);
|
|
122
|
+
button.innerHTML = 'Copy To Clipboard';
|
|
123
|
+
button.onclick = (e)=> navigator.clipboard.writeText(particleSystemCode.value);
|
|
124
|
+
}
|
|
125
|
+
{
|
|
126
|
+
const button = document.createElement('button');
|
|
127
|
+
div.appendChild(button);
|
|
128
|
+
button.innerHTML = 'Reset';
|
|
129
|
+
button.onclick = (e)=>
|
|
130
|
+
{
|
|
131
|
+
if (!confirm('Reset to default?'))
|
|
132
|
+
return;
|
|
133
|
+
particleSystem.destroy();
|
|
134
|
+
makeEmitter();
|
|
135
|
+
updateInputs(0);
|
|
136
|
+
cameraScale = 50;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
{
|
|
140
|
+
inputExpand = document.createElement('input');
|
|
141
|
+
div.appendChild(inputExpand);
|
|
142
|
+
inputExpand.type = 'checkbox';
|
|
143
|
+
inputExpand.style.width = 'initial';
|
|
144
|
+
inputExpand.oninput = (e)=> updateParticles(1);
|
|
145
|
+
div.appendChild(document.createTextNode(' Expand'));
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
//div.appendChild(document.createTextNode('JavaScript Code... '));
|
|
149
|
+
div.appendChild(document.createElement('br'));
|
|
150
|
+
div.appendChild(particleSystemCode = document.createElement('textarea'));
|
|
151
|
+
particleSystemCode.style.width = 500;
|
|
152
|
+
particleSystemCode.style.height = 100;
|
|
153
|
+
particleSystemCode.disabled = true;
|
|
154
|
+
|
|
155
|
+
updateInputs(0);
|
|
156
|
+
|
|
157
|
+
// load from storage
|
|
158
|
+
for (const setting of particleSettings)
|
|
159
|
+
{
|
|
160
|
+
const type = setting.type;
|
|
161
|
+
const storageName = storagePrefix + setting.name;
|
|
162
|
+
const savedValue = localStorage[storageName];
|
|
163
|
+
if (savedValue == undefined)
|
|
164
|
+
continue;
|
|
165
|
+
|
|
166
|
+
if (type == 'checkbox')
|
|
167
|
+
setting.input.checked = savedValue == 'true';
|
|
168
|
+
else
|
|
169
|
+
setting.input.value = savedValue;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
updateParticles();
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function updateParticles(shouldUpdateInput)
|
|
176
|
+
{
|
|
177
|
+
for (const setting of particleSettings)
|
|
178
|
+
{
|
|
179
|
+
const input = setting.input;
|
|
180
|
+
const name = setting.name;
|
|
181
|
+
const type = setting.type;
|
|
182
|
+
const inputFloat = parseFloat(input.value) || 0;
|
|
183
|
+
if (type == 'color')
|
|
184
|
+
{
|
|
185
|
+
const color = new Color().setHex(input.value);
|
|
186
|
+
particleSystem[name].r = color.r;
|
|
187
|
+
particleSystem[name].g = color.g;
|
|
188
|
+
particleSystem[name].b = color.b;
|
|
189
|
+
}
|
|
190
|
+
else if (type == 'alpha')
|
|
191
|
+
{
|
|
192
|
+
if (name == 'colorAlphaStartA')
|
|
193
|
+
particleSystem.colorStartA.a = clamp(inputFloat);
|
|
194
|
+
else if (name == 'colorAlphaStartB')
|
|
195
|
+
particleSystem.colorStartB.a = clamp(inputFloat);
|
|
196
|
+
else if (name == 'colorAlphaEndA')
|
|
197
|
+
particleSystem.colorEndA.a = clamp(inputFloat);
|
|
198
|
+
else if (name == 'colorAlphaEndB')
|
|
199
|
+
particleSystem.colorEndB.a = clamp(inputFloat);
|
|
200
|
+
}
|
|
201
|
+
else if (name == 'tileSizeX')
|
|
202
|
+
{
|
|
203
|
+
particleSystem.tileSize = vec2(parseInt(input.value), particleSystem.tileSize.y);
|
|
204
|
+
}
|
|
205
|
+
else if (name == 'tileSizeY')
|
|
206
|
+
{
|
|
207
|
+
particleSystem.tileSize = vec2(particleSystem.tileSize.x, parseInt(input.value));
|
|
208
|
+
}
|
|
209
|
+
else if (type == 'checkbox')
|
|
210
|
+
particleSystem[name] = input.checked ? 1 : 0;
|
|
211
|
+
else if (name == 'emitRate')
|
|
212
|
+
particleSystem[name] = min(inputFloat,1e3);
|
|
213
|
+
else
|
|
214
|
+
particleSystem[name] = clamp(inputFloat, setting.min, setting.max);
|
|
215
|
+
}
|
|
216
|
+
shouldUpdateInput && updateInputs()
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
function updateInputs(save=1)
|
|
220
|
+
{
|
|
221
|
+
for (const setting of particleSettings)
|
|
222
|
+
{
|
|
223
|
+
const input = setting.input;
|
|
224
|
+
const name = setting.name;
|
|
225
|
+
const type = setting.type;
|
|
226
|
+
|
|
227
|
+
if (type == 'color')
|
|
228
|
+
{
|
|
229
|
+
const color = particleSystem[name];
|
|
230
|
+
input.value = color.hex();
|
|
231
|
+
}
|
|
232
|
+
else if (type == 'alpha')
|
|
233
|
+
{
|
|
234
|
+
if (name == 'colorAlphaStartA')
|
|
235
|
+
input.value = particleSystem.colorStartA.a;
|
|
236
|
+
else if (name == 'colorAlphaStartB')
|
|
237
|
+
input.value = particleSystem.colorStartB.a;
|
|
238
|
+
else if (name == 'colorAlphaEndA')
|
|
239
|
+
input.value = particleSystem.colorEndA.a;
|
|
240
|
+
else if (name == 'colorAlphaEndB')
|
|
241
|
+
input.value = particleSystem.colorEndB.a;
|
|
242
|
+
}
|
|
243
|
+
else if (name == 'tileSizeX')
|
|
244
|
+
input.value = particleSystem.tileSize.x;
|
|
245
|
+
else if (name == 'tileSizeY')
|
|
246
|
+
input.value = particleSystem.tileSize.y;
|
|
247
|
+
else if (type == 'checkbox')
|
|
248
|
+
input.checked = particleSystem[name];
|
|
249
|
+
else
|
|
250
|
+
input.value = particleSystem[name] || '0';
|
|
251
|
+
|
|
252
|
+
if (save)
|
|
253
|
+
{
|
|
254
|
+
const storageName = storagePrefix + setting.name;
|
|
255
|
+
localStorage[storageName] = type == 'checkbox' ?
|
|
256
|
+
input.checked : input.value;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
particleSystemCode.value = getCode();
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
function getCode()
|
|
263
|
+
{
|
|
264
|
+
const expand = inputExpand.checked;
|
|
265
|
+
let code = '';
|
|
266
|
+
|
|
267
|
+
// https://www.codingem.com/javascript-how-to-limit-decimal-places/
|
|
268
|
+
Number.prototype.round = function(n) {
|
|
269
|
+
const d = Math.pow(10, n);
|
|
270
|
+
return Math.round((this + Number.EPSILON) * d) / d;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
code = 'new ParticleEmitter(';
|
|
274
|
+
if (expand)
|
|
275
|
+
code += '\n vec2(), 0,\t//position, angle\n';
|
|
276
|
+
else
|
|
277
|
+
code += 'vec2(), 0, ';
|
|
278
|
+
|
|
279
|
+
let count = 0;
|
|
280
|
+
for (const setting of particleSettings)
|
|
281
|
+
{
|
|
282
|
+
const name = setting.name;
|
|
283
|
+
const type = setting.type;
|
|
284
|
+
let value;
|
|
285
|
+
if (name == 'tileSizeX' || type == 'alpha')
|
|
286
|
+
continue;
|
|
287
|
+
|
|
288
|
+
if (name == 'tileSizeY')
|
|
289
|
+
value = `vec2(${particleSystem.tileSize.x}, ${particleSystem.tileSize.y})`;
|
|
290
|
+
else if (type == 'color')
|
|
291
|
+
{
|
|
292
|
+
const c = particleSystem[name];
|
|
293
|
+
const p = 3;
|
|
294
|
+
value = `new Color(${c.r.round(p)}, ${c.g.round(p)}, ${c.b.round(p)}, ${c.a.round(p)})`;
|
|
295
|
+
}
|
|
296
|
+
else if (type == 'checkbox')
|
|
297
|
+
value = particleSystem[name] ? 1 : 0;
|
|
298
|
+
else
|
|
299
|
+
value = particleSystem[name].round(3);
|
|
300
|
+
if (expand)
|
|
301
|
+
code += ' ';
|
|
302
|
+
code += value;
|
|
303
|
+
|
|
304
|
+
const isEnd = name == 'randomColorLinear';
|
|
305
|
+
if (expand)
|
|
306
|
+
{
|
|
307
|
+
code += ',\t// ' + name;
|
|
308
|
+
if (!isEnd)
|
|
309
|
+
code += '\n';
|
|
310
|
+
}
|
|
311
|
+
else if (!isEnd)
|
|
312
|
+
code += ', ';
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
if (expand)
|
|
316
|
+
code += '\n); // particle emitter';
|
|
317
|
+
else
|
|
318
|
+
code += ');';
|
|
319
|
+
|
|
320
|
+
return code;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
324
|
+
function gameUpdate()
|
|
325
|
+
{
|
|
326
|
+
if (!restartTimer.isSet() && particleSystem.destroyed)
|
|
327
|
+
restartTimer.set(1);
|
|
328
|
+
else if (restartTimer.elapsed())
|
|
329
|
+
{
|
|
330
|
+
restartTimer.unset()
|
|
331
|
+
makeEmitter();
|
|
332
|
+
updateParticles();
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
if (document.activeElement == document.body)
|
|
336
|
+
{
|
|
337
|
+
particleSystem.pos = mouseIsDown(0) ? mousePos : vec2();
|
|
338
|
+
if (mouseWheel)
|
|
339
|
+
{
|
|
340
|
+
cameraScale -= sign(mouseWheel)*cameraScale/5;
|
|
341
|
+
cameraScale = clamp(cameraScale, 10, 300);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
347
|
+
function gameUpdatePost()
|
|
348
|
+
{
|
|
349
|
+
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
353
|
+
function gameRender()
|
|
354
|
+
{
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
358
|
+
function gameRenderPost()
|
|
359
|
+
{
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
363
|
+
// Startup LittleJS Engine
|
|
364
|
+
engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost, 'tiles.png');
|
|
365
|
+
|
|
366
|
+
</script>
|
|
Binary file
|
|
@@ -203,7 +203,7 @@ function decorateTile(pos)
|
|
|
203
203
|
|
|
204
204
|
// make pixel perfect outlines
|
|
205
205
|
const size = i&1 ? vec2(2, 16) : vec2(16, 2);
|
|
206
|
-
tileLayer.context.fillStyle = levelGroundColor.mutate(.1)
|
|
206
|
+
tileLayer.context.fillStyle = levelGroundColor.mutate(.1);
|
|
207
207
|
const drawPos = pos.scale(16)
|
|
208
208
|
.add(vec2(i==1?14:0,(i==0?14:0)))
|
|
209
209
|
.subtract((i&1? vec2(0,8-size.y/2) : vec2(8-size.x/2,0)));
|
|
@@ -228,8 +228,8 @@ function drawSky()
|
|
|
228
228
|
{
|
|
229
229
|
// fill background with a gradient
|
|
230
230
|
const gradient = mainContext.fillStyle = mainContext.createLinearGradient(0, 0, 0, mainCanvas.height);
|
|
231
|
-
gradient.addColorStop(0, skyColor
|
|
232
|
-
gradient.addColorStop(1, horizonColor
|
|
231
|
+
gradient.addColorStop(0, skyColor);
|
|
232
|
+
gradient.addColorStop(1, horizonColor);
|
|
233
233
|
mainContext.fillRect(0, 0, mainCanvas.width, mainCanvas.height);
|
|
234
234
|
}
|
|
235
235
|
|
|
@@ -257,7 +257,7 @@ function drawStars()
|
|
|
257
257
|
(randSeeded(w)+time*speed)%w-extraSpace,
|
|
258
258
|
(randSeeded(h)+time*speed*randSeeded())%h-extraSpace);
|
|
259
259
|
|
|
260
|
-
mainContext.fillStyle = color
|
|
260
|
+
mainContext.fillStyle = color;
|
|
261
261
|
if (size < 9)
|
|
262
262
|
mainContext.fillRect(screenPos.x, screenPos.y, size, size);
|
|
263
263
|
else
|
|
@@ -285,8 +285,8 @@ function initParallaxLayers()
|
|
|
285
285
|
const layerColor = levelColor.mutate(.2).lerp(skyColor,.95-i*.15);
|
|
286
286
|
const gradient = tileParallaxLayer.context.fillStyle =
|
|
287
287
|
tileParallaxLayer.context.createLinearGradient(0,0,0,tileParallaxLayer.canvas.height = parallaxSize.y);
|
|
288
|
-
gradient.addColorStop(0,layerColor
|
|
289
|
-
gradient.addColorStop(1,layerColor.subtract(new Color(1,1,1,0)).mutate(.1).clamp()
|
|
288
|
+
gradient.addColorStop(0,layerColor);
|
|
289
|
+
gradient.addColorStop(1,layerColor.subtract(new Color(1,1,1,0)).mutate(.1).clamp());
|
|
290
290
|
|
|
291
291
|
// draw mountains ranges
|
|
292
292
|
let groundLevel = startGroundLevel, groundSlope = rand(-1,1);
|
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
<link rel=icon type=image/png href=../../favicon.png>
|
|
6
6
|
</head><body>
|
|
7
7
|
|
|
8
|
-
<script src=../../engine/engine.all.js?
|
|
9
|
-
<script src=gameObjects.js?
|
|
10
|
-
<script src=gamePlayer.js?
|
|
11
|
-
<script src=gameEffects.js?
|
|
12
|
-
<script src=gameLevel.js?
|
|
13
|
-
<script src=game.js?
|
|
8
|
+
<script src=../../engine/engine.all.js?108></script>
|
|
9
|
+
<script src=gameObjects.js?108></script>
|
|
10
|
+
<script src=gamePlayer.js?108></script>
|
|
11
|
+
<script src=gameEffects.js?108></script>
|
|
12
|
+
<script src=gameLevel.js?108></script>
|
|
13
|
+
<script src=game.js?103></script>
|
package/examples/puzzle/game.js
CHANGED
|
@@ -43,7 +43,7 @@ function gameInit()
|
|
|
43
43
|
{
|
|
44
44
|
// setup canvas
|
|
45
45
|
canvasFixedSize = vec2(1920, 1080); // 1080p
|
|
46
|
-
mainCanvas.style.background = backgroundColor
|
|
46
|
+
mainCanvas.style.background = backgroundColor;
|
|
47
47
|
|
|
48
48
|
// load high score
|
|
49
49
|
bestScore = localStorage[highScoreKey] || 0;
|
|
@@ -129,7 +129,9 @@ function gameUpdate()
|
|
|
129
129
|
else if (mouseIsDown(0) && dragStartPos)
|
|
130
130
|
{
|
|
131
131
|
// if dragging to a neighbor tile
|
|
132
|
-
|
|
132
|
+
const dx = abs(dragStartPos.x - mouseTilePos.x);
|
|
133
|
+
const dy = abs(dragStartPos.y - mouseTilePos.y);
|
|
134
|
+
if (dx == 1 && dy == 0 || dx == 0 && dy == 1)
|
|
133
135
|
{
|
|
134
136
|
const startTile = getTile(dragStartPos);
|
|
135
137
|
const endTile = getTile(mouseTilePos);
|
package/game.js
CHANGED
|
@@ -5,8 +5,7 @@
|
|
|
5
5
|
'use strict';
|
|
6
6
|
|
|
7
7
|
// popup errors if there are any (help diagnose issues on mobile devices)
|
|
8
|
-
|
|
9
|
-
onerror = (...parameters)=> alert(parameters);
|
|
8
|
+
//onerror = (...parameters)=> alert(parameters);
|
|
10
9
|
|
|
11
10
|
// game variables
|
|
12
11
|
let particleEmiter, clickCount = 0;
|
|
@@ -15,7 +14,7 @@ let particleEmiter, clickCount = 0;
|
|
|
15
14
|
const sound_click = new Sound([.5,.5]);
|
|
16
15
|
|
|
17
16
|
// medals
|
|
18
|
-
const medal_example
|
|
17
|
+
const medal_example = new Medal(0, 'Example Medal', 'Medal description goes here.');
|
|
19
18
|
medalsInit('Hello World');
|
|
20
19
|
|
|
21
20
|
///////////////////////////////////////////////////////////////////////////////
|
|
@@ -109,17 +108,7 @@ function gameRender()
|
|
|
109
108
|
function gameRenderPost()
|
|
110
109
|
{
|
|
111
110
|
// draw to overlay canvas for hud rendering
|
|
112
|
-
|
|
113
|
-
{
|
|
114
|
-
overlayContext.textAlign = 'center';
|
|
115
|
-
overlayContext.textBaseline = 'top';
|
|
116
|
-
overlayContext.font = size + 'px arial';
|
|
117
|
-
overlayContext.fillStyle = '#fff';
|
|
118
|
-
overlayContext.lineWidth = 3;
|
|
119
|
-
overlayContext.strokeText(text, x, y);
|
|
120
|
-
overlayContext.fillText(text, x, y);
|
|
121
|
-
}
|
|
122
|
-
drawText('Hello World', overlayCanvas.width/2, 40);
|
|
111
|
+
drawTextScreen('Hello World', vec2(overlayCanvas.width/2, 80), 80, new Color, 9);
|
|
123
112
|
}
|
|
124
113
|
|
|
125
114
|
///////////////////////////////////////////////////////////////////////////////
|
package/index.html
CHANGED
|
@@ -6,21 +6,21 @@
|
|
|
6
6
|
</head><body>
|
|
7
7
|
|
|
8
8
|
<!-- LittleJS engine scripts -->
|
|
9
|
-
<script src=engine/engineDebug.js?
|
|
10
|
-
<script src=engine/engineUtilities.js?
|
|
11
|
-
<script src=engine/engineSettings.js?
|
|
12
|
-
<script src=engine/engineObject.js?
|
|
13
|
-
<script src=engine/engineDraw.js?
|
|
14
|
-
<script src=engine/engineInput.js?
|
|
15
|
-
<script src=engine/engineAudio.js?
|
|
16
|
-
<script src=engine/engineTileLayer.js?
|
|
17
|
-
<script src=engine/engineParticles.js?
|
|
18
|
-
<script src=engine/engineMedals.js?
|
|
19
|
-
<script src=engine/engineWebGL.js?
|
|
20
|
-
<script src=engine/engine.js?
|
|
9
|
+
<script src=engine/engineDebug.js?108></script>
|
|
10
|
+
<script src=engine/engineUtilities.js?108></script>
|
|
11
|
+
<script src=engine/engineSettings.js?108></script>
|
|
12
|
+
<script src=engine/engineObject.js?108></script>
|
|
13
|
+
<script src=engine/engineDraw.js?108></script>
|
|
14
|
+
<script src=engine/engineInput.js?108></script>
|
|
15
|
+
<script src=engine/engineAudio.js?108></script>
|
|
16
|
+
<script src=engine/engineTileLayer.js?108></script>
|
|
17
|
+
<script src=engine/engineParticles.js?108></script>
|
|
18
|
+
<script src=engine/engineMedals.js?108></script>
|
|
19
|
+
<script src=engine/engineWebGL.js?108></script>
|
|
20
|
+
<script src=engine/engine.js?108></script>
|
|
21
21
|
|
|
22
22
|
<!-- You can also include all engine scripts like this... -->
|
|
23
23
|
<!-- <script src=engine/engine.all.js></script> -->
|
|
24
24
|
|
|
25
25
|
<!-- Add your game scripts here -->
|
|
26
|
-
<script src=game.js?
|
|
26
|
+
<script src=game.js?108></script>
|
package/package.json
CHANGED