LuffyTheFox

Untitled

Apr 5th, 2026
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 21.77 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Neon Arkanoid: Space Edition</title>
  6. <style>
  7. body {
  8. margin: 0;
  9. overflow: hidden;
  10. background-color: #000;
  11. font-family: 'Courier New', Courier, monospace;
  12. color: white;
  13. display: flex;
  14. justify-content: center;
  15. align-items: center;
  16. height: 100vh;
  17. }
  18. canvas {
  19. box-shadow: 0 0 50px rgba(0, 255, 255, 0.1);
  20. border: 2px solid #333;
  21. background: #000; /* Fallback */
  22. }
  23. #ui {
  24. position: absolute;
  25. top: 20px;
  26. left: 50%;
  27. transform: translateX(-50%);
  28. text-align: center;
  29. pointer-events: none;
  30. z-index: 10;
  31. text-shadow: 0 0 10px #fff;
  32. }
  33. h1 { margin: 0; font-size: 24px; letter-spacing: 2px; color: #0ff; }
  34. p { margin: 5px 0; font-size: 14px; opacity: 0.8; }
  35.  
  36. .scanlines {
  37. position: fixed;
  38. top: 0; left: 0; width: 100%; height: 100%;
  39. background: linear-gradient(to bottom, rgba(255,255,255,0), rgba(255,255,255,0) 50%, rgba(0,0,0,0.2) 50%, rgba(0,0,0,0.2));
  40. background-size: 100% 4px;
  41. pointer-events: none;
  42. z-index: 20;
  43. }
  44. </style>
  45. </head>
  46. <body>
  47.  
  48. <div id="ui">
  49. <h1>NEON BREAKER: DEEP SPACE</h1>
  50. <p>Score: <span id="scoreVal">0</span> | Lives: <span id="livesVal">3</span></p>
  51. <p style="font-size: 12px; color: #aaa;">Click to Start / Launch Ball</p>
  52. </div>
  53.  
  54. <div class="scanlines"></div>
  55. <canvas id="gameCanvas"></canvas>
  56.  
  57. <script>
  58. /**
  59. * AUDIO ENGINE (Unchanged)
  60. */
  61. const AudioEngine = {
  62. ctx: new (window.AudioContext || window.webkitAudioContext)(),
  63.  
  64. playTone: function(freq, type, duration, vol = 0.1) {
  65. if(this.ctx.state === 'suspended') this.ctx.resume();
  66. const osc = this.ctx.createOscillator();
  67. const gain = this.ctx.createGain();
  68. osc.type = type;
  69. osc.frequency.setValueAtTime(freq, this.ctx.currentTime);
  70. gain.gain.setValueAtTime(vol, this.ctx.currentTime);
  71. gain.gain.exponentialRampToValueAtTime(0.01, this.ctx.currentTime + duration);
  72. osc.connect(gain);
  73. gain.connect(this.ctx.destination);
  74. osc.start();
  75. osc.stop(this.ctx.currentTime + duration);
  76. },
  77.  
  78. hitBrick: function() { this.playTone(400 + Math.random()*200, 'square', 0.1, 0.05); },
  79. paddleHit: function() { this.playTone(300, 'sine', 0.15, 0.1); },
  80. wallBounce: function() { this.playTone(200, 'triangle', 0.05, 0.05); },
  81. loseLife: function() {
  82. this.playTone(150, 'sawtooth', 0.3, 0.2);
  83. setTimeout(() => this.playTone(100, 'sawtooth', 0.4, 0.2), 100);
  84. },
  85. levelClear: function() {
  86. [500, 600, 800].forEach((f, i) => setTimeout(() => this.playTone(f, 'square', 0.2, 0.1), i * 100));
  87. },
  88. bonus: function(type) {
  89. if(type === 'star') this.playTone(600, 'sine', 0.3, 0.1);
  90. if(type === 'multiplier') this.playTone(800, 'square', 0.2, 0.1);
  91. }
  92. };
  93.  
  94. /**
  95. * GAME LOGIC
  96. */
  97. const canvas = document.getElementById('gameCanvas');
  98. const ctx = canvas.getContext('2d');
  99. const scoreEl = document.getElementById('scoreVal');
  100. const livesEl = document.getElementById('livesVal');
  101.  
  102. // Canvas Setup
  103. function resize() {
  104. canvas.width = 800;
  105. canvas.height = 600;
  106. }
  107. resize();
  108.  
  109. // Game State
  110. let gameRunning = false;
  111. let score = 0;
  112. let lives = 3;
  113. let level = 1;
  114. let multiplier = 1;
  115. let particles = [];
  116. let stars = [];
  117. let powerups = []; // Falling items
  118. let shootingStars = []; // Visual effects
  119.  
  120. // Entities
  121. const paddle = {
  122. x: canvas.width / 2 - 50,
  123. y: canvas.height - 40,
  124. w: 100,
  125. h: 15,
  126. color: '#0ff',
  127. speed: 8,
  128. widthMod: 1, // For powerups
  129. activeTime: 0
  130. };
  131.  
  132. const ball = {
  133. x: canvas.width / 2,
  134. y: canvas.height - 60,
  135. r: 6,
  136. dx: 4,
  137. dy: -4,
  138. speed: 5,
  139. color: '#fff',
  140. trail: []
  141. };
  142.  
  143. // Bricks
  144. const rows = 5;
  145. const cols = 10;
  146. let bricks = [];
  147.  
  148. // Starfield Generation
  149. function initStars() {
  150. stars = [];
  151. for(let i=0; i<100; i++) {
  152. stars.push({
  153. x: Math.random() * canvas.width,
  154. y: Math.random() * canvas.height,
  155. size: Math.random() * 2 + 0.5,
  156. speed: Math.random() * 0.5 + 0.1,
  157. brightness: Math.random()
  158. });
  159. }
  160. }
  161.  
  162. function drawStars() {
  163. stars.forEach(star => {
  164. ctx.fillStyle = `rgba(255, 255, 255, ${star.brightness})`;
  165. ctx.beginPath();
  166. ctx.arc(star.x, star.y, star.size, 0, Math.PI*2);
  167. ctx.fill();
  168.  
  169. // Move stars down for parallax effect
  170. star.y += star.speed;
  171. if(star.y > canvas.height) {
  172. star.y = 0;
  173. star.x = Math.random() * canvas.width;
  174. }
  175. });
  176. }
  177.  
  178. // Powerup Classes
  179. class FallingItem {
  180. constructor(x, y, type) {
  181. this.x = x;
  182. this.y = y;
  183. this.w = 20;
  184. this.h = 20;
  185. this.type = type; // 'width', 'multiplier', 'star'
  186. this.vy = 3;
  187. this.active = true;
  188. }
  189. update() {
  190. this.y += this.vy;
  191. }
  192. draw() {
  193. ctx.save();
  194. ctx.translate(this.x, this.y);
  195.  
  196. if(this.type === 'width') {
  197. ctx.fillStyle = '#0f0'; // Green
  198. ctx.shadowColor = '#0f0';
  199. ctx.font = "16px Arial";
  200. ctx.fillText("W", -5, 5);
  201. } else if (this.type === 'multiplier') {
  202. ctx.fillStyle = '#ff0'; // Yellow
  203. ctx.shadowColor = '#ff0';
  204. ctx.font = "bold 16px Arial";
  205. ctx.fillText("x2", -8, 5);
  206. } else if (this.type === 'star') {
  207. ctx.fillStyle = '#f0f'; // Pink
  208. ctx.shadowColor = '#f0f';
  209. ctx.font = "16px Arial";
  210. ctx.fillText("★", -4, 5);
  211. }
  212.  
  213. ctx.shadowBlur = 10;
  214. ctx.strokeRect(-10, -10, 20, 20);
  215. ctx.restore();
  216. }
  217. }
  218.  
  219. // Shooting Star Visual
  220. class ShootingStar {
  221. constructor() {
  222. this.reset();
  223. }
  224. reset() {
  225. this.x = Math.random() * canvas.width;
  226. this.y = 0;
  227. this.len = 20 + Math.random() * 30;
  228. this.angle = -Math.PI/4;
  229. this.speed = 5 + Math.random() * 3;
  230. this.life = 1.0;
  231. }
  232. update() {
  233. this.x += Math.cos(this.angle) * this.speed;
  234. this.y += Math.sin(this.angle) * this.speed;
  235. this.life -= 0.02;
  236.  
  237. if(this.x > canvas.width || this.y > canvas.height) this.reset();
  238. }
  239. draw() {
  240. ctx.save();
  241. ctx.translate(this.x, this.y);
  242. ctx.rotate(this.angle + Math.PI/2);
  243.  
  244. // Glow
  245. ctx.shadowBlur = 15;
  246. ctx.shadowColor = '#f0f';
  247.  
  248. // Tail
  249. let grad = ctx.createLinearGradient(0, 0, -this.len, 0);
  250. grad.addColorStop(0, "rgba(255, 0, 255, 1)");
  251. grad.addColorStop(1, "rgba(255, 0, 255, 0)");
  252.  
  253. ctx.fillStyle = grad;
  254. ctx.fillRect(-this.len, -2, this.len, 4);
  255. ctx.restore();
  256. }
  257. }
  258.  
  259. function initBricks() {
  260. const brickW = (canvas.width - 40) / cols;
  261. const brickH = 20;
  262. const padding = 10;
  263.  
  264. bricks = [];
  265. for(let c=0; c<cols; c++) {
  266. for(let r=0; r<rows; r++) {
  267. let hue = (r * 40) + 200;
  268. if(r > 3) hue = (c * 20) + 10;
  269.  
  270. bricks.push({
  271. x: c * (brickW + padding) + 20,
  272. y: r * (brickH + 5) + 50,
  273. w: brickW,
  274. h: brickH,
  275. status: 1,
  276. color: `hsl(${hue}, 100%, 50%)`
  277. });
  278. }
  279. }
  280. }
  281.  
  282. // Input Handling
  283. let mouseX = canvas.width / 2;
  284. canvas.addEventListener('mousemove', (e) => {
  285. const rect = canvas.getBoundingClientRect();
  286. mouseX = e.clientX - rect.left;
  287. });
  288.  
  289. canvas.addEventListener('mousedown', () => {
  290. if (!gameRunning) resetGame();
  291. else if (ball.dy > 0 && ball.y + ball.r < paddle.y) {
  292. ball.dy = -ball.speed;
  293. }
  294. });
  295.  
  296. // Particle System
  297. class Particle {
  298. constructor(x, y, color) {
  299. this.x = x;
  300. this.y = y;
  301. this.color = color;
  302. this.size = Math.random() * 3 + 1;
  303. this.speedX = (Math.random() - 0.5) * 4;
  304. this.speedY = (Math.random() - 0.5) * 4;
  305. this.life = 1.0;
  306. }
  307. update() {
  308. this.x += this.speedX;
  309. this.y += this.speedY;
  310. this.life -= 0.02;
  311. }
  312. draw() {
  313. ctx.globalAlpha = this.life;
  314. ctx.fillStyle = this.color;
  315. ctx.beginPath();
  316. ctx.arc(this.x, this.y, this.size, 0, Math.PI*2);
  317. ctx.fill();
  318. ctx.globalAlpha = 1.0;
  319. }
  320. }
  321.  
  322. function createExplosion(x, y, color) {
  323. for(let i=0; i<15; i++) particles.push(new Particle(x, y, color));
  324. }
  325.  
  326. // Core Loop
  327. function update() {
  328. if (!gameRunning) return;
  329.  
  330. // Paddle Move
  331. paddle.x = mouseX - (paddle.w * paddle.widthMod)/2;
  332. if (paddle.x < 0) paddle.x = 0;
  333. if (paddle.x + (paddle.w * paddle.widthMod) > canvas.width) paddle.x = canvas.width - (paddle.w * paddle.widthMod);
  334.  
  335. // Paddle Powerup Timer
  336. if(paddle.activeTime > 0) {
  337. paddle.activeTime--;
  338. if(paddle.activeTime <= 0) {
  339. paddle.widthMod = 1;
  340. paddle.color = '#0ff';
  341. }
  342. }
  343.  
  344. // Ball Physics
  345. ball.trail.push({x: ball.x, y: ball.y});
  346. if(ball.trail.length > 10) ball.trail.shift();
  347.  
  348. ball.x += ball.dx;
  349. ball.y += ball.dy;
  350.  
  351. // Wall Collision
  352. if (ball.x + ball.r > canvas.width || ball.x - ball.r < 0) {
  353. ball.dx *= -1;
  354. AudioEngine.wallBounce();
  355. }
  356. if (ball.y - ball.r < 0) {
  357. ball.dy *= -1;
  358. AudioEngine.wallBounce();
  359. }
  360.  
  361. // Paddle Collision
  362. let pW = paddle.w * paddle.widthMod;
  363. if (ball.y + ball.r > paddle.y &&
  364. ball.y - ball.r < paddle.y + paddle.h &&
  365. ball.x > paddle.x &&
  366. ball.x < paddle.x + pW) {
  367.  
  368. let hitPoint = ball.x - (paddle.x + pW/2);
  369. hitPoint = hitPoint / (pW/2);
  370. let angle = hitPoint * (Math.PI/3);
  371.  
  372. ball.dx = ball.speed * Math.sin(angle);
  373. ball.dy = -ball.speed * Math.cos(angle);
  374.  
  375. AudioEngine.paddleHit();
  376. createExplosion(ball.x, paddle.y, '#fff');
  377. }
  378.  
  379. // Brick Collision & Powerup Drop Chance
  380. let activeBricks = 0;
  381. for(let i=0; i<bricks.length; i++) {
  382. let b = bricks[i];
  383. if(b.status === 1) {
  384. activeBricks++;
  385. if (ball.x > b.x && ball.x < b.x + b.w &&
  386. ball.y > b.y && ball.y < b.y + b.h) {
  387.  
  388. ball.dy *= -1;
  389. b.status = 0;
  390.  
  391. // Score Calculation with Multiplier
  392. let points = 10 * multiplier;
  393. score += points;
  394. scoreEl.innerText = score;
  395.  
  396. AudioEngine.hitBrick();
  397. createExplosion(b.x + b.w/2, b.y + b.h/2, b.color);
  398.  
  399. // Chance to drop item (15%)
  400. if(Math.random() < 0.15) {
  401. let types = ['width', 'multiplier', 'star'];
  402. let type = types[Math.floor(Math.random() * types.length)];
  403. powerups.push(new FallingItem(b.x + b.w/2, b.y, type));
  404. }
  405.  
  406. if(Math.abs(ball.dx) < 7) ball.dx *= 1.05;
  407. if(Math.abs(ball.dy) < 7) ball.dy *= 1.05;
  408. }
  409. }
  410. }
  411.  
  412. // Powerup Collision
  413. for(let i=powerups.length-1; i>=0; i--) {
  414. let p = powerups[i];
  415. p.update();
  416.  
  417. // Check collision with paddle
  418. if(p.y + p.h > paddle.y && p.y < paddle.y + paddle.h &&
  419. p.x > paddle.x && p.x < paddle.x + (paddle.w * paddle.widthMod)) {
  420.  
  421. applyPowerup(p.type);
  422. powerups.splice(i, 1);
  423. } else if (p.y > canvas.height) {
  424. powerups.splice(i, 1);
  425. }
  426. }
  427.  
  428. if (activeBricks === 0) {
  429. AudioEngine.levelClear();
  430. resetLevel();
  431. }
  432.  
  433. // Floor Collision
  434. if (ball.y + ball.r > canvas.height) {
  435. lives--;
  436. livesEl.innerText = lives;
  437. AudioEngine.loseLife();
  438. if (lives <= 0) {
  439. gameRunning = false;
  440. ctx.fillStyle = "rgba(0,0,0,0.8)";
  441. ctx.fillRect(0,0,canvas.width, canvas.height);
  442. ctx.fillStyle = "#f00";
  443. ctx.font = "40px Courier New";
  444. ctx.fillText("GAME OVER", 280, 300);
  445. ctx.fillStyle = "#fff";
  446. ctx.font = "20px Courier New";
  447. ctx.fillText("Click to Restart", 310, 340);
  448. } else {
  449. resetBall();
  450. }
  451. }
  452.  
  453. // Update Particles & Stars
  454. for(let i=particles.length-1; i>=0; i--) {
  455. particles[i].update();
  456. if(particles[i].life <= 0) particles.splice(i, 1);
  457. }
  458.  
  459. // Random Shooting Star
  460. if(Math.random() < 0.005) {
  461. shootingStars.push(new ShootingStar());
  462. }
  463. }
  464.  
  465. function draw() {
  466. // Clear with trail effect
  467. ctx.fillStyle = 'rgba(5, 5, 16, 0.3)';
  468. ctx.fillRect(0, 0, canvas.width, canvas.height);
  469.  
  470. drawStars();
  471.  
  472. // Draw Bricks
  473. bricks.forEach(b => {
  474. if(b.status === 1) {
  475. ctx.shadowBlur = 15;
  476. ctx.shadowColor = b.color;
  477. ctx.fillStyle = b.color;
  478. ctx.fillRect(b.x, b.y, b.w, b.h);
  479. ctx.fillStyle = "rgba(255,255,255,0.3)";
  480. ctx.fillRect(b.x + 2, b.y + 2, b.w - 4, b.h - 4);
  481. }
  482. });
  483.  
  484. // Draw Paddle
  485. ctx.shadowBlur = 20;
  486. ctx.shadowColor = paddle.color;
  487. ctx.fillStyle = paddle.color;
  488. ctx.fillRect(paddle.x, paddle.y, paddle.w * paddle.widthMod, paddle.h);
  489.  
  490. // Draw Ball
  491. ctx.shadowBlur = 10;
  492. ctx.shadowColor = ball.color;
  493. ctx.fillStyle = ball.color;
  494.  
  495. // Trail
  496. for(let i=0; i<ball.trail.length; i++) {
  497. let pos = ball.trail[i];
  498. ctx.globalAlpha = (i / ball.trail.length) * 0.5;
  499. ctx.beginPath();
  500. ctx.arc(pos.x, pos.y, ball.r * (i/ball.trail.length), 0, Math.PI*2);
  501. ctx.fill();
  502. }
  503. ctx.globalAlpha = 1.0;
  504.  
  505. // Ball Head
  506. ctx.beginPath();
  507. ctx.arc(ball.x, ball.y, ball.r, 0, Math.PI*2);
  508. ctx.fill();
  509.  
  510. // Draw Powerups
  511. powerups.forEach(p => p.draw());
  512.  
  513. // Draw Shooting Stars
  514. shootingStars.forEach(s => {
  515. s.update();
  516. s.draw();
  517. });
  518.  
  519. // Draw Particles
  520. particles.forEach(p => p.draw());
  521.  
  522. ctx.shadowBlur = 0;
  523. }
  524.  
  525. function update() {
  526. if (!gameRunning) return;
  527.  
  528. // Paddle Move
  529. paddle.x = mouseX - (paddle.w * paddle.widthMod)/2;
  530. if (paddle.x < 0) paddle.x = 0;
  531. if (paddle.x + (paddle.w * paddle.widthMod) > canvas.width) paddle.x = canvas.width - (paddle.w * paddle.widthMod);
  532.  
  533. // Paddle Powerup Timer
  534. if(paddle.activeTime > 0) {
  535. paddle.activeTime--;
  536. if(paddle.activeTime <= 0) {
  537. paddle.widthMod = 1;
  538. paddle.color = '#0ff';
  539. }
  540. }
  541.  
  542. // Ball Physics
  543. ball.trail.push({x: ball.x, y: ball.y});
  544. if(ball.trail.length > 10) ball.trail.shift();
  545.  
  546. ball.x += ball.dx;
  547. ball.y += ball.dy;
  548.  
  549. // Wall Collision
  550. if (ball.x + ball.r > canvas.width || ball.x - ball.r < 0) {
  551. ball.dx *= -1;
  552. AudioEngine.wallBounce();
  553. }
  554. if (ball.y - ball.r < 0) {
  555. ball.dy *= -1;
  556. AudioEngine.wallBounce();
  557. }
  558.  
  559. // Paddle Collision
  560. let pW = paddle.w * paddle.widthMod;
  561. if (ball.y + ball.r > paddle.y &&
  562. ball.y - ball.r < paddle.y + paddle.h &&
  563. ball.x > paddle.x &&
  564. ball.x < paddle.x + pW) {
  565.  
  566. let hitPoint = ball.x - (paddle.x + pW/2);
  567. hitPoint = hitPoint / (pW/2);
  568. let angle = hitPoint * (Math.PI/3);
  569.  
  570. ball.dx = ball.speed * Math.sin(angle);
  571. ball.dy = -ball.speed * Math.cos(angle);
  572.  
  573. AudioEngine.paddleHit();
  574. createExplosion(ball.x, paddle.y, '#fff');
  575. }
  576.  
  577. // Brick Collision & Powerup Drop Chance
  578. let activeBricks = 0;
  579. for(let i=0; i<bricks.length; i++) {
  580. let b = bricks[i];
  581. if(b.status === 1) {
  582. activeBricks++;
  583. if (ball.x > b.x && ball.x < b.x + b.w &&
  584. ball.y > b.y && ball.y < b.y + b.h) {
  585.  
  586. ball.dy *= -1;
  587. b.status = 0;
  588.  
  589. // Score Calculation with Multiplier
  590. let points = 10 * multiplier;
  591. score += points;
  592. scoreEl.innerText = score;
  593.  
  594. AudioEngine.hitBrick();
  595. createExplosion(b.x + b.w/2, b.y + b.h/2, b.color);
  596.  
  597. // Chance to drop item (15%)
  598. if(Math.random() < 0.15) {
  599. let types = ['width', 'multiplier', 'star'];
  600. let type = types[Math.floor(Math.random() * types.length)];
  601. powerups.push(new FallingItem(b.x + b.w/2, b.y, type));
  602. }
  603.  
  604. if(Math.abs(ball.dx) < 7) ball.dx *= 1.05;
  605. if(Math.abs(ball.dy) < 7) ball.dy *= 1.05;
  606. }
  607. }
  608. }
  609.  
  610. // Powerup Collision
  611. for(let i=powerups.length-1; i>=0; i--) {
  612. let p = powerups[i];
  613. p.update();
  614.  
  615. // Check collision with paddle
  616. if(p.y + p.h > paddle.y && p.y < paddle.y + paddle.h &&
  617. p.x > paddle.x && p.x < paddle.x + (paddle.w * paddle.widthMod)) {
  618.  
  619. applyPowerup(p.type);
  620. powerups.splice(i, 1);
  621. } else if (p.y > canvas.height) {
  622. powerups.splice(i, 1);
  623. }
  624. }
  625.  
  626. if (activeBricks === 0) {
  627. AudioEngine.levelClear();
  628. resetLevel();
  629. }
  630.  
  631. // Floor Collision
  632. if (ball.y + ball.r > canvas.height) {
  633. lives--;
  634. livesEl.innerText = lives;
  635. AudioEngine.loseLife();
  636. if (lives <= 0) {
  637. gameRunning = false;
  638. ctx.fillStyle = "rgba(0,0,0,0.8)";
  639. ctx.fillRect(0,0,canvas.width, canvas.height);
  640. ctx.fillStyle = "#f00";
  641. ctx.font = "40px Courier New";
  642. ctx.fillText("GAME OVER", 280, 300);
  643. ctx.fillStyle = "#fff";
  644. ctx.font = "20px Courier New";
  645. ctx.fillText("Click to Restart", 310, 340);
  646. } else {
  647. resetBall();
  648. }
  649. }
  650.  
  651. // Update Particles & Stars
  652. for(let i=particles.length-1; i>=0; i--) {
  653. particles[i].update();
  654. if(particles[i].life <= 0) particles.splice(i, 1);
  655. }
  656.  
  657. // Random Shooting Star
  658. if(Math.random() < 0.005) {
  659. shootingStars.push(new ShootingStar());
  660. }
  661. }
  662.  
  663. function draw() {
  664. // Clear with trail effect
  665. ctx.fillStyle = 'rgba(5, 5, 16, 0.3)';
  666. ctx.fillRect(0, 0, canvas.width, canvas.height);
  667.  
  668. drawStars();
  669.  
  670. // Draw Bricks
  671. bricks.forEach(b => {
  672. if(b.status === 1) {
  673. ctx.shadowBlur = 15;
  674. ctx.shadowColor = b.color;
  675. ctx.fillStyle = b.color;
  676. ctx.fillRect(b.x, b.y, b.w, b.h);
  677. ctx.fillStyle = "rgba(255,255,255,0.3)";
  678. ctx.fillRect(b.x + 2, b.y + 2, b.w - 4, b.h - 4);
  679. }
  680. });
  681.  
  682. // Draw Paddle
  683. ctx.shadowBlur = 20;
  684. ctx.shadowColor = paddle.color;
  685. ctx.fillStyle = paddle.color;
  686. ctx.fillRect(paddle.x, paddle.y, paddle.w * paddle.widthMod, paddle.h);
  687.  
  688. // Draw Ball
  689. ctx.shadowBlur = 10;
  690. ctx.shadowColor = ball.color;
  691. ctx.fillStyle = ball.color;
  692.  
  693. // Trail
  694. for(let i=0; i<ball.trail.length; i++) {
  695. let pos = ball.trail[i];
  696. ctx.globalAlpha = (i / ball.trail.length) * 0.5;
  697. ctx.beginPath();
  698. ctx.arc(pos.x, pos.y, ball.r * (i/ball.trail.length), 0, Math.PI*2);
  699. ctx.fill();
  700. }
  701. ctx.globalAlpha = 1.0;
  702.  
  703. // Ball Head
  704. ctx.beginPath();
  705. ctx.arc(ball.x, ball.y, ball.r, 0, Math.PI*2);
  706. ctx.fill();
  707.  
  708. // Draw Powerups
  709. powerups.forEach(p => p.draw());
  710.  
  711. // Draw Shooting Stars
  712. shootingStars.forEach(s => {
  713. s.update();
  714. s.draw();
  715. });
  716.  
  717. // Draw Particles
  718. particles.forEach(p => p.draw());
  719.  
  720. ctx.shadowBlur = 0;
  721. }
  722.  
  723. function applyPowerup(type) {
  724. if(type === 'width') {
  725. paddle.widthMod = 1.5;
  726. paddle.color = '#0f0';
  727. paddle.activeTime = 300; // 5 seconds approx
  728. AudioEngine.bonus('star');
  729. } else if (type === 'multiplier') {
  730. multiplier = 2;
  731. scoreEl.innerText = "x2";
  732. setTimeout(() => { multiplier = 1; scoreEl.innerText = score; }, 5000);
  733. AudioEngine.bonus('multiplier');
  734. } else if (type === 'star') {
  735. // Visual flair: spawn a shooting star immediately
  736. shootingStars.push(new ShootingStar());
  737. AudioEngine.bonus('star');
  738. }
  739. }
  740.  
  741. function resetBall() {
  742. ball.x = canvas.width / 2;
  743. ball.y = canvas.height - 60;
  744. ball.dx = 4 * (Math.random() > 0.5 ? 1 : -1);
  745. ball.dy = -4;
  746. ball.speed = 5;
  747. }
  748.  
  749. function resetLevel() {
  750. initBricks();
  751. resetBall();
  752. score += 500;
  753. level++;
  754. }
  755.  
  756. function resetGame() {
  757. score = 0;
  758. lives = 3;
  759. level = 1;
  760. multiplier = 1;
  761. scoreEl.innerText = score;
  762. livesEl.innerText = lives;
  763. initBricks();
  764. resetBall();
  765. gameRunning = true;
  766.  
  767. if(AudioEngine.ctx.state === 'suspended') AudioEngine.ctx.resume();
  768. }
  769.  
  770. // Start
  771. initStars();
  772. initBricks();
  773. loop();
  774.  
  775. function loop() {
  776. update();
  777. draw();
  778. requestAnimationFrame(loop);
  779. }
  780.  
  781. </script>
  782. </body>
  783. </html>
Advertisement
Add Comment
Please, Sign In to add comment