Tank Trouble Laser Pointer

Adds a laser pointer showing shot trajectories in Tank Trouble!

Dieses Skript sollte nicht direkt installiert werden. Es handelt sich hier um eine Bibliothek für andere Skripte, welche über folgenden Befehl in den Metadaten eines Skriptes eingebunden wird // @require https://update.greasyfork.org/scripts/530735/1559176/Tank%20Trouble%20Laser%20Pointer.js

Du musst eine Erweiterung wie Tampermonkey, Greasemonkey oder Violentmonkey installieren, um dieses Skript zu installieren.

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

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

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

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

Sie müssten eine Skript Manager Erweiterung installieren damit sie dieses Skript installieren können

(Ich habe schon ein Skript Manager, Lass mich es installieren!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Tank Trouble Laser Pointer
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Adds a laser pointer showing shot trajectories in Tank Trouble!
// @author       You
// @match        https://tanktrouble.com
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Wait for game to load
    function waitForGame() {
        return new Promise(resolve => {
            const check = setInterval(() => {
                if (typeof window.game !== 'undefined') {
                    clearInterval(check);
                    resolve();
                }
            }, 100);
        });
    }

    // Helper functions
    function getTankPosition() {
        return {
            x: window.game.tank.x,
            y: window.game.tank.y,
            direction: window.game.tank.direction
        };
    }

    function calculateTrajectory(startX, startY, direction) {
        const trajectory = [];
        const speed = 500; // Bullet speed
        let x = startX;
        let y = startY;
        let vx = Math.cos(direction) * speed;
        let vy = Math.sin(direction) * speed;

        // Calculate trajectory points
        while (x >= 0 && x <= window.game.canvas.width &&
               y >= 0 && y <= window.game.canvas.height) {
            trajectory.push({x, y});

            // Check for wall collisions
            const wall = checkWallCollision(x, y);
            if (wall) {
                // Calculate reflection
                if (wall.horizontal) {
                    vy = -vy * 0.8; // Energy loss on bounce
                } else {
                    vx = -vx * 0.8;
                }
            }

            x += vx * 0.016; // Update position
            y += vy * 0.016;
        }

        return trajectory;
    }

    function checkWallCollision(x, y) {
        // Check walls (simplified collision detection)
        const padding = 20;
        if (x <= padding) return { horizontal: false, vertical: true };
        if (x >= window.game.canvas.width - padding) return { horizontal: false, vertical: true };
        if (y <= padding) return { horizontal: true, vertical: false };
        if (y >= window.game.canvas.height - padding) return { horizontal: true, vertical: false };
        return null;
    }

    // Main enhancement function
    async function enhanceGame() {
        await waitForGame();

        // Store original draw function
        const originalDraw = window.game.draw;

        // Override draw function with enhanced visibility
        window.game.draw = function() {
            originalDraw.call(window.game);

            // Draw laser pointer with enhanced visibility
            const ctx = window.game.canvas.getContext('2d');
            const tank = getTankPosition();
            const trajectory = calculateTrajectory(tank.x, tank.y, tank.direction);

            // Draw trajectory with multiple styles for better visibility
            ctx.beginPath();
            ctx.moveTo(tank.x, tank.y);
            trajectory.forEach(point => {
                ctx.lineTo(point.x, point.y);
            });

            // Draw with glow effect
            ctx.shadowBlur = 10;
            ctx.shadowColor = 'rgba(255, 0, 0, 0.8)';
            ctx.strokeStyle = 'rgba(255, 0, 0, 0.8)';
            ctx.lineWidth = 3;
            ctx.stroke();

            // Draw with solid line
            ctx.shadowBlur = 0;
            ctx.strokeStyle = 'rgba(255, 255, 255, 0.8)';
            ctx.lineWidth = 2;
            ctx.stroke();

            // Draw starting point
            ctx.beginPath();
            ctx.arc(tank.x, tank.y, 5, 0, Math.PI * 2);
            ctx.fillStyle = 'rgba(255, 0, 0, 0.8)';
            ctx.fill();
        };
    }

    // Start enhancements when page loads
    enhanceGame();
})();