XTaylorSpenceX

Forest Fury: Arrowgeddon!

Sep 18th, 2025
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 6.20 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6.     <title>Forest Fury: Arrowgeddon!</title>
  7.     <style>
  8.         body {
  9.             margin: 0;
  10.             overflow: hidden;
  11.             background: linear-gradient(to bottom, #2e8b57, #8fbc8f);
  12.             font-family: Arial, sans-serif;
  13.         }
  14.         canvas {
  15.             display: block;
  16.             margin: auto;
  17.             background: rgba(255, 255, 255, 0.2);
  18.             border: 2px solid #fff;
  19.         }
  20.         #ui {
  21.             position: absolute;
  22.             top: 20px;
  23.             left: 20px;
  24.             background: rgba(0, 0, 0, 0.7);
  25.             color: white;
  26.             padding: 10px;
  27.             border-radius: 8px;
  28.         }
  29.         #ui button {
  30.             background: #6ee7b7;
  31.             border: none;
  32.             padding: 8px 12px;
  33.             cursor: pointer;
  34.             margin: 5px;
  35.             border-radius: 5px;
  36.         }
  37.         #ui button:hover {
  38.             background: #51cf66;
  39.         }
  40.     </style>
  41. </head>
  42. <body>
  43.     <div id="ui">
  44.         <h1>Forest Fury: Arrowgeddon!</h1>
  45.         <button id="startBtn">Start Game</button>
  46.     </div>
  47.     <canvas id="gameCanvas"></canvas>
  48.  
  49.     <script>
  50.         const canvas = document.getElementById('gameCanvas');
  51.         const ctx = canvas.getContext('2d');
  52.         canvas.width = window.innerWidth;
  53.         canvas.height = window.innerHeight;
  54.  
  55.         let arrows = [];
  56.         let flowers = [];
  57.         let isGameRunning = false;
  58.         const arrowSpeed = 10;
  59.         const flowerSpawnInterval = 2000; // milliseconds
  60.         let flowerSpawnTimer;
  61.  
  62.         class Arrow {
  63.             constructor(x, y, targetX, targetY) {
  64.                 this.x = x;
  65.                 this.y = y;
  66.                 this.targetX = targetX;
  67.                 this.targetY = targetY;
  68.                 this.angle = Math.atan2(targetY - y, targetX - x);
  69.                 this.speedX = Math.cos(this.angle) * arrowSpeed;
  70.                 this.speedY = Math.sin(this.angle) * arrowSpeed;
  71.                 this.width = 5;
  72.                 this.height = 15;
  73.                 this.color = 'white';
  74.                 this.isActive = true;
  75.             }
  76.  
  77.             update() {
  78.                 this.x += this.speedX;
  79.                 this.y += this.speedY;
  80.  
  81.                 if (this.x < 0 || this.x > canvas.width || this.y < 0 || this.y > canvas.height) {
  82.                     this.isActive = false;
  83.                 }
  84.             }
  85.  
  86.             draw() {
  87.                 ctx.fillStyle = this.color;
  88.                 ctx.save();
  89.                 ctx.translate(this.x, this.y);
  90.                 ctx.rotate(this.angle + Math.PI / 2);
  91.                 ctx.fillRect(-this.width / 2, -this.height / 2, this.width, this.height);
  92.                 ctx.restore();
  93.             }
  94.         }
  95.  
  96.         class Flower {
  97.             constructor(x, y) {
  98.                 this.x = x;
  99.                 this.y = y;
  100.                 this.size = Math.random() * 20 + 10;
  101.                 this.color = `hsl(${Math.random() * 360}, 100%, 50%)`;
  102.                 this.isActive = true;
  103.             }
  104.  
  105.             draw() {
  106.                 ctx.beginPath();
  107.                 ctx.arc(this.x, this.y, this.size, 0, Math.PI * 2);
  108.                 ctx.fillStyle = this.color;
  109.                 ctx.fill();
  110.             }
  111.  
  112.             changeColor() {
  113.                 this.color = `hsl(${Math.random() * 360}, 100%, 50%)`;
  114.             }
  115.         }
  116.  
  117.         function spawnFlower() {
  118.             const x = Math.random() * canvas.width;
  119.             const y = Math.random() * canvas.height;
  120.             flowers.push(new Flower(x, y));
  121.         }
  122.  
  123.         function resetGame() {
  124.             arrows = [];
  125.             flowers = [];
  126.             isGameRunning = true;
  127.             spawnFlower();
  128.             flowerSpawnTimer = setInterval(spawnFlower, flowerSpawnInterval);
  129.             gameLoop();
  130.         }
  131.  
  132.         function stopGame() {
  133.             isGameRunning = false;
  134.             clearInterval(flowerSpawnTimer);
  135.             document.getElementById('startBtn').style.display = 'block';
  136.         }
  137.  
  138.         function gameLoop() {
  139.             if (!isGameRunning) return;
  140.  
  141.             ctx.clearRect(0, 0, canvas.width, canvas.height);
  142.  
  143.             arrows.forEach((arrow, index) => {
  144.                 arrow.update();
  145.                 arrow.draw();
  146.                 if (!arrow.isActive) {
  147.                     arrows.splice(index, 1);
  148.                 }
  149.             });
  150.  
  151.             flowers.forEach((flower, index) => {
  152.                 flower.draw();
  153.                 if (flower.isActive && Math.random() < 0.01) {
  154.                    flower.changeColor();
  155.                 }
  156.             });
  157.  
  158.             checkCollisions();
  159.  
  160.             requestAnimationFrame(gameLoop);
  161.         }
  162.  
  163.         function checkCollisions() {
  164.             arrows.forEach((arrow, arrowIndex) => {
  165.                 flowers.forEach((flower, flowerIndex) => {
  166.                     if (arrow.isActive && flower.isActive) {
  167.                        const dx = arrow.x - flower.x;
  168.                         const dy = arrow.y - flower.y;
  169.                         const distance = Math.sqrt(dx * dx + dy * dy);
  170.  
  171.                         if (distance < flower.size) {
  172.                            flower.isActive = false;
  173.                            arrow.isActive = false;
  174.                            setTimeout(() => {
  175.                                 flowers.splice(flowerIndex, 1);
  176.                             }, 0);
  177.                         }
  178.                     }
  179.                 });
  180.             });
  181.         }
  182.  
  183.         document.getElementById('startBtn').addEventListener('click', () => {
  184.             resetGame();
  185.             document.getElementById('startBtn').style.display = 'none';
  186.         });
  187.  
  188.         canvas.addEventListener('click', (event) => {
  189.             if (isGameRunning) {
  190.                 const rect = canvas.getBoundingClientRect();
  191.                 const x = event.clientX - rect.left;
  192.                 const y = event.clientY - rect.top;
  193.                 arrows.push(new Arrow(canvas.width / 2, canvas.height / 2, x, y));
  194.             }
  195.         });
  196.     </script>
  197. </body>
  198. </html>
  199.  
Add Comment
Please, Sign In to add comment