Cosmetics & Optimizations

This commit is contained in:
MeowcaTheoRange 2022-04-24 23:04:55 +00:00
parent f0fd199ede
commit 8f2be5fff2
7 changed files with 46 additions and 15 deletions

View file

@ -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"

1
.prettierrc Normal file
View file

@ -0,0 +1 @@
tabWidth: 4

View file

@ -146,7 +146,7 @@ export function tween(func, attrs, timeLen, minVal, maxVal, ease, type, onFinish
var upd = onUpdate(() => { var upd = onUpdate(() => {
switch (type(time(), stTime, timeLen)) { switch (type(time(), stTime, timeLen)) {
case "CALLBACK": case "CALLBACK":
for (h in attrs) { for (let h in attrs) {
func[attrs[h]] = maxVal; func[attrs[h]] = maxVal;
} }
upd(); upd();
@ -155,7 +155,7 @@ export function tween(func, attrs, timeLen, minVal, maxVal, ease, type, onFinish
stTime = time(); stTime = time();
break; break;
case "CONTINUE": case "CONTINUE":
for (h in attrs) { for (let h in attrs) {
func[attrs[h]] = minVal; func[attrs[h]] = minVal;
} }
break; break;
@ -168,7 +168,7 @@ export function tween(func, attrs, timeLen, minVal, maxVal, ease, type, onFinish
default: default:
break; break;
} }
for (i in attrs) { for (let i in attrs) {
func[attrs[i]] = lerp(minVal, maxVal, ease((time() - stTime) / timeLen)); func[attrs[i]] = lerp(minVal, maxVal, ease((time() - stTime) / timeLen));
} }
}); });

View file

@ -11,7 +11,7 @@ kaboom({
}); });
load(new Promise((resolve, reject) => { 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 // Music
loadSound("tutorial", "sounds/Getting it Done.mp3"); //135 loadSound("tutorial", "sounds/Getting it Done.mp3"); //135
loadSound("faith", "sounds/The Friendly Faith Plate.mp3"); //120 loadSound("faith", "sounds/The Friendly Faith Plate.mp3"); //120
@ -21,6 +21,7 @@ load(new Promise((resolve, reject) => {
// //
// Sounds // Sounds
loadSound("nullHit", "sounds/nullHit.mp3");
loadSound("score", "sounds/score.mp3"); loadSound("score", "sounds/score.mp3");
loadSound("metro", "sounds/metro.wav"); loadSound("metro", "sounds/metro.wav");
loadSound("explode", "sounds/explode.mp3"); loadSound("explode", "sounds/explode.mp3");
@ -477,7 +478,7 @@ scene("Game", (arr) => {
]) ])
onUpdate(() => { onUpdate(() => {
if (health > 1) health = 1; 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");} if (music.time() > music.duration() && health >= 0) {go("Title");}
strumLine = lerp(18, width() / 2, health); strumLine = lerp(18, width() / 2, health);
noteClick.pos.x = strumLine - 5; noteClick.pos.x = strumLine - 5;
@ -550,6 +551,11 @@ scene("Game", (arr) => {
} }
}); });
onKeyPress("space", () => {judgeHitsLol()}); onKeyPress("space", () => {judgeHitsLol()});
onKeyPress("backspace", () => {
underlay.stop();
music.stop();
go("Help")
});
onKeyPress("a", () => {autoplay = !autoplay}); onKeyPress("a", () => {autoplay = !autoplay});
onKeyPress("d", () => {debugMode = !debugMode}); onKeyPress("d", () => {debugMode = !debugMode});
onClick(() => {judgeHitsLol()}); onClick(() => {judgeHitsLol()});
@ -696,6 +702,7 @@ scene("Game", (arr) => {
} }
function judgeHitsLol() { function judgeHitsLol() {
var iv = false; var iv = false;
var hits = 0;
every("note", (j) => { every("note", (j) => {
if (!iv) { if (!iv) {
if (!j.empty) { if (!j.empty) {
@ -703,6 +710,7 @@ scene("Game", (arr) => {
var theColor = WHITE; var theColor = WHITE;
if(j.pos.x >= strumLine - 20) { if(j.pos.x >= strumLine - 20) {
if(j.pos.x <= strumLine + 22) { if(j.pos.x <= strumLine + 22) {
hits++;
iv = true; iv = true;
destroy(j); //Destroys note. No score. destroy(j); //Destroys note. No score.
noteClick.play("click"); noteClick.play("click");
@ -718,17 +726,15 @@ scene("Game", (arr) => {
str = "Perfect!"; str = "Perfect!";
theColor = MAGENTA; theColor = MAGENTA;
} }
if(j.pos.x <= strumLine) { if(j.pos.x <= strumLine + 5) {
score += 50; score += 50;
health += 0.02; health += 0.02;
str = "Marvelous!"; str = "Perfect!!";
theColor = YELLOW;
} }
if(j.pos.x <= strumLine - 3) { if(j.pos.x <= strumLine - 3) {
score += 50; score += 50;
health -= 0.01; health -= 0.01;
str = "Perfect!"; str = "Perfect!";
theColor = MAGENTA;
} }
if(j.pos.x <= strumLine - 8) { if(j.pos.x <= strumLine - 8) {
score -= 100; score -= 100;
@ -755,6 +761,9 @@ scene("Game", (arr) => {
} }
} }
}); });
if (hits <= 0) {
play("nullHit");
}
} }
function beatHit() { function beatHit() {
every("dances", (obj) => { every("dances", (obj) => {
@ -958,7 +967,7 @@ scene("Title", () => {
onTouchStart(() => {go("Help", ["tutorial"]);/*losemus.stop();*/}); onTouchStart(() => {go("Help", ["tutorial"]);/*losemus.stop();*/});
}); });
scene("Lose", (score) => { scene("Lose", (score, song) => {
const lost = add([ const lost = add([
sprite("jellybeanFail"), sprite("jellybeanFail"),
"dances", "dances",
@ -985,9 +994,8 @@ scene("Lose", (score) => {
pos: vec2(0, height() - 30) pos: vec2(0, height() - 30)
}); });
}) })
onKeyPress("space", () => {go("Title");losemus.stop();}); onKeyPress("space", () => {go("Game", song);losemus.stop();});
onClick(() => {go("Title");losemus.stop();}); onClick(() => {go("Game", song);losemus.stop();});
onTouchStart(() => {go("Title");losemus.stop();});
}); });
scene("Chart", (song) => { scene("Chart", (song) => {

View file

@ -8,7 +8,7 @@
</head> </head>
<body style="background-color: black; height: 100vh; width: 100vw; margin: 0; padding: 0; overflow: hidden;"> <body style="background-color: black; height: 100vh; width: 100vw; margin: 0; padding: 0; overflow: hidden;">
<canvas id="kaboom"></canvas> <canvas id="kaboom"></canvas>
<script src="code/game.js" type="module"></script> <!-- I hate how the scrollbar is still there on Replit --> <script src="code/main.js" type="module"></script> <!-- I hate how the scrollbar is still there on Replit -->
<style> <style>
#kaboom {position: absolute;top: calc(50vh - 200px);left: calc(50vw - 350px);} #kaboom {position: absolute;top: calc(50vh - 200px);left: calc(50vw - 350px);}
</style> </style>

View file

@ -4,3 +4,5 @@
* Good practices in Js code * Good practices in Js code
* Module code * Module code
* Custom font
* More minimization?

BIN
sounds/nullHit.mp3 Normal file

Binary file not shown.