diff --git a/.fleet/settings.json b/.fleet/settings.json new file mode 100644 index 0000000000000000000000000000000000000000..355411eb7789d29ced6c9f734d17d3f7bafff95c --- /dev/null +++ b/.fleet/settings.json @@ -0,0 +1,8 @@ +{ + "plugins": [ + { + "type": "add", + "pluginName": "fleet.javascript" + } + ] +} \ No newline at end of file diff --git a/assets/large.png b/assets/large.png new file mode 100644 index 0000000000000000000000000000000000000000..108f0a9e15decabedfdd544be6db62fe37e549f8 Binary files /dev/null and b/assets/large.png differ diff --git a/assets/large.xcf b/assets/large.xcf new file mode 100644 index 0000000000000000000000000000000000000000..c184785b1c2ad7c8df25a8e18d997fd0a3889e3c Binary files /dev/null and b/assets/large.xcf differ diff --git a/assets/small.png b/assets/small.png new file mode 100644 index 0000000000000000000000000000000000000000..2eb828d4f16258b0c068da0fc02f5f9ec6086c94 Binary files /dev/null and b/assets/small.png differ diff --git a/assets/small.xcf b/assets/small.xcf new file mode 100644 index 0000000000000000000000000000000000000000..0c60c27631a89f79c86820c0ec6d92689580d05e Binary files /dev/null and b/assets/small.xcf differ diff --git a/hampsterengine b/hampsterengine index 32245348ac2e1223b8742bfb60d68391e29ffe7e..568efde05f8520563f979227fb37362cce842d31 160000 --- a/hampsterengine +++ b/hampsterengine @@ -1 +1 @@ -Subproject commit 32245348ac2e1223b8742bfb60d68391e29ffe7e +Subproject commit 568efde05f8520563f979227fb37362cce842d31 diff --git a/src/js/objects/player.js b/src/js/objects/player.js index df4db12d61482005cadd3b36bc045c8f5fa528e2..67795607728c94f08f406eac75803caf4bfd4d1b 100644 --- a/src/js/objects/player.js +++ b/src/js/objects/player.js @@ -1,6 +1,5 @@ import {Entity} from "../../../hampsterengine/src/things"; -import {abs, easeOutSine, GRAVITY_X, GRAVITY_Y, round, roundToRatio} from "../extras"; -import {rm_game} from "../rooms/game"; +import {abs, easeOutSine, GRAVITY_X, GRAVITY_Y, roundToRatio} from "../extras"; export default class Player extends Entity { constructor(props) { @@ -20,7 +19,7 @@ export default class Player extends Entity { this.headTarget = {x:this.x, y:this.y}; this.headPos = {x:this.x, y: this.y}; this.headPosStart = {x:this.x, y: this.y}; - this.headTrans = 25; + this.headTrans = 1000; this.headStartTime = performance.now(); this.collideRects = [ @@ -58,7 +57,7 @@ export default class Player extends Entity { } } - if ((!(engine.physicsFrames % 15) && this.vx == 0) || this.vy) this.stepUp = 0; + if ((!(engine.physicsFrames % 15) && this.vx === 0) || this.vy) this.stepUp = 0; const entities = engine.room.entities; @@ -95,7 +94,7 @@ export default class Player extends Entity { if (abs(this.vy) < 1) this.vy = 0; if (abs(this.vx) < 1) this.vx = 0; - if (player.x !== player.lastFramePos.x || player.y !== player.lastFramePos.y || !this.stepUp ) { + if (player.x !== player.lastFramePos.x || player.y !== player.lastFramePos.y || !this.stepUp) { this.headTarget = {x: this.x, y: this.y - (this.stepUp ? 1 : 0)} this.headPosStart = structuredClone(this.headPos); this.headStartTime = performance.now(); @@ -128,9 +127,9 @@ export default class Player extends Entity { let distX = this.headTarget.x - this.headPosStart.x; let distY = this.headTarget.y - this.headPosStart.y; - const elapsed = Math.min(performance.now() - this.headStartTime, this.headTrans); const end = this.headTrans; - const pos = easeOutSine(elapsed / end || 1); + const elapsed = Math.min(performance.now() - this.headStartTime, end); + const pos = elapsed / end || 1; this.headPos.x = Math.min( this.headTarget.x, @@ -144,8 +143,8 @@ export default class Player extends Entity { // Draw the head canvas.drawImage( engine.assetStore.get`player_head`.sprite, - roundToRatio(this.headPos.x - 1), - roundToRatio(this.headPos.y - 7), + this.headPos.x - 1, + this.headPos.y - 7, engine.assetStore.get`player_head`.size, engine.assetStore.get`player_head`.size ) diff --git a/src/js/sb-player-small.js b/src/js/sb-player-small.js index a03cff8530f6ebcb21b434361eb9be1affe4fc01..b0ca2a8fd4374c32e11c9b0cbb3d15358d18d853 100644 --- a/src/js/sb-player-small.js +++ b/src/js/sb-player-small.js @@ -45,31 +45,31 @@ const SoundBox = function () { //-------------------------------------------------------------------------- // Oscillators - var osc_sin = function (value) { + const osc_sin = function (value) { return Math.sin(value * 6.283184); }; - var osc_saw = function (value) { + const osc_saw = function (value) { return 2 * (value % 1) - 1; }; - var osc_square = function (value) { + const osc_square = function (value) { return (value % 1) < 0.5 ? 1 : -1; }; - var osc_tri = function (value) { - var v2 = (value % 1) * 4; + const osc_tri = function (value) { + const v2 = (value % 1) * 4; if (v2 < 2) return v2 - 1; return 3 - v2; }; - var getnotefreq = function (n) { + const getnotefreq = function (n) { // 174.61.. / 44100 = 0.003959503758 (F3) return 0.003959503758 * (2 ** ((n - 128) / 12)); }; - var createNote = function (instr, n, rowLen) { - var osc1 = mOscillators[instr.i[0]], + const createNote = function (instr, n, rowLen) { + const osc1 = mOscillators[instr.i[0]], o1vol = instr.i[1], o1xenv = instr.i[3] / 32, osc2 = mOscillators[instr.i[4]], @@ -80,17 +80,17 @@ const SoundBox = function () { sustain = instr.i[11] * instr.i[11] * 4, release = instr.i[12] * instr.i[12] * 4, releaseInv = 1 / release, - expDecay = -instr.i[13] / 16, - arp = instr.i[14], - arpInterval = rowLen * (2 ** (2 - instr.i[15])); + expDecay = -instr.i[13] / 16; + let arp = instr.i[14]; + const arpInterval = rowLen * (2 ** (2 - instr.i[15])); - var noteBuf = new Int32Array(attack + sustain + release); + const noteBuf = new Int32Array(attack + sustain + release); // Re-trig oscillators - var c1 = 0, c2 = 0; + let c1 = 0, c2 = 0; // Local variables. - var j, j2, e, t, rsample, o1t, o2t; + let j, j2, e, t, rsample, o1t, o2t; // Generate one note (attack + sustain + release) for (j = 0, j2 = 0; j < attack + sustain + release; j++, j2++) { @@ -147,7 +147,7 @@ const SoundBox = function () { ]; // Private variables set up by init() - var mSong, mLastRow, mCurrentCol, mNumWords, mMixBuf; + let mSong, mLastRow, mCurrentCol, mNumWords, mMixBuf; //-------------------------------------------------------------------------- @@ -177,21 +177,21 @@ const SoundBox = function () { // Generate audio data for a single track this.generate = function () { // Local variables - var i, j, b, p, row, col, n, cp, + let i, j, b, p, row, col, n, cp, k, t, lfor, e, x, rsample, rowStartSample, f, da; // Put performance critical items in local variables - var chnBuf = new Int32Array(mNumWords), + const chnBuf = new Int32Array(mNumWords), instr = mSong.songData[mCurrentCol], rowLen = mSong.rowLen, patternLen = mSong.patternLen; // Clear effect state - var low = 0, band = 0, high; - var lsample, filterActive = false; + let low = 0, band = 0, high; + let lsample, filterActive = false; // Clear note cache. - var noteCache = []; + let noteCache = []; // Patterns for (p = 0; p <= mLastRow; ++p) { @@ -200,7 +200,7 @@ const SoundBox = function () { // Pattern rows for (row = 0; row < patternLen; ++row) { // Execute effect command. - var cmdNo = cp ? instr.c[cp - 1].f[row] : 0; + const cmdNo = cp ? instr.c[cp - 1].f[row] : 0; if (cmdNo) { instr.i[cmdNo - 1] = instr.c[cp - 1].f[row + patternLen] || 0; @@ -211,7 +211,7 @@ const SoundBox = function () { } // Put performance critical instrument properties in local variables - var oscLFO = mOscillators[instr.i[16]], + const oscLFO = mOscillators[instr.i[16]], lfoAmt = instr.i[17] / 512, lfoFreq = (2 ** (instr.i[18] - 9)) / rowLen, fxLFO = instr.i[19], @@ -237,7 +237,7 @@ const SoundBox = function () { } // Copy note from the note cache - var noteBuf = noteCache[n]; + const noteBuf = noteCache[n]; for (j = 0, i = rowStartSample * 2; j < noteBuf.length; j++, i += 2) { chnBuf[i] += noteBuf[j]; } @@ -311,10 +311,10 @@ const SoundBox = function () { // Create a AudioBuffer from the generated audio data this.createAudioBuffer = function (context) { - var buffer = context.createBuffer(2, mNumWords / 2, 44100); - for (var i = 0; i < 2; i++) { - var data = buffer.getChannelData(i); - for (var j = i; j < mNumWords; j += 2) { + const buffer = context.createBuffer(2, mNumWords / 2, 44100); + for (let i = 0; i < 2; i++) { + const data = buffer.getChannelData(i); + for (let j = i; j < mNumWords; j += 2) { data[j >> 1] = mMixBuf[j] / 65536; } } @@ -324,10 +324,10 @@ const SoundBox = function () { // Create a WAVE formatted Uint8Array from the generated audio data this.createWave = function () { // Create WAVE header - var headerLen = 44; - var l1 = headerLen + mNumWords * 2 - 8; - var l2 = l1 - 36; - var wave = new Uint8Array(headerLen + mNumWords * 2); + const headerLen = 44; + const l1 = headerLen + mNumWords * 2 - 8; + const l2 = l1 - 36; + const wave = new Uint8Array(headerLen + mNumWords * 2); wave.set( [82, 73, 70, 70, l1 & 255, (l1 >> 8) & 255, (l1 >> 16) & 255, (l1 >> 24) & 255, @@ -337,9 +337,10 @@ const SoundBox = function () { ); // Append actual wave data - for (var i = 0, idx = headerLen; i < mNumWords; ++i) { + let i = 0, idx = headerLen; + for (; i < mNumWords; ++i) { // Note: We clamp here - var y = mMixBuf[i]; + let y = mMixBuf[i]; y = y < -32767 ? -32767 : (y > 32767 ? 32767 : y); wave[idx++] = y & 255; wave[idx++] = (y >> 8) & 255; @@ -351,10 +352,10 @@ const SoundBox = function () { // Get n samples of wave data at time t [s]. Wave data in range [-2,2]. this.getData = function (t, n) { - var i = 2 * Math.floor(t * 44100); - var d = new Array(n); - for (var j = 0; j < 2 * n; j += 1) { - var k = i + j; + const i = 2 * Math.floor(t * 44100); + const d = new Array(n); + for (let j = 0; j < 2 * n; j += 1) { + const k = i + j; d[j] = t > 0 && k < mMixBuf.length ? mMixBuf[k] / 32768 : 0; } return d; diff --git a/utils/size.js b/utils/size.js index b7fe8a6d44121a2f7ace2bb2024b6383b979cd0c..9c40b3774c5ba8ad62dc18398c2fcdbde96a4830 100644 --- a/utils/size.js +++ b/utils/size.js @@ -1,14 +1,13 @@ +const fs = require("fs"); +const stats = fs.statSync("build/game.zip"); +const fileSizeInBytes = stats.size; +const fileSizeInKilobytes = fileSizeInBytes / 1024; -var fs = require("fs"); -var stats = fs.statSync("build/game.zip"); -var fileSizeInBytes = stats.size; -var fileSizeInKilobytes = fileSizeInBytes / 1024; +const statsUncompressed = fs.statSync("build/index.html"); +const fileSizeInBytesUncompressed = statsUncompressed.size; +const fileSizeInKilobytesUncompressed = fileSizeInBytesUncompressed / 1024; -var statsUncompressed = fs.statSync("build/index.html"); -var fileSizeInBytesUncompressed = statsUncompressed.size; -var fileSizeInKilobytesUncompressed = fileSizeInBytesUncompressed / 1024; - -var compressionRatio = fileSizeInBytesUncompressed / fileSizeInBytes; +const compressionRatio = fileSizeInBytesUncompressed / fileSizeInBytes; console.log(`Current game size: ${Math.round(fileSizeInKilobytes*10)/10}/13.0 KB (${Math.round((fileSizeInKilobytes/13)*100)}%)`); console.log(`Current game size (uncompressed): ${fileSizeInKilobytesUncompressed.toFixed(1)}/${(13.0 * compressionRatio).toFixed(1)} KB (${Math.round((fileSizeInKilobytesUncompressed/(13 * compressionRatio))*100)}%)`)