aboutsummaryrefslogtreecommitdiff
path: root/race/cars/keymap.js
diff options
context:
space:
mode:
authorMinteck <46352972+Minteck@users.noreply.github.com>2021-07-09 00:51:46 +0200
committerMinteck <46352972+Minteck@users.noreply.github.com>2021-07-09 00:51:46 +0200
commitb9e7ec33542bb8041857eb997d17b29ffeae40c8 (patch)
treeb90eed32c2acdc79f2f362ee031e762983195bfd /race/cars/keymap.js
parent8886d5111aa4ae75f54f46c93f09fa7548979969 (diff)
downloadkartik-client-b9e7ec33542bb8041857eb997d17b29ffeae40c8.tar.gz
kartik-client-b9e7ec33542bb8041857eb997d17b29ffeae40c8.tar.bz2
kartik-client-b9e7ec33542bb8041857eb997d17b29ffeae40c8.zip
Add cooldown to rotations
This helps fix some bugs such as an out of border usebug and a bug that enables players to count a lap as they die. This also makes the game more realistic by removing the possibility of doing moves that are not supposed to be possible in real life.
Diffstat (limited to 'race/cars/keymap.js')
-rw-r--r--race/cars/keymap.js170
1 files changed, 89 insertions, 81 deletions
diff --git a/race/cars/keymap.js b/race/cars/keymap.js
index 221a7ec..d1fdf24 100644
--- a/race/cars/keymap.js
+++ b/race/cars/keymap.js
@@ -24,108 +24,116 @@ startHooks.push(() => {
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)") {
- require('electron').ipcRenderer.send('addstats', { catalog: "ingame", key: "turns", add: 1 });
- 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)") {
- require('electron').ipcRenderer.send('addstats', { catalog: "ingame", key: "turns", add: 1 });
- 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)") {
- require('electron').ipcRenderer.send('addstats', { catalog: "ingame", key: "turns", add: 1 });
- 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)") {
- require('electron').ipcRenderer.send('addstats', { catalog: "ingame", key: "turns", add: 1 });
- 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;
+
+ // Car 0
+ if (car0collisionon) {
+ 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("car1").style.transform !== "rotate(-90deg)") {
- document.getElementById("car1").style.transform = "rotate(-90deg)";
- car1collisionon = false;
+ if (document.getElementById("car0").style.transform !== "rotate(-90deg)") {
+ require('electron').ipcRenderer.send('addstats', { catalog: "ingame", key: "turns", add: 1 });
+ document.getElementById("car0").style.transform = "rotate(-90deg)";
+ car0collisionon = false;
setTimeout(() => {
- car1collisionon = true;
+ car0collisionon = true;
}, 500)
}
}
- if (e.keyCode === 40) { // down
- if (car1cspeed < car1speed) {
- car1cspeed = car1cspeed + 0.2;
+ if (e.keyCode === 83 || ((location.search === "?sp" || location.search === "?online") && e.keyCode === 40)) { // S
+ if (car0cspeed < car0speed) {
+ car0cspeed = car0cspeed + 0.2;
}
- if (document.getElementById("car1").style.transform !== "rotate(90deg)") {
- document.getElementById("car1").style.transform = "rotate(90deg)";
- car1collisionon = false;
+ if (document.getElementById("car0").style.transform !== "rotate(90deg)") {
+ require('electron').ipcRenderer.send('addstats', { catalog: "ingame", key: "turns", add: 1 });
+ document.getElementById("car0").style.transform = "rotate(90deg)";
+ car0collisionon = false;
setTimeout(() => {
- car1collisionon = true;
+ car0collisionon = true;
}, 500)
}
}
- if (e.keyCode === 37) { // left
- if (car1cspeed < car1speed) {
- car1cspeed = car1cspeed + 0.2;
+ 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("car1").style.transform !== "rotate(180deg)") {
- document.getElementById("car1").style.transform = "rotate(180deg)";
- car1collisionon = false;
+ if (document.getElementById("car0").style.transform !== "rotate(180deg)") {
+ require('electron').ipcRenderer.send('addstats', { catalog: "ingame", key: "turns", add: 1 });
+ document.getElementById("car0").style.transform = "rotate(180deg)";
+ car0collisionon = false;
setTimeout(() => {
- car1collisionon = true;
+ car0collisionon = true;
}, 500)
}
}
- if (e.keyCode === 39) { // right
- if (car1cspeed < car1speed) {
- car1cspeed = car1cspeed + 0.2;
+ if (e.keyCode === 68 || ((location.search === "?sp" || location.search === "?online") && e.keyCode === 39)) { // D
+ if (car0cspeed < car0speed) {
+ car0cspeed = car0cspeed + 0.2;
}
- if (document.getElementById("car1").style.transform !== "rotate(0deg)") {
- document.getElementById("car1").style.transform = "rotate(0deg)";
- car1collisionon = false;
+ if (document.getElementById("car0").style.transform !== "rotate(0deg)") {
+ require('electron').ipcRenderer.send('addstats', { catalog: "ingame", key: "turns", add: 1 });
+ document.getElementById("car0").style.transform = "rotate(0deg)";
+ car0collisionon = false;
setTimeout(() => {
- car1collisionon = true;
+ car0collisionon = true;
}, 500)
}
}
}
+
+ // Car 1
+ if (car1collisionon) {
+ 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);
}