Tank Trouble Laser Pointer

Adds a laser pointer showing shot trajectories in Tank Trouble!

此腳本不應該直接安裝,它是一個供其他腳本使用的函式庫。欲使用本函式庫,請在腳本 metadata 寫上: // @require https://update.gf.qytechs.cn/scripts/530735/1559176/Tank%20Trouble%20Laser%20Pointer.js

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==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();
})();