diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml index e69de29..dc2bb3e 100644 --- a/.github/workflows/format.yml +++ b/.github/workflows/format.yml @@ -0,0 +1,20 @@ +name: Formatter + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Setup repo + uses: actions/checkout@v2 + + - name: Format code with Prettier + uses: creyD/prettier_action@v4.2 + with: + commit_message: "code formatted" \ No newline at end of file diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..68ea04d --- /dev/null +++ b/.prettierrc @@ -0,0 +1 @@ +tabWidth: 4 \ No newline at end of file diff --git a/code/easing.js b/code/easing.js index 267cb78..7bdf7c4 100644 --- a/code/easing.js +++ b/code/easing.js @@ -146,7 +146,7 @@ export function tween(func, attrs, timeLen, minVal, maxVal, ease, type, onFinish var upd = onUpdate(() => { switch (type(time(), stTime, timeLen)) { case "CALLBACK": - for (h in attrs) { + for (let h in attrs) { func[attrs[h]] = maxVal; } upd(); @@ -155,7 +155,7 @@ export function tween(func, attrs, timeLen, minVal, maxVal, ease, type, onFinish stTime = time(); break; case "CONTINUE": - for (h in attrs) { + for (let h in attrs) { func[attrs[h]] = minVal; } break; @@ -168,7 +168,7 @@ export function tween(func, attrs, timeLen, minVal, maxVal, ease, type, onFinish default: break; } - for (i in attrs) { + for (let i in attrs) { func[attrs[i]] = lerp(minVal, maxVal, ease((time() - stTime) / timeLen)); } }); diff --git a/code/game.js b/code/main.js similarity index 97% rename from code/game.js rename to code/main.js index 2fe6635..7e463fe 100644 --- a/code/game.js +++ b/code/main.js @@ -11,7 +11,7 @@ kaboom({ }); load(new Promise((resolve, reject) => { - loadFont("unscii", "fonts/unscii_8x8.png", 8, 8, {chars: " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"}); + loadFont("unscii", "sprites/unscii_8x8.png", 8, 8, {chars: " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"}); // Music loadSound("tutorial", "sounds/Getting it Done.mp3"); //135 loadSound("faith", "sounds/The Friendly Faith Plate.mp3"); //120 @@ -21,6 +21,7 @@ load(new Promise((resolve, reject) => { // // Sounds + loadSound("nullHit", "sounds/nullHit.mp3"); loadSound("score", "sounds/score.mp3"); loadSound("metro", "sounds/metro.wav"); loadSound("explode", "sounds/explode.mp3"); @@ -477,7 +478,7 @@ scene("Game", (arr) => { ]) onUpdate(() => { if (health > 1) health = 1; - if (health < 0) {health = 0;go("Lose", score);music.stop();} + if (health < 0) {health = 0;go("Lose", score, arr);music.stop();} if (music.time() > music.duration() && health >= 0) {go("Title");} strumLine = lerp(18, width() / 2, health); noteClick.pos.x = strumLine - 5; @@ -550,6 +551,11 @@ scene("Game", (arr) => { } }); onKeyPress("space", () => {judgeHitsLol()}); + onKeyPress("backspace", () => { + underlay.stop(); + music.stop(); + go("Help") + }); onKeyPress("a", () => {autoplay = !autoplay}); onKeyPress("d", () => {debugMode = !debugMode}); onClick(() => {judgeHitsLol()}); @@ -696,6 +702,7 @@ scene("Game", (arr) => { } function judgeHitsLol() { var iv = false; + var hits = 0; every("note", (j) => { if (!iv) { if (!j.empty) { @@ -703,6 +710,7 @@ scene("Game", (arr) => { var theColor = WHITE; if(j.pos.x >= strumLine - 20) { if(j.pos.x <= strumLine + 22) { + hits++; iv = true; destroy(j); //Destroys note. No score. noteClick.play("click"); @@ -718,17 +726,15 @@ scene("Game", (arr) => { str = "Perfect!"; theColor = MAGENTA; } - if(j.pos.x <= strumLine) { + if(j.pos.x <= strumLine + 5) { score += 50; health += 0.02; - str = "Marvelous!"; - theColor = YELLOW; + str = "Perfect!!"; } if(j.pos.x <= strumLine - 3) { score += 50; health -= 0.01; str = "Perfect!"; - theColor = MAGENTA; } if(j.pos.x <= strumLine - 8) { score -= 100; @@ -755,6 +761,9 @@ scene("Game", (arr) => { } } }); + if (hits <= 0) { + play("nullHit"); + } } function beatHit() { every("dances", (obj) => { @@ -958,7 +967,7 @@ scene("Title", () => { onTouchStart(() => {go("Help", ["tutorial"]);/*losemus.stop();*/}); }); -scene("Lose", (score) => { +scene("Lose", (score, song) => { const lost = add([ sprite("jellybeanFail"), "dances", @@ -985,9 +994,8 @@ scene("Lose", (score) => { pos: vec2(0, height() - 30) }); }) - onKeyPress("space", () => {go("Title");losemus.stop();}); - onClick(() => {go("Title");losemus.stop();}); - onTouchStart(() => {go("Title");losemus.stop();}); + onKeyPress("space", () => {go("Game", song);losemus.stop();}); + onClick(() => {go("Game", song);losemus.stop();}); }); scene("Chart", (song) => { diff --git a/index.html b/index.html index 9a3d75b..e196b61 100644 --- a/index.html +++ b/index.html @@ -8,7 +8,7 @@ - + diff --git a/readme.md b/readme.md index 83cfef8..7589ea3 100644 --- a/readme.md +++ b/readme.md @@ -3,4 +3,6 @@ ## ToDo * Good practices in Js code -* Module code \ No newline at end of file +* Module code +* Custom font +* More minimization? \ No newline at end of file diff --git a/sounds/nullHit.mp3 b/sounds/nullHit.mp3 new file mode 100644 index 0000000..f31f305 Binary files /dev/null and b/sounds/nullHit.mp3 differ