LuffyTheFox

Untitled

Mar 20th, 2026 (edited)
583
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.28 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="ru">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>TRON: ARCANOID</title>
  6. <style>
  7. body { margin: 0; overflow: hidden; background: #050505; font-family: 'Courier New', monospace; }
  8. canvas { display: block; }
  9. #ui { position: absolute; top: 20px; left: 20px; color: #0ff; font-size: 18px; text-shadow: 0 0 10px #0ff; pointer-events: none; }
  10. </style>
  11. </head>
  12. <body>
  13. <div id="ui">SCORE: <span id="score">0</span> | LIVES: <span id="lives">3</span></div>
  14. <canvas id="game"></canvas>
  15.  
  16. <script>
  17. const canvas = document.getElementById('game');
  18. const ctx = canvas.getContext('2d');
  19. let width, height;
  20.  
  21. let score = 0;
  22. let lives = 3;
  23. let gameRunning = true;
  24. let audioCtx;
  25. const PADDLE_COLOR = '#0ff'; // Cyan
  26. const BALL_COLOR = '#fff'; // White
  27. const BRICK_COLORS = ['#f0f', '#f00', '#0ff']; // Magenta, Red, Cyan
  28. const GLOW = 15;
  29.  
  30. function initAudio() {
  31. if (!audioCtx) audioCtx = new (window.AudioContext || window.webkitAudioContext)();
  32. }
  33.  
  34. function playTone(freq, type, duration) {
  35. if (!audioCtx) return;
  36. const osc = audioCtx.createOscillator();
  37. const gain = audioCtx.createGain();
  38. osc.type = type;
  39. osc.frequency.setValueAtTime(freq, audioCtx.currentTime);
  40. gain.gain.setValueAtTime(0.1, audioCtx.currentTime);
  41. gain.gain.exponentialRampToValueAtTime(0.001, audioCtx.currentTime + duration);
  42. osc.connect(gain);
  43. gain.connect(audioCtx.destination);
  44. osc.start();
  45. osc.stop(audioCtx.currentTime + duration);
  46. }
  47.  
  48. function playHit() { playTone(400, 'sawtooth', 0.1); }
  49. function playPaddle() { playTone(200, 'square', 0.15); }
  50. function playBrick() { playTone(Math.random() * 300 + 600, 'triangle', 0.1); }
  51. function playDeath() { playTone(100, 'sawtooth', 0.5); }
  52.  
  53. const paddle = { x: 0, y: 0, w: 100, h: 15 };
  54. let ball = { x: 0, y: 0, r: 6, dx: 0, dy: 0, speed: 7 };
  55.  
  56. let bricks = [];
  57. const brickRows = 5;
  58. const brickCols = 8;
  59.  
  60. function resize() {
  61. width = canvas.width = window.innerWidth;
  62. height = canvas.height = window.innerHeight;
  63. paddle.y = height - 40;
  64. paddle.x = width / 2 - paddle.w / 2;
  65. }
  66.  
  67. function initBricks() {
  68. bricks = [];
  69. const w = (width - 40) / brickCols;
  70. for (let r = 0; r < brickRows; r++) {
  71. for (let c = 0; c < brickCols; c++) {
  72. bricks.push({
  73. x: 20 + c * w,
  74. y: 80 + r * 30,
  75. w: w - 4,
  76. h: 25,
  77. color: BRICK_COLORS[r % 3],
  78. active: true
  79. });
  80. }
  81. }
  82. }
  83.  
  84. function resetBall() {
  85. ball.x = paddle.x + paddle.w / 2;
  86. ball.y = paddle.y - 20;
  87. ball.dx = (Math.random() * 4 - 2) * ball.speed;
  88. ball.dy = -ball.speed;
  89. }
  90.  
  91. canvas.addEventListener('mousemove', (e) => {
  92. paddle.x = e.clientX - paddle.w / 2;
  93. });
  94.  
  95. canvas.addEventListener('mousedown', () => {
  96. if (!gameRunning && lives > 0) resetBall(); // Start on click after death
  97. initAudio();
  98. });
  99.  
  100.  
  101. function update() {
  102. if (!gameRunning) return;
  103.  
  104. ball.x += ball.dx;
  105. ball.y += ball.dy;
  106.  
  107. if (ball.x < 0 || ball.x > width) { ball.dx *= -1; playTone(300, 'sine', 0.05); }
  108. if (ball.y < 0) { ball.dy *= -1; playTone(300, 'sine', 0.05); }
  109.  
  110. if (ball.y + ball.r > paddle.y && ball.x > paddle.x && ball.x < paddle.x + paddle.w) {
  111. ball.dy = -Math.abs(ball.dy);
  112. let hitPoint = ball.x - (paddle.x + paddle.w / 2);
  113. ball.dx = hitPoint * 0.15;
  114. playPaddle();
  115. }
  116.  
  117. for (let b of bricks) {
  118. if (!b.active) continue;
  119. if (ball.x > b.x && ball.x < b.x + b.w && ball.y > b.y && ball.y < b.y + b.h) {
  120. ball.dy *= -1;
  121. b.active = false;
  122. score += 10;
  123. document.getElementById('score').innerText = score;
  124. playBrick();
  125. createExplosion(b.x + b.w/2, b.y + b.h/2, b.color);
  126. break;
  127. }
  128. }
  129.  
  130. if (ball.y > height) {
  131. lives--;
  132. document.getElementById('lives').innerText = lives;
  133. playDeath();
  134. if (lives <= 0) {
  135. gameRunning = false;
  136. alert("GAME OVER. Score: " + score);
  137. location.reload();
  138. } else {
  139. resetBall();
  140. }
  141. }
  142. }
  143.  
  144. let particles = [];
  145. function createExplosion(x, y, color) {
  146. for (let i = 0; i < 8; i++) {
  147. particles.push({
  148. x: x, y: y,
  149. dx: (Math.random() - 0.5) * 5,
  150. dy: (Math.random() - 0.5) * 5,
  151. life: 1.0,
  152. color: color
  153. });
  154. }
  155. }
  156.  
  157. function drawParticles() {
  158. particles.forEach((p, i) => {
  159. p.x += p.dx;
  160. p.y += p.dy;
  161. p.life -= 0.02;
  162. ctx.globalAlpha = p.life;
  163. ctx.fillStyle = p.color;
  164. ctx.fillRect(p.x, p.y, 3, 3);
  165. if (p.life <= 0) particles.splice(i, 1);
  166. });
  167. ctx.globalAlpha = 1.0;
  168. }
  169.  
  170. function draw() {
  171. ctx.fillStyle = '#050505';
  172. ctx.fillRect(0, 0, width, height);
  173.  
  174. ctx.strokeStyle = '#111';
  175. ctx.lineWidth = 1;
  176. for(let x=0; x<width; x+=40) { ctx.beginPath(); ctx.moveTo(x,0); ctx.lineTo(x,height); ctx.stroke(); }
  177. for(let y=0; y<height; y+=40) { ctx.beginPath(); ctx.moveTo(0,y); ctx.lineTo(width,y); ctx.stroke(); }
  178.  
  179. ctx.shadowBlur = GLOW;
  180. ctx.shadowColor = PADDLE_COLOR;
  181.  
  182. ctx.fillStyle = PADDLE_COLOR;
  183. ctx.fillRect(paddle.x, paddle.y, paddle.w, paddle.h);
  184.  
  185. ctx.shadowColor = BALL_COLOR;
  186. ctx.beginPath();
  187. ctx.arc(ball.x, ball.y, ball.r, 0, Math.PI * 2);
  188. ctx.fillStyle = BALL_COLOR;
  189. ctx.fill();
  190.  
  191. bricks.forEach(b => {
  192. if (!b.active) return;
  193. ctx.shadowColor = b.color;
  194. ctx.fillStyle = b.color;
  195. ctx.fillRect(b.x, b.y, b.w, b.h);
  196.  
  197. ctx.strokeStyle = '#fff';
  198. ctx.lineWidth = 2;
  199. ctx.strokeRect(b.x + 4, b.y + 4, b.w - 8, b.h - 8);
  200. });
  201.  
  202. drawParticles();
  203.  
  204. ctx.shadowBlur = 5;
  205. ctx.strokeStyle = '#fff';
  206. ctx.lineWidth = 1;
  207. ctx.beginPath();
  208. ctx.moveTo(ball.x, ball.y);
  209. ctx.lineTo(ball.x - ball.dx * 2, ball.y - ball.dy * 2);
  210. ctx.stroke();
  211.  
  212. requestAnimationFrame(loop);
  213. }
  214.  
  215. function loop() {
  216. update();
  217. draw();
  218. }
  219.  
  220. window.addEventListener('resize', resize);
  221. resize();
  222. initBricks();
  223. resetBall();
  224. loop();
  225. </script>
  226. </body>
  227. </html>
Advertisement
Add Comment
Please, Sign In to add comment