Advertisement
Guest User

Untitled

a guest
Dec 7th, 2019
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. Save New Duplicate & Edit Just Text Twitter
  3. >
  4. boxer = {
  5.   theme: {
  6.     background: "#000000",
  7.     border: "#FFFFFF",
  8.     virus: "#666666",
  9.     pellet: "#FF1555"
  10.   },
  11.   keybind: {
  12.     split: 32,
  13.     eject: 87,
  14.     double: 71,
  15.     quad: 84,
  16.     names: 78,
  17.     mass: 77,
  18.     sector: 66,
  19.     smallbots: 86,
  20.     pellet: 70,
  21.     skin: 83,
  22.     clearchat: 67,
  23.     bot: 81,
  24.     box: 9
  25.   },
  26.   settings: {
  27.     animationstyle: "linear",
  28.     linear: 125,
  29.     interpolate: 0.1,
  30.     names: true,
  31.     mass: true,
  32.     abbreviate: true,
  33.     pellet: true,
  34.     border: true,
  35.     sector: false,
  36.     skin: true,
  37.     border: true,
  38.     sector: true,
  39.     mousefeed: false,
  40.     mousesplit: false,
  41.     minimapguide: true,
  42.     smallbots: true,
  43.     activecellindicator: "arrow"
  44.   },
  45.   user: {
  46.     index: 0,
  47.     profile: [],
  48.     setProfile: (letter, src) => {
  49.       if (src) {
  50.         $(`.preview-${letter}`).css({"background-image": `url(${src})`});
  51.  
  52.         if (letter === "a") {
  53.           $(".profile-preview").eq(boxer.user.index).css({"background-image": `url(${src})`});
  54.           boxer.user.profile[boxer.user.index].skina = loadImage(src);
  55.         } else {
  56.           boxer.user.profile[boxer.user.index].skinb = loadImage(src);
  57.         }
  58.       } else {
  59.         $(`.preview-${letter}`).css({"background-image": "none"});
  60.  
  61.         if (letter === "a") {
  62.           $(".profile-preview").eq(boxer.user.index).css({"background-image": "none"});
  63.           boxer.user.profile[boxer.user.index].skina = loadImage("");
  64.         } else {
  65.           boxer.user.profile[boxer.user.index].skinb = loadImage("");
  66.         }
  67.       }
  68.     }
  69.   },
  70.   util: {
  71.     check: (url) => url.match(/^https?:\/\/(\w+\.)?imgur.com\/(\w*\d\w*)+(\.[a-zA-Z]{3})?$/)
  72.   },
  73.   core: {
  74.     camera: {
  75.       x: 0,
  76.       y: 0,
  77.       scale: 0.01,
  78.       dx: 0,
  79.       dy: 0,
  80.       dscale: 1
  81.     },
  82.     map: {
  83.       minX: -7071,
  84.       minY: -7071,
  85.       maxX: 7071,
  86.       maxY: 7071,
  87.       dimension: 14142
  88.     },
  89.     sound: {
  90.       message: "message",
  91.       send: "send",
  92.       connected: "connected",
  93.       disconnected: "disconnected"
  94.     }
  95.   },
  96.   cache: {
  97.     nick: [],
  98.     mass: []
  99.   },
  100.   offset: {
  101.     switch: false,
  102.     arrow: 0
  103.   },
  104.   connect: (address) => {
  105.     $(".control-connect").html(`<i class="fas fa-spin fa-circle-notch"></i>`);
  106.     $("#chat-hud").html("");
  107.  
  108.     multibox.a.self = [];
  109.     multibox.b.self = [];
  110.     multibox.a.entities = [];
  111.     multibox.b.entities = [];
  112.  
  113.     if (multibox.a.socket) {
  114.       multibox.a.socket.close();
  115.     }
  116.  
  117.     if (multibox.b.socket) {
  118.       multibox.b.socket.close();
  119.     }
  120.  
  121.     setTimeout(() => {
  122.       multibox.a.socket = new WebSocket(address);
  123.       multibox.b.socket = new WebSocket(address);
  124.       multibox.a.socket.binaryType = "arraybuffer";
  125.       multibox.b.socket.binaryType = "arraybuffer";
  126.  
  127.       multibox.a.socket.onopen = () => {
  128.         $(".control-connect").html("Connect");
  129.         multibox.a.send(Buffer.from([254, 5, 0, 0, 0]));
  130.         multibox.a.send(Buffer.from([255, 0, 0, 0, 0]));
  131.         multibox.ctrl = multibox.a;
  132.         console.log("Tab A Connected");
  133.       };
  134.  
  135.       multibox.b.socket.onopen = () => {
  136.         multibox.b.send(Buffer.from([254, 5, 0, 0, 0]));
  137.         multibox.b.send(Buffer.from([255, 0, 0, 0, 0]));
  138.         console.log("Tab B Connected");
  139.       };
  140.  
  141.       multibox.a.socket.onmessage = ({ data }) => {
  142.         const buffer = new Reader(data);
  143.         const packet = buffer.readUInt8();
  144.  
  145.         switch (packet) {
  146.           case 16:
  147.             const E = buffer.readUInt16();
  148.             buffer.skipBytes(E * 8);
  149.  
  150.             while (true) {
  151.               const id = buffer.readUInt32();
  152.  
  153.               if (id === 0) break;
  154.  
  155.               let entity;
  156.  
  157.               if (arrayHasID(multibox.a.entities, id)) {
  158.                 entity = multibox.a.entities[indexInArray(multibox.a.entities, id)];
  159.               } else {
  160.                 entity = new Entity(id);
  161.               }
  162.  
  163.               entity.id = id;
  164.               entity.x = buffer.readInt32();
  165.               entity.y = buffer.readInt32();
  166.               entity.r = buffer.readInt16();
  167.               entity.rgb = [];
  168.               entity.rgb[0] = buffer.readUInt8();
  169.               entity.rgb[1] = buffer.readUInt8();
  170.               entity.rgb[2] = buffer.readUInt8();
  171.  
  172.               const type = buffer.readUInt8();
  173.  
  174.               if (type & 1) {
  175.                 entity.type = "VIRUS";
  176.               }
  177.  
  178.               if (type & 2) {
  179.                 buffer.readUInt32();
  180.               }
  181.  
  182.               if (type & 4) {
  183.                 buffer.readZeroUTF8String()
  184.               }
  185.  
  186.               if (type & 128) {
  187.                 entity.type = "EJECTED";
  188.               }
  189.  
  190.               if (entity.r < 20) {
  191.                 entity.type = "PELLET";
  192.               }
  193.  
  194.               const nick = buffer.readZeroUTF16String();
  195.  
  196.               if (nick) {
  197.                 entity.nick = nick;
  198.               }
  199.  
  200.               if (arrayHasID(multibox.a.entities, id)) {
  201.                 multibox.a.entities[indexInArray(multibox.a.entities, id)] = entity;
  202.               } else if (arrayHasID(multibox.b.entities, id)) {
  203.                 multibox.a.entities.push(multibox.b.entities[indexInArray(multibox.b.entities, id)]);
  204.                 multibox.b.entities.splice(indexInArray(multibox.b.entities, id), 1);
  205.               } else {
  206.                 multibox.a.entities.push(entity);
  207.               }
  208.  
  209.               if (arrayHasID(multibox.a.self, id)) {
  210.                 if (typeof entity.nick != "undefined") {
  211.                   multibox.a.nick = entity.nick;
  212.                 }
  213.  
  214.                 multibox.a.self[indexInArray(multibox.a.self, id)].nick = entity.nick;
  215.                 multibox.a.self[indexInArray(multibox.a.self, id)].x = entity.x;
  216.                 multibox.a.self[indexInArray(multibox.a.self, id)].y = entity.y;
  217.                 multibox.a.self[indexInArray(multibox.a.self, id)].r = entity.r;
  218.               }
  219.             }
  220.  
  221.             const D = buffer.readUInt32();
  222.  
  223.             for (let i = 0; i < D; i++) {
  224.               const id = buffer.readUInt32();
  225.  
  226.               if (arrayHasID(multibox.a.entities, id)) {
  227.                 multibox.a.entities.splice(indexInArray(multibox.a.entities, id), 1);
  228.               }
  229.  
  230.               if (arrayHasID(multibox.a.self, id)) {
  231.                 multibox.a.self.splice(indexInArray(multibox.a.self, id), 1);
  232.  
  233.                 if (!multibox.a.self.length) {
  234.                   //death
  235.                 }
  236.               }
  237.             }
  238.           break;
  239.           case 17:
  240.             multibox.a.camera = {
  241.               x: buffer.readFloat(),
  242.               y: buffer.readFloat(),
  243.               scale: buffer.readFloat()
  244.             }
  245.           break;
  246.           case 20:
  247.             multibox.a.self = [];
  248.             multibox.a.entities = [];
  249.           break;
  250.           case 32:
  251.             multibox.a.self.push(new Entity(buffer.readUInt32()));
  252.           break;
  253.           case 49:
  254.             const count = buffer.readUInt32();
  255.  
  256.             $("#leaderboard-ul").html("");
  257.  
  258.             for (let i = 0; i < count; i++) {
  259.               const id = buffer.readUInt32();
  260.               let nick = "";
  261.  
  262.               while (true) {
  263.                 const char = buffer.readUInt16();
  264.                 if (char === 0) break;
  265.                 nick += String.fromCharCode(char);
  266.               }
  267.  
  268.               $("#leaderboard-ul").append(`<li class="leaderboard-li leaderboard-li-${(arrayHasID(multibox.a.self, id) ? arrayHasID(multibox.a.self, id) : arrayHasID(multibox.b.self, id))}">${nick} <div class="leaderboard-position">${(i + 1)}</div></li>`)
  269.             }
  270.           break;
  271.           case 64:
  272.             boxer.core.map.minX = buffer.readDouble();
  273.             boxer.core.map.minY = buffer.readDouble();
  274.             boxer.core.map.maxX = buffer.readDouble();
  275.             boxer.core.map.maxY = buffer.readDouble();
  276.  
  277.             boxer.core.map.dimension = (boxer.core.map.maxX + boxer.core.map.maxY) / 2;
  278.           break;
  279.           case 99:
  280.           $("#chat-hud").append(`<div class="chat-message"><strong>${buffer["readZeroUTF16String"]()}</strong>: ${buffer["readZeroUTF16String"]()}</div>`).animate({scrollTop: $("#chat-hud").prop("scrollHeight")}, 1e3);
  281.           createjs.Sound.play(boxer.core.sound.message);
  282.           break;
  283.         }
  284.       };
  285.  
  286.       multibox.b.socket.onmessage = ({ data }) => {
  287.         const buffer = new Reader(data);
  288.         const packet = buffer.readUInt8();
  289.  
  290.         switch (packet) {
  291.           case 16:
  292.             const E = buffer.readUInt16();
  293.             buffer.skipBytes(E * 8);
  294.  
  295.             while (true) {
  296.               const id = buffer.readUInt32();
  297.  
  298.               if (id === 0) break;
  299.  
  300.               let entity;
  301.  
  302.               if (arrayHasID(multibox.b.entities, id)) {
  303.                 entity = multibox.b.entities[indexInArray(multibox.b.entities, id)];
  304.               } else {
  305.                 entity = new Entity(id);
  306.               }
  307.  
  308.               entity.id = id;
  309.               entity.x = buffer.readInt32();
  310.               entity.y = buffer.readInt32();
  311.               entity.r = buffer.readInt16();
  312.               entity.rgb = [];
  313.               entity.rgb[0] = buffer.readUInt8();
  314.               entity.rgb[1] = buffer.readUInt8();
  315.               entity.rgb[2] = buffer.readUInt8();
  316.  
  317.               const type = buffer.readUInt8();
  318.  
  319.               if (type & 1) {
  320.                 entity.type = "VIRUS";
  321.               }
  322.  
  323.               if (type & 2) {
  324.                 buffer.readUInt32();
  325.               }
  326.  
  327.               if (type & 4) {
  328.                 buffer.readZeroUTF8String()
  329.               }
  330.  
  331.               if (type & 128) {
  332.                 entity.type = "EJECTED";
  333.               }
  334.  
  335.               if (entity.r < 20) {
  336.                 entity.type = "PELLET";
  337.               }
  338.  
  339.               const nick = buffer.readZeroUTF16String();
  340.  
  341.               if (nick) {
  342.                 entity.nick = nick;
  343.               }
  344.  
  345.               if (arrayHasID(multibox.b.entities, id)) {
  346.                 multibox.b.entities[indexInArray(multibox.b.entities, id)] = entity;
  347.               } else {
  348.                 multibox.b.entities.push(entity);
  349.               }
  350.  
  351.               if (arrayHasID(multibox.b.self, id)) {
  352.                 if (typeof entity.nick != "undefined") {
  353.                   multibox.b.nick = entity.nick;
  354.                 }
  355.  
  356.                 multibox.b.self[indexInArray(multibox.b.self, id)].nick = entity.nick;
  357.                 multibox.b.self[indexInArray(multibox.b.self, id)].x = entity.x;
  358.                 multibox.b.self[indexInArray(multibox.b.self, id)].y = entity.y;
  359.                 multibox.b.self[indexInArray(multibox.b.self, id)].r = entity.r;
  360.               }
  361.             }
  362.  
  363.             const D = buffer.readUInt32();
  364.  
  365.             for (let i = 0; i < D; i++) {
  366.               const id = buffer.readUInt32();
  367.  
  368.               if (arrayHasID(multibox.b.entities, id)) {
  369.                 multibox.b.entities.splice(indexInArray(multibox.b.entities, id), 1);
  370.               }
  371.  
  372.               if (arrayHasID(multibox.b.self, id)) {
  373.                 multibox.b.self.splice(indexInArray(multibox.b.self, id), 1);
  374.  
  375.                 if (!multibox.b.self.length) {
  376.                   //death
  377.                 }
  378.               }
  379.             }
  380.           break;
  381.           case 17:
  382.             multibox.b.camera = {
  383.               x: buffer.readFloat(),
  384.               y: buffer.readFloat(),
  385.               scale: buffer.readFloat()
  386.             }
  387.           break;
  388.           case 20:
  389.             multibox.b.self = [];
  390.             multibox.b.entities = [];
  391.           break;
  392.           case 32:
  393.             multibox.b.self.push(new Entity(buffer.readUInt32()));
  394.           break;
  395.         }
  396.       };
  397.     }, 5e2);
  398.   },
  399.   sendMouseMove: () => {
  400.     if (!$("#content").is(":visible")) {
  401.       let buffer = new Writer();
  402.  
  403.       buffer.writeUInt8(16);
  404.       buffer.writeDouble((mouseX - width * 0.5) / boxer.core.camera.dscale + boxer.core.camera.dx);
  405.       buffer.writeDouble((mouseY - height * 0.5) / boxer.core.camera.dscale + boxer.core.camera.dy);
  406.       buffer.writeUInt32(0);
  407.  
  408.       if (multibox.ctrl) {
  409.         multibox.ctrl.send(buffer.getBuffer());
  410.       }
  411.     }
  412.   },
  413.   setCamera: () => {
  414.     if (multibox.a.self.length || multibox.b.self.length) {
  415.       boxer.core.camera.x = 0;
  416.       boxer.core.camera.y = 0;
  417.       let c = 0, x = 0, y = 0;
  418.  
  419.       for (let i = 0; i < multibox.a.self.length; i++) {
  420.         if (!isNaN(multibox.a.self[i].x) && !isNaN(multibox.a.self[i].y)) {
  421.           boxer.core.camera.x += multibox.a.self[i].x;
  422.           boxer.core.camera.y += multibox.a.self[i].y;
  423.           x += multibox.a.self[i].x;
  424.           y += multibox.a.self[i].y;
  425.           c += 1;
  426.         }
  427.       }
  428.  
  429.       x /= c;
  430.       y /= c;
  431.  
  432.       if (!isNaN(x) && !isNaN(y)) {
  433.         multibox.a.node = {x: x, y: y};
  434.       }
  435.  
  436.       x = 0;
  437.       y = 0;
  438.  
  439.       for (let i = 0; i < multibox.b.self.length; i++) {
  440.         if (!isNaN(multibox.b.self[i].x) && !isNaN(multibox.b.self[i].y)) {
  441.           boxer.core.camera.x += multibox.b.self[i].x;
  442.           boxer.core.camera.y += multibox.b.self[i].y;
  443.           x += multibox.b.self[i].x;
  444.           y += multibox.b.self[i].y;
  445.           c += 1;
  446.         }
  447.       }
  448.  
  449.       x /= c - multibox.a.self.length;
  450.       y /= c - multibox.a.self.length;
  451.  
  452.       if (!isNaN(x) && !isNaN(y)) {
  453.         multibox.b.node = {x: x, y: y};
  454.       }
  455.  
  456.       boxer.core.camera.x /= c;
  457.       boxer.core.camera.y /= c;
  458.     }
  459.  
  460.     if (isNaN(boxer.core.camera.x) || isNaN(boxer.core.camera.y)) {
  461.       boxer.core.camera.x = 0;
  462.       boxer.core.camera.y = 0;
  463.     }
  464.   },
  465.   set: (a, b) => localStorage.setItem(a, b),
  466.   get: (a) => localStorage.getItem(a)
  467. };
  468.  
  469. multibox = {
  470.   a: {
  471.     socket: null,
  472.     self: [],
  473.     entities: [],
  474.     node: {
  475.       x: 0,
  476.       y: 0
  477.     },
  478.     spawn: () => {
  479.       let buffer = new Writer();
  480.       buffer.writeUInt8(0);
  481.       buffer.writeZeroUTF16String(document.getElementsByClassName("data-nick-a")[0].value);
  482.       multibox.a.send(buffer.getBuffer());
  483.     },
  484.     send: (packet) => {
  485.       if (multibox.a.socket && multibox.a.socket.readyState === WebSocket.OPEN) {
  486.         multibox.a.socket.send(packet);
  487.       }
  488.     }
  489.   },
  490.   b: {
  491.     socket: null,
  492.     self: [],
  493.     entities: [],
  494.     node: {
  495.       x: 0,
  496.       y: 0
  497.     },
  498.     spawn: () => {
  499.       let buffer = new Writer();
  500.       buffer.writeUInt8(0);
  501.       buffer.writeZeroUTF16String(document.getElementsByClassName("data-nick-b")[0].value);
  502.       multibox.b.send(buffer.getBuffer());
  503.     },
  504.     send: (packet) => {
  505.       if (multibox.b.socket && multibox.b.socket.readyState === WebSocket.OPEN) {
  506.         multibox.b.socket.send(packet);
  507.       }
  508.     }
  509.   },
  510.   ctrl: null
  511. };
  512.  
  513. class Entity {
  514.   constructor (id) {
  515.     this.id = id;
  516.   }
  517.  
  518.   render () {
  519.     if (!isNaN(this.dx) && !isNaN(this.dy) && !isNaN(this.dr)) {
  520.       push();
  521.       translate(this.dx, this.dy);
  522.  
  523.       switch (this.type) {
  524.         case "VIRUS": {
  525.           fill(boxer.theme.virus);
  526.           stroke("#FFFFFF");
  527.           strokeWeight(3 * boxer.core.camera.dscale);
  528.           ellipse(0, 0, this.dr * 2, this.dr * 2, 50);
  529.         } break;
  530.         case "EJECTED": {
  531.           fill(this.rgb);
  532.           noStroke();
  533.           ellipse(0, 0, this.dr * 2, this.dr * 2, 8);
  534.         } break;
  535.         case "PELLET": {
  536.           if (boxer.settings.pellet) {
  537.             fill(boxer.theme.pellet);
  538.             noStroke();
  539.             ellipse(this.dx, this.dy, 30, 30, 8);
  540.           }
  541.         } break;
  542.         default: {
  543.           if ((this.dr * this.dr) / 1e2 < 20 && !boxer.settings.smallbots) {
  544.             break;
  545.           }
  546.  
  547.           fill(this.rgb);
  548.           noStroke();
  549.           ellipse(0, 0, this.dr * 2, this.dr * 2, 50);
  550.  
  551.           if (arrayHasID(multibox.a.self, this.id) || arrayHasID(multibox.b.self, this.id)) {
  552.             if (arrayHasID(multibox.ctrl.self, this.id) && (this.dr * this.dr) / 1e2 <= 6e2) {
  553.               if (boxer.settings.activecellindicator == "arrow") {
  554.                 fill("#FF1555");
  555.                 noStroke();
  556.                 triangle(- 40, - this.dr - 60 - boxer.offset.arrow, 40, - this.dr - 60 - boxer.offset.arrow, 0, - this.dr - 20 - boxer.offset.arrow);
  557.               }
  558.             } else if ((this.dr * this.dr) / 1e2 <= 6e2) {
  559.               if (boxer.settings.activecellindicator == "arrow") {
  560.                 fill("#FFFFFF");
  561.                 noStroke();
  562.                 triangle(- 35, - this.dr - 55, 35, - this.dr - 55, 0, - this.dr - 20);
  563.               }
  564.             }
  565.           }
  566.  
  567.           if (boxer.settings.skin) {
  568.             if (arrayHasID(multibox.a.self, this.id)) {
  569.               renderMultiboxSkin(boxer.user.profile[boxer.user.index].skina, this.dr * 2);
  570.             } else if (arrayHasID(multibox.b.self, this.id)) {
  571.               renderMultiboxSkin(boxer.user.profile[boxer.user.index].skinb, this.dr * 2);
  572.             }
  573.           }
  574.  
  575.           if (boxer.settings.names && this.nick) {
  576.             if (this.dr * boxer.core.camera.dscale > 18) {
  577.               if (arrayHasID(boxer.cache.nick, this.nick)) {
  578.                 noFill();
  579.                 noStroke();
  580.                 texture(boxer.cache.nick[indexInArray(boxer.cache.nick, this.nick)]);
  581.                 plane(this.dr * 2);
  582.               } else if (this.nick != "") {
  583.                 let nick = createGraphics(512, 512);
  584.                 nick.background(0, 0, 0, 0);
  585.                 nick.translate(nick.width * 0.5, nick.height * 0.5);
  586.                 nick.fill("#FFFFFF");
  587.                 nick.noStroke();
  588.                 nick.textAlign(CENTER);
  589.                 nick.textFont("Roboto Condensed");
  590.                 nick.textSize(100);
  591.                 nick.text(this.nick, 0, textSize() * 0.25);
  592.                 nick.id = this.nick;
  593.                 boxer.cache.nick.push(nick);
  594.               }
  595.             }
  596.           }
  597.  
  598.           if (boxer.settings.mass) {
  599.             if (this.dr * boxer.core.camera.dscale > 18) {
  600.               if (arrayHasID(boxer.cache.mass, Math.floor((this.dr * this.dr) / 1e2))) {
  601.                 noFill();
  602.                 noStroke();
  603.                 texture(boxer.cache.mass[indexInArray(boxer.cache.mass, Math.floor((this.dr * this.dr) / 1e2))]);
  604.                 plane(this.dr * 2);
  605.               } else {
  606.                 let mass = createGraphics(512, 512);
  607.                 mass.background(0, 0, 0, 0);
  608.                 mass.translate(mass.width * 0.5, mass.height * 0.75);
  609.                 mass.fill("#FFFFFF");
  610.                 mass.noStroke();
  611.                 mass.textAlign(CENTER);
  612.                 mass.textFont("Roboto Condensed");
  613.                 mass.textSize(125);
  614.                 mass.text(Math.floor((this.dr * this.dr) / 1e2), 0, textSize() * 0.25);
  615.                 mass.id = Math.floor((this.dr * this.dr) / 1e2);
  616.                 boxer.cache.mass.push(mass);
  617.               }
  618.               /*(fill("#FFFFFF");
  619.               noStroke();
  620.               textAlign(CENTER);
  621.               textFont("Roboto Condensed");
  622.               textSize(this.dr);
  623.  
  624.               let mass = Math.floor((this.dr * this.dr) / 1e2);
  625.  
  626.               if (Math.floor((this.dr * this.dr) / 1e2) >= 1e3 && boxer.settings.abbreviate) {
  627.                 mass = Math.floor(mass * Math.pow(10, 1) / Math.pow(10, 3)) / Math.pow(10, 1) + "k";
  628.               }
  629.  
  630.               text(mass, 0, this.dr * 0.6 + (textSize() * 0.25));*/
  631.             }
  632.           }
  633.         } break;
  634.       }
  635.       pop();
  636.     }
  637.   }
  638.  
  639.   update () {
  640.     if (typeof this.x != "undefined" && typeof this.y != "undefined") {
  641.       if (this.dx == undefined || this.dy == undefined || this.dr == undefined) {
  642.         this.dx = this.x;
  643.         this.dy = this.y;
  644.         this.dr = this.r;
  645.       }
  646.  
  647.       this.dx += (this.x - this.dx) / ((boxer.settings.linear - 50) / 10);
  648.       this.dy += (this.y - this.dy) / ((boxer.settings.linear - 50) / 10);
  649.       this.dr += (this.r - this.dr) / ((boxer.settings.linear - 50) / 10);
  650.  
  651.       this.dx = Math.round(this.dx);
  652.       this.dy = Math.round(this.dy);
  653.       this.dr = Math.round(this.dr);
  654.     }
  655.   }
  656. }
  657.  
  658. function setup () {
  659.   createCanvas(windowWidth, windowHeight, WEBGL);
  660.   $("canvas").attr("id", "P5Canvas");
  661.   $("#minimap-hud").append(`<canvas id="minimap-nodes"></canvas>`);
  662.   imageMode(CENTER);
  663.  
  664.   setInterval(() => {
  665.     boxer.sendMouseMove();
  666.   }, 25);
  667.  
  668.   createjs.Sound.registerSound("Sounds/message.wav", boxer.core.sound.message);
  669.  
  670.   boxer.user.index = !isNaN(boxer.get("index")) ? boxer.get("index") : 0;
  671.  
  672.   for (let i = 0; i < 5; i++) {
  673.     boxer.user.profile.push({
  674.       nicka: boxer.get(`profile#${i + 1}nicka`) ? boxer.get(`profile#${i + 1}nicka`) : `Profile #${i + 1}`,
  675.       nickb: boxer.get(`profile#${i + 1}nickb`) ? boxer.get(`profile#${i + 1}nickb`) : `Profile #${i + 1}`,
  676.       urla: boxer.get(`profile#${i + 1}urla`) ? boxer.get(`profile#${i + 1}urla`) : "https://i.imgur.com/HIPT5O0.png",
  677.       urlb: boxer.get(`profile#${i + 1}urlb`) ? boxer.get(`profile#${i + 1}urlb`) : "https://i.imgur.com/HIPT5O0.png",
  678.     });
  679.  
  680.     if (boxer.util.check(boxer.user.profile[i].urla)) {
  681.       $(".profile-preview").eq(i).css({"background-image": `url(${boxer.user.profile[i].urla})`});
  682.     }
  683.   }
  684.  
  685.   $(".emote").on("click", function () {
  686.     let message = $("#message").val() + $(this).html();
  687.     $("#message").val(message).focus();
  688.   })
  689.  
  690.   $(".control-connect").on("click", () => {
  691.     if ($(".data-ip-address").val() != "") {
  692.       boxer.connect(`ws://${$(".data-ip-address").val()}`);
  693.     }
  694.   });
  695.  
  696.   $(".data-ip-address").on("keyup", () => {
  697.     boxer.set("address", $(".data-ip-address").val());
  698.   }).val(boxer.get("address") || "");
  699.  
  700.   $(".control-spawn").on("click", () => {
  701.     multibox.a.spawn();
  702.     $("#content").fadeOut("fast");
  703.   });
  704.  
  705.   $(".data-nick-a").on("keyup", () => {
  706.     boxer.set(`profile#${(boxer.user.index + 1)}nicka`, $(".data-nick-a").val());
  707.     boxer.user.profile[boxer.user.index].nicka = $(".data-nick-a").val();
  708.   }).val(boxer.user.profile[boxer.user.index].nicka);
  709.  
  710.   $(".data-nick-b").on("keyup", () => {
  711.     boxer.set(`profile#${(boxer.user.index + 1)}nickb`, $(".data-nick-b").val());
  712.     boxer.user.profile[boxer.user.index].nickb = $(".data-nick-b").val();
  713.   }).val(boxer.user.profile[boxer.user.index].nickb);
  714.  
  715.   $(".data-url-a").on("keyup", () => {
  716.     boxer.set(`profile#${(boxer.user.index + 1)}urla`, $(".data-url-a").val());
  717.     boxer.user.profile[boxer.user.index].urla = $(".data-url-a").val();
  718.  
  719.     if (boxer.util.check($(".data-url-a").val())) {
  720.       boxer.user.setProfile("a", $(".data-url-a").val());
  721.     } else {
  722.       boxer.user.setProfile("a", false);
  723.     }
  724.   }).val(boxer.get(`profile#${boxer.user.index + 1}urla`) || boxer.user.profile[boxer.user.index].urla);
  725.  
  726.   $(".data-url-b").on("keyup", () => {
  727.     boxer.set(`profile#${(boxer.user.index + 1)}urlb`, $(".data-url-b").val());
  728.     boxer.user.profile[boxer.user.index].urlb = $(".data-url-b").val();
  729.  
  730.     if (boxer.util.check($(".data-url-b").val())) {
  731.       boxer.user.setProfile("b", $(".data-url-b").val());
  732.     } else {
  733.       boxer.user.setProfile("b", false);
  734.     }
  735.   }).val(boxer.get(`profile#${boxer.user.index + 1}urlb`) || boxer.user.profile[boxer.user.index].urlb);
  736.  
  737.   $(".profile-box").on("click", function () {
  738.     $(".profile-box").attr("value", "false");
  739.     $(this).attr("value", "true");
  740.     boxer.user.index = Number($(this).attr("data-id")) - 1;
  741.     boxer.set("index", boxer.user.index);
  742.  
  743.     $(".data-nick-a").val(boxer.user.profile[boxer.user.index].nicka);
  744.     $(".data-nick-b").val(boxer.user.profile[boxer.user.index].nickb);
  745.     $(".data-url-a").val(boxer.user.profile[boxer.user.index].urla);
  746.     $(".data-url-b").val(boxer.user.profile[boxer.user.index].urlb);
  747.  
  748.     boxer.user.setProfile("a", $(".data-url-a").val());
  749.     boxer.user.setProfile("b", $(".data-url-b").val());
  750.   });
  751.  
  752.   $(".profile-box").eq(boxer.user.index).attr("value", "true");
  753.  
  754.   boxer.user.setProfile("a", $(".data-url-a").val());
  755.   boxer.user.setProfile("b", $(".data-url-b").val());
  756.  
  757.   boxer.render = {
  758.     border: () => {
  759.       noFill();
  760.       stroke(boxer.theme.border);
  761.       strokeWeight(100 * boxer.core.camera.dscale);
  762.       rectMode(CENTER);
  763.       rect(0, 0, (boxer.core.map.dimension * 2) + 100, (boxer.core.map.dimension * 2) + 100);
  764.     },
  765.     sector: () => {
  766.       push();
  767.       noFill();
  768.       stroke("#252529");
  769.       strokeWeight(200);
  770.       strokeCap(SQUARE);
  771.       rectMode(CENTER);
  772.       rect(0, 0, (boxer.core.map.dimension * 2) - 100, (boxer.core.map.dimension * 2) - 100);
  773.       rectMode(CORNER);
  774.  
  775.       for (let i = - boxer.core.map.dimension / 5 * 3; i < boxer.core.map.dimension; i += (boxer.core.map.dimension * 2) / 5) {
  776.         line(i, - boxer.core.map.dimension, i, boxer.core.map.dimension);
  777.         for (let j = - boxer.core.map.dimension / 5 * 3; j < boxer.core.map.dimension; j += (boxer.core.map.dimension * 2) / 5) {
  778.           line(- boxer.core.map.dimension, j, boxer.core.map.dimension, j);
  779.         }
  780.       }
  781.  
  782.       fill("#252529");
  783.       noStroke();
  784.       textSize(3250);
  785.       textAlign(CENTER);
  786.       textFont("Roboto Condensed");
  787.  
  788.       let SECTOR = "ABCDE", NUMBER = 1, INDEX = 0;
  789.  
  790.       for (let i = - boxer.core.map.dimension; i < boxer.core.map.dimension; i += (boxer.core.map.dimension * 2) / 5) {
  791.         for (let j = - boxer.core.map.dimension; j < boxer.core.map.dimension; j += (boxer.core.map.dimension * 2) / 5) {
  792.           text(SECTOR.charAt(INDEX) + NUMBER, i + ((boxer.core.map.dimension / 5)), j + ((boxer.core.map.dimension / 5) * (textSize() * 0.000435)));
  793.           INDEX += 1;
  794.         }
  795.  
  796.         INDEX = INDEX > SECTOR.length - 1 ? 0 : INDEX;
  797.  
  798.         NUMBER += 1;
  799.       }
  800.  
  801.       pop();
  802.     }
  803.   }
  804. }
  805.  
  806. function draw () {
  807.   background(boxer.theme.background);
  808.   //translate(width * 0.5, height * 0.5);
  809.   scale(boxer.core.camera.dscale);
  810.  
  811.   boxer.setCamera();
  812.   translate(- boxer.core.camera.dx, - boxer.core.camera.dy);
  813.  
  814.   if (boxer.settings.border) {
  815.     boxer.render.border();
  816.   }
  817.  
  818.   if (boxer.settings.sector) {
  819.     //boxer.render.sector();
  820.   }
  821.  
  822.   boxer.core.camera.dx = lerp(boxer.core.camera.dx, boxer.core.camera.x, 0.1);
  823.   boxer.core.camera.dy = lerp(boxer.core.camera.dy, boxer.core.camera.y, 0.1);
  824.   boxer.core.camera.dscale = lerp(boxer.core.camera.dscale, boxer.core.camera.scale, 0.1);
  825.   boxer.core.camera.scale = constrain(boxer.core.camera.scale, 0.01, 1);
  826.   boxer.settings.linear = constrain(boxer.settings.linear, 100, 200);
  827.  
  828.   let a = multibox.a.entities, b = multibox.b.entities;
  829.  
  830.   for (let i = b.length - 1; i >= 0; i--) {
  831.     if (arrayHasID(a, b[i].id)) {
  832.       if (typeof a[indexInArray(a, b[i].id)].dx == "undefined" || typeof a[indexInArray(a, b[i].id)].dy == "undefined" || typeof a[indexInArray(a, b[i].id)].dr == "undefined") {
  833.         a[indexInArray(a, b[i].id)].dx = b[indexInArray(b, b[i].id)].dx;
  834.         a[indexInArray(a, b[i].id)].dy = b[indexInArray(b, b[i].id)].dy;
  835.         a[indexInArray(a, b[i].id)].dr = b[indexInArray(b, b[i].id)].dr;
  836.       }
  837.  
  838.       b.splice(indexInArray(b, b[i].id), 1);
  839.     }
  840.   }
  841.  
  842.   let c = a.concat(b);
  843.   let sorted = c.slice(0).sort((a, b) => {
  844.     return (a.dr ? a.dr : a.r) === (b.dr ? b.dr : b.r) ? a.id - b.id : (a.dr ? a.dr : a.r) - (b.dr ? b.dr : b.r);
  845.   });
  846.  
  847.   sorted.forEach((entity) => {
  848.     entity.render();
  849.     entity.update();
  850.   });
  851.  
  852.   if (keyIsDown(boxer.keybind.eject)) {
  853.     multibox.ctrl.send(new Uint8Array([21]));
  854.   }
  855.  
  856.   $("#minimap-nodes")[0].width = $("#minimap-nodes")[0].height = Number($("#minimap-hud").css("width").match(/\d*/)[0]);
  857.   $("#minimap-nodes")[0].getContext("2d").clearRect(0, 0, $("#minimap-nodes")[0].width, $("#minimap-nodes")[0].height);
  858.   $("#minimap-nodes")[0].getContext("2d").translate(($("#minimap-nodes")[0].width * 0.5), ($("#minimap-nodes")[0].height * 0.5));
  859.   if (multibox.a.node instanceof Object) {
  860.     let position = coordsToScale(multibox.a.node.x, multibox.a.node.y, $("#minimap-nodes")[0].width, boxer.core.map.dimension * 2);
  861.     renderMinimapNode(position.x, position.y, multibox.ctrl == multibox.a, multibox.a.nick);
  862.   }
  863.  
  864.   if (multibox.b.node instanceof Object) {
  865.     let position = coordsToScale(multibox.b.node.x, multibox.b.node.y, $("#minimap-nodes")[0].width, boxer.core.map.dimension * 2);
  866.     renderMinimapNode(position.x, position.y, multibox.ctrl == multibox.b, multibox.b.nick);
  867.   }
  868.  
  869.   if (boxer.settings.minimapguide) {
  870.     let ctrl = multibox.ctrl == multibox.a ? multibox.a : multibox.b, position = coordsToScale(ctrl.node.x, ctrl.node.y, $("#minimap-nodes")[0].width, boxer.core.map.dimension * 2);
  871.     renderMinimapGuide(position.x, position.y);
  872.   }
  873.  
  874.   if (!boxer.offset.switch) {
  875.     boxer.offset.arrow += 2;
  876.  
  877.     if (boxer.offset.arrow >= 40) {
  878.       boxer.offset.switch = true;
  879.     }
  880.   } else {
  881.     boxer.offset.arrow -= 2;
  882.  
  883.     if (boxer.offset.arrow <= 0) {
  884.       boxer.offset.switch = false;
  885.     }
  886.   }
  887. }
  888.  
  889. function windowResized () {
  890.   resizeCanvas(windowWidth, windowHeight);
  891. }
  892.  
  893. function mouseWheel (event) {
  894.   if (event.delta > 0) {
  895.     boxer.core.camera.scale -= boxer.core.camera.scale / 15;
  896.   } else {
  897.     boxer.core.camera.scale += boxer.core.camera.scale / 15;
  898.   }
  899. }
  900.  
  901. function arrayHasID (array, id) {
  902.   return array.findIndex(index => index.id == id) >= 0;
  903. }
  904.  
  905. function indexInArray (array, id) {
  906.   return array.findIndex(index => index.id == id);
  907. }
  908.  
  909. function renderMultiboxSkin (skin, r) {
  910.   push();
  911.   texture(skin);
  912.   ellipse(0, 0, r, r, 50);
  913.   pop();
  914. }
  915.  
  916. function renderMinimapNode (x, y, a, n) {
  917.   let context = $("#minimap-nodes")[0].getContext("2d");
  918.  
  919.   context.beginPath();
  920.   context.fillStyle = a ? "#FF1555" : "#FFFFFF";
  921.   context.arc(x, y, 4.5, 1, Math.PI * 2);
  922.   context.fill();
  923.  
  924.   if (!a) {
  925.     context.fillStyle = "#FFFFFF";
  926.     context.font = `${(innerWidth * 0.005)}px Roboto Condensed`;
  927.     context.textAlign = "center";
  928.     context.fillText(n, x, y + 10);
  929.   }
  930.   context.closePath();
  931. }
  932.  
  933. function renderMinimapGuide (x, y) {
  934.   let context = $("#minimap-nodes")[0].getContext("2d"), w = $("#minimap-nodes")[0].width, h = $("#minimap-nodes")[0].height;
  935.  
  936.   context.strokeStyle = "#FF1555";
  937.  
  938.   context.beginPath();
  939.   context.moveTo(- w * 0.5, y);
  940.   context.lineTo(x - 7, y);
  941.   context.stroke();
  942.   context.moveTo(w * 0.5, y);
  943.   context.lineTo(x + 7, y);
  944.   context.stroke();
  945.   context.moveTo(x, - h * 0.5);
  946.   context.lineTo(x, y - 7);
  947.   context.stroke();
  948.   context.moveTo(x, h * 0.5);
  949.   context.lineTo(x, y + 7);
  950.   context.stroke();
  951.   context.closePath();
  952. }
  953.  
  954. function coordsToScale (x, y, d, m) {
  955.   return {x: x * (d / m), y: y * (d / m)};
  956. }
  957.  
  958. function keyPressed () {
  959.   if (!$("#content").is(":visible")) {
  960.     if ($("#message").is(":focus")) {
  961.       switch (keyCode) {
  962.         case 13: {
  963.           if ($("#message").val().length) {
  964.             let buffer = new Writer();
  965.             buffer.writeUInt8(0x63);
  966.             buffer.writeUInt8(0);
  967.             buffer.writeZeroUTF16String($("#message").val());
  968.             multibox.ctrl.send(buffer.getBuffer());
  969.           }
  970.  
  971.           $("#message").val("");
  972.           $("#message-hud").toggle();
  973.         } break;
  974.       }
  975.     } else {
  976.       switch (keyCode) {
  977.         case boxer.keybind.split: {
  978.           multibox.ctrl.send(new Uint8Array([17]));
  979.         } break;
  980.         case boxer.keybind.double: {
  981.           for (let i = 0; i < 2; i++) {
  982.             setTimeout(() => {
  983.               multibox.ctrl.send(new Uint8Array([17]));
  984.             }, i * 45);
  985.           }
  986.         } break;
  987.         case boxer.keybind.quad: {
  988.           for (let i = 0; i < 4; i++) {
  989.             setTimeout(() => {
  990.               multibox.ctrl.send(new Uint8Array([17]));
  991.             }, i * 45);
  992.           }
  993.         } break;
  994.         case boxer.keybind.names: {
  995.           boxer.settings.names = !boxer.settings.names;
  996.         } break;
  997.         case boxer.keybind.mass: {
  998.           boxer.settings.mass = !boxer.settings.mass;
  999.         } break;
  1000.         case boxer.keybind.sector: {
  1001.           boxer.settings.sector = !boxer.settings.sector;
  1002.         } break;
  1003.         case boxer.keybind.smallbots: {
  1004.           boxer.settings.smallbots = !boxer.settings.smallbots;
  1005.         } break;
  1006.         case boxer.keybind.pellet: {
  1007.           boxer.settings.pellet = !boxer.settings.pellet;
  1008.         } break;
  1009.         case boxer.keybind.skin: {
  1010.           boxer.settings.skin = !boxer.settings.skin;
  1011.         } break;
  1012.         case boxer.keybind.sector: {
  1013.           boxer.settings.sector = !boxer.settings.sector;
  1014.         } break;
  1015.         case boxer.keybind.clearchat: {
  1016.           $("#chat-hud").html("");
  1017.         } break;
  1018.         case boxer.keybind.bot: {
  1019.           multibox.ctrl.send(new Uint8Array([19]));
  1020.           multibox.ctrl.send(new Uint8Array([18]));
  1021.         } break;
  1022.         case boxer.keybind.box: {
  1023.           if (multibox.ctrl == multibox.a) {
  1024.             multibox.ctrl = multibox.b;
  1025.             multibox.b.spawn();
  1026.           } else {
  1027.             multibox.ctrl = multibox.a;
  1028.             multibox.a.spawn();
  1029.           }
  1030.         } break;
  1031.         case 27: {
  1032.           $("#content").fadeIn("fast");
  1033.         } break;
  1034.         case 13: {
  1035.           $("#message-hud").toggle();
  1036.           $("#message").focus();
  1037.         } break;
  1038.       }
  1039.  
  1040.       return false;
  1041.     }
  1042.   }
  1043. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement