Skip to content

Commit

Permalink
docs
Browse files Browse the repository at this point in the history
combine some settings to vector2
  • Loading branch information
KilledByAPixel committed Nov 3, 2021
1 parent 8f0d1fe commit 7e31cb1
Show file tree
Hide file tree
Showing 60 changed files with 747 additions and 1,021 deletions.
2 changes: 1 addition & 1 deletion docs/Audio.html

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions docs/Color.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/Debug.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/Draw.html

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions docs/EngineObject.html

Large diffs are not rendered by default.

96 changes: 48 additions & 48 deletions docs/Input.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/Medal.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/Medals.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/Music.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/Newgrounds.html

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions docs/Particle.html

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions docs/ParticleEmitter.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/Random.html

Large diffs are not rendered by default.

636 changes: 213 additions & 423 deletions docs/Settings.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/Sound.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/TileCollision.html

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions docs/TileLayer.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/TileLayerData.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/Timer.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/Utilities.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/Vector2.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/WebGL.html

Large diffs are not rendered by default.

33 changes: 15 additions & 18 deletions docs/engine.js.html

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions docs/engineAudio.js.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/engineDebug.js.html

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions docs/engineDraw.js.html

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions docs/engineInput.js.html

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions docs/engineMedals.js.html

Large diffs are not rendered by default.

32 changes: 16 additions & 16 deletions docs/engineObject.js.html

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions docs/engineParticles.js.html

Large diffs are not rendered by default.

75 changes: 31 additions & 44 deletions docs/engineSettings.js.html

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions docs/engineTileLayer.js.html

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions docs/engineUtilities.js.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/engineWebGL.js.html

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions docs/global.html

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions docs/index.html

Large diffs are not rendered by default.

204 changes: 94 additions & 110 deletions engine/engine.all.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion engine/engine.all.min.js

Large diffs are not rendered by default.

204 changes: 94 additions & 110 deletions engine/engine.all.release.js

Large diffs are not rendered by default.

31 changes: 14 additions & 17 deletions engine/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
const engineName = 'LittleJS';

/** Version of engine */
const engineVersion = '1.1.6';
const engineVersion = '1.1.8';

/** Frames per second to update objects
* @default */
Expand Down Expand Up @@ -147,31 +147,28 @@ function engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRender
frameTimeBufferMS += deltaSmooth;
}

if (fixedWidth)
if (fixedSize.x)
{
// clear set fixed size
mainCanvas.width = fixedWidth;
mainCanvas.height = fixedHeight;
mainCanvas.width = fixedSize.x;
mainCanvas.height = fixedSize.y;

if (fixedFitToWindow)
// fit to window by adding space on top or bottom if necessary
const aspect = innerWidth / innerHeight;
const fixedAspect = mainCanvas.width / mainCanvas.height;
mainCanvas.style.width = overlayCanvas.style.width = aspect < fixedAspect ? '100%' : '';
mainCanvas.style.height = overlayCanvas.style.height = aspect < fixedAspect ? '' : '100%';
if (glCanvas)
{
// fit to window by adding space on top or bottom if necessary
const aspect = innerWidth / innerHeight;
const fixedAspect = fixedWidth / fixedHeight;
mainCanvas.style.width = overlayCanvas.style.width = aspect < fixedAspect ? '100%' : '';
mainCanvas.style.height = overlayCanvas.style.height = aspect < fixedAspect ? '' : '100%';
if (glCanvas)
{
glCanvas.style.width = mainCanvas.style.width;
glCanvas.style.height = mainCanvas.style.height;
}
glCanvas.style.width = mainCanvas.style.width;
glCanvas.style.height = mainCanvas.style.height;
}
}
else
{
// clear and set size to same as window
mainCanvas.width = min(innerWidth, maxWidth);
mainCanvas.height = min(innerHeight, maxHeight);
mainCanvas.width = min(innerWidth, maxSize.x);
mainCanvas.height = min(innerHeight, maxSize.y);
}

