aboutsummaryrefslogtreecommitdiff
path: root/race/cars/car1ai.js
diff options
context:
space:
mode:
authorMinteck <nekostarfan@gmail.com>2021-06-05 19:27:48 +0200
committerMinteck <nekostarfan@gmail.com>2021-06-05 19:27:48 +0200
commit8cf5cefe6e91a5a1ed6eeaae4d94760d84c304a6 (patch)
tree7096b67b189c0220826123c7d5b121752545d140 /race/cars/car1ai.js
downloadkartik-client-8cf5cefe6e91a5a1ed6eeaae4d94760d84c304a6.tar.gz
kartik-client-8cf5cefe6e91a5a1ed6eeaae4d94760d84c304a6.tar.bz2
kartik-client-8cf5cefe6e91a5a1ed6eeaae4d94760d84c304a6.zip
Presque sortie du jeu
Diffstat (limited to 'race/cars/car1ai.js')
-rw-r--r--race/cars/car1ai.js160
1 files changed, 160 insertions, 0 deletions
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