Mid-Simulator/code/main.js

979 lines
23 KiB
JavaScript
Raw Normal View History

2022-04-26 21:55:28 +00:00
"use strict";
2022-04-24 21:35:14 +00:00
import { kaboom, easings, tween, tweentypes } from "../deps.js";
2022-04-26 21:55:28 +00:00
import { charts } from "./charts.js";
2022-04-18 01:14:39 +00:00
// initialize context
kaboom({
width: 700,
height: 400,
2022-04-24 21:35:14 +00:00
background: [ 0, 0, 0 ],
crisp: true,
touchToMouse: true,
2022-04-26 21:55:28 +00:00
canvas: document.querySelector("#kaboom"),
font: "MidSim",
scale: 1,
2022-04-18 01:14:39 +00:00
});
2022-04-26 21:55:28 +00:00
var ismobile = isTouch();
2022-04-18 01:14:39 +00:00
load(new Promise((resolve, reject) => {
2022-04-24 23:04:55 +00:00
loadFont("unscii", "sprites/unscii_8x8.png", 8, 8, {chars: " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"});
2022-04-26 21:55:28 +00:00
loadFont("MidSim", "sprites/MidSimFont2.png", 10, 10, {chars: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz:;><^%-.!?/()[]\"'|1234567890"});
2022-04-18 01:14:39 +00:00
// Music
loadSound("gameover", "sounds/gameover.mp3");
//
// Sounds
2022-04-24 23:04:55 +00:00
loadSound("nullHit", "sounds/nullHit.mp3");
2022-04-18 01:14:39 +00:00
loadSound("score", "sounds/score.mp3");
loadSound("metro", "sounds/metro.wav");
loadSound("explode", "sounds/explode.mp3");
//
//Menus
loadSprite("bgCake", "sprites/bgCake.png");
loadSprite("jellybeanTitle", "sprites/jellybeanTitle.png");
loadSprite("logo", "sprites/logo.png");
loadSprite("jellybeanFail", "sprites/jellybeanFail.png");
//
// Main Game
loadSprite("noteClick", "sprites/noteClick.png", {
sliceX: 4,
sliceY: 2,
anims: {
idle: {
from: 7,
to: 7,
speed: 30
},
click: {
from: 0,
to: 7,
speed: 60
}
},
})
2022-04-24 09:47:31 +00:00
2022-04-26 21:55:28 +00:00
for (let ided in charts) {
console.log("Loading game assets...");
charts[ided].events.preload();
console.log("Assets of song " + charts[ided].name + " loaded.");
}
2022-04-18 01:14:39 +00:00
resolve("All assets loaded.");
2022-04-26 21:55:28 +00:00
}));
2022-04-18 01:14:39 +00:00
2022-04-26 21:55:28 +00:00
scene("Game", (idx, noTrans) => {
var song = charts[idx.song].id; //Also Chart access
var char = charts[idx.song].characters[idx.character][0];
var hitsound = "hitsound" + charts[idx.song].characters[idx.character][0];
var chart = charts[idx.song].chart;
var crochet = ((60 / charts[idx.song].bpm) * 1000);
2022-04-18 01:14:39 +00:00
var board = width() - strumLine;
var curBeat;
2022-04-24 21:35:14 +00:00
var prevBeat;
var prevStep;
2022-04-18 01:14:39 +00:00
var curStep;
var autoplay = false;
var debugMode = false;
var score = 0;
var combo = 0;
var health = 1;
2022-04-26 21:55:28 +00:00
var font = "MidSim";
2022-04-18 01:14:39 +00:00
if (char == "MarkyMark") {
font = "unscii";
}
2022-04-26 21:55:28 +00:00
// Music
2022-04-18 01:14:39 +00:00
var strumLine = width() / 2;
2022-04-26 21:55:28 +00:00
const music = play(charts[idx.song].id, {
2022-04-18 01:14:39 +00:00
volume: 1,
loop: false
});
const underlay = play("score", {
volume: 1,
loop: false
});
music.pause()
2022-04-26 21:55:28 +00:00
wait(charts[idx.song].speed, () => {
2022-04-18 01:14:39 +00:00
underlay.pause();
music.play();
2022-04-26 21:55:28 +00:00
underlay.play(music.time() + charts[idx.song].speed);
2022-04-18 01:14:39 +00:00
});
2022-04-26 21:55:28 +00:00
// Sprites
2022-04-18 01:14:39 +00:00
layers([
"bg",
"JELLYBEAN",
"SKELETONS",
"fg",
"ui0",
"ui1"
], "ui0");
2022-04-26 21:55:28 +00:00
var players = {
main: 0,
empty: 0,
};
var bg;
var tweenVals = {
fade: 1,
triggered: false
}
tween(tweenVals, ["fade"], 1, 1, 0, easings.easeOutCirc, tweentypes.NORMAL);
if (!charts[idx.song].makeScript.customChar) {
players.main = add([
2022-04-24 09:47:31 +00:00
sprite(char + song),
layer("JELLYBEAN"),
"dances",
2022-04-27 02:27:01 +00:00
pos(charts[idx.song].characters[idx.character][2], charts[idx.song].characters[idx.character][3]),
2022-04-26 21:55:28 +00:00
scale(charts[idx.song].scale)
]);
}
if (!charts[idx.song].makeScript.customBG) {
bg = add([
sprite(song + "BG0"),
layer("bg"),
scale(charts[idx.song].scale)
]);
const fg = add([
sprite(song + "FG0"),
(song == "faith" ? layer("bg") : layer("fg")),
scale(charts[idx.song].scale)
]);
2022-04-24 09:47:31 +00:00
}
2022-04-26 21:55:28 +00:00
var script = charts[idx.song].makeScript.script(players, char, bg);
if (script.returnType != undefined && script.returnType == "character") {
players.main = script.main;
players.empty = script.empty;
2022-04-18 01:14:39 +00:00
}
const noteClick = add([
sprite("noteClick"),
scale(0.25),
pos(strumLine, 15)
])
2022-04-26 21:55:28 +00:00
const bspButton = add([
pos(0, 0),
color(CYAN),
text(ismobile ? "<" : "BACKSPACE TO EXIT", {
size: ismobile? 32 : 20, // 48 pixels tall
}),
area({
offset: ismobile ? vec2(canvas.offsetLeft, canvas.offsetTop) : vec2(0, 0),
}),
"back"
])
const entButton = add([
pos(width(), 0),
origin("topright"),
color(YELLOW),
text(ismobile ? "||" : "ENTER TO PAUSE", {
size: ismobile? 32 : 20, // 48 pixels tall
}),
area({
offset: ismobile ? vec2(canvas.offsetLeft, canvas.offsetTop) : vec2(0, 0),
}),
"ent"
])
// Gameplay
2022-04-18 01:14:39 +00:00
onUpdate(() => {
if (health > 1) health = 1;
2022-04-26 21:55:28 +00:00
if (health < 0) {
health = 0;
if(!tweenVals.triggered) {
tween(tweenVals, ["fade"], 1, 0, 1, easings.easeOutCirc, tweentypes.NORMAL, function () {
underlay.stop();
music.stop();
go("Lose", score, idx);
});
underlay.pause();
music.pause();
tweenVals.triggered = true;
}
}
if (music.time() > music.duration() && health >= 0) {
if(!tweenVals.triggered) {
tween(tweenVals, ["fade"], 1, 0, 1, easings.easeOutCirc, tweentypes.NORMAL, function () {
go("Help");
});
tweenVals.triggered = true;
}
}
2022-04-18 01:14:39 +00:00
strumLine = lerp(18, width() / 2, health);
noteClick.pos.x = strumLine - 5;
curBeat = Math.floor(((music.time() * 1000) / crochet) * 10) / 10;
curStep = Math.floor((music.time() * 1000) / (crochet / 4));
prevBeat = Math.floor(((underlay.time() * 1000) / crochet));
prevStep = Math.floor((underlay.time() * 1000) / (crochet / 4));
if (!get("bar" + prevBeat).length) {
var bar = add([
prevBeat % 4 == 0 ? rect(3, 50) : rect(2, 50),
pos(width(), 20),
color(255, 255, 255),
("bar" + prevBeat),
{
mainBar: prevBeat % 4 == 0,
created: underlay.time()
},
"bar"
]);
}
if (!get("note" + prevStep).length) {
2022-04-26 21:55:28 +00:00
makeNote(charts[idx.song].chart[Math.floor(prevStep)]);
2022-04-18 01:14:39 +00:00
}
if (!underlay.isPaused()) {
every("bar", (j) => {
2022-04-26 21:55:28 +00:00
j.pos.x = lerp(width(), strumLine, (underlay.time() - j.created) / charts[idx.song].speed);
2022-04-18 01:14:39 +00:00
if(j.pos.x <= strumLine) {
beatHit();
if (debugMode) play("metro", {detune: j.mainBar ? 200 : 0});
destroy(j);
}
2022-04-26 21:55:28 +00:00
if (charts[idx.song].events.onBeat != undefined) {
charts[idx.song].events.onBeat(curBeat);
}
2022-04-18 01:14:39 +00:00
});
every("note", (j) => {
2022-04-26 21:55:28 +00:00
j.pos.x = lerp(width(), strumLine, (underlay.time() - j.created) / charts[idx.song].speed);
2022-04-18 01:14:39 +00:00
if(autoplay) {
2022-04-24 09:47:31 +00:00
if(j.pos.x <= strumLine && !j.empty) {
2022-04-18 01:14:39 +00:00
play(hitsound);
2022-04-26 21:55:28 +00:00
players.main.play("talk"); //Check this area later, you want to add in Note Modularity!
2022-04-18 01:14:39 +00:00
destroy(j);
}
} else {
2022-04-24 09:47:31 +00:00
if(j.pos.x <= strumLine - 20 && !j.empty) {
2022-04-18 01:14:39 +00:00
score -= 200;
destroy(j);
play("explode");
2022-04-26 21:55:28 +00:00
players.main.play("miss");
2022-04-18 01:14:39 +00:00
shake(5);
combo = 0;
health -= 0.1;
}
}
2022-04-26 21:55:28 +00:00
if(j.pos.x <= strumLine && j.empty) {
if (!j.normal) {
2022-04-27 17:39:10 +00:00
j.function(j.empty, curBeat, j.type);
2022-04-24 09:47:31 +00:00
}
2022-04-26 21:55:28 +00:00
destroy(j);
players.empty?.play("talk");
2022-04-24 09:47:31 +00:00
}
2022-04-18 01:14:39 +00:00
});
}
})
var mt;
onKeyPress("enter", () => {
if (!underlay.isPaused()) {
underlay.pause();
music.pause();
mt = [underlay.time(), music.time()];
} else {
underlay.play(mt[0]);
music.play(mt[1]);
}
});
onKeyPress("space", () => {judgeHitsLol()});
2022-04-24 23:04:55 +00:00
onKeyPress("backspace", () => {
2022-04-26 21:55:28 +00:00
tween(tweenVals, ["fade"], 1, 0, 1, easings.easeOutCirc, tweentypes.NORMAL, function () {
underlay.stop();
music.stop();
go("Help");
});
underlay.pause();
music.pause();
2022-04-24 23:04:55 +00:00
});
2022-04-18 01:14:39 +00:00
onKeyPress("a", () => {autoplay = !autoplay});
onKeyPress("d", () => {debugMode = !debugMode});
2022-04-26 21:55:28 +00:00
onClick("back", () => {
tween(tweenVals, ["fade"], 1, 0, 1, easings.easeOutCirc, tweentypes.NORMAL, function () {
underlay.stop();
music.stop();
go("Help");
});
underlay.pause();
music.pause();
});
onClick("ent", () => {
if (!underlay.isPaused()) {
underlay.pause();
music.pause();
mt = [underlay.time(), music.time()];
} else {
underlay.play(mt[0]);
music.play(mt[1]);
}
});
2022-04-18 01:14:39 +00:00
onClick(() => {judgeHitsLol()});
onDraw(() => {
drawLine({
p1: vec2(0, 20),
p2: vec2(width(), 20),
width: 2,
color: rgb(255, 255, 255),
})
drawLine({
p1: vec2(0, 70),
p2: vec2(width(), 70),
width: 2,
color: rgb(255, 255, 255),
})
drawLines({ // 80 * 240, 20 * 60
pts: [ vec2(strumLine, 18), vec2(strumLine + 10, 18), vec2(strumLine + 10, 72), vec2(strumLine, 72), vec2(strumLine, 18) ],
width: 2,
pos: vec2(100, 200),
color: rgb(255, 255, 255),
})
drawText({
2022-04-26 21:55:28 +00:00
text: "MID-SIMULATOR DEMO",
2022-04-18 01:14:39 +00:00
size: 20,
2022-04-26 21:55:28 +00:00
pos: vec2(0, height() - 20),
2022-04-18 01:14:39 +00:00
font: font
});
if (debugMode) {
drawText({
text: underlay.time() * 1000,
size: 20,
pos: vec2(0, 20),
font: font
});
drawText({
text: curBeat,
size: 20,
pos: vec2(0, 40),
font: font
});
drawText({
2022-04-26 21:55:28 +00:00
text: prevStep + "/" + (charts[idx.song].chart.length - 1),
2022-04-18 01:14:39 +00:00
size: 20,
pos: vec2(0, 60),
font: font
});
drawText({
2022-04-26 21:55:28 +00:00
text: (charts[idx.song].chart[Math.floor(prevStep)] ? charts[idx.song].chart[Math.floor(prevStep)] : "."),
2022-04-18 01:14:39 +00:00
size: 20,
pos: vec2(0, 80),
font: font
});
drawText({
2022-04-26 21:55:28 +00:00
text: (charts[idx.song].chart[Math.floor(curStep)] ? charts[idx.song].chart[Math.floor(curStep)] : "."),
2022-04-18 01:14:39 +00:00
size: 20,
pos: vec2(0, 100),
font: font
});
drawText({
text: "Health: " + health,
size: 20,
pos: vec2(strumLine, 120),
font: font
});
}
drawText({
text: "Score: " + score,
size: 20,
pos: vec2(strumLine, 80),
font: font
});
drawText({
text: "Combo: " + combo,
size: 20,
pos: vec2(strumLine, 100),
font: font
});
if (autoplay) {
drawText({
text: "AUTOPLAY",
size: 20,
2022-04-26 21:55:28 +00:00
pos: vec2(strumLine, debugMode? 140: 120),
2022-04-18 01:14:39 +00:00
font: font
});
}
2022-04-26 21:55:28 +00:00
drawRect({
width: 702,
height: 402,
pos: vec2(-1, -1),
color: BLACK,
opacity: tweenVals.fade
})
2022-04-18 01:14:39 +00:00
})
2022-04-26 21:55:28 +00:00
//Functions
2022-04-18 01:14:39 +00:00
function makeNote(letter) {
2022-04-26 21:55:28 +00:00
if (charts[idx.song].noteTypes.hasOwnProperty(letter)) {
2022-04-27 17:39:10 +00:00
charts[idx.song].noteTypes[letter](underlay.time(), prevStep, char);
2022-04-18 01:14:39 +00:00
}
}
function judgeHitsLol() {
var iv = false;
2022-04-24 23:04:55 +00:00
var hits = 0;
2022-04-18 01:14:39 +00:00
every("note", (j) => {
if (!iv) {
2022-04-24 09:47:31 +00:00
if (!j.empty) {
var str = "No Rating";
var theColor = WHITE;
if(j.pos.x >= strumLine - 20) {
if(j.pos.x <= strumLine + 22) {
2022-04-24 23:04:55 +00:00
hits++;
2022-04-24 09:47:31 +00:00
iv = true;
2022-04-26 21:55:28 +00:00
if (!j.normal) {
2022-04-27 17:39:10 +00:00
j.function(j.empty, curBeat, j.type);
2022-04-26 21:55:28 +00:00
}
2022-04-24 09:47:31 +00:00
destroy(j); //Destroys note. No score.
noteClick.play("click");
combo += 1;
str = "MID";
theColor = RED;
}
if(j.pos.x <= strumLine + 12) {
play(hitsound); //Plays sound!
2022-04-26 21:55:28 +00:00
players.main.play("talk");
2022-04-24 09:47:31 +00:00
score += 20;
health += 0.01;
str = "Perfect!";
theColor = MAGENTA;
}
2022-04-24 23:04:55 +00:00
if(j.pos.x <= strumLine + 5) {
2022-04-24 09:47:31 +00:00
score += 50;
health += 0.02;
2022-04-24 23:04:55 +00:00
str = "Perfect!!";
2022-04-24 09:47:31 +00:00
}
if(j.pos.x <= strumLine - 3) {
score += 50;
health -= 0.01;
str = "Perfect!";
}
if(j.pos.x <= strumLine - 8) {
score -= 100;
health -= 0.02;
str = "Overshot";
theColor = CYAN;
}
2022-04-18 01:14:39 +00:00
}
2022-04-24 09:47:31 +00:00
if (str != "No Rating") {
var origpos = strumLine - 16;
var ratingtxt = add([
text(str, {
size: 30, // 48 pixels tall
}),
pos(origpos, 48),
color(theColor),
origin("right")
]);
tween(ratingtxt.pos, ["y"], 5, 48, 300, easings.easeOutSine, tweentypes.NORMAL);
tween(ratingtxt, ["opacity"], 5, 1, 0, easings.easeOutSine, tweentypes.NORMAL, function() {
destroy(ratingtxt);
});
2022-04-18 01:14:39 +00:00
}
}
}
});
2022-04-24 23:04:55 +00:00
if (hits <= 0) {
play("nullHit");
}
2022-04-18 01:14:39 +00:00
}
function beatHit() {
every("dances", (obj) => {
2022-04-26 21:55:28 +00:00
if (obj.curAnim() != "talk" && obj.curAnim() != "miss") {
2022-04-18 01:14:39 +00:00
obj.play("idle");
}
});
}
});
2022-04-26 21:55:28 +00:00
scene("Help", (noTrans) => {
var index = {
character: 0,
song: 0
2022-04-18 01:14:39 +00:00
}
2022-04-26 21:55:28 +00:00
var tweenVals = {
fade: 0
}
if (!noTrans) tween(tweenVals, ["fade"], 1, 1, 0, easings.easeOutCirc, tweentypes.NORMAL);
2022-04-18 01:14:39 +00:00
const bg = add([
sprite("bgCake")
]);
onDraw(() => {
2022-04-26 21:55:28 +00:00
if (!ismobile) {
drawText({
text: "D: ENABLE DEBUG MODE",
size: 30,
pos: vec2(25, 25)
});
drawText({
text: "A: ENABLE AUTOPLAY",
size: 30,
pos: vec2(25, 60)
});
}
2022-04-18 01:14:39 +00:00
drawText({
2022-04-26 21:55:28 +00:00
text: ismobile ? "TAP TO HIT NOTES" : "SPACE/CLICK: HIT NOTE",
2022-04-18 01:14:39 +00:00
size: 30,
2022-04-26 21:55:28 +00:00
pos: ismobile ? vec2(25, 60) : vec2(25, 95)
2022-04-18 01:14:39 +00:00
});
drawText({
2022-04-26 21:55:28 +00:00
text: charts[index.song].characters[index.character][1] + " ("+ (index.character + 1) +"/"+ charts[index.song].characters.length +")",
2022-04-18 01:14:39 +00:00
size: 30,
pos: vec2(width() / 2, 200),
origin: "top"
});
drawText({
2022-04-26 21:55:28 +00:00
text: charts[index.song].name,
2022-04-18 01:14:39 +00:00
size: 30,
pos: vec2(width() / 2, 160),
origin: "top"
});
drawSprite({
2022-04-26 21:55:28 +00:00
sprite: charts[index.song].characters[index.character][0] + "Pre",
2022-04-18 01:14:39 +00:00
width: 64,
height: 64,
pos: vec2((width() / 2) - 34, 248)
});
2022-04-26 21:55:28 +00:00
drawRect({
width: 702,
height: 402,
pos: vec2(-1, -1),
color: BLACK,
opacity: tweenVals.fade
})
2022-04-18 01:14:39 +00:00
})
add([
pos(0, 140),
rect(700, 200),
color(0, 0, 0)
2022-04-26 21:55:28 +00:00
])
2022-04-18 01:14:39 +00:00
var lt = add([
pos(10, 200),
text("<", {
size: 30
}),
2022-04-26 21:55:28 +00:00
area({
height: 30,
offset: ismobile ? vec2(canvas.offsetLeft, canvas.offsetTop) : vec2(0, 0),
width: 30,
cursor: "pointer"
}),
2022-04-18 01:14:39 +00:00
"LeftText"
])
var rt = add([
2022-04-26 21:55:28 +00:00
pos(width() - 10, 200),
origin("topright"),
2022-04-18 01:14:39 +00:00
text(">", {
size: 30
}),
2022-04-26 21:55:28 +00:00
area({
height: 30,
offset: ismobile ? vec2(canvas.offsetLeft, canvas.offsetTop) : vec2(0, 0),
width: 30,
cursor: "pointer"
}),
2022-04-18 01:14:39 +00:00
"RightText"
])
var dt = add([
pos(10, 160),
2022-04-26 21:55:28 +00:00
text("%", {
2022-04-18 01:14:39 +00:00
size: 30
}),
2022-04-26 21:55:28 +00:00
area({
height: 30,
offset: ismobile ? vec2(canvas.offsetLeft, canvas.offsetTop) : vec2(0, 0),
width: 30,
cursor: "pointer"
}),
2022-04-18 01:14:39 +00:00
"DownText"
])
var ut = add([
2022-04-26 21:55:28 +00:00
pos(width() - 10, 160),
origin("topright"),
2022-04-18 01:14:39 +00:00
text("^", {
size: 30
}),
2022-04-26 21:55:28 +00:00
area({
height: 30,
offset: ismobile ? vec2(canvas.offsetLeft, canvas.offsetTop) : vec2(0, 0),
width: 30,
cursor: "pointer"
}),
2022-04-18 01:14:39 +00:00
"UpText"
])
var clickText = add([
2022-04-26 21:55:28 +00:00
pos(width() / 2, height() - 45),
text(ismobile ? "TAP HERE TO START" : "SPACE TO START", {
2022-04-18 01:14:39 +00:00
size: 30
}),
2022-04-26 21:55:28 +00:00
origin("top"),
area({
height: 30,
offset: ismobile ? vec2(canvas.offsetLeft, canvas.offsetTop) : vec2(0, 0),
width: 700,
cursor: "pointer"
}),
2022-04-18 01:14:39 +00:00
"TEXT TEXT"
])
function changeIdx(amt) {
2022-04-26 21:55:28 +00:00
index.character += amt;
if (index.character < 0) {
index.character = charts[index.song].characters.length - 1;
} else if (index.character >= charts[index.song].characters.length) {
index.character = 0;
2022-04-18 01:14:39 +00:00
}
}
function changeSongIdx(amt) {
2022-04-26 21:55:28 +00:00
index.song += amt;
index.character = 0;
if (index.song < 0) {
index.song = charts.length - 1;
} else if (index.song >= charts.length) {
index.song = 0;
2022-04-18 01:14:39 +00:00
}
}
onKeyPress("left", () => {changeIdx(-1)});
onKeyPress("right", () => {changeIdx(1)});
2022-04-26 21:55:28 +00:00
onKeyPress("down", () => {changeSongIdx(-1)});
onKeyPress("up", () => {changeSongIdx(1)});
onKeyPress("`", () => {go("Chart", index.song)});
lt.onClick(() => {changeIdx(-1)});
rt.onClick(() => {changeIdx(1)});
dt.onClick(() => {changeSongIdx(-1)});
ut.onClick(() => {changeSongIdx(1)});
onKeyPress("space", () => {
tween(tweenVals, ["fade"], 1, 0, 1, easings.easeOutCirc, tweentypes.NORMAL, function () {
go("Game", index);
});
});
clickText.onClick(() => {go("Game", index);/*losemus.stop();*/});
2022-04-18 01:14:39 +00:00
});
scene("Title", () => {
const bg = add([
sprite("bgCake")
]);
const jb = add([
sprite("jellybeanTitle"),
pos(0, height() - 320)
]);
const logo = add([
sprite("logo"),
pos(0, 0),
scale(0.5, 0.5)
]);
onDraw(() => {
drawText({
2022-04-26 21:55:28 +00:00
text: "SPACE TO START",
2022-04-18 01:14:39 +00:00
size: 30,
2022-04-26 21:55:28 +00:00
origin: "top",
pos: vec2(width() / 2, height() - 45)
2022-04-18 01:14:39 +00:00
});
})
2022-04-26 21:55:28 +00:00
onKeyPress("space", () => {go("Help", true);/*losemus.stop();*/});
onClick(() => {go("Help", true);/*losemus.stop();*/});
onTouchStart(() => {go("Help", true);/*losemus.stop();*/});
2022-04-18 01:14:39 +00:00
});
2022-04-24 23:04:55 +00:00
scene("Lose", (score, song) => {
2022-04-18 01:14:39 +00:00
const lost = add([
sprite("jellybeanFail"),
"dances",
pos((width() / 2) - 162, height() / 2 - 162)
])
const losemus = play("gameover", {
volume: 1,
loop: true
});
onDraw(() => {
drawText({
2022-04-26 21:55:28 +00:00
text: "OUCHIE!",
2022-04-18 01:14:39 +00:00
size: 60,
pos: vec2(0, height() - 120)
});
drawText({
2022-04-26 21:55:28 +00:00
text: ismobile ? "TAP TO RESTART" : "SPACE TO RESTART",
2022-04-18 01:14:39 +00:00
size: 30,
pos: vec2(0, height() - 60)
});
drawText({
text: "SCORE: " + score,
size: 30,
pos: vec2(0, height() - 30)
});
})
2022-04-24 23:04:55 +00:00
onKeyPress("space", () => {go("Game", song);losemus.stop();});
onClick(() => {go("Game", song);losemus.stop();});
2022-04-18 01:14:39 +00:00
});
2022-04-26 21:55:28 +00:00
scene("Chart", (idx) => {
var chart = charts[idx].chart;
var crochet = ((60 / charts[idx].bpm) * 1000);
2022-04-18 01:14:39 +00:00
var curBeat;
var curStep;
var songTime = 0;
var tool = "J";
2022-04-26 21:55:28 +00:00
const music = play(charts[idx].id, {
2022-04-18 01:14:39 +00:00
volume: 1,
loop: false
});
2022-04-26 21:55:28 +00:00
music.pause();
2022-04-18 01:14:39 +00:00
var lastTargeted = 4;
var tempChart = Array.from(Array(Math.floor((music.duration() * 1000) / (crochet / 4))), () => ".");
// Incredibly redundant, sadly I don't care
var coords = [
width() * 0.1,
width() * 0.2,
width() * 0.3,
width() * 0.4,
width() * 0.5,
width() * 0.6,
width() * 0.7,
width() * 0.8,
width() * 0.9
];
var theEmpty = add([
pos(width() * 0.2, height() * 0.8),
rect(60, 60),
text(".", {
size: 48, // 48 pixels tall
width: 60
}),
color(255, 255, 255),
outline(4, WHITE),
origin("center"),
area(),
"theEmpty"
]);
var theJ = add([
pos(width() * 0.4, height() * 0.8),
rect(60, 60),
text("J", {
size: 48, // 48 pixels tall
width: 60
}),
color(255, 255, 255),
outline(4, WHITE),
origin("center"),
area(),
"theJ"
]);
var theP = add([
pos(width() * 0.6, height() * 0.8),
2022-04-24 09:47:31 +00:00
rect(60, 30),
2022-04-18 01:14:39 +00:00
text("P", {
2022-04-24 09:47:31 +00:00
size: 24, // 48 pixels tall
2022-04-18 01:14:39 +00:00
width: 60
}),
color(255, 255, 255),
outline(4, WHITE),
origin("center"),
area(),
"theP"
]);
2022-04-24 09:47:31 +00:00
var theD = add([
pos(width() * 0.6, height() * 0.8 + 30),
rect(60, 30),
text("D", {
size: 24, // 48 pixels tall
width: 60
}),
color(255, 255, 255),
outline(4, WHITE),
origin("center"),
area(),
"theD"
]);
2022-04-18 01:14:39 +00:00
var consoleButton = add([
pos(width() * 0.8, height() * 0.8),
rect(60, 60),
text("EXPORT", {
size: 30, // 48 pixels tall
}),
color(255, 255, 255),
outline(4, WHITE),
origin("center"),
area(),
"consoleButton"
]);
onClick("theEmpty", (o) => {tool = "."})
onClick("theJ", (o) => {tool = "J"})
onClick("theP", (o) => {tool = "P"})
2022-04-24 09:47:31 +00:00
onClick("theD", (o) => {tool = "D"})
2022-04-18 01:14:39 +00:00
onClick("consoleButton", (o) => {console.log(tempChart.join(""));})
onUpdate(() => {
curBeat = Math.floor(((music.time() * 1000) / crochet) * 10) / 10;
curStep = Math.floor((music.time() * 1000) / (crochet / 4));
if (mousePos().y >= height() * 0.4 && mousePos().y < (height() / 2) + 34) { // I shouldve used a Switch Case here :/
if (mousePos().x < width() * 0.15) {
// blk0
lastTargeted = 0;
} else if (mousePos().x < width() * 0.25) {
// blk1
lastTargeted = 1;
} else if (mousePos().x < width() * 0.35) {
// blk2
lastTargeted = 2;
} else if (mousePos().x < width() * 0.45) {
// blk3
lastTargeted = 3;
} else if (mousePos().x < width() * 0.55) {
// blk4
lastTargeted = 4;
} else if (mousePos().x < width() * 0.65) {
// blk5
lastTargeted = 5;
} else if (mousePos().x < width() * 0.75) {
// blk6
lastTargeted = 6;
} else if (mousePos().x < width() * 0.85) {
// blk7
lastTargeted = 7;
} else if (mousePos().x < width()) {
// blk8
lastTargeted = 8;
}
}
});
onMouseDown(() => {
if (mousePos().y >= height() * 0.4 && mousePos().y < (height() / 2) + 34) {
tempChart[curStep + lastTargeted] = tool;
}
});
onDraw(() => {
drawText({
text: songTime * 1000,
size: 20,
pos: vec2(0, )
});
drawText({
text: music.time() * 1000,
size: 20,
pos: vec2(0, 20)
});
drawText({
text: curBeat,
size: 20,
pos: vec2(0, 40)
});
drawText({
text: curStep + "/" + (tempChart.length - 1),
size: 20,
pos: vec2(0, 60)
});
drawText({
text: tool,
size: 50,
pos: vec2(width() / 2, height() * 0.65),
origin: "center"
});
drawLine({
p1: vec2(coords[lastTargeted] - 30, (height() / 2) + 30),
p2: vec2(coords[lastTargeted] + 30, (height() / 2) + 30),
width: 4,
color: rgb(255, 0, 0),
})
drawText({
text: tempChart[curStep] ? tempChart[curStep] : "",
size: 30,
pos: vec2(coords[0], height() / 2),
color: curStep % 4 == 0 ? RED : MAGENTA,
origin: "center"
})
drawText({
text: tempChart[curStep + 1] ? tempChart[curStep + 1] : "",
size: 30,
pos: vec2(coords[1], height() / 2),
color: (curStep + 1) % 4 == 0 ? RED : WHITE,
origin: "center"
})
drawText({
text: tempChart[curStep + 2] ? tempChart[curStep + 2] : "",
size: 30,
pos: vec2(coords[2], height() / 2),
color: (curStep + 2) % 4 == 0 ? RED : WHITE,
origin: "center"
})
drawText({
text: tempChart[curStep + 3] ? tempChart[curStep + 3] : "",
size: 30,
pos: vec2(coords[3], height() / 2),
color: (curStep + 3) % 4 == 0 ? RED : WHITE,
origin: "center"
})
drawText({
text: tempChart[curStep + 4] ? tempChart[curStep + 4] : "",
size: 30,
pos: vec2(coords[4], height() / 2),
color: (curStep + 4) % 4 == 0 ? RED : WHITE,
origin: "center"
})
drawText({
text: tempChart[curStep + 5] ? tempChart[curStep + 5] : "",
size: 30,
pos: vec2(coords[5], height() / 2),
color: (curStep + 5) % 4 == 0 ? RED : WHITE,
origin: "center"
})
drawText({
text: tempChart[curStep + 6] ? tempChart[curStep + 6] : "",
size: 30,
pos: vec2(coords[6], height() / 2),
color: (curStep + 6) % 4 == 0 ? RED : WHITE,
origin: "center"
})
drawText({
text: tempChart[curStep + 7] ? tempChart[curStep + 7] : "",
size: 30,
pos: vec2(coords[7], height() / 2),
color: (curStep + 7) % 4 == 0 ? RED : WHITE,
origin: "center"
})
drawText({
text: tempChart[curStep + 8] ? tempChart[curStep + 8] : "",
size: 30,
pos: vec2(coords[8], height() / 2),
color: (curStep + 8) % 4 == 0 ? RED : WHITE,
origin: "center"
})
});
onKeyPress("left", () => {
music.pause();
songTime = songTime - ((crochet / 4) / 1000);
try {
music.play(songTime);
} catch (err) {
console.log(err);
songTime = 0;
music.play(0);
}
music.pause();
});
onKeyPress("right", () => {
music.pause();
songTime = songTime + ((crochet / 4) / 1000);
try {
music.play(songTime);
} catch (err) {
console.log(err);
songTime = 0;
music.play(0);
}
music.pause();
});
onKeyPress("space", () => {
if (!music.isPaused()) {
music.pause();
songTime = music.time();
} else {
try {
music.play(songTime);
} catch (err) {
console.log(err);
songTime = 0;
music.play(0);
}
}
});
});
2022-04-27 02:27:01 +00:00
go("Title");