// save canvas size and clear overlay canvas
Expand Down
14 changes: 7 additions & 7 deletions engine/engineAudio.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ class Sound
{
/** Create a sound object and cache the zzfx samples for later use
* @param {Array} zzfxSound - Array of zzfx parameters, ex. [.5,.5]
* @param {Number} [range=defaultSoundRange] - World space max range of sound, will not play if camera is farther away
* @param {Number} [taper=defaultSoundTaper] - At what percentage of range should it start tapering off
* @param {Number} [range=soundDefaultRange] - World space max range of sound, will not play if camera is farther away
* @param {Number} [taper=soundDefaultTaper] - At what percentage of range should it start tapering off
*/
constructor(zzfxSound, range=defaultSoundRange, taper=defaultSoundTaper)
constructor(zzfxSound, range=soundDefaultRange, taper=soundDefaultTaper)
{
if (!soundEnable) return;

Expand Down Expand Up @@ -157,7 +157,7 @@ function playAudioFile(url, volume=1, loop=1)
if (!soundEnable) return;

const audio = new Audio(url);
audio.volume = audioVolume * volume;
audio.volume = soundVolume * volume;
audio.loop = loop;
audio.play();
return audio;
Expand All @@ -182,7 +182,7 @@ function speak(text, language='', volume=1, rate=1, pitch=1)
// build utterance and speak
const utterance = new SpeechSynthesisUtterance(text);
utterance.lang = language;
utterance.volume = 2*volume*audioVolume;
utterance.volume = 2*volume*soundVolume;
utterance.rate = rate;
utterance.pitch = pitch;
speechSynthesis.speak(utterance);
Expand Down Expand Up @@ -235,7 +235,7 @@ function playSamples(sampleChannels, volume=1, rate=1, pan=0, loop=0)
// create pan and gain nodes
source
.connect(new StereoPannerNode(audioContext, {'pan':clamp(pan, 1, -1)}))
.connect(new GainNode(audioContext, {'gain':audioVolume*volume}))
.connect(new GainNode(audioContext, {'gain':soundVolume*volume}))
.connect(audioContext.destination);

// play and return sound
Expand Down Expand Up @@ -303,7 +303,7 @@ function zzfxG
1 - tremolo + tremolo*Math.sin(PI2*i/repeatTime) // tremolo
: 1) *
sign(s)*(abs(s)**shapeCurve) * // curve 0=square, 2=pointy
volume * audioVolume * ( // envelope
volume * soundVolume * ( // envelope
i < attack ? i/attack : // attack
i < attack + decay ? // decay
1-((i-attack)/decay)*(1-sustainVolume) : // decay falloff
Expand Down
12 changes: 6 additions & 6 deletions engine/engineDraw.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ const worldToScreen = (worldPos)=>
* @param {Vector2} pos - Center of the tile in world space
* @param {Vector2} [size=new Vector2(1,1)] - Size of the tile in world space, width and height
* @param {Number} [tileIndex=-1] - Tile index to use, negative is untextured
* @param {Vector2} [tileSize=defaultTileSize] - Tile size in source pixels
* @param {Vector2} [tileSize=tileSizeDefault] - Tile size in source pixels
* @param {Color} [color=new Color(1,1,1)] - Color to modulate with
* @param {Number} [angle=0] - Angle to rotate by
* @param {Boolean} [mirror=0] - If true image is flipped along the Y axis
* @param {Color} [additiveColor=new Color(0,0,0,0)] - Additive color to be applied
* @param {Boolean} [useWebGL=glEnable] - Use accelerated WebGL rendering
* @memberof Draw */
function drawTile(pos, size=vec2(1), tileIndex=-1, tileSize=defaultTileSize, color=new Color, angle=0, mirror,
function drawTile(pos, size=vec2(1), tileIndex=-1, tileSize=tileSizeDefault, color=new Color, angle=0, mirror,
additiveColor=new Color(0,0,0,0), useWebGL=glEnable)
{
showWatermark && ++drawCount;
Expand Down Expand Up @@ -128,14 +128,14 @@ function drawTile(pos, size=vec2(1), tileIndex=-1, tileSize=defaultTileSize, col
* @memberof Draw */
function drawRect(pos, size, color, angle, useWebGL)
{
drawTile(pos, size, -1, defaultTileSize, color, angle, 0, 0, useWebGL);
drawTile(pos, size, -1, tileSizeDefault, color, angle, 0, 0, useWebGL);
}

/** Draw textured tile centered on pos in screen space
* @param {Vector2} pos - Center of the tile
* @param {Vector2} [size=new Vector2(1,1)] - Size of the tile
* @param {Number} [tileIndex=-1] - Tile index to use, negative is untextured
* @param {Vector2} [tileSize=defaultTileSize] - Tile size in source pixels
* @param {Vector2} [tileSize=tileSizeDefault] - Tile size in source pixels
* @param {Color} [color=new Color]
* @param {Number} [angle=0]
* @param {Boolean} [mirror=0]
Expand All @@ -156,7 +156,7 @@ function drawTileScreenSpace(pos, size=vec2(1), tileIndex, tileSize, color, angl
* @memberof Draw */
function drawRectScreenSpace(pos, size, color, angle, useWebGL)
{
drawTileSrceenSpace(pos, size, -1, defaultTileSize, color, angle, 0, 0, useWebGL);
drawTileSrceenSpace(pos, size, -1, tileSizeDefault, color, angle, 0, 0, useWebGL);
}

/** Draw colored line between two points
Expand Down Expand Up @@ -203,7 +203,7 @@ function drawCanvas2D(pos, size, angle, mirror, drawFunction, context = mainCont
* @param {Color} [lineColor=new Color(0,0,0)]
* @param {String} [textAlign='center']
* @memberof Draw */
function drawText(text, pos, size=1, color=new Color, lineWidth=0, lineColor=new Color(0,0,0), textAlign='center', font=defaultFont)
function drawText(text, pos, size=1, color=new Color, lineWidth=0, lineColor=new Color(0,0,0), textAlign='center', font=fontDefault)
{
pos = worldToScreen(pos);
overlayContext.font = size*cameraScale + 'px '+ font;
Expand Down
14 changes: 7 additions & 7 deletions engine/engineInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ let mouseWheel = 0;

/** Returns true if user is using gamepad (has more recently pressed a gamepad button)
* @memberof Input */
let usingGamepad = 0;
let isUsingGamepad = 0;

/** Returns true if gamepad button is down
* @param {Number} button
Expand Down Expand Up @@ -129,20 +129,20 @@ function inputUpdatePost()
onkeydown = e=>
{
if (debug && e.target != document.body) return;
e.repeat || (inputData[usingGamepad = 0][remapKeyCode(e.keyCode)] = 3);
e.repeat || (inputData[isUsingGamepad = 0][remapKeyCode(e.keyCode)] = 3);
debug || e.preventDefault();
}
onkeyup = e=>
{
if (debug && e.target != document.body) return;
inputData[0][remapKeyCode(e.keyCode)] = 4;
}
const remapKeyCode = c=> copyWASDToDpad ? c==87?38 : c==83?40 : c==65?37 : c==68?39 : c : c;
const remapKeyCode = c=> inputWASDEmulateDirection ? c==87?38 : c==83?40 : c==65?37 : c==68?39 : c : c;

///////////////////////////////////////////////////////////////////////////////
// Mouse event handlers

onmousedown = e=> {inputData[usingGamepad = 0][e.button] = 3; onmousemove(e); e.button && e.preventDefault();}
onmousedown = e=> {inputData[isUsingGamepad = 0][e.button] = 3; onmousemove(e); e.button && e.preventDefault();}
onmouseup = e=> inputData[0][e.button] = inputData[0][e.button] & 2 | 4;
onmousemove = e=>
{
Expand Down Expand Up @@ -190,10 +190,10 @@ function gamepadsUpdate()
{
const button = gamepad.buttons[j];
data[j] = button.pressed ? 1 + 2*!gamepadIsDown(j,i) : 4*gamepadIsDown(j,i);
usingGamepad |= !i && button.pressed;
isUsingGamepad |= !i && button.pressed;
}

if (copyGamepadDirectionToStick)
if (gamepadDirectionEmulateStick)
{
// copy dpad to left analog stick when pressed
const dpad = vec2(gamepadIsDown(15,i) - gamepadIsDown(14,i), gamepadIsDown(12,i) - gamepadIsDown(13,i));
Expand All @@ -210,7 +210,7 @@ function gamepadsUpdate()
/** True if a touch device has been detected
* @const {boolean}
* @memberof Input */
const isTouchDevice = touchInputEnable && window.ontouchstart !== undefined;
const isTouchDevice = inputTouchEnable && window.ontouchstart !== undefined;
if (isTouchDevice)
{
// handle all touch events the same way
Expand Down
6 changes: 3 additions & 3 deletions engine/engineMedals.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ class Medal

// draw the text
context.textAlign = 'left';
context.font = '3em '+ defaultFont;
context.font = '3em '+ fontDefault;
context.fillText(this.name, x+medalDisplayIconSize+25, y+35);
context.font = '1.5em '+ defaultFont;
context.font = '1.5em '+ fontDefault;
context.restore(context.fillText(this.description, x+medalDisplayIconSize+25, y+70));
}

Expand All @@ -130,7 +130,7 @@ class Medal
const context = overlayContext;
context.textAlign = 'center';
context.textBaseline = 'middle';
context.font = size*.6 + 'px '+ defaultFont;
context.font = size*.6 + 'px '+ fontDefault;
context.fillStyle = '#000';
if (this.image)
context.drawImage(this.image, x-size/2, y-size/2, size, size);
Expand Down
30 changes: 15 additions & 15 deletions engine/engineObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ class EngineObject
{
/** Create an engine object and adds it to the list of objects
* @param {Vector2} [position=new Vector2(0,0)] - World space position of the object
* @param {Vector2} [size=defaultObjectSize] - World space size of the object
* @param {Vector2} [size=objectDefaultSize] - World space size of the object
* @param {Number} [tileIndex=-1] - Tile to use to render object, untextured if -1
* @param {Vector2} [tileSize=defaultTileSize] - Size of tile in source pixels
* @param {Vector2} [tileSize=tileSizeDefault] - Size of tile in source pixels
* @param {Number} [angle=0] - Angle to rotate the object
* @param {Color} [color] - Color to apply to tile when rendered
* @param {Number} [renderOrder=0] - Objects sorted by renderOrder before being rendered
*/
constructor(pos=vec2(), size=defaultObjectSize, tileIndex=-1, tileSize=defaultTileSize, angle=0, color, renderOrder=0)
constructor(pos=vec2(), size=objectDefaultSize, tileIndex=-1, tileSize=tileSizeDefault, angle=0, color, renderOrder=0)
{
// set passed in params
ASSERT(pos && pos.x != undefined && size.x != undefined); // ensure pos and size are vec2s
Expand All @@ -55,16 +55,16 @@ class EngineObject
this.additiveColor;

// set object defaults
/** @property {Number} [mass=defaultObjectMass] - How heavy the object is */
this.mass = defaultObjectMass;
/** @property {Number} [damping=defaultObjectDamping] - How much to slow down velocity each frame (0-1) */
this.damping = defaultObjectDamping;
/** @property {Number} [angleDamping=defaultObjectAngleDamping] - How much to slow down rotation each frame (0-1) */
this.angleDamping = defaultObjectAngleDamping;
/** @property {Number} [elasticity=defaultObjectElasticity] - How bouncy the object is when colliding (0-1) */
this.elasticity = defaultObjectElasticity;
/** @property {Number} [friction=defaultObjectFriction] - How much friction to apply when sliding (0-1) */
this.friction = defaultObjectFriction;
/** @property {Number} [mass=objectDefaultMass] - How heavy the object is */
this.mass = objectDefaultMass;
/** @property {Number} [damping=objectDefaultDamping] - How much to slow down velocity each frame (0-1) */
this.damping = objectDefaultDamping;
/** @property {Number} [angleDamping=objectDefaultAngleDamping] - How much to slow down rotation each frame (0-1) */
this.angleDamping = objectDefaultAngleDamping;
/** @property {Number} [elasticity=objectDefaultElasticity] - How bouncy the object is when colliding (0-1) */
this.elasticity = objectDefaultElasticity;
/** @property {Number} [friction=objectDefaultFriction] - How much friction to apply when sliding (0-1) */
this.friction = objectDefaultFriction;
/** @property {Number} [gravityScale=1] - How much to scale gravity by for this object */
this.gravityScale = 1;
/** @property {Number} [renderOrder=0] - Objects are sorted by render order */
Expand Down Expand Up @@ -93,8 +93,8 @@ class EngineObject
}

// limit max speed to prevent missing collisions
this.velocity.x = clamp(this.velocity.x, maxObjectSpeed, -maxObjectSpeed);
this.velocity.y = clamp(this.velocity.y, maxObjectSpeed, -maxObjectSpeed);
this.velocity.x = clamp(this.velocity.x, objectMaxSpeed, -objectMaxSpeed);
this.velocity.y = clamp(this.velocity.y, objectMaxSpeed, -objectMaxSpeed);

// apply physics
const oldPos = this.pos.copy();
Expand Down
6 changes: 3 additions & 3 deletions engine/engineParticles.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class ParticleEmitter extends EngineObject
* @param {Number} [emitRate=100] - How many particles per second to spawn, does not emit if 0
* @param {Number} [emitConeAngle=PI] - Local angle to apply velocity to particles from emitter
* @param {Number} [tileIndex=-1] - Index into tile sheet, if <0 no texture is applied
* @param {Number} [tileSize=defaultTileSize] - Tile size for particles
* @param {Number} [tileSize=tileSizeDefault] - Tile size for particles
* @param {Color} [colorStartA=new Color(1,1,1)] - Color at start of life 1, randomized between start colors
* @param {Color} [colorStartB=new Color(1,1,1)] - Color at start of life 2, randomized between start colors
* @param {Color} [colorEndA=new Color(1,1,1,0)] - Color at end of life 1, randomized between end colors
Expand Down Expand Up @@ -62,7 +62,7 @@ class ParticleEmitter extends EngineObject
emitRate = 100,
emitConeAngle = PI,
tileIndex = -1,
tileSize = defaultTileSize,
tileSize = tileSizeDefault,
colorStartA = new Color,
colorStartB = new Color,
colorEndA = new Color(1,1,1,0),
Expand Down Expand Up @@ -233,7 +233,7 @@ class Particle extends EngineObject
* Create a particle with the given settings
* @param {Vector2} position - World space position of the particle
* @param {Number} [tileIndex=-1] - Tile to use to render, untextured if -1
* @param {Vector2} [tileSize=defaultTileSize] - Size of tile in source pixels
* @param {Vector2} [tileSize=tileSizeDefault] - Size of tile in source pixels
* @param {Number} [angle=0] - Angle to rotate the particle
*/
constructor(pos, tileIndex, tileSize, angle) { super(pos, new Vector2, tileIndex, tileSize, angle); }
Expand Down
Loading

0 comments on commit 7e31cb1

Please sign in to comment.