From 8c4735f3f22abf1135fb65906031096dcbb25e1a Mon Sep 17 00:00:00 2001 From: Renan LE CARO Date: Mon, 3 Mar 2025 22:14:28 +0100 Subject: [PATCH] Added a palette for bricks color --- Readme.md | 2 ++ app/src/main/assets/game.js | 5 +++-- app/src/main/assets/levels.js | 6 +++--- editclient.js | 38 +++++++++++++++++------------------ 4 files changed, 27 insertions(+), 24 deletions(-) diff --git a/Readme.md b/Readme.md index f24a9dd..234742b 100644 --- a/Readme.md +++ b/Readme.md @@ -160,9 +160,11 @@ The "engine" could be better - option : don't pause on mobile when lifting finger - option : accelerated relative movements on mobile - maybe just have 10 background, and always use the same one for the nth level of each run ? +- would be nice to have a leaderboard for not using each perk too. Like "best runs without hot start" There are many possible perks left to implement : - offer next level choice after upgrade pick +- ban 3 random perks from pool, doesn't tell you which ones, gain 2 upgrades - 3 random perks immediately, or maybe "all level get twice as many upgrades, but they are applied randomly, and you aren't told which ones you have." - wrap left / right - pause and cheat again diff --git a/app/src/main/assets/game.js b/app/src/main/assets/game.js index df527f6..2040fda 100644 --- a/app/src/main/assets/game.js +++ b/app/src/main/assets/game.js @@ -23,6 +23,7 @@ const randomPatterns=[ ] let attributed=0 allLevels.forEach(l => { + l.bricks=l.bricks.split('').map(c=>palette[c]) if (!l.color && !l.svg) { l.svg = randomPatterns[attributed%randomPatterns.length] attributed++ @@ -87,7 +88,7 @@ function resetCombo(x, y) { type: "text", text: "-" + lost, time: levelTime, - color: "red", + color: "r", x: x, y: y, duration: 150, @@ -110,7 +111,7 @@ function decreaseCombo(by, x, y) { type: "text", text: "-" + lost, time: levelTime, - color: "red", + color: "r", x: x, y: y, duration: 300, diff --git a/app/src/main/assets/levels.js b/app/src/main/assets/levels.js index 2e57874..4debfb1 100644 --- a/app/src/main/assets/levels.js +++ b/app/src/main/assets/levels.js @@ -260,9 +260,9 @@ let allLevels=[ "focus": false }, { - "name": "Greed", + "name": "Dollar", "size": 17, - "bricks": "________________________k_k______________k_k____________kkkkkkk_________kkkkkkkkk_______kk__k_k__kk______kk__k_k__kk______kk__k_k___________kkkkkkkk__________kkkkkkkk___________k_k__kk______kk__k_k__kk______kk__k_k__kk_______kkkkkkkkk_________kkkkkkk____________k_k______________k_k________________________", + "bricks": "________________________G_G______________G_G____________GGGGGGG_________GGGGGGGGG_______GG__G_G__GG______GG__G_G__GG______GG__G_G___________GGGGGGGG__________GGGGGGGG___________G_G__GG______GG__G_G__GG______GG__G_G__GG_______GGGGGGGGG_________GGGGGGG____________G_G______________G_G________________________", "svg": "", "color": "", "focus": false @@ -414,7 +414,7 @@ let allLevels=[ { "name": "B71", "size": 10, - "bricks": "__________rrryyyy_r_r__r__yrr_r__r__y_r_rrr__y__r_r__r_y__r_r__ry___r_rrr_y__rrr__________", + "bricks": "__________bbbtttt_b_b__b__tbb_b__b__t_b_bbb__t__b_b__b_t__b_b__bt___b_bbb_t__bbb__________", "svg": "", "focus": false }, diff --git a/editclient.js b/editclient.js index 8abfed7..a364ee8 100644 --- a/editclient.js +++ b/editclient.js @@ -129,32 +129,29 @@ document.getElementById('levels').addEventListener('click', e => { if (!levelIndexStr) return if (e.target.tagName!=='BUTTON') return - const levelIndex = parseInt(levelIndexStr) const level = allLevels[levelIndex] const {bricks, size} = level; if (resize) { const newSize = size + parseInt(resize) - const newBricks = [] + const newBricks = new Array(newSize*newSize).fill('_') for (let x = 0; x < Math.min(size, newSize); x++) { for (let y = 0; y < Math.min(size, newSize); y++) { - newBricks[y * newSize + x] = bricks[y * size + x] || '' + newBricks[y * newSize + x] = bricks.split('')[y * size + x] || '_' } } - level.size = newSize; - level.bricks = newBricks; + level.bricks = newBricks.map(b=>b||'_').join(''); } else if (moveX && moveY) { const dx = parseInt(moveX), dy = parseInt(moveY) - const moved = [] + const newBricks = new Array(size*size).fill('_') for (let x = 0; x < size; x++) { for (let y = 0; y < size; y++) { - moved[(y + dy) * size + (x + dx)] = bricks[y * size + x] || '' + newBricks[(y + dy) * size + (x + dx)] = bricks.split('')[y * size + x]|| '_' } } - - level.bricks = moved; + level.bricks = newBricks.map(b=>b||'_').join(''); } else if (e.target.getAttribute('data-rename')) { const newName = prompt('Name ? ', level.name) if (newName) { @@ -182,38 +179,41 @@ document.getElementById('levels').addEventListener('click', e => { }, true) -let applying = undefined +let applying = '' function colorPixel(e) { - if (typeof applying === 'undefined') return + if ( applying == '') return const index = e.target.getAttribute('data-set-color-of') const level = e.target.getAttribute('data-level') if (index && level) { const levelIndex = parseInt(level) - e.target.style.background = applying || 'transparent' - allLevels[levelIndex].bricks[index] = applying + e.target.style.background = palette[applying] + setBrick(levelIndex,parseInt(index),applying) + } } - +function setBrick(levelIndex,index,chr) { + const bricks=allLevels[levelIndex].bricks + allLevels[levelIndex].bricks = bricks.substring(0,index) + chr + bricks.substring(index+1); +} document.getElementById('levels').addEventListener('mousedown', e => { - const index = e.target.getAttribute('data-set-color-of') + const index = parseInt(e.target.getAttribute('data-set-color-of')) const level = e.target.getAttribute('data-level') if (index && level) { - const before = allLevels[parseInt(level)].bricks[parseInt(index)] || '' + const before = allLevels[parseInt(level)].bricks[parseInt(index)] || '_' applying = before === currentCode ? '_' : currentCode colorPixel(e) } }) document.getElementById('levels').addEventListener('mouseenter', e => { - if (typeof applying !== undefined) { - + if (applying !== '') { colorPixel(e) } }, true) document.addEventListener('mouseup', e => { - applying = undefined + applying = '' save() })