littlejsengine 1.11.17 → 1.12.6
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/dist/box2d.wasm.js +630 -0
- package/dist/box2d.wasm.wasm +0 -0
- package/dist/littlejs.d.ts +158 -81
- package/dist/littlejs.esm.js +882 -793
- package/dist/littlejs.esm.min.js +1 -1
- package/dist/littlejs.js +3048 -175
- package/dist/littlejs.min.js +1 -1
- package/dist/littlejs.release.js +3047 -172
- package/examples/box2d/game.js +82 -56
- package/examples/box2d/gameObjects.js +114 -107
- package/examples/box2d/index.html +2 -7
- package/examples/box2d/scenes.js +72 -78
- package/examples/box2d/tiles.png +0 -0
- package/examples/breakout/game.js +63 -28
- package/examples/breakout/gameObjects.js +45 -47
- package/examples/breakout/index.html +1 -5
- package/examples/breakoutTutorial/game.js +36 -29
- package/examples/breakoutTutorial/index.html +1 -3
- package/examples/empty/game.js +5 -2
- package/examples/empty/index.html +1 -3
- package/examples/htmlMenu/game.js +24 -15
- package/examples/htmlMenu/index.html +5 -7
- package/examples/index.html +24 -17
- package/examples/module/game.js +32 -34
- package/examples/module/index.html +1 -1
- package/examples/particles/index.html +27 -22
- package/examples/platformer/game.js +62 -45
- package/examples/platformer/gameCharacter.js +42 -34
- package/examples/platformer/gameEffects.js +82 -75
- package/examples/platformer/gameLevel.js +67 -38
- package/examples/platformer/{gameLevelData.js → gameLevelData.json} +1 -11
- package/examples/platformer/gameObjects.js +70 -64
- package/examples/platformer/gamePlayer.js +12 -7
- package/examples/platformer/index.html +1 -9
- package/examples/puzzle/game.js +59 -40
- package/examples/puzzle/index.html +1 -3
- package/examples/shorts/base.html +3 -2
- package/examples/shorts/box2d.js +46 -0
- package/examples/shorts/box2dCar.js +49 -0
- package/examples/shorts/particles.js +1 -1
- package/examples/shorts/platformer.js +1 -1
- package/examples/shorts/postProcess.js +45 -0
- package/examples/shorts/tileLayer.js +5 -6
- package/examples/shorts/tiles.png +0 -0
- package/examples/shorts/uiSystem.js +39 -0
- package/examples/starter/game.js +9 -10
- package/examples/starter/index.html +13 -13
- package/examples/stress/index.html +44 -44
- package/examples/typescript/build.js +17 -18
- package/examples/typescript/game.js +32 -34
- package/examples/typescript/game.ts +32 -34
- package/examples/typescript/index.html +1 -1
- package/examples/uiSystem/game.js +34 -31
- package/examples/uiSystem/index.html +1 -5
- package/package.json +1 -1
- package/plugins/box2d.js +28 -30
- package/plugins/pluginExport.js +2 -3
- package/plugins/uiSystem.js +9 -3
- package/reference.md +29 -27
- package/src/engine.js +10 -11
- package/src/engineAudio.js +24 -15
- package/src/engineBuild.js +25 -8
- package/src/engineDebug.js +1 -3
- package/src/engineExport.js +3 -6
- package/src/engineInput.js +6 -4
- package/src/engineObject.js +18 -14
- package/src/engineSettings.js +6 -6
- package/src/engineTileLayer.js +179 -96
- package/src/engineUtilities.js +16 -0
- package/src/engineWebGL.js +13 -1
- package/examples/typescript/build/dist/littlejs.esm.js +0 -4834
- package/examples/typescript/build/examples/typescript/build.js +0 -24
- package/examples/typescript/build/examples/typescript/game.js +0 -102
|
@@ -9,18 +9,20 @@ input { width:99px; }
|
|
|
9
9
|
button { margin:1px; }
|
|
10
10
|
</style>
|
|
11
11
|
</head><body>
|
|
12
|
+
<script type=module>
|
|
12
13
|
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
// import LittleJS module
|
|
15
|
+
import * as LJS from '../../dist/littlejs.esm.js';
|
|
16
|
+
const {vec2} = LJS;
|
|
15
17
|
|
|
16
18
|
'use strict';
|
|
17
19
|
|
|
18
20
|
// fix texture bleeding by shrinking tiles slightly
|
|
19
|
-
|
|
21
|
+
LJS.setTileFixBleedScale(.5);
|
|
20
22
|
|
|
21
23
|
let particleEditor = 0, particleSystem, particleSystemDiv, particleSystemCode;
|
|
22
24
|
let inputExpand;
|
|
23
|
-
let restartTimer = new Timer();
|
|
25
|
+
let restartTimer = new LJS.Timer();
|
|
24
26
|
const storagePrefix = 'particles_';
|
|
25
27
|
|
|
26
28
|
const particleSettings = [];
|
|
@@ -62,8 +64,8 @@ function makeEmitter()
|
|
|
62
64
|
{
|
|
63
65
|
if (particleSystem)
|
|
64
66
|
particleSystem.destroy();
|
|
65
|
-
particleSystem = new ParticleEmitter(cameraPos);
|
|
66
|
-
particleSystem.tileInfo = tile();
|
|
67
|
+
particleSystem = new LJS.ParticleEmitter(LJS.cameraPos);
|
|
68
|
+
particleSystem.tileInfo = LJS.tile();
|
|
67
69
|
particleSystem.emitConeAngle =
|
|
68
70
|
particleSystem.particleConeAngle = 3.14;
|
|
69
71
|
}
|
|
@@ -72,8 +74,8 @@ function makeEmitter()
|
|
|
72
74
|
function gameInit()
|
|
73
75
|
{
|
|
74
76
|
makeEmitter();
|
|
75
|
-
|
|
76
|
-
|
|
77
|
+
LJS.setGravity(vec2(0,-.01));
|
|
78
|
+
LJS.setCameraScale(64);
|
|
77
79
|
|
|
78
80
|
const div = particleSystemDiv = document.createElement('div');
|
|
79
81
|
div.innerHTML = '<big><b>LittleJS Particle Tool';
|
|
@@ -164,7 +166,7 @@ function gameInit()
|
|
|
164
166
|
return;
|
|
165
167
|
makeEmitter();
|
|
166
168
|
updateInputs();
|
|
167
|
-
|
|
169
|
+
LJS.setCameraScale(50);
|
|
168
170
|
}
|
|
169
171
|
}
|
|
170
172
|
{
|
|
@@ -214,7 +216,7 @@ function updateParticles(shouldUpdateInput)
|
|
|
214
216
|
const inputFloat = parseFloat(input.value) || 0;
|
|
215
217
|
if (type == 'color')
|
|
216
218
|
{
|
|
217
|
-
const color = new Color().setHex(input.value);
|
|
219
|
+
const color = new LJS.Color().setHex(input.value);
|
|
218
220
|
particleSystem[name].r = color.r;
|
|
219
221
|
particleSystem[name].g = color.g;
|
|
220
222
|
particleSystem[name].b = color.b;
|
|
@@ -222,28 +224,28 @@ function updateParticles(shouldUpdateInput)
|
|
|
222
224
|
else if (type == 'alpha')
|
|
223
225
|
{
|
|
224
226
|
if (name == 'colorStartA_alpha')
|
|
225
|
-
particleSystem.colorStartA.a = clamp(inputFloat);
|
|
227
|
+
particleSystem.colorStartA.a = LJS.clamp(inputFloat);
|
|
226
228
|
else if (name == 'colorStartB_alpha')
|
|
227
|
-
particleSystem.colorStartB.a = clamp(inputFloat);
|
|
229
|
+
particleSystem.colorStartB.a = LJS.clamp(inputFloat);
|
|
228
230
|
else if (name == 'colorEndA_alpha')
|
|
229
|
-
particleSystem.colorEndA.a = clamp(inputFloat);
|
|
231
|
+
particleSystem.colorEndA.a = LJS.clamp(inputFloat);
|
|
230
232
|
else if (name == 'colorEndB_alpha')
|
|
231
|
-
particleSystem.colorEndB.a = clamp(inputFloat);
|
|
233
|
+
particleSystem.colorEndB.a = LJS.clamp(inputFloat);
|
|
232
234
|
}
|
|
233
235
|
else if (name == 'tileIndex')
|
|
234
236
|
{
|
|
235
237
|
const tileIndex = parseInt(input.value);
|
|
236
238
|
particleSystem.tileIndex = tileIndex
|
|
237
|
-
particleSystem.tileInfo = tile(tileIndex, particleSystem.tileInfo.size);
|
|
239
|
+
particleSystem.tileInfo = LJS.tile(tileIndex, particleSystem.tileInfo.size);
|
|
238
240
|
}
|
|
239
241
|
else if (name == 'tileSize')
|
|
240
242
|
particleSystem.tileInfo.size = vec2(parseInt(input.value));
|
|
241
243
|
else if (type == 'checkbox')
|
|
242
244
|
particleSystem[name] = input.checked ? 1 : 0;
|
|
243
245
|
else if (name == 'emitRate')
|
|
244
|
-
particleSystem[name] = min(inputFloat,
|
|
246
|
+
particleSystem[name] = LJS.min(inputFloat,1e4);
|
|
245
247
|
else
|
|
246
|
-
particleSystem[name] = clamp(inputFloat, setting.min, setting.max);
|
|
248
|
+
particleSystem[name] = LJS.clamp(inputFloat, setting.min, setting.max);
|
|
247
249
|
}
|
|
248
250
|
shouldUpdateInput && updateInputs()
|
|
249
251
|
}
|
|
@@ -367,11 +369,14 @@ function gameUpdate()
|
|
|
367
369
|
|
|
368
370
|
if (document.activeElement == document.body)
|
|
369
371
|
{
|
|
370
|
-
particleSystem.pos = mouseIsDown(0) ? mousePos : vec2();
|
|
371
|
-
if (mouseWheel)
|
|
372
|
+
particleSystem.pos = LJS.mouseIsDown(0) ? LJS.mousePos : vec2();
|
|
373
|
+
if (LJS.mouseWheel)
|
|
372
374
|
{
|
|
373
|
-
|
|
374
|
-
cameraScale =
|
|
375
|
+
// zoom camera
|
|
376
|
+
let cameraScale = LJS.cameraScale;
|
|
377
|
+
cameraScale -= LJS.sign(LJS.mouseWheel)*cameraScale/5;
|
|
378
|
+
cameraScale = LJS.clamp(cameraScale, 10, 300);
|
|
379
|
+
LJS.setCameraScale(cameraScale);
|
|
375
380
|
}
|
|
376
381
|
}
|
|
377
382
|
}
|
|
@@ -394,6 +399,6 @@ function gameRenderPost()
|
|
|
394
399
|
|
|
395
400
|
///////////////////////////////////////////////////////////////////////////////
|
|
396
401
|
// Startup LittleJS Engine
|
|
397
|
-
engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost, ['tiles.png']);
|
|
402
|
+
LJS.engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost, ['tiles.png']);
|
|
398
403
|
|
|
399
404
|
</script>
|
|
@@ -8,22 +8,50 @@
|
|
|
8
8
|
|
|
9
9
|
'use strict';
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
// import LittleJS module
|
|
12
|
+
import * as LJS from '../../dist/littlejs.esm.js';
|
|
13
|
+
import * as GameObjects from './gameObjects.js';
|
|
14
|
+
import * as GameEffects from './gameEffects.js';
|
|
15
|
+
import * as GamePlayer from './gamePlayer.js';
|
|
16
|
+
import * as GameLevel from './gameLevel.js';
|
|
17
|
+
const {vec2} = LJS;
|
|
18
|
+
|
|
19
|
+
// load the game level data
|
|
20
|
+
export const gameLevelData = await LJS.fetchJSON('gameLevelData.json');
|
|
21
|
+
|
|
22
|
+
// globals
|
|
23
|
+
export let spriteAtlas, player, score, deaths;
|
|
24
|
+
export function addToScore(delta=1) { score += delta; }
|
|
25
|
+
export function addToDeaths() { ++deaths; }
|
|
12
26
|
|
|
13
27
|
// enable touch gamepad on touch devices
|
|
14
|
-
|
|
28
|
+
LJS.setTouchGamepadEnable(true);
|
|
15
29
|
|
|
16
30
|
///////////////////////////////////////////////////////////////////////////////
|
|
17
|
-
function
|
|
31
|
+
function loadLevel()
|
|
32
|
+
{
|
|
33
|
+
// setup level
|
|
34
|
+
GameLevel.buildLevel();
|
|
35
|
+
|
|
36
|
+
// spawn player
|
|
37
|
+
player = new GamePlayer.Player(GameLevel.playerStartPos);
|
|
38
|
+
LJS.setCameraPos(GameLevel.getCameraTarget());
|
|
39
|
+
|
|
40
|
+
// init game
|
|
41
|
+
score = deaths = 0;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
45
|
+
async function gameInit()
|
|
18
46
|
{
|
|
19
47
|
// engine settings
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
48
|
+
LJS.setGravity(vec2(0,-.01));
|
|
49
|
+
LJS.setObjectDefaultDamping(.99);
|
|
50
|
+
LJS.setObjectDefaultAngleDamping(.99);
|
|
51
|
+
LJS.setCameraScale(4*16);
|
|
24
52
|
|
|
25
53
|
// create a table of all sprites
|
|
26
|
-
const gameTile = (i, size=16)=>
|
|
54
|
+
const gameTile = (i, size=16)=> LJS.tile(i, size, 0, 1);
|
|
27
55
|
spriteAtlas =
|
|
28
56
|
{
|
|
29
57
|
// large tiles
|
|
@@ -38,11 +66,7 @@ function gameInit()
|
|
|
38
66
|
grenade: gameTile(vec2(1,2),8),
|
|
39
67
|
};
|
|
40
68
|
|
|
41
|
-
|
|
42
|
-
buildLevel();
|
|
43
|
-
|
|
44
|
-
// init game
|
|
45
|
-
score = deaths = 0;
|
|
69
|
+
loadLevel();
|
|
46
70
|
}
|
|
47
71
|
|
|
48
72
|
///////////////////////////////////////////////////////////////////////////////
|
|
@@ -51,48 +75,40 @@ function gameUpdate()
|
|
|
51
75
|
// respawn player
|
|
52
76
|
if (player.deadTimer > 1)
|
|
53
77
|
{
|
|
54
|
-
player = new Player(playerStartPos);
|
|
78
|
+
player = new GamePlayer.Player(GameLevel.playerStartPos);
|
|
55
79
|
player.velocity = vec2(0,.1);
|
|
56
|
-
sound_jump.play();
|
|
80
|
+
GameEffects.sound_jump.play();
|
|
57
81
|
}
|
|
58
82
|
|
|
59
83
|
// mouse wheel = zoom
|
|
60
|
-
|
|
84
|
+
LJS.setCameraScale(LJS.clamp(LJS.cameraScale*(1-LJS.mouseWheel/10), 1, 1e3));
|
|
61
85
|
|
|
62
86
|
// T = drop test crate
|
|
63
|
-
if (keyWasPressed('KeyT'))
|
|
64
|
-
new Crate(mousePos);
|
|
87
|
+
if (LJS.keyWasPressed('KeyT'))
|
|
88
|
+
new GameObjects.Crate(LJS.mousePos);
|
|
65
89
|
|
|
66
90
|
// E = drop enemy
|
|
67
|
-
if (keyWasPressed('KeyE'))
|
|
68
|
-
new Enemy(mousePos);
|
|
91
|
+
if (LJS.keyWasPressed('KeyE'))
|
|
92
|
+
new GameObjects.Enemy(LJS.mousePos);
|
|
69
93
|
|
|
70
94
|
// X = make explosion
|
|
71
|
-
if (keyWasPressed('KeyX'))
|
|
72
|
-
explosion(mousePos);
|
|
95
|
+
if (LJS.keyWasPressed('KeyX'))
|
|
96
|
+
GameEffects.explosion(LJS.mousePos);
|
|
73
97
|
|
|
74
98
|
// M = move player to mouse
|
|
75
|
-
if (keyWasPressed('KeyM'))
|
|
76
|
-
player.pos = mousePos;
|
|
99
|
+
if (LJS.keyWasPressed('KeyM'))
|
|
100
|
+
player.pos = LJS.mousePos;
|
|
77
101
|
|
|
78
102
|
// R = restart level
|
|
79
|
-
if (keyWasPressed('KeyR'))
|
|
80
|
-
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
84
|
-
function getCameraTarget()
|
|
85
|
-
{
|
|
86
|
-
// camera is above player
|
|
87
|
-
const offset = 200/cameraScale*percent(mainCanvasSize.y, 300, 600);
|
|
88
|
-
return player.pos.add(vec2(0, offset));
|
|
103
|
+
if (LJS.keyWasPressed('KeyR'))
|
|
104
|
+
loadLevel();
|
|
89
105
|
}
|
|
90
106
|
|
|
91
107
|
///////////////////////////////////////////////////////////////////////////////
|
|
92
108
|
function gameUpdatePost()
|
|
93
109
|
{
|
|
94
110
|
// update camera
|
|
95
|
-
cameraPos
|
|
111
|
+
LJS.setCameraPos(LJS.cameraPos.lerp(GameLevel.getCameraTarget(), LJS.clamp(player.getAliveTime()/2)));
|
|
96
112
|
}
|
|
97
113
|
|
|
98
114
|
///////////////////////////////////////////////////////////////////////////////
|
|
@@ -106,18 +122,19 @@ function gameRenderPost()
|
|
|
106
122
|
// draw to overlay canvas for hud rendering
|
|
107
123
|
const drawText = (text, x, y, size=40) =>
|
|
108
124
|
{
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
125
|
+
const context = LJS.overlayContext;
|
|
126
|
+
context.textAlign = 'center';
|
|
127
|
+
context.textBaseline = 'top';
|
|
128
|
+
context.font = size + 'px arial';
|
|
129
|
+
context.fillStyle = '#fff';
|
|
130
|
+
context.lineWidth = 3;
|
|
131
|
+
context.strokeText(text, x, y);
|
|
132
|
+
context.fillText(text, x, y);
|
|
116
133
|
}
|
|
117
|
-
drawText('Score: ' + score, overlayCanvas.width*1/4, 20);
|
|
118
|
-
drawText('Deaths: ' + deaths, overlayCanvas.width*3/4, 20);
|
|
134
|
+
drawText('Score: ' + score, LJS.overlayCanvas.width*1/4, 20);
|
|
135
|
+
drawText('Deaths: ' + deaths, LJS.overlayCanvas.width*3/4, 20);
|
|
119
136
|
}
|
|
120
137
|
|
|
121
138
|
///////////////////////////////////////////////////////////////////////////////
|
|
122
139
|
// Startup LittleJS Engine
|
|
123
|
-
engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost, ['tiles.png', 'tilesLevel.png']);
|
|
140
|
+
LJS.engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost, ['tiles.png', 'tilesLevel.png']);
|
|
@@ -11,13 +11,21 @@
|
|
|
11
11
|
|
|
12
12
|
'use strict';
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
// import LittleJS module
|
|
15
|
+
import * as LJS from '../../dist/littlejs.esm.js';
|
|
16
|
+
import * as GameObjects from './gameObjects.js';
|
|
17
|
+
import * as GameEffects from './gameEffects.js';
|
|
18
|
+
import * as GameLevel from './gameLevel.js';
|
|
19
|
+
import * as Game from './game.js';
|
|
20
|
+
const {vec2, hsl, Timer} = LJS;
|
|
21
|
+
|
|
22
|
+
export class Character extends GameObjects.GameObject
|
|
15
23
|
{
|
|
16
24
|
constructor(pos)
|
|
17
25
|
{
|
|
18
26
|
super(pos, vec2(.6,.95));
|
|
19
27
|
|
|
20
|
-
this.weapon = new Weapon(pos, this);
|
|
28
|
+
this.weapon = new GameObjects.Weapon(pos, this);
|
|
21
29
|
this.lastPos = pos;
|
|
22
30
|
this.groundTimer = new Timer;
|
|
23
31
|
this.jumpTimer = new Timer;
|
|
@@ -27,7 +35,7 @@ class Character extends GameObject
|
|
|
27
35
|
this.deadTimer = new Timer;
|
|
28
36
|
this.grenadeThrowTimer = new Timer;
|
|
29
37
|
this.drawSize = vec2(1);
|
|
30
|
-
this.color = hsl(rand(),1,.7);
|
|
38
|
+
this.color = hsl(LJS.rand(),1,.7);
|
|
31
39
|
this.renderOrder = 10;
|
|
32
40
|
this.walkCyclePercent = 0;
|
|
33
41
|
this.health = 1;
|
|
@@ -63,7 +71,7 @@ class Character extends GameObject
|
|
|
63
71
|
if (this.dodgeTimer.active())
|
|
64
72
|
{
|
|
65
73
|
// update roll
|
|
66
|
-
this.angle = this.getMirrorSign()*2*PI*this.dodgeTimer.getPercent();
|
|
74
|
+
this.angle = this.getMirrorSign()*2*LJS.PI*this.dodgeTimer.getPercent();
|
|
67
75
|
if (this.groundObject)
|
|
68
76
|
this.velocity.x += this.getMirrorSign()*.1;
|
|
69
77
|
}
|
|
@@ -77,7 +85,7 @@ class Character extends GameObject
|
|
|
77
85
|
this.dodgeTimer.set(.4);
|
|
78
86
|
this.dodgeRechargeTimer.set(2);
|
|
79
87
|
this.jumpTimer.unset();
|
|
80
|
-
sound_dodge.play(this.pos);
|
|
88
|
+
GameEffects.sound_dodge.play(this.pos);
|
|
81
89
|
|
|
82
90
|
if (!this.groundObject && this.getAliveTime() > .2)
|
|
83
91
|
this.velocity.y += .2;
|
|
@@ -85,10 +93,11 @@ class Character extends GameObject
|
|
|
85
93
|
if (this.pressingThrow && !this.wasPressingThrow && !this.grenadeThrowTimer.active())
|
|
86
94
|
{
|
|
87
95
|
// throw grenade
|
|
88
|
-
const grenade = new Grenade(this.pos);
|
|
89
|
-
|
|
90
|
-
grenade.
|
|
91
|
-
|
|
96
|
+
const grenade = new GameObjects.Grenade(this.pos);
|
|
97
|
+
const speed = vec2(this.getMirrorSign(),LJS.rand(.8,.7)).normalize(.2+LJS.rand(.02));
|
|
98
|
+
grenade.velocity = this.velocity.add(speed);
|
|
99
|
+
grenade.angleVelocity = this.getMirrorSign() * LJS.rand(.8,.5);
|
|
100
|
+
GameEffects.sound_jump.play(this.pos);
|
|
92
101
|
this.grenadeThrowTimer.set(1);
|
|
93
102
|
}
|
|
94
103
|
this.wasPressingThrow = this.pressingThrow;
|
|
@@ -99,8 +108,8 @@ class Character extends GameObject
|
|
|
99
108
|
for (let y=2;y--;)
|
|
100
109
|
{
|
|
101
110
|
const testPos = this.pos.add(vec2(0, y + .1*moveInput.y - this.size.y/2));
|
|
102
|
-
const collisionData = getTileCollisionData(testPos);
|
|
103
|
-
touchingLadder ||= collisionData == tileType_ladder;
|
|
111
|
+
const collisionData = LJS.getTileCollisionData(testPos);
|
|
112
|
+
touchingLadder ||= collisionData == GameLevel.tileType_ladder;
|
|
104
113
|
}
|
|
105
114
|
if (!touchingLadder)
|
|
106
115
|
this.climbingLadder = false;
|
|
@@ -120,11 +129,11 @@ class Character extends GameObject
|
|
|
120
129
|
|
|
121
130
|
// pull towards ladder
|
|
122
131
|
const delta = (this.pos.x|0)+.5 - this.pos.x;
|
|
123
|
-
this.velocity.x += .02*delta*abs(moveInput.x ? 0:moveInput.y);
|
|
132
|
+
this.velocity.x += .02*delta*LJS.abs(moveInput.x ? 0:moveInput.y);
|
|
124
133
|
moveInput.x *= .2;
|
|
125
134
|
|
|
126
135
|
// exit ladder if ground is below
|
|
127
|
-
this.climbingLadder = moveInput.y >= 0 || getTileCollisionData(this.pos.subtract(vec2(0,1))) <= 0;
|
|
136
|
+
this.climbingLadder = moveInput.y >= 0 || LJS.getTileCollisionData(this.pos.subtract(vec2(0,1))) <= 0;
|
|
128
137
|
}
|
|
129
138
|
else
|
|
130
139
|
{
|
|
@@ -132,8 +141,7 @@ class Character extends GameObject
|
|
|
132
141
|
if (this.groundObject || this.climbingWall)
|
|
133
142
|
{
|
|
134
143
|
if (!this.groundTimer.isSet())
|
|
135
|
-
sound_walk.play(this.pos); // land sound
|
|
136
|
-
|
|
144
|
+
GameEffects.sound_walk.play(this.pos); // land sound
|
|
137
145
|
this.groundTimer.set(.1);
|
|
138
146
|
}
|
|
139
147
|
|
|
@@ -150,7 +158,7 @@ class Character extends GameObject
|
|
|
150
158
|
this.velocity.y = .15;
|
|
151
159
|
this.jumpTimer.set(.2);
|
|
152
160
|
}
|
|
153
|
-
sound_jump.play(this.pos);
|
|
161
|
+
GameEffects.sound_jump.play(this.pos);
|
|
154
162
|
}
|
|
155
163
|
}
|
|
156
164
|
|
|
@@ -165,20 +173,20 @@ class Character extends GameObject
|
|
|
165
173
|
if (!this.groundObject)
|
|
166
174
|
{
|
|
167
175
|
// air control
|
|
168
|
-
if (sign(moveInput.x) == sign(this.velocity.x))
|
|
176
|
+
if (LJS.sign(moveInput.x) == LJS.sign(this.velocity.x))
|
|
169
177
|
moveInput.x *= .1; // moving with velocity
|
|
170
178
|
else
|
|
171
179
|
moveInput.x *= .2; // moving against velocity (stopping)
|
|
172
180
|
|
|
173
181
|
// slight extra gravity when moving down
|
|
174
182
|
if (this.velocity.y < 0)
|
|
175
|
-
this.velocity.y += gravity*.2;
|
|
183
|
+
this.velocity.y += LJS.gravity.y*.2;
|
|
176
184
|
}
|
|
177
185
|
}
|
|
178
186
|
|
|
179
187
|
// apply movement acceleration and clamp
|
|
180
188
|
const maxCharacterSpeed = .2;
|
|
181
|
-
this.velocity.x = clamp(this.velocity.x + moveInput.x * .04, -maxCharacterSpeed, maxCharacterSpeed);
|
|
189
|
+
this.velocity.x = LJS.clamp(this.velocity.x + moveInput.x * .04, -maxCharacterSpeed, maxCharacterSpeed);
|
|
182
190
|
|
|
183
191
|
// track last pos for ladder collision code
|
|
184
192
|
this.lastPos = this.pos.copy();
|
|
@@ -191,7 +199,7 @@ class Character extends GameObject
|
|
|
191
199
|
if (this.climbingLadder || this.groundTimer.active() && !this.dodgeTimer.active())
|
|
192
200
|
{
|
|
193
201
|
this.walkCyclePercent += speed * .5;
|
|
194
|
-
this.walkCyclePercent = speed > .01 ? mod(this.walkCyclePercent) : 0;
|
|
202
|
+
this.walkCyclePercent = speed > .01 ? LJS.mod(this.walkCyclePercent) : 0;
|
|
195
203
|
}
|
|
196
204
|
else
|
|
197
205
|
this.walkCyclePercent = 0;
|
|
@@ -203,7 +211,7 @@ class Character extends GameObject
|
|
|
203
211
|
if (this.walkSoundTime > 1)
|
|
204
212
|
{
|
|
205
213
|
this.walkSoundTime = this.walkSoundTime%1;
|
|
206
|
-
sound_walk.play(this.pos);
|
|
214
|
+
GameEffects.sound_walk.play(this.pos);
|
|
207
215
|
}
|
|
208
216
|
}
|
|
209
217
|
else
|
|
@@ -220,18 +228,18 @@ class Character extends GameObject
|
|
|
220
228
|
const animationFrame = this.isDead() ? 0 :
|
|
221
229
|
this.climbingLadder || this.groundTimer.active() ?
|
|
222
230
|
2*this.walkCyclePercent|0 : 1;
|
|
223
|
-
this.tileInfo = spriteAtlas.player.frame(animationFrame);
|
|
231
|
+
this.tileInfo = Game.spriteAtlas.player.frame(animationFrame);
|
|
224
232
|
|
|
225
233
|
let bodyPos = this.pos;
|
|
226
234
|
if (!this.isDead())
|
|
227
235
|
{
|
|
228
236
|
// bounce pos with walk cycle
|
|
229
|
-
bodyPos = bodyPos.add(vec2(0,.01+.05*Math.sin(this.walkCyclePercent*PI)));
|
|
237
|
+
bodyPos = bodyPos.add(vec2(0,.01+.05*Math.sin(this.walkCyclePercent*LJS.PI)));
|
|
230
238
|
|
|
231
239
|
// make bottom flush
|
|
232
240
|
bodyPos = bodyPos.add(vec2(0,(this.drawSize.y-this.size.y)/2));
|
|
233
241
|
}
|
|
234
|
-
drawTile(bodyPos, this.drawSize, this.tileInfo, this.color, this.angle, this.mirror);
|
|
242
|
+
LJS.drawTile(bodyPos, this.drawSize, this.tileInfo, this.color, this.angle, this.mirror);
|
|
235
243
|
}
|
|
236
244
|
|
|
237
245
|
damage(damage, damagingObject)
|
|
@@ -239,7 +247,7 @@ class Character extends GameObject
|
|
|
239
247
|
if (this.isDead() || this.getAliveTime() < 1 || this.dodgeTimer.active())
|
|
240
248
|
return 0;
|
|
241
249
|
|
|
242
|
-
makeBlood(damagingObject ? damagingObject.pos : this.pos);
|
|
250
|
+
GameEffects.makeBlood(damagingObject ? damagingObject.pos : this.pos);
|
|
243
251
|
return super.damage(damage, damagingObject);
|
|
244
252
|
}
|
|
245
253
|
|
|
@@ -248,14 +256,14 @@ class Character extends GameObject
|
|
|
248
256
|
if (this.isDead())
|
|
249
257
|
return;
|
|
250
258
|
|
|
251
|
-
makeBlood(this.pos, 100);
|
|
252
|
-
sound_die.play(this.pos);
|
|
259
|
+
GameEffects.makeBlood(this.pos, 100);
|
|
260
|
+
GameEffects.sound_die.play(this.pos);
|
|
253
261
|
|
|
254
262
|
this.health = 0;
|
|
255
263
|
this.deadTimer.set();
|
|
256
264
|
this.size = this.size.scale(.5);
|
|
257
|
-
const fallDirection = damagingObject ? sign(damagingObject.velocity.x) : randSign();
|
|
258
|
-
this.angleVelocity = fallDirection*rand(.22,.14);
|
|
265
|
+
const fallDirection = damagingObject ? LJS.sign(damagingObject.velocity.x) : LJS.randSign();
|
|
266
|
+
this.angleVelocity = fallDirection*LJS.rand(.22,.14);
|
|
259
267
|
this.angleDamping = .9;
|
|
260
268
|
this.renderOrder = -1; // move to back layer
|
|
261
269
|
if (this.weapon)
|
|
@@ -267,15 +275,15 @@ class Character extends GameObject
|
|
|
267
275
|
if (!data)
|
|
268
276
|
return false;
|
|
269
277
|
|
|
270
|
-
if (data == tileType_ladder)
|
|
278
|
+
if (data == GameLevel.tileType_ladder)
|
|
271
279
|
{
|
|
272
280
|
// handle ladder collisions
|
|
273
281
|
if (pos.y + 1 > this.lastPos.y - this.size.y/2)
|
|
274
282
|
return false;
|
|
275
283
|
|
|
276
|
-
if (getTileCollisionData(pos.add(vec2(0,1))) // above
|
|
277
|
-
&& !getTileCollisionData(pos.add(vec2(1,0))) // left
|
|
278
|
-
&& !getTileCollisionData(pos.add(vec2(1,0)))) // right
|
|
284
|
+
if (LJS.getTileCollisionData(pos.add(vec2(0,1))) // above
|
|
285
|
+
&& !LJS.getTileCollisionData(pos.add(vec2(1,0))) // left
|
|
286
|
+
&& !LJS.getTileCollisionData(pos.add(vec2(1,0)))) // right
|
|
279
287
|
return false; // don't collide if something above it and nothing to left or right
|
|
280
288
|
|
|
281
289
|
// allow standing on top of ladders
|
|
@@ -284,7 +292,7 @@ class Character extends GameObject
|
|
|
284
292
|
|
|
285
293
|
const d = pos.y - this.pos.y;
|
|
286
294
|
if (!this.climbingLadder && this.velocity.y > .1 && d > 0 && d < this.size.y/2)
|
|
287
|
-
if (destroyTile(pos))
|
|
295
|
+
if (GameEffects.destroyTile(pos))
|
|
288
296
|
{
|
|
289
297
|
// break blocks above
|
|
290
298
|
this.velocity.y = 0;
|