littlejsengine 1.3.8 → 1.4.5
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 +30 -9
- package/build.bat +1 -1
- package/buildSetup.bat +2 -2
- package/engine/engine.all.js +276 -167
- package/engine/engine.all.min.js +1 -1
- package/engine/engine.all.module.js +4812 -0
- package/engine/engine.all.release.js +259 -143
- package/engine/engine.all.release.module.js +4457 -0
- package/engine/engine.js +12 -8
- package/engine/engineBuild.bat +1 -1
- package/engine/engineBuildModule.mjs +14 -0
- package/engine/engineDebug.js +17 -24
- package/engine/engineDraw.js +16 -16
- package/engine/engineExportModule.js +333 -0
- package/engine/engineInput.js +9 -8
- package/engine/engineMedals.js +10 -6
- package/engine/engineObject.js +4 -4
- package/engine/engineParticles.js +45 -21
- package/engine/engineTileLayer.js +2 -2
- package/engine/engineUtilities.js +47 -25
- package/engine/engineWebGL.js +114 -54
- package/engine/index.d.ts +64 -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/game.js +1 -1
- package/examples/platformer/gameObjects.js +7 -7
- 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 +10 -12
- package/index.html +13 -13
- package/package.json +36 -32
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
|
|
@@ -568,6 +571,26 @@ declare class Vector2 {
|
|
|
568
571
|
* @return {String} */
|
|
569
572
|
toString(digits?: float): string;
|
|
570
573
|
}
|
|
574
|
+
/**
|
|
575
|
+
* Create a color object with RGBA values
|
|
576
|
+
* @param {Number} [r=1]
|
|
577
|
+
* @param {Number} [g=1]
|
|
578
|
+
* @param {Number} [b=1]
|
|
579
|
+
* @param {Number} [a=1]
|
|
580
|
+
* @return {Color}
|
|
581
|
+
* @memberof Utilities
|
|
582
|
+
*/
|
|
583
|
+
declare function colorRGBA(r?: number, g?: number, b?: number, a?: number): Color;
|
|
584
|
+
/**
|
|
585
|
+
* Create a color object with HSLA values
|
|
586
|
+
* @param {Number} [h=0]
|
|
587
|
+
* @param {Number} [s=0]
|
|
588
|
+
* @param {Number} [l=1]
|
|
589
|
+
* @param {Number} [a=1]
|
|
590
|
+
* @return {Color}
|
|
591
|
+
* @memberof Utilities
|
|
592
|
+
*/
|
|
593
|
+
declare function colorHSLA(h?: number, s?: number, l?: number, a?: number): Color;
|
|
571
594
|
/**
|
|
572
595
|
* Color object (red, green, blue, alpha) with some helpful functions
|
|
573
596
|
* @example
|
|
@@ -637,19 +660,17 @@ declare class Color {
|
|
|
637
660
|
* @param {Number} [alphaAmount=0]
|
|
638
661
|
* @return {Color} */
|
|
639
662
|
mutate(amount?: number, alphaAmount?: number): Color;
|
|
640
|
-
/** 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
|
|
641
665
|
* @return {String} */
|
|
642
|
-
toString(): string;
|
|
643
|
-
/** Returns this color expressed as 32 bit integer RGBA value
|
|
644
|
-
* @return {Number} */
|
|
645
|
-
rgbaInt(): number;
|
|
666
|
+
toString(useAlpha?: boolean): string;
|
|
646
667
|
/** Set this color from a hex code
|
|
647
668
|
* @param {String} hex - html hex code
|
|
648
669
|
* @return {Color} */
|
|
649
670
|
setHex(hex: string): Color;
|
|
650
|
-
/** Returns this color expressed as
|
|
651
|
-
* @return {
|
|
652
|
-
|
|
671
|
+
/** Returns this color expressed as 32 bit RGBA value
|
|
672
|
+
* @return {Number} */
|
|
673
|
+
rgbaInt(): number;
|
|
653
674
|
}
|
|
654
675
|
/**
|
|
655
676
|
* Timer object tracks how long has passed since it was set
|
|
@@ -689,6 +710,9 @@ declare class Timer {
|
|
|
689
710
|
/** Returns this timer expressed as a string
|
|
690
711
|
* @return {String} */
|
|
691
712
|
toString(): string;
|
|
713
|
+
/** Get how long since elapsed, returns 0 if not set (returns negative if currently active)
|
|
714
|
+
* @return {Number} */
|
|
715
|
+
valueOf(): number;
|
|
692
716
|
}
|
|
693
717
|
/** The max size of the canvas, centered if window is larger
|
|
694
718
|
* @type {Vector2}
|
|
@@ -933,7 +957,7 @@ declare class EngineObject {
|
|
|
933
957
|
* @param {Vector2} pos - tile where the raycast is
|
|
934
958
|
* @return {Boolean} - true if the raycast should hit */
|
|
935
959
|
collideWithTileRaycast(tileData: number, pos: Vector2): boolean;
|
|
936
|
-
/** Called to check if a
|
|
960
|
+
/** Called to check if a object collision should be resolved
|
|
937
961
|
* @param {EngineObject} object - the object to test against
|
|
938
962
|
* @return {Boolean} - true if the collision should be resolved
|
|
939
963
|
*/
|
|
@@ -959,8 +983,8 @@ declare class EngineObject {
|
|
|
959
983
|
* @param {EngineObject} child */
|
|
960
984
|
removeChild(child: EngineObject): void;
|
|
961
985
|
/** Set how this object collides
|
|
962
|
-
* @param {boolean} [collideSolidObjects=
|
|
963
|
-
* @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)
|
|
964
988
|
* @param {boolean} [collideTiles=1] - Does it collide with the tile collision */
|
|
965
989
|
setCollision(collideSolidObjects?: boolean, isSolid?: boolean, collideTiles?: boolean): void;
|
|
966
990
|
collideSolidObjects: boolean;
|
|
@@ -1018,13 +1042,13 @@ declare function worldToScreen(worldPos: Vector2): Vector2;
|
|
|
1018
1042
|
declare let engineFontImage: any;
|
|
1019
1043
|
declare class FontImage {
|
|
1020
1044
|
/** Create an image font
|
|
1021
|
-
* @param {
|
|
1045
|
+
* @param {HTMLImageElement} [image] - The image the font is stored in, if undefined the default font is used
|
|
1022
1046
|
* @param {Vector2} [tileSize=vec2(8)] - The size of the font source tiles
|
|
1023
1047
|
* @param {Vector2} [paddingSize=vec2(0,1)] - How much extra space to add between characters
|
|
1024
1048
|
* @param {Number} [startTileIndex=0] - Tile index in image where font starts
|
|
1025
1049
|
* @param {CanvasRenderingContext2D} [context=overlayContext] - context to draw to
|
|
1026
1050
|
*/
|
|
1027
|
-
constructor(image?:
|
|
1051
|
+
constructor(image?: HTMLImageElement, tileSize?: Vector2, paddingSize?: Vector2, startTileIndex?: number, context?: CanvasRenderingContext2D);
|
|
1028
1052
|
image: any;
|
|
1029
1053
|
tileSize: Vector2;
|
|
1030
1054
|
paddingSize: Vector2;
|
|
@@ -1136,10 +1160,10 @@ declare const stickData: any[];
|
|
|
1136
1160
|
/** Pulse the vibration hardware if it exists
|
|
1137
1161
|
* @param {Number} [pattern=100] - a single value in miliseconds or vibration interval array
|
|
1138
1162
|
* @memberof Input */
|
|
1139
|
-
declare function vibrate(pattern?: number):
|
|
1163
|
+
declare function vibrate(pattern?: number): boolean;
|
|
1140
1164
|
/** Cancel any ongoing vibration
|
|
1141
1165
|
* @memberof Input */
|
|
1142
|
-
declare function vibrateStop():
|
|
1166
|
+
declare function vibrateStop(): boolean;
|
|
1143
1167
|
/** True if a touch device has been detected
|
|
1144
1168
|
* @const {boolean}
|
|
1145
1169
|
* @memberof Input */
|
|
@@ -1419,8 +1443,9 @@ declare class ParticleEmitter extends EngineObject {
|
|
|
1419
1443
|
* @param {Boolean} [additive=0] - Should particles use addtive blend
|
|
1420
1444
|
* @param {Boolean} [randomColorLinear=1] - Should color be randomized linearly or across each component
|
|
1421
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)
|
|
1422
1447
|
*/
|
|
1423
|
-
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);
|
|
1424
1449
|
/** @property {Number} - World space size of the emitter (float for circle diameter, vec2 for rect) */
|
|
1425
1450
|
emitSize: number;
|
|
1426
1451
|
/** @property {Number} - How long to stay alive (0 is forever) */
|
|
@@ -1459,6 +1484,8 @@ declare class ParticleEmitter extends EngineObject {
|
|
|
1459
1484
|
collideTiles: boolean;
|
|
1460
1485
|
/** @property {Number} - Should particles use addtive blend */
|
|
1461
1486
|
additive: boolean;
|
|
1487
|
+
/** @property {Boolean} - Should it be in local space of emitter */
|
|
1488
|
+
localSpace: boolean;
|
|
1462
1489
|
/** @property {Number} - If set the partile is drawn as a trail, stretched in the drection of velocity */
|
|
1463
1490
|
trailScale: number;
|
|
1464
1491
|
emitTimeBuffer: number;
|
|
@@ -1486,10 +1513,6 @@ declare const medals: any[];
|
|
|
1486
1513
|
/** Set to stop medals from being unlockable (like if cheats are enabled)
|
|
1487
1514
|
* @memberof Medals */
|
|
1488
1515
|
declare let medalsPreventUnlock: any;
|
|
1489
|
-
/** This can used to enable Newgrounds functionality
|
|
1490
|
-
* @type {Newgrounds}
|
|
1491
|
-
* @memberof Medals */
|
|
1492
|
-
declare let newgrounds: Newgrounds;
|
|
1493
1516
|
declare let medalsDisplayQueue: any[];
|
|
1494
1517
|
declare let medalsSaveName: any;
|
|
1495
1518
|
declare let medalsDisplayTimeLast: any;
|
|
@@ -1534,6 +1557,7 @@ declare class Medal {
|
|
|
1534
1557
|
renderIcon(x: number, y: number, size?: number): void;
|
|
1535
1558
|
storageKey(): string;
|
|
1536
1559
|
}
|
|
1560
|
+
declare let newgrounds: any;
|
|
1537
1561
|
/**
|
|
1538
1562
|
* Newgrounds API wrapper object
|
|
1539
1563
|
* @example
|
|
@@ -1595,11 +1619,16 @@ declare let glContext: WebGLRenderingContext;
|
|
|
1595
1619
|
declare let glTileTexture: WebGLTexture;
|
|
1596
1620
|
declare let glActiveTexture: any;
|
|
1597
1621
|
declare let glShader: any;
|
|
1622
|
+
declare let glArrayBuffer: any;
|
|
1623
|
+
declare let glVertexData: any;
|
|
1598
1624
|
declare let glPositionData: any;
|
|
1599
1625
|
declare let glColorData: any;
|
|
1600
1626
|
declare let glBatchCount: any;
|
|
1601
1627
|
declare let glBatchAdditive: any;
|
|
1602
1628
|
declare let glAdditive: any;
|
|
1629
|
+
declare let glPostShader: any;
|
|
1630
|
+
declare let glPostArrayBuffer: any;
|
|
1631
|
+
declare let glPostTexture: any;
|
|
1603
1632
|
declare const gl_ONE: 1;
|
|
1604
1633
|
declare const gl_TRIANGLES: 4;
|
|
1605
1634
|
declare const gl_SRC_ALPHA: 770;
|
|
@@ -1607,6 +1636,7 @@ declare const gl_ONE_MINUS_SRC_ALPHA: 771;
|
|
|
1607
1636
|
declare const gl_BLEND: 3042;
|
|
1608
1637
|
declare const gl_TEXTURE_2D: 3553;
|
|
1609
1638
|
declare const gl_UNSIGNED_BYTE: 5121;
|
|
1639
|
+
declare const gl_BYTE: 5120;
|
|
1610
1640
|
declare const gl_FLOAT: 5126;
|
|
1611
1641
|
declare const gl_RGBA: 6408;
|
|
1612
1642
|
declare const gl_NEAREST: 9728;
|
|
@@ -1617,12 +1647,16 @@ declare const gl_TEXTURE_WRAP_S: 10242;
|
|
|
1617
1647
|
declare const gl_TEXTURE_WRAP_T: 10243;
|
|
1618
1648
|
declare const gl_COLOR_BUFFER_BIT: 16384;
|
|
1619
1649
|
declare const gl_CLAMP_TO_EDGE: 33071;
|
|
1650
|
+
declare const gl_TEXTURE0: 33984;
|
|
1651
|
+
declare const gl_TEXTURE1: 33985;
|
|
1620
1652
|
declare const gl_ARRAY_BUFFER: 34962;
|
|
1653
|
+
declare const gl_STATIC_DRAW: 35044;
|
|
1621
1654
|
declare const gl_DYNAMIC_DRAW: 35048;
|
|
1622
1655
|
declare const gl_FRAGMENT_SHADER: 35632;
|
|
1623
1656
|
declare const gl_VERTEX_SHADER: 35633;
|
|
1624
1657
|
declare const gl_COMPILE_STATUS: 35713;
|
|
1625
1658
|
declare const gl_LINK_STATUS: 35714;
|
|
1659
|
+
declare const gl_UNPACK_FLIP_Y_WEBGL: 37440;
|
|
1626
1660
|
declare const gl_VERTICES_PER_QUAD: 6;
|
|
1627
1661
|
declare const gl_INDICIES_PER_VERT: 6;
|
|
1628
1662
|
declare const gl_MAX_BATCH: number;
|
|
@@ -1630,7 +1664,7 @@ declare const gl_VERTEX_BYTE_STRIDE: number;
|
|
|
1630
1664
|
/** Name of engine */
|
|
1631
1665
|
declare const engineName: "LittleJS";
|
|
1632
1666
|
/** Version of engine */
|
|
1633
|
-
declare const engineVersion: "1.
|
|
1667
|
+
declare const engineVersion: "1.4.5";
|
|
1634
1668
|
/** Frames per second to update objects
|
|
1635
1669
|
* @default */
|
|
1636
1670
|
declare const frameRate: 60;
|
|
@@ -1655,5 +1689,5 @@ declare let tileImageSize: any;
|
|
|
1655
1689
|
declare let tileImageFixBleed: any;
|
|
1656
1690
|
declare let averageFPS: any;
|
|
1657
1691
|
declare let drawCount: any;
|
|
1658
|
-
declare const styleBody:
|
|
1692
|
+
declare const styleBody: "margin:0;overflow:hidden;background:#000";
|
|
1659
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
|