Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Forest Fury: Arrowgeddon!</title>
- <style>
- body {
- margin: 0;
- overflow: hidden;
- background: linear-gradient(to bottom, #2e8b57, #8fbc8f);
- font-family: Arial, sans-serif;
- }
- canvas {
- display: block;
- margin: auto;
- background: rgba(255, 255, 255, 0.2);
- border: 2px solid #fff;
- }
- #ui {
- position: absolute;
- top: 20px;
- left: 20px;
- background: rgba(0, 0, 0, 0.7);
- color: white;
- padding: 10px;
- border-radius: 8px;
- }
- #ui button {
- background: #6ee7b7;
- border: none;
- padding: 8px 12px;
- cursor: pointer;
- margin: 5px;
- border-radius: 5px;
- }
- #ui button:hover {
- background: #51cf66;
- }
- </style>
- </head>
- <body>
- <div id="ui">
- <h1>Forest Fury: Arrowgeddon!</h1>
- <button id="startBtn">Start Game</button>
- </div>
- <canvas id="gameCanvas"></canvas>
- <script>
- const canvas = document.getElementById('gameCanvas');
- const ctx = canvas.getContext('2d');
- canvas.width = window.innerWidth;
- canvas.height = window.innerHeight;
- let arrows = [];
- let flowers = [];
- let isGameRunning = false;
- const arrowSpeed = 10;
- const flowerSpawnInterval = 2000; // milliseconds
- let flowerSpawnTimer;
- class Arrow {
- constructor(x, y, targetX, targetY) {
- this.x = x;
- this.y = y;
- this.targetX = targetX;
- this.targetY = targetY;
- this.angle = Math.atan2(targetY - y, targetX - x);
- this.speedX = Math.cos(this.angle) * arrowSpeed;
- this.speedY = Math.sin(this.angle) * arrowSpeed;
- this.width = 5;
- this.height = 15;
- this.color = 'white';
- this.isActive = true;
- }
- update() {
- this.x += this.speedX;
- this.y += this.speedY;
- if (this.x < 0 || this.x > canvas.width || this.y < 0 || this.y > canvas.height) {
- this.isActive = false;
- }
- }
- draw() {
- ctx.fillStyle = this.color;
- ctx.save();
- ctx.translate(this.x, this.y);
- ctx.rotate(this.angle + Math.PI / 2);
- ctx.fillRect(-this.width / 2, -this.height / 2, this.width, this.height);
- ctx.restore();
- }
- }
- class Flower {
- constructor(x, y) {
- this.x = x;
- this.y = y;
- this.size = Math.random() * 20 + 10;
- this.color = `hsl(${Math.random() * 360}, 100%, 50%)`;
- this.isActive = true;
- }
- draw() {
- ctx.beginPath();
- ctx.arc(this.x, this.y, this.size, 0, Math.PI * 2);
- ctx.fillStyle = this.color;
- ctx.fill();
- }
- changeColor() {
- this.color = `hsl(${Math.random() * 360}, 100%, 50%)`;
- }
- }
- function spawnFlower() {
- const x = Math.random() * canvas.width;
- const y = Math.random() * canvas.height;
- flowers.push(new Flower(x, y));
- }
- function resetGame() {
- arrows = [];
- flowers = [];
- isGameRunning = true;
- spawnFlower();
- flowerSpawnTimer = setInterval(spawnFlower, flowerSpawnInterval);
- gameLoop();
- }
- function stopGame() {
- isGameRunning = false;
- clearInterval(flowerSpawnTimer);
- document.getElementById('startBtn').style.display = 'block';
- }
- function gameLoop() {
- if (!isGameRunning) return;
- ctx.clearRect(0, 0, canvas.width, canvas.height);
- arrows.forEach((arrow, index) => {
- arrow.update();
- arrow.draw();
- if (!arrow.isActive) {
- arrows.splice(index, 1);
- }
- });
- flowers.forEach((flower, index) => {
- flower.draw();
- if (flower.isActive && Math.random() < 0.01) {
- flower.changeColor();
- }
- });
- checkCollisions();
- requestAnimationFrame(gameLoop);
- }
- function checkCollisions() {
- arrows.forEach((arrow, arrowIndex) => {
- flowers.forEach((flower, flowerIndex) => {
- if (arrow.isActive && flower.isActive) {
- const dx = arrow.x - flower.x;
- const dy = arrow.y - flower.y;
- const distance = Math.sqrt(dx * dx + dy * dy);
- if (distance < flower.size) {
- flower.isActive = false;
- arrow.isActive = false;
- setTimeout(() => {
- flowers.splice(flowerIndex, 1);
- }, 0);
- }
- }
- });
- });
- }
- document.getElementById('startBtn').addEventListener('click', () => {
- resetGame();
- document.getElementById('startBtn').style.display = 'none';
- });
- canvas.addEventListener('click', (event) => {
- if (isGameRunning) {
- const rect = canvas.getBoundingClientRect();
- const x = event.clientX - rect.left;
- const y = event.clientY - rect.top;
- arrows.push(new Arrow(canvas.width / 2, canvas.height / 2, x, y));
- }
- });
- </script>
- </body>
- </html>
Add Comment
Please, Sign In to add comment