aboutsummaryrefslogtreecommitdiff
path: root/race/cars
diff options
context:
space:
mode:
Diffstat (limited to 'race/cars')
-rw-r--r--race/cars/car0.js212
-rw-r--r--race/cars/car1.js224
-rw-r--r--race/cars/car1ai.js160
-rw-r--r--race/cars/keymap.js162
4 files changed, 758 insertions, 0 deletions
diff --git a/race/cars/car0.js b/race/cars/car0.js
new file mode 100644
index 0000000..ddfe8c5
--- /dev/null
+++ b/race/cars/car0.js
@@ -0,0 +1,212 @@
+startHooks.push(() => {
+ car0speed = 16;
+ car0cspeed = 0;
+ if (online && role === "guest") {
+ car0startx = 388.9;
+ car0starty = 79.4;
+ } else {
+ car0startx = 428;
+ car0starty = 42.9;
+ }
+ car0collisionon = true;
+ car0enableOOBChecker = false;
+
+// Collision Manager
+ function car0collision() {
+ if (!keysEnabled) { return; }
+
+ if (started) {
+ carshb = document.getElementById("car0").getBoundingClientRect();
+ hitbox = document.getElementById("barrier").getBoundingClientRect();
+
+ var overlap = !(carshb.right < hitbox.left ||
+ carshb.left > hitbox.right ||
+ carshb.bottom < hitbox.top ||
+ carshb.top > hitbox.bottom)
+
+ if (overlap) {
+ info("CarManager:car0", "Reversal prevented at X " + document.getElementById("car0").style.left + ", Y " + document.getElementById("car0").style.top);
+ document.getElementById("car0").style.left = car0startx + "px";
+ document.getElementById("car0").style.top = car0starty + "px";
+ document.getElementById("car0").style.transform = "rotate(0deg)";
+ car0cspeed = 0;
+ }
+ }
+
+ if (!car0collisionon) { return; }
+
+ walls = Array.from(document.getElementsByClassName("wall"));
+
+ walls.forEach((wall) => {
+ carshb = document.getElementById("car0").getBoundingClientRect();
+ hitbox = wall.getBoundingClientRect();
+
+ var overlap = !(carshb.right < hitbox.left ||
+ carshb.left > hitbox.right ||
+ carshb.bottom < hitbox.top ||
+ carshb.top > hitbox.bottom)
+
+ if (overlap) {
+ info("CarManager:car0", "Wall collision at X " + document.getElementById("car0").style.left + ", Y " + document.getElementById("car0").style.top);
+ if (location.search === "?sp") {
+ scenar("wall1", "happy");
+ }
+ Sound.crash()
+ document.getElementById("car0").style.left = car0startx + "px";
+ document.getElementById("car0").style.top = car0starty + "px";
+ Array.from(document.getElementById('oil').children).forEach((item) => {
+ spreadOil(item);
+ })
+ document.getElementById("car0").style.transform = "rotate(0deg)";
+ car0cspeed = 0;
+ }
+ })
+
+ Array.from(document.getElementById('oil').children).forEach((item) => {
+ carshb = document.getElementById("car0").getBoundingClientRect();
+ hitbox = item.getBoundingClientRect();
+
+ var overlap = !(carshb.right < hitbox.left ||
+ carshb.left > hitbox.right ||
+ carshb.bottom < hitbox.top ||
+ carshb.top > hitbox.bottom)
+
+ if (overlap) {
+ car0cspeed = 7;
+ }
+ })
+
+ carshb = document.getElementById("car0").getBoundingClientRect();
+ hitbox = document.getElementById("arrival").getBoundingClientRect();
+
+ var overlap = !(carshb.right < hitbox.left ||
+ carshb.left > hitbox.right ||
+ carshb.bottom < hitbox.top ||
+ carshb.top > hitbox.bottom)
+
+ if (overlap && started) {
+ started = false;
+ if ((document.getElementById('laps-car0').innerText.split("/")[0] - 1 + 1) < 4) {
+ info("CarManager:car0", "New lap");
+ Array.from(document.getElementById('oil').children).forEach((item) => {
+ spreadOil(item);
+ })
+ if ((document.getElementById('laps-car0').innerText.split("/")[0] - 1 + 1) < 3) {
+ Sound.pass()
+ } else {
+ Sound.last()
+ }
+ document.getElementById('laps-car0').innerText = (document.getElementById('laps-car0').innerText.split("/")[0] - 1 + 2).toString();
+ if (location.search === "?sp") {
+ if ((document.getElementById('laps-car0').innerText.split("/")[0] - 1 + 1) > (document.getElementById('laps-car1').innerText.split("/")[0] - 1 + 1)) {
+ scenar("ahead1", "angry");
+ } else {
+ scenar("ahead2", "happy");
+ }
+ }
+ } else {
+ info("CarManager:car0", "Car won the game");
+ if (location.search === "?sp") {
+ scenar("won1", "sad");
+ }
+ try { document.getElementById('music').src = "about:blank"; } catch (e) { console.error(e); }
+ Sound.win();
+ keysEnabled = false;
+ car0cspeed = 0;
+ car0speed = 0;
+ document.getElementById('laps-car0').innerText = (document.getElementById('laps-car0').innerText.split("/")[0] - 1 + 2).toString();
+ $("#box").fadeOut(500);
+ setTimeout(() => {
+ if (online) {
+ clientWriter(JSON.stringify({
+ _type: "ipc",
+ action: "progressLose",
+ message: null
+ }) + "|")
+ }
+ if (location.search === "?sp" || online) {
+ location.href = "win.html?sp#car0";
+ } else {
+ location.href = "win.html#car0";
+ }
+ }, 3500)
+ }
+ document.getElementById("car0").style.left = car0startx + "px";
+ document.getElementById("car0").style.top = car0starty + "px";
+ document.getElementById("car0").style.transform = "rotate(0deg)";
+ Array.from(document.getElementById('oil').children).forEach((item) => {
+ spreadOil(item);
+ })
+ car0cspeed = 0;
+ setTimeout(() => {
+ started = true;
+ }, 150)
+ }
+
+ carshb = document.getElementById("car0").getBoundingClientRect();
+ hitbox = document.getElementById("car1").getBoundingClientRect();
+
+ var overlap = !(carshb.right < hitbox.left ||
+ carshb.left > hitbox.right ||
+ carshb.bottom < hitbox.top ||
+ carshb.top > hitbox.bottom)
+
+ if (overlap) {
+ if (location.search === "?sp") {
+ scenar("wall1", "happy");
+ }
+ Sound.crash();
+ document.getElementById("car0").style.left = car0startx + "px";
+ document.getElementById("car0").style.top = car0starty + "px";
+ Array.from(document.getElementById('oil').children).forEach((item) => {
+ spreadOil(item);
+ })
+ document.getElementById("car0").style.transform = "rotate(0deg)";
+ car0cspeed = 0;
+ }
+ }
+
+// General Movements
+ setInterval(() => {
+ if (!paused) {
+ if (car0cspeed > 0) {
+ car0cspeed = car0cspeed - 0.1;
+ }
+ switch (document.getElementById("car0").style.transform) {
+ case "rotate(0deg)":
+ document.getElementById("car0").style.left = ((document.getElementById("car0").style.left.split("p")[0] - 1) + (1 + car0cspeed)) + "px";
+ break;
+ case "rotate(180deg)":
+ document.getElementById("car0").style.left = ((document.getElementById("car0").style.left.split("p")[0] - 1) - (1 + car0cspeed)) + "px";
+ break;
+ case "rotate(90deg)":
+ document.getElementById("car0").style.top = ((document.getElementById("car0").style.top.split("p")[0] - 1) + (1 + car0cspeed)) + "px";
+ break;
+ case "rotate(-90deg)":
+ document.getElementById("car0").style.top = ((document.getElementById("car0").style.top.split("p")[0] - 1) - (1 + car0cspeed)) + "px";
+ break;
+ }
+ if (document.getElementById("car0").style.left.split("p")[0] - 1 + 1 > (window.innerWidth - 30)) {
+ warn("CarManager:car0", "Colliding with screen border");
+ document.getElementById("car0").style.left = (window.innerWidth - 30) + "px";
+ }
+ if (document.getElementById("car0").style.top.split("p")[0] - 1 + 1 > (window.innerHeight - 30)) {
+ warn("CarManager:car0", "Colliding with screen border");
+ document.getElementById("car0").style.top = (window.innerHeight - 30) + "px";
+ }
+ if (document.getElementById("car0").style.top.split("p")[0] - 1 + 1 < 30) {
+ warn("CarManager:car0", "Colliding with screen border");
+ document.getElementById("car0").style.top = "30px";
+ }
+ if (document.getElementById("car0").style.left.split("p")[0] - 1 + 1 < 30) {
+ warn("CarManager:car0", "Colliding with screen border");
+ document.getElementById("car0").style.left = "30px";
+ }
+ if (car0cspeed > -0.1 && car0cspeed < 0) {
+ car0cspeed = 0;
+ }
+ car0collision();
+ }
+ }, 200)
+
+}) \ No newline at end of file
diff --git a/race/cars/car1.js b/race/cars/car1.js
new file mode 100644
index 0000000..750cbb3
--- /dev/null
+++ b/race/cars/car1.js
@@ -0,0 +1,224 @@
+startHooks.push(() => {
+ car1speed = 16;
+ car1cspeed = 0;
+ if (online && role === "guest") {
+ car1startx = 428;
+ car1starty = 42.9;
+ } else {
+ car1startx = 388.9;
+ car1starty = 79.4;
+ }
+ if (online) {
+ car1collisionon = false;
+ } else {
+ car1collisionon = true;
+ }
+ car1enableOOBChecker = false;
+
+// Collision Manager
+ function car1collision() {
+ if (!keysEnabled) { return; }
+
+ if (started) {
+ carshb = document.getElementById("car0").getBoundingClientRect();
+ hitbox = document.getElementById("barrier").getBoundingClientRect();
+
+ var overlap = !(carshb.right < hitbox.left ||
+ carshb.left > hitbox.right ||
+ carshb.bottom < hitbox.top ||
+ carshb.top > hitbox.bottom)
+
+ if (overlap) {
+ info("CarManager:car0", "Reversal prevented at X " + document.getElementById("car0").style.left + ", Y " + document.getElementById("car0").style.top);
+ document.getElementById("car0").style.left = car0startx + "px";
+ document.getElementById("car0").style.top = car0starty + "px";
+ document.getElementById("car0").style.transform = "rotate(0deg)";
+ car0cspeed = 0;
+ }
+ }
+
+ if (!car1collisionon) { return; }
+
+ walls = Array.from(document.getElementsByClassName("wall"));
+
+ walls.forEach((wall) => {
+ carshb = document.getElementById("car1").getBoundingClientRect();
+ hitbox = wall.getBoundingClientRect();
+
+ var overlap = !(carshb.right < hitbox.left ||
+ carshb.left > hitbox.right ||
+ carshb.bottom < hitbox.top ||
+ carshb.top > hitbox.bottom)
+
+ if (overlap) {
+ info("CarManager:car1", "Wall collision at X " + document.getElementById("car1").style.left + ", Y " + document.getElementById("car1").style.top);
+ if (location.search === "?sp") {
+ scenar("wall2", "angry");
+ }
+ Sound.crash()
+ document.getElementById("car1").style.left = car1startx + "px";
+ document.getElementById("car1").style.top = car1starty + "px";
+ Array.from(document.getElementById('oil').children).forEach((item) => {
+ spreadOil(item);
+ })
+ document.getElementById("car1").style.transform = "rotate(0deg)";
+ car1cspeed = 0;
+ }
+ })
+
+ Array.from(document.getElementById('oil').children).forEach((item) => {
+ carshb = document.getElementById("car1").getBoundingClientRect();
+ hitbox = item.getBoundingClientRect();
+
+ var overlap = !(carshb.right < hitbox.left ||
+ carshb.left > hitbox.right ||
+ carshb.bottom < hitbox.top ||
+ carshb.top > hitbox.bottom)
+
+ if (overlap) {
+ car1cspeed = 7;
+ }
+ })
+
+ carshb = document.getElementById("car1").getBoundingClientRect();
+ hitbox = document.getElementById("arrival").getBoundingClientRect();
+
+ var overlap = !(carshb.right < hitbox.left ||
+ carshb.left > hitbox.right ||
+ carshb.bottom < hitbox.top ||
+ carshb.top > hitbox.bottom)
+
+ if (overlap && started) {
+ started = false;
+ if ((document.getElementById('laps-car1').innerText.split("/")[0] - 1 + 1) < 4) {
+ info("CarManager:car1", "New lap");
+ Array.from(document.getElementById('oil').children).forEach((item) => {
+ spreadOil(item);
+ })
+ if ((document.getElementById('laps-car1').innerText.split("/")[0] - 1 + 1) < 3) {
+ Sound.pass()
+ } else {
+ Sound.last()
+ }
+ document.getElementById('laps-car1').innerText = (document.getElementById('laps-car1').innerText.split("/")[0] - 1 + 2).toString();
+ if (location.search === "?sp") {
+ if ((document.getElementById('laps-car0').innerText.split("/")[0] - 1 + 1) > (document.getElementById('laps-car1').innerText.split("/")[0] - 1 + 1)) {
+ scenar("ahead1", "angry");
+ } else {
+ scenar("ahead2", "happy");
+ }
+ }
+ } else {
+ info("CarManager:car1", "Car won the game");
+ if (location.search === "?sp") {
+ scenar("won2", "happy");
+ }
+ try { document.getElementById('music').src = "about:blank"; } catch (e) { console.error(e); }
+ Sound.win();
+ keysEnabled = false;
+ car1cspeed = 0;
+ car1speed = 0;
+ document.getElementById('laps-car1').innerText = (document.getElementById('laps-car1').innerText.split("/")[0] - 1 + 2).toString();
+ $("#box").fadeOut(500);
+ setTimeout(() => {
+ setTimeout(() => {
+ if (location.search === "?sp" || (online && role === "guest")) {
+ if (online) {} else {
+ location.href = "win.html?sp#car1";
+ }
+ } else {
+ location.href = "win.html#car1";
+ }
+ }, 3500)
+ }, 3000)
+ }
+ document.getElementById("car1").style.left = car1startx + "px";
+ document.getElementById("car1").style.top = car1starty + "px";
+ Array.from(document.getElementById('oil').children).forEach((item) => {
+ spreadOil(item);
+ })
+ document.getElementById("car1").style.transform = "rotate(0deg)";
+ Array.from(document.getElementById('oil').children).forEach((item) => {
+ spreadOil(item);
+ })
+ car1cspeed = 0;
+ setTimeout(() => {
+ started = true;
+ }, 150)
+ }
+
+ carshb = document.getElementById("car1").getBoundingClientRect();
+ hitbox = document.getElementById("car0").getBoundingClientRect();
+
+ var overlap = !(carshb.right < hitbox.left ||
+ carshb.left > hitbox.right ||
+ carshb.bottom < hitbox.top ||
+ carshb.top > hitbox.bottom)
+
+ if (overlap) {
+ if (location.search === "?sp") {
+ scenar("wall2", "angry");
+ }
+ Sound.crash();
+ document.getElementById("car1").style.left = car1startx + "px";
+ document.getElementById("car1").style.top = car1starty + "px";
+ document.getElementById("car1").style.transform = "rotate(0deg)";
+ Array.from(document.getElementById('oil').children).forEach((item) => {
+ spreadOil(item);
+ })
+ car1cspeed = 0;
+ }
+ }
+
+// General Movements
+ setInterval(() => {
+ if (!paused) {
+ if (car1cspeed > 0) {
+ car1cspeed = car1cspeed - 0.1;
+ }
+ switch (document.getElementById("car1").style.transform) {
+ case "rotate(0deg)":
+ document.getElementById("car1").style.left = ((document.getElementById("car1").style.left.split("p")[0] - 1) + (1 + car1cspeed)) + "px";
+ break;
+ case "rotate(180deg)":
+ document.getElementById("car1").style.left = ((document.getElementById("car1").style.left.split("p")[0] - 1) - (1 + car1cspeed)) + "px";
+ break;
+ case "rotate(90deg)":
+ document.getElementById("car1").style.top = ((document.getElementById("car1").style.top.split("p")[0] - 1) + (1 + car1cspeed)) + "px";
+ break;
+ case "rotate(-90deg)":
+ document.getElementById("car1").style.top = ((document.getElementById("car1").style.top.split("p")[0] - 1) - (1 + car1cspeed)) + "px";
+ break;
+ }
+ if (document.getElementById("car1").style.left.split("p")[0] - 1 + 1 > (window.innerWidth - 30)) {
+ warn("CarManager:car1", "Colliding with screen border");
+ if (car1enableOOBChecker) {
+ document.getElementById("car1").style.left = (window.innerWidth - 30) + "px";
+ }
+ }
+ if (document.getElementById("car1").style.top.split("p")[0] - 1 + 1 > (window.innerHeight - 30)) {
+ warn("CarManager:car1", "Colliding with screen border");
+ if (car1enableOOBChecker) {
+ document.getElementById("car1").style.top = (window.innerHeight - 30) + "px";
+ }
+ }
+ if (document.getElementById("car1").style.top.split("p")[0] - 1 + 1 < 30) {
+ warn("CarManager:car1", "Colliding with screen border");
+ if (car1enableOOBChecker) {
+ document.getElementById("car1").style.top = "30px";
+ }
+ }
+ if (document.getElementById("car1").style.left.split("p")[0] - 1 + 1 < 30) {
+ warn("CarManager:car1", "Colliding with screen border");
+ if (car1enableOOBChecker) {
+ document.getElementById("car1").style.left = "30px";
+ }
+ }
+ if (car1cspeed > -0.1 && car1cspeed < 0) {
+ car1cspeed = 0;
+ }
+ car1collision();
+ }
+ }, 200)
+
+}) \ No newline at end of file
diff --git a/race/cars/car1ai.js b/race/cars/car1ai.js
new file mode 100644
index 0000000..25e1819
--- /dev/null
+++ b/race/cars/car1ai.js
@@ -0,0 +1,160 @@
+aiorient = "right";
+elem = 10;
+
+function enableAI() {
+ car1enableOOBChecker = false;
+ setInterval(() => {
+ if (aiorient === "top") {
+ ai_up();
+ } else if (aiorient === "right") {
+ ai_right();
+ } else if (aiorient === "bottom") {
+ ai_down();
+ } else if (aiorient === "left") {
+ ai_left();
+ }
+ }, 100)
+ setInterval(() => {
+ carshb = document.getElementById("aibox-near").getBoundingClientRect();
+ hitbox = document.getElementById('barrier').getBoundingClientRect();
+
+ var overlap = !(carshb.right < hitbox.left ||
+ carshb.left > hitbox.right ||
+ carshb.bottom < hitbox.top ||
+ carshb.top > hitbox.bottom)
+
+ if (overlap) {
+ aiorient = "right";
+ }
+
+ if (elem < 10) { elem++; }
+ if (elem !== 10) { return; }
+
+ walls = Array.from(document.getElementsByClassName("wall"));
+
+ walls.forEach((wall) => {
+ carshb = document.getElementById("aibox-far").getBoundingClientRect();
+ hitbox = wall.getBoundingClientRect();
+
+ var overlap = !(carshb.right < hitbox.left ||
+ carshb.left > hitbox.right ||
+ carshb.bottom < hitbox.top ||
+ carshb.top > hitbox.bottom)
+
+ carshb2 = document.getElementById("aibox-near").getBoundingClientRect();
+
+ var overlap2 = !(carshb2.right < hitbox.left ||
+ carshb2.left > hitbox.right ||
+ carshb2.bottom < hitbox.top ||
+ carshb2.top > hitbox.bottom)
+
+ if (overlap2) {
+ car1speed = 8;
+ } else if (overlap) {
+ car1speed = 9;
+ } else {
+ car1speed = 10;
+ }
+
+ carshb = document.getElementById("aibox-far").getBoundingClientRect();
+ hitbox = wall.getBoundingClientRect();
+
+ var overlap = !(carshb.right < hitbox.left ||
+ carshb.left > hitbox.right ||
+ carshb.bottom < hitbox.top ||
+ carshb.top > hitbox.bottom)
+
+ if (overlap) {
+ if (aiorient === "top") {
+ aiorient = "right";
+ elem = 0;
+ } else if (aiorient === "right") {
+ aiorient = "bottom";
+ elem = 0;
+ } else if (aiorient === "bottom") {
+ aiorient = "left";
+ elem = 0;
+ } else if (aiorient === "left") {
+ aiorient = "top";
+ elem = 0;
+ }
+ }
+
+ carshb = document.getElementById("aibox-near").getBoundingClientRect();
+ hitbox = document.getElementById('car0').getBoundingClientRect();
+
+ var overlap = !(carshb.right < hitbox.left ||
+ carshb.left > hitbox.right ||
+ carshb.bottom < hitbox.top ||
+ carshb.top > hitbox.bottom)
+
+ if (overlap) {
+ if (aiorient === "top") {
+ aiorient = "bottom";
+ elem = 0;
+ } else if (aiorient === "right") {
+ aiorient = "left";
+ elem = 0;
+ } else if (aiorient === "bottom") {
+ aiorient = "top";
+ elem = 0;
+ } else if (aiorient === "left") {
+ aiorient = "right";
+ elem = 0;
+ }
+ }
+ })
+ }, 50)
+}
+
+function ai_up() {
+ if (car1cspeed < car1speed) {
+ car1cspeed = car1cspeed + 0.2;
+ }
+ if (document.getElementById("car1").style.transform !== "rotate(-90deg)") {
+ document.getElementById("car1").style.transform = "rotate(-90deg)";
+ car1collisionon = false;
+ setTimeout(() => {
+ car1collisionon = true;
+ }, 500)
+ }
+}
+
+function ai_down() {
+ if (car1cspeed < car1speed) {
+ car1cspeed = car1cspeed + 0.2;
+ }
+ if (document.getElementById("car1").style.transform !== "rotate(90deg)") {
+ document.getElementById("car1").style.transform = "rotate(90deg)";
+ car1collisionon = false;
+ setTimeout(() => {
+ car1collisionon = true;
+ }, 500)
+ }
+}
+
+function ai_left() {
+ if (car1cspeed < car1speed) {
+ car1cspeed = car1cspeed + 0.2;
+ }
+ if (document.getElementById("car1").style.transform !== "rotate(180deg)") {
+ document.getElementById("car1").style.transform = "rotate(180deg)";
+ car1collisionon = false;
+ setTimeout(() => {
+ car1collisionon = true;
+ }, 500)
+ }
+}
+
+function ai_right() {
+ if (car1cspeed < car1speed) {
+ car1cspeed = car1cspeed + 0.2;
+ }
+ if (document.getElementById("car1").style.transform !== "rotate(0deg)") {
+ document.getElementById("car1").style.transform = "rotate(0deg)";
+ car1collisionon = false;
+ setTimeout(() => {
+ car1collisionon = true;
+ }, 500)
+ }
+} \ No newline at end of file
diff --git a/race/cars/keymap.js b/race/cars/keymap.js
new file mode 100644
index 0000000..74cce0a
--- /dev/null
+++ b/race/cars/keymap.js
@@ -0,0 +1,162 @@
+startHooks.push(() => {
+ $(document).keydown(function(e) {
+ if (online && role === null) {
+ if (e.keyCode === 27 || e.keyCode === 8) { // esc
+ require('electron').ipcRenderer.send('prefademusic', "");
+ $("body").fadeOut(200);
+ setTimeout(() => {
+ location.href = "menu.html?back";
+ }, 250)
+ }
+ }
+ if (keysEnabled) {
+ if (!paused) {
+ if (e.keyCode === 115) { // F4
+ if (hitshow) {
+ hitshow = false;
+ document.getElementById("circuit").classList.remove("hitboxes");
+ document.getElementById('hitboxes').innerText = lang.game.gpause.showhb;
+ info("GameWindow", "Hitboxes hidden");
+ } else {
+ hitshow = true;
+ document.getElementById("circuit").classList.add("hitboxes");
+ document.getElementById('hitboxes').innerText = lang.game.gpause.hidehb;
+ info("GameWindow", "Hitboxes shown");
+ }
+ }
+ if (e.keyCode === 90 || e.keyCode === 87 || ((location.search === "?sp" || location.search === "?online") && e.keyCode === 38)) { // Z
+ if (car0cspeed < car0speed) {
+ car0cspeed = car0cspeed + 0.2;
+ }
+ if (document.getElementById("car0").style.transform !== "rotate(-90deg)") {
+ document.getElementById("car0").style.transform = "rotate(-90deg)";
+ car0collisionon = false;
+ setTimeout(() => {
+ car0collisionon = true;
+ }, 500)
+ }
+ }
+ if (e.keyCode === 83 || ((location.search === "?sp" || location.search === "?online") && e.keyCode === 40)) { // S
+ if (car0cspeed < car0speed) {
+ car0cspeed = car0cspeed + 0.2;
+ }
+ if (document.getElementById("car0").style.transform !== "rotate(90deg)") {
+ document.getElementById("car0").style.transform = "rotate(90deg)";
+ car0collisionon = false;
+ setTimeout(() => {
+ car0collisionon = true;
+ }, 500)
+ }
+ }
+ if (e.keyCode === 81 || e.keyCode === 65 || ((location.search === "?sp" || location.search === "?online") && e.keyCode === 37)) { // Q
+ if (car0cspeed < car0speed) {
+ car0cspeed = car0cspeed + 0.2;
+ }
+ if (document.getElementById("car0").style.transform !== "rotate(180deg)") {
+ document.getElementById("car0").style.transform = "rotate(180deg)";
+ car0collisionon = false;
+ setTimeout(() => {
+ car0collisionon = true;
+ }, 500)
+ }
+ }
+ if (e.keyCode === 68 || ((location.search === "?sp" || location.search === "?online") && e.keyCode === 39)) { // D
+ if (car0cspeed < car0speed) {
+ car0cspeed = car0cspeed + 0.2;
+ }
+ if (document.getElementById("car0").style.transform !== "rotate(0deg)") {
+ document.getElementById("car0").style.transform = "rotate(0deg)";
+ car0collisionon = false;
+ setTimeout(() => {
+ car0collisionon = true;
+ }, 500)
+ }
+ }
+ if (location.search !== "?sp" && location.search !== "?online") {
+ if (e.keyCode === 38) { // up
+ if (car1cspeed < car1speed) {
+ car1cspeed = car1cspeed + 0.2;
+ }
+ if (document.getElementById("car1").style.transform !== "rotate(-90deg)") {
+ document.getElementById("car1").style.transform = "rotate(-90deg)";
+ car1collisionon = false;
+ setTimeout(() => {
+ car1collisionon = true;
+ }, 500)
+ }
+ }
+ if (e.keyCode === 40) { // down
+ if (car1cspeed < car1speed) {
+ car1cspeed = car1cspeed + 0.2;
+ }
+ if (document.getElementById("car1").style.transform !== "rotate(90deg)") {
+ document.getElementById("car1").style.transform = "rotate(90deg)";
+ car1collisionon = false;
+ setTimeout(() => {
+ car1collisionon = true;
+ }, 500)
+ }
+ }
+ if (e.keyCode === 37) { // left
+ if (car1cspeed < car1speed) {
+ car1cspeed = car1cspeed + 0.2;
+ }
+ if (document.getElementById("car1").style.transform !== "rotate(180deg)") {
+ document.getElementById("car1").style.transform = "rotate(180deg)";
+ car1collisionon = false;
+ setTimeout(() => {
+ car1collisionon = true;
+ }, 500)
+ }
+ }
+ if (e.keyCode === 39) { // right
+ if (car1cspeed < car1speed) {
+ car1cspeed = car1cspeed + 0.2;
+ }
+ if (document.getElementById("car1").style.transform !== "rotate(0deg)") {
+ document.getElementById("car1").style.transform = "rotate(0deg)";
+ car1collisionon = false;
+ setTimeout(() => {
+ car1collisionon = true;
+ }, 500)
+ }
+ }
+ }
+ if (e.keyCode === 27 || e.keyCode === 8) { // esc
+ pause(true);
+ }
+ } else {
+ if (e.keyCode === 13 || e.keyCode === 88 || e.keyCode === 32 || e.keyCode === 16) { // enter
+ if ($(".services").is(":visible")) {
+ selectOption();
+ } else {
+ $(".services").show();
+ }
+ }
+ if (e.keyCode === 38 || e.keyCode === 90) { // up
+ Sound.menu();
+ var selected = $(".selected");
+ $(".services li").removeClass("selected");
+ if (selected.prev().length === 0) {
+ selected.siblings().last().addClass("selected");
+ } else {
+ selected.prev().addClass("selected");
+ }
+ }
+ if (e.keyCode === 40 || e.keyCode === 83) { // down
+ Sound.menu();
+ var selected = $(".selected");
+ $(".services li").removeClass("selected");
+ if (selected.next().length === 0) {
+ selected.siblings().first().addClass("selected");
+ } else {
+ selected.next().addClass("selected");
+ }
+ }
+ if (e.keyCode === 27 || e.keyCode === 8) { // esc
+ pause(false);
+ }
+ }
+ }
+ });
+}) \ No newline at end of file