littlejsengine 1.4.0 → 1.4.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/build.bat +1 -1
- package/buildSetup.bat +2 -2
- package/engine/engine.all.js +244 -161
- package/engine/engine.all.min.js +1 -1
- package/engine/engine.all.module.js +4812 -0
- package/engine/engine.all.release.js +228 -138
- package/engine/engine.all.release.module.js +4457 -0
- package/engine/engine.js +12 -8
- package/engine/engineBuild.bat +21 -2
- package/engine/engineDebug.js +16 -23
- package/engine/engineDraw.js +13 -13
- package/engine/engineExport.js +333 -0
- package/engine/engineInput.js +8 -7
- package/engine/engineMedals.js +10 -6
- package/engine/engineObject.js +4 -4
- package/engine/engineParticles.js +45 -21
- package/engine/engineTileLayer.js +1 -1
- package/engine/engineUtilities.js +21 -25
- package/engine/engineWebGL.js +114 -54
- package/engine/index.d.ts +41 -30
- package/examples/breakout/game.js +63 -11
- package/examples/breakout/gameObjects.js +14 -12
- package/examples/breakout/index.html +3 -3
- package/examples/empty/game.js +35 -0
- package/examples/empty/index.html +9 -0
- package/examples/empty/tiles.png +0 -0
- package/examples/module/game.js +122 -0
- package/examples/module/index.html +9 -0
- package/examples/module/tiles.png +0 -0
- package/examples/particles/index.html +14 -14
- package/examples/particles/tiles.png +0 -0
- package/examples/platformer/gameObjects.js +5 -5
- package/examples/platformer/gamePlayer.js +7 -5
- package/examples/platformer/index.html +6 -6
- package/examples/puzzle/index.html +2 -2
- package/examples/stress/index.html +2 -2
- package/game.js +9 -11
- package/index.html +13 -13
- package/package.json +35 -25
- package/README.md +0 -54
package/engine/index.d.ts
CHANGED
|
@@ -70,7 +70,7 @@ declare function setBlendMode(additive?: boolean, useWebGL?: boolean): void;
|
|
|
70
70
|
* @param {Color} [lineColor=new Color(0,0,0)]
|
|
71
71
|
* @param {String} [textAlign='center']
|
|
72
72
|
* @memberof Draw */
|
|
73
|
-
declare function drawTextScreen(text: string, pos: Vector2, size?: number, color?: Color, lineWidth?: number, lineColor?: Color, textAlign?: string, font?: string): void;
|
|
73
|
+
declare function drawTextScreen(text: string, pos: Vector2, size?: number, color?: Color, lineWidth?: number, lineColor?: Color, textAlign?: string, font?: string, context?: CanvasRenderingContext2D): void;
|
|
74
74
|
/** Draw text on overlay canvas in world space
|
|
75
75
|
* Automatically splits new lines into rows
|
|
76
76
|
* @param {String} text
|
|
@@ -151,6 +151,11 @@ declare function tileCollisionRaycast(posStart: Vector2, posEnd: Vector2, object
|
|
|
151
151
|
* @memberof Medals */
|
|
152
152
|
declare function medalsInit(saveName: string): void;
|
|
153
153
|
declare function medalsRender(): void;
|
|
154
|
+
/** This can used to enable Newgrounds functionality
|
|
155
|
+
* @param {Number} app_id - The newgrounds App ID
|
|
156
|
+
* @param {String} [cipher] - The encryption Key (AES-128/Base64)
|
|
157
|
+
* @memberof Medals */
|
|
158
|
+
declare function newgroundsInit(app_id: number, cipher?: string): void;
|
|
154
159
|
declare function glInit(): void;
|
|
155
160
|
/** Set the WebGl blend mode, normally you should call setBlendMode instead
|
|
156
161
|
* @param {Boolean} [additive=0]
|
|
@@ -173,13 +178,6 @@ declare function glCompileShader(source: string, type: any): WebGLShader;
|
|
|
173
178
|
* @return {WebGLProgram}
|
|
174
179
|
* @memberof WebGL */
|
|
175
180
|
declare function glCreateProgram(vsSource: WebGLShader, fsSource: WebGLShader): WebGLProgram;
|
|
176
|
-
/** Create WebGL buffer
|
|
177
|
-
* @param bufferType
|
|
178
|
-
* @param size
|
|
179
|
-
* @param usage
|
|
180
|
-
* @return {WebGLBuffer}
|
|
181
|
-
* @memberof WebGL */
|
|
182
|
-
declare function glCreateBuffer(bufferType: any, size: any, usage: any): WebGLBuffer;
|
|
183
181
|
/** Create WebGL texture from an image and set the texture settings
|
|
184
182
|
* @param {Image} image
|
|
185
183
|
* @return {WebGLTexture}
|
|
@@ -208,6 +206,11 @@ declare function glCopyToContext(context: CanvasRenderingContext2D, forceDraw?:
|
|
|
208
206
|
* @param [rgbaAdditive=0]
|
|
209
207
|
* @memberof WebGL */
|
|
210
208
|
declare function glDraw(x: any, y: any, sizeX: any, sizeY: any, angle: any, uv0X: any, uv0Y: any, uv1X: any, uv1Y: any, rgba?: number, rgbaAdditive?: number): void;
|
|
209
|
+
/** Set up a post processing shader
|
|
210
|
+
* @param {String} shaderCode
|
|
211
|
+
* @memberof WebGL */
|
|
212
|
+
declare function glInitPostProcess(shaderCode: string): void;
|
|
213
|
+
declare function glRenderPostProcess(): void;
|
|
211
214
|
/** Start up LittleJS engine with your callback functions
|
|
212
215
|
* @param {Function} gameInit - Called once after the engine starts up, setup the game
|
|
213
216
|
* @param {Function} gameUpdate - Called every frame at 60 frames per second, handle input and update the game state
|
|
@@ -657,19 +660,17 @@ declare class Color {
|
|
|
657
660
|
* @param {Number} [alphaAmount=0]
|
|
658
661
|
* @return {Color} */
|
|
659
662
|
mutate(amount?: number, alphaAmount?: number): Color;
|
|
660
|
-
/** Returns this color expressed as
|
|
663
|
+
/** Returns this color expressed as a hex color code
|
|
664
|
+
* @param {Boolean} [useAlpha=1] - if alpha should be included in result
|
|
661
665
|
* @return {String} */
|
|
662
|
-
toString(): string;
|
|
663
|
-
/** Returns this color expressed as 32 bit integer RGBA value
|
|
664
|
-
* @return {Number} */
|
|
665
|
-
rgbaInt(): number;
|
|
666
|
+
toString(useAlpha?: boolean): string;
|
|
666
667
|
/** Set this color from a hex code
|
|
667
668
|
* @param {String} hex - html hex code
|
|
668
669
|
* @return {Color} */
|
|
669
670
|
setHex(hex: string): Color;
|
|
670
|
-
/** Returns this color expressed as
|
|
671
|
-
* @return {
|
|
672
|
-
|
|
671
|
+
/** Returns this color expressed as 32 bit RGBA value
|
|
672
|
+
* @return {Number} */
|
|
673
|
+
rgbaInt(): number;
|
|
673
674
|
}
|
|
674
675
|
/**
|
|
675
676
|
* Timer object tracks how long has passed since it was set
|
|
@@ -956,7 +957,7 @@ declare class EngineObject {
|
|
|
956
957
|
* @param {Vector2} pos - tile where the raycast is
|
|
957
958
|
* @return {Boolean} - true if the raycast should hit */
|
|
958
959
|
collideWithTileRaycast(tileData: number, pos: Vector2): boolean;
|
|
959
|
-
/** Called to check if a
|
|
960
|
+
/** Called to check if a object collision should be resolved
|
|
960
961
|
* @param {EngineObject} object - the object to test against
|
|
961
962
|
* @return {Boolean} - true if the collision should be resolved
|
|
962
963
|
*/
|
|
@@ -982,8 +983,8 @@ declare class EngineObject {
|
|
|
982
983
|
* @param {EngineObject} child */
|
|
983
984
|
removeChild(child: EngineObject): void;
|
|
984
985
|
/** Set how this object collides
|
|
985
|
-
* @param {boolean} [collideSolidObjects=
|
|
986
|
-
* @param {boolean} [isSolid=
|
|
986
|
+
* @param {boolean} [collideSolidObjects=1] - Does it collide with solid objects
|
|
987
|
+
* @param {boolean} [isSolid=1] - Does it collide with and block other objects (expensive in large numbers)
|
|
987
988
|
* @param {boolean} [collideTiles=1] - Does it collide with the tile collision */
|
|
988
989
|
setCollision(collideSolidObjects?: boolean, isSolid?: boolean, collideTiles?: boolean): void;
|
|
989
990
|
collideSolidObjects: boolean;
|
|
@@ -1041,13 +1042,13 @@ declare function worldToScreen(worldPos: Vector2): Vector2;
|
|
|
1041
1042
|
declare let engineFontImage: any;
|
|
1042
1043
|
declare class FontImage {
|
|
1043
1044
|
/** Create an image font
|
|
1044
|
-
* @param {
|
|
1045
|
+
* @param {HTMLImageElement} [image] - The image the font is stored in, if undefined the default font is used
|
|
1045
1046
|
* @param {Vector2} [tileSize=vec2(8)] - The size of the font source tiles
|
|
1046
1047
|
* @param {Vector2} [paddingSize=vec2(0,1)] - How much extra space to add between characters
|
|
1047
1048
|
* @param {Number} [startTileIndex=0] - Tile index in image where font starts
|
|
1048
1049
|
* @param {CanvasRenderingContext2D} [context=overlayContext] - context to draw to
|
|
1049
1050
|
*/
|
|
1050
|
-
constructor(image?:
|
|
1051
|
+
constructor(image?: HTMLImageElement, tileSize?: Vector2, paddingSize?: Vector2, startTileIndex?: number, context?: CanvasRenderingContext2D);
|
|
1051
1052
|
image: any;
|
|
1052
1053
|
tileSize: Vector2;
|
|
1053
1054
|
paddingSize: Vector2;
|
|
@@ -1159,10 +1160,10 @@ declare const stickData: any[];
|
|
|
1159
1160
|
/** Pulse the vibration hardware if it exists
|
|
1160
1161
|
* @param {Number} [pattern=100] - a single value in miliseconds or vibration interval array
|
|
1161
1162
|
* @memberof Input */
|
|
1162
|
-
declare function vibrate(pattern?: number):
|
|
1163
|
+
declare function vibrate(pattern?: number): boolean;
|
|
1163
1164
|
/** Cancel any ongoing vibration
|
|
1164
1165
|
* @memberof Input */
|
|
1165
|
-
declare function vibrateStop():
|
|
1166
|
+
declare function vibrateStop(): boolean;
|
|
1166
1167
|
/** True if a touch device has been detected
|
|
1167
1168
|
* @const {boolean}
|
|
1168
1169
|
* @memberof Input */
|
|
@@ -1442,8 +1443,9 @@ declare class ParticleEmitter extends EngineObject {
|
|
|
1442
1443
|
* @param {Boolean} [additive=0] - Should particles use addtive blend
|
|
1443
1444
|
* @param {Boolean} [randomColorLinear=1] - Should color be randomized linearly or across each component
|
|
1444
1445
|
* @param {Number} [renderOrder=0] - Render order for particles (additive is above other stuff by default)
|
|
1446
|
+
* @param {Boolean} [localSpace=0] - Should it be in local space of emitter (world space is default)
|
|
1445
1447
|
*/
|
|
1446
|
-
constructor(pos: any, angle?: number, emitSize?: number, emitTime?: number, emitRate?: number, emitConeAngle?: number, tileIndex?: number, tileSize?: number, colorStartA?: Color, colorStartB?: Color, colorEndA?: Color, colorEndB?: Color, particleTime?: number, sizeStart?: number, sizeEnd?: number, speed?: number, angleSpeed?: number, damping?: number, angleDamping?: number, gravityScale?: number, particleConeAngle?: number, fadeRate?: number, randomness?: number, collideTiles?: boolean, additive?: boolean, randomColorLinear?: boolean, renderOrder?: number);
|
|
1448
|
+
constructor(pos: any, angle?: number, emitSize?: number, emitTime?: number, emitRate?: number, emitConeAngle?: number, tileIndex?: number, tileSize?: number, colorStartA?: Color, colorStartB?: Color, colorEndA?: Color, colorEndB?: Color, particleTime?: number, sizeStart?: number, sizeEnd?: number, speed?: number, angleSpeed?: number, damping?: number, angleDamping?: number, gravityScale?: number, particleConeAngle?: number, fadeRate?: number, randomness?: number, collideTiles?: boolean, additive?: boolean, randomColorLinear?: boolean, renderOrder?: number, localSpace?: boolean);
|
|
1447
1449
|
/** @property {Number} - World space size of the emitter (float for circle diameter, vec2 for rect) */
|
|
1448
1450
|
emitSize: number;
|
|
1449
1451
|
/** @property {Number} - How long to stay alive (0 is forever) */
|
|
@@ -1482,6 +1484,8 @@ declare class ParticleEmitter extends EngineObject {
|
|
|
1482
1484
|
collideTiles: boolean;
|
|
1483
1485
|
/** @property {Number} - Should particles use addtive blend */
|
|
1484
1486
|
additive: boolean;
|
|
1487
|
+
/** @property {Boolean} - Should it be in local space of emitter */
|
|
1488
|
+
localSpace: boolean;
|
|
1485
1489
|
/** @property {Number} - If set the partile is drawn as a trail, stretched in the drection of velocity */
|
|
1486
1490
|
trailScale: number;
|
|
1487
1491
|
emitTimeBuffer: number;
|
|
@@ -1509,10 +1513,6 @@ declare const medals: any[];
|
|
|
1509
1513
|
/** Set to stop medals from being unlockable (like if cheats are enabled)
|
|
1510
1514
|
* @memberof Medals */
|
|
1511
1515
|
declare let medalsPreventUnlock: any;
|
|
1512
|
-
/** This can used to enable Newgrounds functionality
|
|
1513
|
-
* @type {Newgrounds}
|
|
1514
|
-
* @memberof Medals */
|
|
1515
|
-
declare let newgrounds: Newgrounds;
|
|
1516
1516
|
declare let medalsDisplayQueue: any[];
|
|
1517
1517
|
declare let medalsSaveName: any;
|
|
1518
1518
|
declare let medalsDisplayTimeLast: any;
|
|
@@ -1557,6 +1557,7 @@ declare class Medal {
|
|
|
1557
1557
|
renderIcon(x: number, y: number, size?: number): void;
|
|
1558
1558
|
storageKey(): string;
|
|
1559
1559
|
}
|
|
1560
|
+
declare let newgrounds: any;
|
|
1560
1561
|
/**
|
|
1561
1562
|
* Newgrounds API wrapper object
|
|
1562
1563
|
* @example
|
|
@@ -1618,11 +1619,16 @@ declare let glContext: WebGLRenderingContext;
|
|
|
1618
1619
|
declare let glTileTexture: WebGLTexture;
|
|
1619
1620
|
declare let glActiveTexture: any;
|
|
1620
1621
|
declare let glShader: any;
|
|
1622
|
+
declare let glArrayBuffer: any;
|
|
1623
|
+
declare let glVertexData: any;
|
|
1621
1624
|
declare let glPositionData: any;
|
|
1622
1625
|
declare let glColorData: any;
|
|
1623
1626
|
declare let glBatchCount: any;
|
|
1624
1627
|
declare let glBatchAdditive: any;
|
|
1625
1628
|
declare let glAdditive: any;
|
|
1629
|
+
declare let glPostShader: any;
|
|
1630
|
+
declare let glPostArrayBuffer: any;
|
|
1631
|
+
declare let glPostTexture: any;
|
|
1626
1632
|
declare const gl_ONE: 1;
|
|
1627
1633
|
declare const gl_TRIANGLES: 4;
|
|
1628
1634
|
declare const gl_SRC_ALPHA: 770;
|
|
@@ -1630,6 +1636,7 @@ declare const gl_ONE_MINUS_SRC_ALPHA: 771;
|
|
|
1630
1636
|
declare const gl_BLEND: 3042;
|
|
1631
1637
|
declare const gl_TEXTURE_2D: 3553;
|
|
1632
1638
|
declare const gl_UNSIGNED_BYTE: 5121;
|
|
1639
|
+
declare const gl_BYTE: 5120;
|
|
1633
1640
|
declare const gl_FLOAT: 5126;
|
|
1634
1641
|
declare const gl_RGBA: 6408;
|
|
1635
1642
|
declare const gl_NEAREST: 9728;
|
|
@@ -1640,12 +1647,16 @@ declare const gl_TEXTURE_WRAP_S: 10242;
|
|
|
1640
1647
|
declare const gl_TEXTURE_WRAP_T: 10243;
|
|
1641
1648
|
declare const gl_COLOR_BUFFER_BIT: 16384;
|
|
1642
1649
|
declare const gl_CLAMP_TO_EDGE: 33071;
|
|
1650
|
+
declare const gl_TEXTURE0: 33984;
|
|
1651
|
+
declare const gl_TEXTURE1: 33985;
|
|
1643
1652
|
declare const gl_ARRAY_BUFFER: 34962;
|
|
1653
|
+
declare const gl_STATIC_DRAW: 35044;
|
|
1644
1654
|
declare const gl_DYNAMIC_DRAW: 35048;
|
|
1645
1655
|
declare const gl_FRAGMENT_SHADER: 35632;
|
|
1646
1656
|
declare const gl_VERTEX_SHADER: 35633;
|
|
1647
1657
|
declare const gl_COMPILE_STATUS: 35713;
|
|
1648
1658
|
declare const gl_LINK_STATUS: 35714;
|
|
1659
|
+
declare const gl_UNPACK_FLIP_Y_WEBGL: 37440;
|
|
1649
1660
|
declare const gl_VERTICES_PER_QUAD: 6;
|
|
1650
1661
|
declare const gl_INDICIES_PER_VERT: 6;
|
|
1651
1662
|
declare const gl_MAX_BATCH: number;
|
|
@@ -1653,7 +1664,7 @@ declare const gl_VERTEX_BYTE_STRIDE: number;
|
|
|
1653
1664
|
/** Name of engine */
|
|
1654
1665
|
declare const engineName: "LittleJS";
|
|
1655
1666
|
/** Version of engine */
|
|
1656
|
-
declare const engineVersion: "1.4.
|
|
1667
|
+
declare const engineVersion: "1.4.6";
|
|
1657
1668
|
/** Frames per second to update objects
|
|
1658
1669
|
* @default */
|
|
1659
1670
|
declare const frameRate: 60;
|
|
@@ -1678,5 +1689,5 @@ declare let tileImageSize: any;
|
|
|
1678
1689
|
declare let tileImageFixBleed: any;
|
|
1679
1690
|
declare let averageFPS: any;
|
|
1680
1691
|
declare let drawCount: any;
|
|
1681
|
-
declare const styleBody:
|
|
1692
|
+
declare const styleBody: "margin:0;overflow:hidden;background:#000";
|
|
1682
1693
|
declare const styleCanvas: "position:absolute;top:50%;left:50%;transform:translate(-50%,-50%)";
|
|
@@ -4,12 +4,12 @@
|
|
|
4
4
|
|
|
5
5
|
'use strict';
|
|
6
6
|
|
|
7
|
-
let levelSize, ball, paddle, score,
|
|
7
|
+
let levelSize, ball, paddle, score, brickCount;
|
|
8
8
|
|
|
9
9
|
// sound effects
|
|
10
|
-
const sound_start
|
|
11
|
-
const
|
|
12
|
-
const sound_bounce
|
|
10
|
+
const sound_start = new Sound([,0,500,,.04,.3,1,2,,,570,.02,.02,,,,.04]);
|
|
11
|
+
const sound_break = new Sound([,,90,,.01,.03,4,,,,,,,9,50,.2,,.2,.01], 0);
|
|
12
|
+
const sound_bounce = new Sound([,,1e3,,.03,.02,1,2,,,940,.03,,,,,.2,.6,,.06], 0);
|
|
13
13
|
|
|
14
14
|
///////////////////////////////////////////////////////////////////////////////
|
|
15
15
|
function gameInit()
|
|
@@ -18,13 +18,15 @@ function gameInit()
|
|
|
18
18
|
levelSize = vec2(72, 40);
|
|
19
19
|
cameraPos = levelSize.scale(.5);
|
|
20
20
|
paddle = new Paddle(vec2(levelSize.x/2-12,2));
|
|
21
|
-
score =
|
|
21
|
+
score = brickCount = 0;
|
|
22
22
|
|
|
23
|
-
// spawn
|
|
23
|
+
// spawn bricks
|
|
24
24
|
const pos = vec2();
|
|
25
25
|
for (pos.x = 6; pos.x <= levelSize.x-6; pos.x += 4)
|
|
26
26
|
for (pos.y = levelSize.y/2; pos.y <= levelSize.y-4; pos.y += 2)
|
|
27
|
-
new
|
|
27
|
+
new Brick(pos);
|
|
28
|
+
|
|
29
|
+
initPostProcess(); // set up a post processing shader
|
|
28
30
|
}
|
|
29
31
|
|
|
30
32
|
///////////////////////////////////////////////////////////////////////////////
|
|
@@ -48,8 +50,8 @@ function gameUpdatePost()
|
|
|
48
50
|
function gameRender()
|
|
49
51
|
{
|
|
50
52
|
// draw a the background
|
|
51
|
-
drawRect(cameraPos, levelSize.scale(2), new Color(.
|
|
52
|
-
drawRect(cameraPos, levelSize, new Color(.
|
|
53
|
+
drawRect(cameraPos, levelSize.scale(2), new Color(.5,.5,.5));
|
|
54
|
+
drawRect(cameraPos, levelSize, new Color(.05,.05,.05));
|
|
53
55
|
}
|
|
54
56
|
|
|
55
57
|
///////////////////////////////////////////////////////////////////////////////
|
|
@@ -58,12 +60,62 @@ function gameRenderPost()
|
|
|
58
60
|
// use built in image font for text
|
|
59
61
|
const font = new FontImage;
|
|
60
62
|
font.drawText('Score: ' + score, cameraPos.add(vec2(0,22)), .2, 1);
|
|
61
|
-
if (!
|
|
63
|
+
if (!brickCount)
|
|
62
64
|
font.drawText('You Win!', cameraPos.add(vec2(0,-5)), .25, 1);
|
|
63
65
|
else if (!ball)
|
|
64
66
|
font.drawText('Click to Play', cameraPos.add(vec2(0,-5)), .25, 1);
|
|
65
67
|
}
|
|
66
68
|
|
|
69
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
70
|
+
// an example shader that can be used to apply a post processing effect
|
|
71
|
+
function initPostProcess()
|
|
72
|
+
{
|
|
73
|
+
const televisionShader = `
|
|
74
|
+
// Simple TV Shader Code
|
|
75
|
+
float hash(vec2 p)
|
|
76
|
+
{
|
|
77
|
+
p=fract(p*.3197);
|
|
78
|
+
return fract(1.+sin(51.*p.x+73.*p.y)*13753.3);
|
|
79
|
+
}
|
|
80
|
+
float noise(vec2 p)
|
|
81
|
+
{
|
|
82
|
+
vec2 i=floor(p),f=fract(p),u=f*f*(3.-2.*f);
|
|
83
|
+
return mix(mix(hash(i),hash(i+vec2(1,0)),u.x),mix(hash(i+vec2(0,1)),hash(i+1.),u.x),u.y);
|
|
84
|
+
}
|
|
85
|
+
void mainImage(out vec4 c, vec2 p)
|
|
86
|
+
{
|
|
87
|
+
p /= iResolution.xy;
|
|
88
|
+
|
|
89
|
+
// apply fuzz as horizontal offset
|
|
90
|
+
const float fuzz = .001;
|
|
91
|
+
const float fuzzScale = 800.;
|
|
92
|
+
p.x += fuzz*(noise(vec2(p.y*fuzzScale, iTime*9.))*2.-1.);
|
|
93
|
+
|
|
94
|
+
// init output color
|
|
95
|
+
c = texture2D(iChannel0, p);
|
|
96
|
+
|
|
97
|
+
// chromatic aberration
|
|
98
|
+
const float chromatic = .003;
|
|
99
|
+
c.r = texture2D(iChannel0, p - vec2(chromatic, 0)).r;
|
|
100
|
+
c.b = texture2D(iChannel0, p + vec2(chromatic, 0)).b;
|
|
101
|
+
|
|
102
|
+
// tv static noise
|
|
103
|
+
const float staticNoise = .1;
|
|
104
|
+
c += staticNoise * hash(vec2(p + mod(iTime, 1e3)));
|
|
105
|
+
|
|
106
|
+
// scan lines
|
|
107
|
+
const float scanlineScale = 800.;
|
|
108
|
+
const float scanlineAlpha = .1;
|
|
109
|
+
c *= 1. + scanlineAlpha*sin(p.y*scanlineScale);
|
|
110
|
+
|
|
111
|
+
// black vignette around the outside
|
|
112
|
+
const float vignette = 2.;
|
|
113
|
+
float dx = 2.*p.x - 1., dy = 2.*p.y - 1.;
|
|
114
|
+
c *= 1.-pow((dx*dx + dy*dy)/vignette, 6.);
|
|
115
|
+
}`;
|
|
116
|
+
glInitPostProcess(televisionShader);
|
|
117
|
+
}
|
|
118
|
+
|
|
67
119
|
///////////////////////////////////////////////////////////////////////////////
|
|
68
120
|
// Startup LittleJS Engine
|
|
69
|
-
engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost, 'tiles.png
|
|
121
|
+
engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost, 'tiles.png');
|
|
@@ -12,7 +12,7 @@ class Paddle extends EngineObject
|
|
|
12
12
|
super(pos, vec2(8,1));
|
|
13
13
|
|
|
14
14
|
// set to collide
|
|
15
|
-
this.setCollision(
|
|
15
|
+
this.setCollision();
|
|
16
16
|
this.mass = 0;
|
|
17
17
|
}
|
|
18
18
|
|
|
@@ -29,40 +29,42 @@ class Paddle extends EngineObject
|
|
|
29
29
|
this.pos.x = mousePos.x;
|
|
30
30
|
}
|
|
31
31
|
this.pos.x = clamp(this.pos.x, this.size.x/2, levelSize.x - this.size.x/2);
|
|
32
|
+
super.update();
|
|
32
33
|
}
|
|
33
34
|
}
|
|
34
35
|
|
|
35
36
|
///////////////////////////////////////////////////////////////////////////////
|
|
36
|
-
class
|
|
37
|
+
class Brick extends EngineObject
|
|
37
38
|
{
|
|
38
39
|
constructor(pos)
|
|
39
40
|
{
|
|
40
41
|
super(pos, vec2(4,2), 1, vec2(32,16), 0, randColor());
|
|
41
42
|
|
|
42
43
|
// set to collide
|
|
43
|
-
this.setCollision(
|
|
44
|
+
this.setCollision();
|
|
44
45
|
this.mass = 0;
|
|
45
|
-
++
|
|
46
|
+
++brickCount;
|
|
46
47
|
}
|
|
47
48
|
|
|
48
49
|
collideWithObject(o)
|
|
49
50
|
{
|
|
50
|
-
// destroy
|
|
51
|
+
// destroy brick when hit with ball
|
|
51
52
|
this.destroy();
|
|
52
53
|
++score;
|
|
53
|
-
--
|
|
54
|
-
|
|
54
|
+
--brickCount;
|
|
55
|
+
sound_break.play(this.pos);
|
|
55
56
|
|
|
56
57
|
const color1 = this.color;
|
|
57
58
|
const color2 = color1.lerp(new Color, .5);
|
|
58
59
|
new ParticleEmitter(
|
|
59
|
-
this.pos, 0,
|
|
60
|
+
this.pos, 0, // emitPos, emitAngle
|
|
61
|
+
this.size, .1, 200, PI, // emitSize, emitTime, emitRate, emiteCone
|
|
60
62
|
0, vec2(16), // tileIndex, tileSize
|
|
61
63
|
color1, color2, // colorStartA, colorStartB
|
|
62
64
|
color1.scale(1,0), color2.scale(1,0), // colorEndA, colorEndB
|
|
63
|
-
.2, 1,
|
|
64
|
-
.99, .95, .4, PI,
|
|
65
|
-
1, 0, 1
|
|
65
|
+
.2, 1, 2, .1, .05, // time, sizeStart, sizeEnd, speed, angleSpeed
|
|
66
|
+
.99, .95, .4, PI, // damping, angleDamping, gravityScale, cone
|
|
67
|
+
.1, .5, 0, 1 // fadeRate, randomness, collide, additive
|
|
66
68
|
);
|
|
67
69
|
|
|
68
70
|
return 1;
|
|
@@ -77,7 +79,7 @@ class Ball extends EngineObject
|
|
|
77
79
|
super(pos, vec2(1), 0);
|
|
78
80
|
|
|
79
81
|
// make a bouncy ball
|
|
80
|
-
this.setCollision(
|
|
82
|
+
this.setCollision();
|
|
81
83
|
this.velocity = vec2(randSign(), -1).scale(.2);
|
|
82
84
|
this.elasticity = 1;
|
|
83
85
|
this.damping = 1;
|
|
@@ -5,6 +5,6 @@
|
|
|
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=
|
|
10
|
-
<script src=
|
|
8
|
+
<script src=../../engine/engine.all.js?118></script>
|
|
9
|
+
<script src=gameObjects.js?118></script>
|
|
10
|
+
<script src=game.js?118></script>
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/*
|
|
2
|
+
LittleJS Empty Project Example
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
'use strict';
|
|
6
|
+
|
|
7
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
8
|
+
function gameInit()
|
|
9
|
+
{
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
13
|
+
function gameUpdate()
|
|
14
|
+
{
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
18
|
+
function gameUpdatePost()
|
|
19
|
+
{
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
23
|
+
function gameRender()
|
|
24
|
+
{
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
28
|
+
function gameRenderPost()
|
|
29
|
+
{
|
|
30
|
+
drawTextScreen('LittleJS Empty Project', mainCanvasSize.scale(.5), 80);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
34
|
+
// Startup LittleJS Engine
|
|
35
|
+
engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost, 'tiles.png');
|
|
@@ -0,0 +1,9 @@
|
|
|
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
|
+
</head><body>
|
|
7
|
+
|
|
8
|
+
<script src=../../engine/engine.all.js></script>
|
|
9
|
+
<script src=game.js></script>
|
|
Binary file
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/*
|
|
2
|
+
LittleJS Hello World Starter Game
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
'use strict';
|
|
6
|
+
|
|
7
|
+
// import module
|
|
8
|
+
import * as LittleJS from '../../engine/engine.all.module.js';
|
|
9
|
+
const Vector2 = LittleJS.Vector2;
|
|
10
|
+
const Color = LittleJS.Color;
|
|
11
|
+
const Timer = LittleJS.Timer;
|
|
12
|
+
const vec2 = LittleJS.vec2;
|
|
13
|
+
|
|
14
|
+
// sound effects
|
|
15
|
+
const sound_click = new LittleJS.Sound([.5,.5]);
|
|
16
|
+
|
|
17
|
+
// medals
|
|
18
|
+
const medal_example = new LittleJS.Medal(0, 'Example Medal', 'Welcome to LittleJS!');
|
|
19
|
+
LittleJS.medalsInit('Hello World');
|
|
20
|
+
|
|
21
|
+
// game variables
|
|
22
|
+
let particleEmiter;
|
|
23
|
+
|
|
24
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
25
|
+
function gameInit()
|
|
26
|
+
{
|
|
27
|
+
// create tile collision and visible tile layer
|
|
28
|
+
LittleJS.initTileCollision(vec2(32, 16));
|
|
29
|
+
const tileLayer = new LittleJS.TileLayer(vec2(), LittleJS.tileCollisionSize);
|
|
30
|
+
const pos = vec2();
|
|
31
|
+
|
|
32
|
+
// get level data from the tiles image
|
|
33
|
+
const imageLevelDataRow = 1;
|
|
34
|
+
const mainContext = LittleJS.mainContext;
|
|
35
|
+
mainContext.drawImage(LittleJS.tileImage, 0, 0);
|
|
36
|
+
for (pos.x = LittleJS.tileCollisionSize.x; pos.x--;)
|
|
37
|
+
for (pos.y = LittleJS.tileCollisionSize.y; pos.y--;)
|
|
38
|
+
{
|
|
39
|
+
const data = mainContext.getImageData(pos.x, 16*(imageLevelDataRow+1)-pos.y-1, 1, 1).data;
|
|
40
|
+
if (data[0])
|
|
41
|
+
{
|
|
42
|
+
LittleJS.setTileCollisionData(pos, 1);
|
|
43
|
+
|
|
44
|
+
const tileIndex = 1;
|
|
45
|
+
const direction = LittleJS.randInt(4)
|
|
46
|
+
const mirror = LittleJS.randInt(2);
|
|
47
|
+
const color = LittleJS.randColor();
|
|
48
|
+
const data = new LittleJS.TileLayerData(tileIndex, direction, mirror, color);
|
|
49
|
+
tileLayer.setData(pos, data);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
tileLayer.redraw();
|
|
53
|
+
|
|
54
|
+
// move camera to center of collision
|
|
55
|
+
LittleJS.setCameraPos(LittleJS.tileCollisionSize.scale(.5));
|
|
56
|
+
LittleJS.setCameraScale(32);
|
|
57
|
+
|
|
58
|
+
// enable gravity
|
|
59
|
+
LittleJS.setGravity(-.01);
|
|
60
|
+
|
|
61
|
+
// create particle emitter
|
|
62
|
+
const center = LittleJS.tileCollisionSize.scale(.5).add(vec2(0,9));
|
|
63
|
+
particleEmiter = new LittleJS.ParticleEmitter(
|
|
64
|
+
center, 0, // emitPos, emitAngle
|
|
65
|
+
1, 0, 500, Math.PI, // emitSize, emitTime, emitRate, emiteCone
|
|
66
|
+
0, vec2(16), // tileIndex, tileSize
|
|
67
|
+
new Color(1,1,1), new Color(0,0,0), // colorStartA, colorStartB
|
|
68
|
+
new Color(1,1,1,0), new Color(0,0,0,0), // colorEndA, colorEndB
|
|
69
|
+
2, .2, .2, .1, .05, // time, sizeStart, sizeEnd, speed, angleSpeed
|
|
70
|
+
.99, 1, 1, Math.PI, // damping, angleDamping, gravityScale, cone
|
|
71
|
+
.05, .5, 1, 1 // fadeRate, randomness, collide, additive
|
|
72
|
+
);
|
|
73
|
+
particleEmiter.elasticity = .3; // bounce when it collides
|
|
74
|
+
particleEmiter.trailScale = 2; // stretch in direction of motion
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
78
|
+
function gameUpdate()
|
|
79
|
+
{
|
|
80
|
+
if (LittleJS.mouseWasPressed(0))
|
|
81
|
+
{
|
|
82
|
+
// play sound when mouse is pressed
|
|
83
|
+
sound_click.play(LittleJS.mousePos);
|
|
84
|
+
|
|
85
|
+
// change particle color and set to fade out
|
|
86
|
+
particleEmiter.colorStartA = new Color;
|
|
87
|
+
particleEmiter.colorStartB = LittleJS.randColor();
|
|
88
|
+
particleEmiter.colorEndA = particleEmiter.colorStartA.scale(1,0);
|
|
89
|
+
particleEmiter.colorEndB = particleEmiter.colorStartB.scale(1,0);
|
|
90
|
+
|
|
91
|
+
// unlock medals
|
|
92
|
+
medal_example.unlock();
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// move particles to mouse location if on screen
|
|
96
|
+
if (LittleJS.mousePosScreen.x)
|
|
97
|
+
particleEmiter.pos = LittleJS.mousePos;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
101
|
+
function gameUpdatePost()
|
|
102
|
+
{
|
|
103
|
+
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
107
|
+
function gameRender()
|
|
108
|
+
{
|
|
109
|
+
// draw a grey square in the background without using webgl
|
|
110
|
+
LittleJS.drawRect(LittleJS.cameraPos, LittleJS.tileCollisionSize.add(vec2(5)), new Color(.2,.2,.2), 0, 0);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
114
|
+
function gameRenderPost()
|
|
115
|
+
{
|
|
116
|
+
// draw to overlay canvas for hud rendering
|
|
117
|
+
LittleJS.drawTextScreen('LittleJS with Modules', vec2(LittleJS.mainCanvasSize.x/2, 80), 80);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
121
|
+
// Startup LittleJS Engine
|
|
122
|
+
LittleJS.engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost, 'tiles.png');
|
|
@@ -0,0 +1,9 @@
|
|
|
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
|
+
</head><body>
|
|
7
|
+
|
|
8
|
+
<!-- Add your game scripts here -->
|
|
9
|
+
<script src=game.js?118 type=module></script>
|
|
Binary file
|
|
@@ -15,18 +15,18 @@ button
|
|
|
15
15
|
</style>
|
|
16
16
|
</head><body>
|
|
17
17
|
|
|
18
|
-
<script src=../../engine/engineDebug.js?
|
|
19
|
-
<script src=../../engine/engineUtilities.js?
|
|
20
|
-
<script src=../../engine/engineSettings.js?
|
|
21
|
-
<script src=../../engine/engineObject.js?
|
|
22
|
-
<script src=../../engine/engineDraw.js?
|
|
23
|
-
<script src=../../engine/engineInput.js?
|
|
24
|
-
<script src=../../engine/engineAudio.js?
|
|
25
|
-
<script src=../../engine/engineTileLayer.js?
|
|
26
|
-
<script src=../../engine/engineParticles.js?
|
|
27
|
-
<script src=../../engine/engineMedals.js?
|
|
28
|
-
<script src=../../engine/engineWebGL.js?
|
|
29
|
-
<script src=../../engine/engine.js?
|
|
18
|
+
<script src=../../engine/engineDebug.js?118></script>
|
|
19
|
+
<script src=../../engine/engineUtilities.js?118></script>
|
|
20
|
+
<script src=../../engine/engineSettings.js?118></script>
|
|
21
|
+
<script src=../../engine/engineObject.js?118></script>
|
|
22
|
+
<script src=../../engine/engineDraw.js?118></script>
|
|
23
|
+
<script src=../../engine/engineInput.js?118></script>
|
|
24
|
+
<script src=../../engine/engineAudio.js?118></script>
|
|
25
|
+
<script src=../../engine/engineTileLayer.js?118></script>
|
|
26
|
+
<script src=../../engine/engineParticles.js?118></script>
|
|
27
|
+
<script src=../../engine/engineMedals.js?118></script>
|
|
28
|
+
<script src=../../engine/engineWebGL.js?118></script>
|
|
29
|
+
<script src=../../engine/engine.js?118></script>
|
|
30
30
|
<script>
|
|
31
31
|
|
|
32
32
|
'use strict';
|
|
@@ -103,7 +103,7 @@ function gameInit()
|
|
|
103
103
|
if (type == 'color')
|
|
104
104
|
{
|
|
105
105
|
const color = particleSystem[name];
|
|
106
|
-
defaultValue = color.
|
|
106
|
+
defaultValue = color.toString(0);
|
|
107
107
|
}
|
|
108
108
|
else if (type == 'alpha')
|
|
109
109
|
{
|
|
@@ -277,7 +277,7 @@ function updateSetting(setting, save=1)
|
|
|
277
277
|
if (type == 'color')
|
|
278
278
|
{
|
|
279
279
|
const color = particleSystem[name];
|
|
280
|
-
input.value = color.
|
|
280
|
+
input.value = color.toString(0);
|
|
281
281
|
}
|
|
282
282
|
else if (type == 'alpha')
|
|
283
283
|
{
|
|
Binary file
|