Diep.io Bullet Tracker (Enhanced)

Tracks and visualizes bullets in Diep.io for collision detection

Tendrás que instalar una extensión para tu navegador como Tampermonkey, Greasemonkey o Violentmonkey si quieres utilizar este script.

You will need to install an extension such as Tampermonkey to install this script.

Tendrás que instalar una extensión como Tampermonkey o Violentmonkey para instalar este script.

Necesitarás instalar una extensión como Tampermonkey o Userscripts para instalar este script.

Tendrás que instalar una extensión como Tampermonkey antes de poder instalar este script.

Necesitarás instalar una extensión para administrar scripts de usuario si quieres instalar este script.

(Ya tengo un administrador de scripts de usuario, déjame instalarlo)

Tendrás que instalar una extensión como Stylus antes de poder instalar este script.

Tendrás que instalar una extensión como Stylus antes de poder instalar este script.

Tendrás que instalar una extensión como Stylus antes de poder instalar este script.

Para poder instalar esto tendrás que instalar primero una extensión de estilos de usuario.

Para poder instalar esto tendrás que instalar primero una extensión de estilos de usuario.

Para poder instalar esto tendrás que instalar primero una extensión de estilos de usuario.

(Ya tengo un administrador de estilos de usuario, déjame instalarlo)

// ==UserScript==
// @name         Diep.io Bullet Tracker (Enhanced)
// @namespace    http://tampermonkey.net/
// @version      1.2
// @description  Tracks and visualizes bullets in Diep.io for collision detection
// @author       King's Group
// @author       David Bett
// @match        *://diep.io/*
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    // Create canvas overlay
    const canvas = document.createElement('canvas');
    canvas.style.position = 'absolute';
    canvas.style.top = '0';
    canvas.style.left = '0';
    canvas.style.pointerEvents = 'none';
    canvas.style.zIndex = '9999';
    document.body.appendChild(canvas);
    const ctx = canvas.getContext('2d');

    function resizeCanvas() {
        canvas.width = window.innerWidth;
        canvas.height = window.innerHeight;
    }
    window.addEventListener('resize', resizeCanvas);
    resizeCanvas();

    // Function to detect if a bullet is near the player
    function isBulletNearPlayer(bullet, player, threshold = 100) {
        const dx = bullet.x - player.x;
        const dy = bullet.y - player.y;
        const distance = Math.sqrt(dx * dx + dy * dy);
        return distance < threshold;
    }

    // Main drawing function
    function draw() {
        ctx.clearRect(0, 0, canvas.width, canvas.height);

        // Accessing game variables
        const player = window.player; // Assuming 'window.player' holds the player's position
        const bullets = window.bullets; // Assuming 'window.bullets' is an array of bullet objects

        if (!player || !bullets) return;

        // Draw safe zone around player
        ctx.strokeStyle = 'green';
        ctx.lineWidth = 2;
        ctx.beginPath();
        ctx.arc(player.x, player.y, 50, 0, Math.PI * 2);
        ctx.stroke();

        // Draw bullets
        bullets.forEach(bullet => {
            // Check if bullet is near the player
            const isNear = isBulletNearPlayer(bullet, player);

            ctx.fillStyle = isNear ? 'red' : 'white';
            ctx.beginPath();
            ctx.arc(bullet.x, bullet.y, 5, 0, Math.PI * 2);
            ctx.fill();

            // Update bullet position
            bullet.x += bullet.dx;
            bullet.y += bullet.dy;
        });

        requestAnimationFrame(draw);
    }

    draw();
})();