Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>Neon Arkanoid: Space Edition</title>
- <style>
- body {
- margin: 0;
- overflow: hidden;
- background-color: #000;
- font-family: 'Courier New', Courier, monospace;
- color: white;
- display: flex;
- justify-content: center;
- align-items: center;
- height: 100vh;
- }
- canvas {
- box-shadow: 0 0 50px rgba(0, 255, 255, 0.1);
- border: 2px solid #333;
- background: #000; /* Fallback */
- }
- #ui {
- position: absolute;
- top: 20px;
- left: 50%;
- transform: translateX(-50%);
- text-align: center;
- pointer-events: none;
- z-index: 10;
- text-shadow: 0 0 10px #fff;
- }
- h1 { margin: 0; font-size: 24px; letter-spacing: 2px; color: #0ff; }
- p { margin: 5px 0; font-size: 14px; opacity: 0.8; }
- .scanlines {
- position: fixed;
- top: 0; left: 0; width: 100%; height: 100%;
- 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));
- background-size: 100% 4px;
- pointer-events: none;
- z-index: 20;
- }
- </style>
- </head>
- <body>
- <div id="ui">
- <h1>NEON BREAKER: DEEP SPACE</h1>
- <p>Score: <span id="scoreVal">0</span> | Lives: <span id="livesVal">3</span></p>
- <p style="font-size: 12px; color: #aaa;">Click to Start / Launch Ball</p>
- </div>
- <div class="scanlines"></div>
- <canvas id="gameCanvas"></canvas>
- <script>
- /**
- * AUDIO ENGINE (Unchanged)
- */
- const AudioEngine = {
- ctx: new (window.AudioContext || window.webkitAudioContext)(),
- playTone: function(freq, type, duration, vol = 0.1) {
- if(this.ctx.state === 'suspended') this.ctx.resume();
- const osc = this.ctx.createOscillator();
- const gain = this.ctx.createGain();
- osc.type = type;
- osc.frequency.setValueAtTime(freq, this.ctx.currentTime);
- gain.gain.setValueAtTime(vol, this.ctx.currentTime);
- gain.gain.exponentialRampToValueAtTime(0.01, this.ctx.currentTime + duration);
- osc.connect(gain);
- gain.connect(this.ctx.destination);
- osc.start();
- osc.stop(this.ctx.currentTime + duration);
- },
- hitBrick: function() { this.playTone(400 + Math.random()*200, 'square', 0.1, 0.05); },
- paddleHit: function() { this.playTone(300, 'sine', 0.15, 0.1); },
- wallBounce: function() { this.playTone(200, 'triangle', 0.05, 0.05); },
- loseLife: function() {
- this.playTone(150, 'sawtooth', 0.3, 0.2);
- setTimeout(() => this.playTone(100, 'sawtooth', 0.4, 0.2), 100);
- },
- levelClear: function() {
- [500, 600, 800].forEach((f, i) => setTimeout(() => this.playTone(f, 'square', 0.2, 0.1), i * 100));
- },
- bonus: function(type) {
- if(type === 'star') this.playTone(600, 'sine', 0.3, 0.1);
- if(type === 'multiplier') this.playTone(800, 'square', 0.2, 0.1);
- }
- };
- /**
- * GAME LOGIC
- */
- const canvas = document.getElementById('gameCanvas');
- const ctx = canvas.getContext('2d');
- const scoreEl = document.getElementById('scoreVal');
- const livesEl = document.getElementById('livesVal');
- // Canvas Setup
- function resize() {
- canvas.width = 800;
- canvas.height = 600;
- }
- resize();
- // Game State
- let gameRunning = false;
- let score = 0;
- let lives = 3;
- let level = 1;
- let multiplier = 1;
- let particles = [];
- let stars = [];
- let powerups = []; // Falling items
- let shootingStars = []; // Visual effects
- // Entities
- const paddle = {
- x: canvas.width / 2 - 50,
- y: canvas.height - 40,
- w: 100,
- h: 15,
- color: '#0ff',
- speed: 8,
- widthMod: 1, // For powerups
- activeTime: 0
- };
- const ball = {
- x: canvas.width / 2,
- y: canvas.height - 60,
- r: 6,
- dx: 4,
- dy: -4,
- speed: 5,
- color: '#fff',
- trail: []
- };
- // Bricks
- const rows = 5;
- const cols = 10;
- let bricks = [];
- // Starfield Generation
- function initStars() {
- stars = [];
- for(let i=0; i<100; i++) {
- stars.push({
- x: Math.random() * canvas.width,
- y: Math.random() * canvas.height,
- size: Math.random() * 2 + 0.5,
- speed: Math.random() * 0.5 + 0.1,
- brightness: Math.random()
- });
- }
- }
- function drawStars() {
- stars.forEach(star => {
- ctx.fillStyle = `rgba(255, 255, 255, ${star.brightness})`;
- ctx.beginPath();
- ctx.arc(star.x, star.y, star.size, 0, Math.PI*2);
- ctx.fill();
- // Move stars down for parallax effect
- star.y += star.speed;
- if(star.y > canvas.height) {
- star.y = 0;
- star.x = Math.random() * canvas.width;
- }
- });
- }
- // Powerup Classes
- class FallingItem {
- constructor(x, y, type) {
- this.x = x;
- this.y = y;
- this.w = 20;
- this.h = 20;
- this.type = type; // 'width', 'multiplier', 'star'
- this.vy = 3;
- this.active = true;
- }
- update() {
- this.y += this.vy;
- }
- draw() {
- ctx.save();
- ctx.translate(this.x, this.y);
- if(this.type === 'width') {
- ctx.fillStyle = '#0f0'; // Green
- ctx.shadowColor = '#0f0';
- ctx.font = "16px Arial";
- ctx.fillText("W", -5, 5);
- } else if (this.type === 'multiplier') {
- ctx.fillStyle = '#ff0'; // Yellow
- ctx.shadowColor = '#ff0';
- ctx.font = "bold 16px Arial";
- ctx.fillText("x2", -8, 5);
- } else if (this.type === 'star') {
- ctx.fillStyle = '#f0f'; // Pink
- ctx.shadowColor = '#f0f';
- ctx.font = "16px Arial";
- ctx.fillText("★", -4, 5);
- }
- ctx.shadowBlur = 10;
- ctx.strokeRect(-10, -10, 20, 20);
- ctx.restore();
- }
- }
- // Shooting Star Visual
- class ShootingStar {
- constructor() {
- this.reset();
- }
- reset() {
- this.x = Math.random() * canvas.width;
- this.y = 0;
- this.len = 20 + Math.random() * 30;
- this.angle = -Math.PI/4;
- this.speed = 5 + Math.random() * 3;
- this.life = 1.0;
- }
- update() {
- this.x += Math.cos(this.angle) * this.speed;
- this.y += Math.sin(this.angle) * this.speed;
- this.life -= 0.02;
- if(this.x > canvas.width || this.y > canvas.height) this.reset();
- }
- draw() {
- ctx.save();
- ctx.translate(this.x, this.y);
- ctx.rotate(this.angle + Math.PI/2);
- // Glow
- ctx.shadowBlur = 15;
- ctx.shadowColor = '#f0f';
- // Tail
- let grad = ctx.createLinearGradient(0, 0, -this.len, 0);
- grad.addColorStop(0, "rgba(255, 0, 255, 1)");
- grad.addColorStop(1, "rgba(255, 0, 255, 0)");
- ctx.fillStyle = grad;
- ctx.fillRect(-this.len, -2, this.len, 4);
- ctx.restore();
- }
- }
- function initBricks() {
- const brickW = (canvas.width - 40) / cols;
- const brickH = 20;
- const padding = 10;
- bricks = [];
- for(let c=0; c<cols; c++) {
- for(let r=0; r<rows; r++) {
- let hue = (r * 40) + 200;
- if(r > 3) hue = (c * 20) + 10;
- bricks.push({
- x: c * (brickW + padding) + 20,
- y: r * (brickH + 5) + 50,
- w: brickW,
- h: brickH,
- status: 1,
- color: `hsl(${hue}, 100%, 50%)`
- });
- }
- }
- }
- // Input Handling
- let mouseX = canvas.width / 2;
- canvas.addEventListener('mousemove', (e) => {
- const rect = canvas.getBoundingClientRect();
- mouseX = e.clientX - rect.left;
- });
- canvas.addEventListener('mousedown', () => {
- if (!gameRunning) resetGame();
- else if (ball.dy > 0 && ball.y + ball.r < paddle.y) {
- ball.dy = -ball.speed;
- }
- });
- // Particle System
- class Particle {
- constructor(x, y, color) {
- this.x = x;
- this.y = y;
- this.color = color;
- this.size = Math.random() * 3 + 1;
- this.speedX = (Math.random() - 0.5) * 4;
- this.speedY = (Math.random() - 0.5) * 4;
- this.life = 1.0;
- }
- update() {
- this.x += this.speedX;
- this.y += this.speedY;
- this.life -= 0.02;
- }
- draw() {
- ctx.globalAlpha = this.life;
- ctx.fillStyle = this.color;
- ctx.beginPath();
- ctx.arc(this.x, this.y, this.size, 0, Math.PI*2);
- ctx.fill();
- ctx.globalAlpha = 1.0;
- }
- }
- function createExplosion(x, y, color) {
- for(let i=0; i<15; i++) particles.push(new Particle(x, y, color));
- }
- // Core Loop
- function update() {
- if (!gameRunning) return;
- // Paddle Move
- paddle.x = mouseX - (paddle.w * paddle.widthMod)/2;
- if (paddle.x < 0) paddle.x = 0;
- if (paddle.x + (paddle.w * paddle.widthMod) > canvas.width) paddle.x = canvas.width - (paddle.w * paddle.widthMod);
- // Paddle Powerup Timer
- if(paddle.activeTime > 0) {
- paddle.activeTime--;
- if(paddle.activeTime <= 0) {
- paddle.widthMod = 1;
- paddle.color = '#0ff';
- }
- }
- // Ball Physics
- ball.trail.push({x: ball.x, y: ball.y});
- if(ball.trail.length > 10) ball.trail.shift();
- ball.x += ball.dx;
- ball.y += ball.dy;
- // Wall Collision
- if (ball.x + ball.r > canvas.width || ball.x - ball.r < 0) {
- ball.dx *= -1;
- AudioEngine.wallBounce();
- }
- if (ball.y - ball.r < 0) {
- ball.dy *= -1;
- AudioEngine.wallBounce();
- }
- // Paddle Collision
- let pW = paddle.w * paddle.widthMod;
- if (ball.y + ball.r > paddle.y &&
- ball.y - ball.r < paddle.y + paddle.h &&
- ball.x > paddle.x &&
- ball.x < paddle.x + pW) {
- let hitPoint = ball.x - (paddle.x + pW/2);
- hitPoint = hitPoint / (pW/2);
- let angle = hitPoint * (Math.PI/3);
- ball.dx = ball.speed * Math.sin(angle);
- ball.dy = -ball.speed * Math.cos(angle);
- AudioEngine.paddleHit();
- createExplosion(ball.x, paddle.y, '#fff');
- }
- // Brick Collision & Powerup Drop Chance
- let activeBricks = 0;
- for(let i=0; i<bricks.length; i++) {
- let b = bricks[i];
- if(b.status === 1) {
- activeBricks++;
- if (ball.x > b.x && ball.x < b.x + b.w &&
- ball.y > b.y && ball.y < b.y + b.h) {
- ball.dy *= -1;
- b.status = 0;
- // Score Calculation with Multiplier
- let points = 10 * multiplier;
- score += points;
- scoreEl.innerText = score;
- AudioEngine.hitBrick();
- createExplosion(b.x + b.w/2, b.y + b.h/2, b.color);
- // Chance to drop item (15%)
- if(Math.random() < 0.15) {
- let types = ['width', 'multiplier', 'star'];
- let type = types[Math.floor(Math.random() * types.length)];
- powerups.push(new FallingItem(b.x + b.w/2, b.y, type));
- }
- if(Math.abs(ball.dx) < 7) ball.dx *= 1.05;
- if(Math.abs(ball.dy) < 7) ball.dy *= 1.05;
- }
- }
- }
- // Powerup Collision
- for(let i=powerups.length-1; i>=0; i--) {
- let p = powerups[i];
- p.update();
- // Check collision with paddle
- if(p.y + p.h > paddle.y && p.y < paddle.y + paddle.h &&
- p.x > paddle.x && p.x < paddle.x + (paddle.w * paddle.widthMod)) {
- applyPowerup(p.type);
- powerups.splice(i, 1);
- } else if (p.y > canvas.height) {
- powerups.splice(i, 1);
- }
- }
- if (activeBricks === 0) {
- AudioEngine.levelClear();
- resetLevel();
- }
- // Floor Collision
- if (ball.y + ball.r > canvas.height) {
- lives--;
- livesEl.innerText = lives;
- AudioEngine.loseLife();
- if (lives <= 0) {
- gameRunning = false;
- ctx.fillStyle = "rgba(0,0,0,0.8)";
- ctx.fillRect(0,0,canvas.width, canvas.height);
- ctx.fillStyle = "#f00";
- ctx.font = "40px Courier New";
- ctx.fillText("GAME OVER", 280, 300);
- ctx.fillStyle = "#fff";
- ctx.font = "20px Courier New";
- ctx.fillText("Click to Restart", 310, 340);
- } else {
- resetBall();
- }
- }
- // Update Particles & Stars
- for(let i=particles.length-1; i>=0; i--) {
- particles[i].update();
- if(particles[i].life <= 0) particles.splice(i, 1);
- }
- // Random Shooting Star
- if(Math.random() < 0.005) {
- shootingStars.push(new ShootingStar());
- }
- }
- function draw() {
- // Clear with trail effect
- ctx.fillStyle = 'rgba(5, 5, 16, 0.3)';
- ctx.fillRect(0, 0, canvas.width, canvas.height);
- drawStars();
- // Draw Bricks
- bricks.forEach(b => {
- if(b.status === 1) {
- ctx.shadowBlur = 15;
- ctx.shadowColor = b.color;
- ctx.fillStyle = b.color;
- ctx.fillRect(b.x, b.y, b.w, b.h);
- ctx.fillStyle = "rgba(255,255,255,0.3)";
- ctx.fillRect(b.x + 2, b.y + 2, b.w - 4, b.h - 4);
- }
- });
- // Draw Paddle
- ctx.shadowBlur = 20;
- ctx.shadowColor = paddle.color;
- ctx.fillStyle = paddle.color;
- ctx.fillRect(paddle.x, paddle.y, paddle.w * paddle.widthMod, paddle.h);
- // Draw Ball
- ctx.shadowBlur = 10;
- ctx.shadowColor = ball.color;
- ctx.fillStyle = ball.color;
- // Trail
- for(let i=0; i<ball.trail.length; i++) {
- let pos = ball.trail[i];
- ctx.globalAlpha = (i / ball.trail.length) * 0.5;
- ctx.beginPath();
- ctx.arc(pos.x, pos.y, ball.r * (i/ball.trail.length), 0, Math.PI*2);
- ctx.fill();
- }
- ctx.globalAlpha = 1.0;
- // Ball Head
- ctx.beginPath();
- ctx.arc(ball.x, ball.y, ball.r, 0, Math.PI*2);
- ctx.fill();
- // Draw Powerups
- powerups.forEach(p => p.draw());
- // Draw Shooting Stars
- shootingStars.forEach(s => {
- s.update();
- s.draw();
- });
- // Draw Particles
- particles.forEach(p => p.draw());
- ctx.shadowBlur = 0;
- }
- function update() {
- if (!gameRunning) return;
- // Paddle Move
- paddle.x = mouseX - (paddle.w * paddle.widthMod)/2;
- if (paddle.x < 0) paddle.x = 0;
- if (paddle.x + (paddle.w * paddle.widthMod) > canvas.width) paddle.x = canvas.width - (paddle.w * paddle.widthMod);
- // Paddle Powerup Timer
- if(paddle.activeTime > 0) {
- paddle.activeTime--;
- if(paddle.activeTime <= 0) {
- paddle.widthMod = 1;
- paddle.color = '#0ff';
- }
- }
- // Ball Physics
- ball.trail.push({x: ball.x, y: ball.y});
- if(ball.trail.length > 10) ball.trail.shift();
- ball.x += ball.dx;
- ball.y += ball.dy;
- // Wall Collision
- if (ball.x + ball.r > canvas.width || ball.x - ball.r < 0) {
- ball.dx *= -1;
- AudioEngine.wallBounce();
- }
- if (ball.y - ball.r < 0) {
- ball.dy *= -1;
- AudioEngine.wallBounce();
- }
- // Paddle Collision
- let pW = paddle.w * paddle.widthMod;
- if (ball.y + ball.r > paddle.y &&
- ball.y - ball.r < paddle.y + paddle.h &&
- ball.x > paddle.x &&
- ball.x < paddle.x + pW) {
- let hitPoint = ball.x - (paddle.x + pW/2);
- hitPoint = hitPoint / (pW/2);
- let angle = hitPoint * (Math.PI/3);
- ball.dx = ball.speed * Math.sin(angle);
- ball.dy = -ball.speed * Math.cos(angle);
- AudioEngine.paddleHit();
- createExplosion(ball.x, paddle.y, '#fff');
- }
- // Brick Collision & Powerup Drop Chance
- let activeBricks = 0;
- for(let i=0; i<bricks.length; i++) {
- let b = bricks[i];
- if(b.status === 1) {
- activeBricks++;
- if (ball.x > b.x && ball.x < b.x + b.w &&
- ball.y > b.y && ball.y < b.y + b.h) {
- ball.dy *= -1;
- b.status = 0;
- // Score Calculation with Multiplier
- let points = 10 * multiplier;
- score += points;
- scoreEl.innerText = score;
- AudioEngine.hitBrick();
- createExplosion(b.x + b.w/2, b.y + b.h/2, b.color);
- // Chance to drop item (15%)
- if(Math.random() < 0.15) {
- let types = ['width', 'multiplier', 'star'];
- let type = types[Math.floor(Math.random() * types.length)];
- powerups.push(new FallingItem(b.x + b.w/2, b.y, type));
- }
- if(Math.abs(ball.dx) < 7) ball.dx *= 1.05;
- if(Math.abs(ball.dy) < 7) ball.dy *= 1.05;
- }
- }
- }
- // Powerup Collision
- for(let i=powerups.length-1; i>=0; i--) {
- let p = powerups[i];
- p.update();
- // Check collision with paddle
- if(p.y + p.h > paddle.y && p.y < paddle.y + paddle.h &&
- p.x > paddle.x && p.x < paddle.x + (paddle.w * paddle.widthMod)) {
- applyPowerup(p.type);
- powerups.splice(i, 1);
- } else if (p.y > canvas.height) {
- powerups.splice(i, 1);
- }
- }
- if (activeBricks === 0) {
- AudioEngine.levelClear();
- resetLevel();
- }
- // Floor Collision
- if (ball.y + ball.r > canvas.height) {
- lives--;
- livesEl.innerText = lives;
- AudioEngine.loseLife();
- if (lives <= 0) {
- gameRunning = false;
- ctx.fillStyle = "rgba(0,0,0,0.8)";
- ctx.fillRect(0,0,canvas.width, canvas.height);
- ctx.fillStyle = "#f00";
- ctx.font = "40px Courier New";
- ctx.fillText("GAME OVER", 280, 300);
- ctx.fillStyle = "#fff";
- ctx.font = "20px Courier New";
- ctx.fillText("Click to Restart", 310, 340);
- } else {
- resetBall();
- }
- }
- // Update Particles & Stars
- for(let i=particles.length-1; i>=0; i--) {
- particles[i].update();
- if(particles[i].life <= 0) particles.splice(i, 1);
- }
- // Random Shooting Star
- if(Math.random() < 0.005) {
- shootingStars.push(new ShootingStar());
- }
- }
- function draw() {
- // Clear with trail effect
- ctx.fillStyle = 'rgba(5, 5, 16, 0.3)';
- ctx.fillRect(0, 0, canvas.width, canvas.height);
- drawStars();
- // Draw Bricks
- bricks.forEach(b => {
- if(b.status === 1) {
- ctx.shadowBlur = 15;
- ctx.shadowColor = b.color;
- ctx.fillStyle = b.color;
- ctx.fillRect(b.x, b.y, b.w, b.h);
- ctx.fillStyle = "rgba(255,255,255,0.3)";
- ctx.fillRect(b.x + 2, b.y + 2, b.w - 4, b.h - 4);
- }
- });
- // Draw Paddle
- ctx.shadowBlur = 20;
- ctx.shadowColor = paddle.color;
- ctx.fillStyle = paddle.color;
- ctx.fillRect(paddle.x, paddle.y, paddle.w * paddle.widthMod, paddle.h);
- // Draw Ball
- ctx.shadowBlur = 10;
- ctx.shadowColor = ball.color;
- ctx.fillStyle = ball.color;
- // Trail
- for(let i=0; i<ball.trail.length; i++) {
- let pos = ball.trail[i];
- ctx.globalAlpha = (i / ball.trail.length) * 0.5;
- ctx.beginPath();
- ctx.arc(pos.x, pos.y, ball.r * (i/ball.trail.length), 0, Math.PI*2);
- ctx.fill();
- }
- ctx.globalAlpha = 1.0;
- // Ball Head
- ctx.beginPath();
- ctx.arc(ball.x, ball.y, ball.r, 0, Math.PI*2);
- ctx.fill();
- // Draw Powerups
- powerups.forEach(p => p.draw());
- // Draw Shooting Stars
- shootingStars.forEach(s => {
- s.update();
- s.draw();
- });
- // Draw Particles
- particles.forEach(p => p.draw());
- ctx.shadowBlur = 0;
- }
- function applyPowerup(type) {
- if(type === 'width') {
- paddle.widthMod = 1.5;
- paddle.color = '#0f0';
- paddle.activeTime = 300; // 5 seconds approx
- AudioEngine.bonus('star');
- } else if (type === 'multiplier') {
- multiplier = 2;
- scoreEl.innerText = "x2";
- setTimeout(() => { multiplier = 1; scoreEl.innerText = score; }, 5000);
- AudioEngine.bonus('multiplier');
- } else if (type === 'star') {
- // Visual flair: spawn a shooting star immediately
- shootingStars.push(new ShootingStar());
- AudioEngine.bonus('star');
- }
- }
- function resetBall() {
- ball.x = canvas.width / 2;
- ball.y = canvas.height - 60;
- ball.dx = 4 * (Math.random() > 0.5 ? 1 : -1);
- ball.dy = -4;
- ball.speed = 5;
- }
- function resetLevel() {
- initBricks();
- resetBall();
- score += 500;
- level++;
- }
- function resetGame() {
- score = 0;
- lives = 3;
- level = 1;
- multiplier = 1;
- scoreEl.innerText = score;
- livesEl.innerText = lives;
- initBricks();
- resetBall();
- gameRunning = true;
- if(AudioEngine.ctx.state === 'suspended') AudioEngine.ctx.resume();
- }
- // Start
- initStars();
- initBricks();
- loop();
- function loop() {
- update();
- draw();
- requestAnimationFrame(loop);
- }
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment