Created
August 10, 2026 16:29
-
-
Save courtesysoft/e2d79a67f6ad25d66f7dc94d3cf7e58a to your computer and use it in GitHub Desktop.
Shooter game produced with Deepseek V4 Flash 0731 IQ4_XS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>DeepSeek Shooter</title> | |
| <style> | |
| * { margin: 0; padding: 0; box-sizing: border-box; } | |
| body { | |
| background: #05060f; | |
| display: flex; | |
| align-items: center; | |
| justify-content: center; | |
| min-height: 100vh; | |
| font-family: 'Courier New', monospace; | |
| overflow: hidden; | |
| } | |
| canvas { display: block; border-radius: 8px; box-shadow: 0 0 40px rgba(80,120,255,.25); } | |
| </style> | |
| </head> | |
| <body> | |
| <canvas id="game" width="800" height="600"></canvas> | |
| <script> | |
| const c = document.getElementById('game'); | |
| const ctx = c.getContext('2d'); | |
| // safe storage wrapper (localStorage can throw in privacy/sandboxed contexts) | |
| function loadHi(){ try{ return +(localStorage.getItem('nebulaHi')||0); }catch(e){ return 0; } } | |
| function saveHi(v){ try{ localStorage.setItem('nebulaHi',v); }catch(e){} } | |
| // ---------- Sound engine (Web Audio, no external files) ---------- | |
| let actx=null; | |
| function ensureAudio(){ | |
| if(!actx){ | |
| try{ actx=new (window.AudioContext||window.webkitAudioContext)(); } | |
| catch(e){} | |
| } | |
| if(actx && actx.state==='suspended') actx.resume(); | |
| } | |
| // single oscillator blip at an absolute time | |
| function noteAt(freq,t,dur,type,vol){ | |
| if(!actx) return; | |
| const o=actx.createOscillator(), g=actx.createGain(); | |
| o.type=type||'square'; o.frequency.value=freq; | |
| g.gain.setValueAtTime(vol,t); | |
| g.gain.exponentialRampToValueAtTime(.001,t+dur); | |
| o.connect(g); g.connect(actx.destination); | |
| o.start(t); o.stop(t+dur+.02); | |
| } | |
| // quick pitch-slide tone | |
| function sweep(freq,dur,type,vol,slide){ | |
| if(!actx) return; | |
| const t=actx.currentTime, o=actx.createOscillator(), g=actx.createGain(); | |
| o.type=type||'square'; | |
| o.frequency.setValueAtTime(freq,t); | |
| if(slide) o.frequency.exponentialRampToValueAtTime(Math.max(1,slide),t+dur); | |
| g.gain.setValueAtTime(vol,t); | |
| g.gain.exponentialRampToValueAtTime(.001,t+dur); | |
| o.connect(g); g.connect(actx.destination); | |
| o.start(t); o.stop(t+dur+.02); | |
| } | |
| // filtered noise burst (explosions) | |
| function noiseBurst(dur,vol,cutoff){ | |
| if(!actx) return; | |
| const len=Math.max(1,Math.floor(actx.sampleRate*dur)); | |
| const buf=actx.createBuffer(1,len,actx.sampleRate); | |
| const d=buf.getChannelData(0); | |
| for(let i=0;i<len;i++) d[i]=(Math.random()*2-1)*(1-i/len); | |
| const src=actx.createBufferSource(); src.buffer=buf; | |
| const f=actx.createBiquadFilter(); f.type='lowpass'; f.frequency.value=cutoff||1000; | |
| const t=actx.currentTime, g=actx.createGain(); | |
| g.gain.setValueAtTime(vol,t); | |
| g.gain.exponentialRampToValueAtTime(.001,t+dur); | |
| src.connect(f); f.connect(g); g.connect(actx.destination); | |
| src.start(t); | |
| } | |
| // rising arpeggio (pickups) | |
| function arp(freqs,type,vol,step){ | |
| if(!actx) return; | |
| const t0=actx.currentTime+.01; | |
| freqs.forEach((f,i)=>noteAt(f,t0+i*step,.15,type||'square',vol)); | |
| } | |
| const SFX={ | |
| laser(){ sweep(900,.09,'square',.05,220); }, | |
| hit(){ noiseBurst(.12,.18,1400); noteAt(200,actx?actx.currentTime:0,.08,'sawtooth',.06); }, | |
| boom(){ noiseBurst(.4,.3,700); sweep(150,.35,'triangle',.22,45); }, | |
| powerup(){ arp([523,659,784],'square',.14,.07); }, | |
| life(){ arp([392,494,587,784],'triangle',.16,.09); }, | |
| shieldTick(){ noteAt(1200,(actx?actx.currentTime:0),.03,'square',.07); }, | |
| hurt(){ noiseBurst(.25,.18,500); sweep(320,.3,'sawtooth',.2,70); }, | |
| bossDie(){ noiseBurst(.9,.4,400); [80,60,40].forEach((f,i)=>noteAt(f,(actx?actx.currentTime:0)+i*.15,.5,'triangle',.25)); } | |
| }; | |
| // ---------- Procedural techno music (Web Audio sequencer) ---------- | |
| // Each stage gets a distinct pumping techno loop built from a 16-step grid. | |
| const MUSIC = { | |
| 0:{bpm:132, root:45, scale:[0,3,5,7,10], bass:'sawtooth', lead:'square'}, | |
| 1:{bpm:138, root:41, scale:[0,2,4,7,9], bass:'triangle',lead:'square'}, | |
| 2:{bpm:140, root:48, scale:[0,3,5,8,10], bass:'sawtooth', lead:'square'}, | |
| 3:{bpm:136, root:43, scale:[0,2,5,7,9], bass:'triangle',lead:'sawtooth'}, | |
| 4:{bpm:144, root:38, scale:[0,3,6,8,10], bass:'sawtooth', lead:'square'}, | |
| 5:{bpm:150, root:40, scale:[0,2,3,7,9], bass:'triangle',lead:'square'}, | |
| 6:{bpm:160, root:36, scale:[0,1,4,7,8], bass:'sawtooth', lead:'sawtooth'}, | |
| // final-form boss theme: fast, loud, relentless | |
| 7:{bpm:190, root:33, scale:[0,1,3,6,8,10], bass:'square', lead:'sawtooth', | |
| intense:true}, | |
| // victory / congratulations western theme (relaxing) | |
| 8:{bpm:88, root:52, scale:[0,4,7,11], bass:'triangle', lead:'triangle', | |
| western:true} | |
| }; | |
| let musicTimer=null; // interval handle for the sequencer | |
| let musicStep=0; // current 16th-note step | |
| let musicTrack=null; // active track config | |
| function midiToFreq(m){ return 440*Math.pow(2,(m-69)/12); } | |
| function kick(t){ | |
| if(!actx) return; | |
| const o=actx.createOscillator(), g=actx.createGain(); | |
| o.type='sine'; | |
| o.frequency.setValueAtTime(150,t); | |
| o.frequency.exponentialRampToValueAtTime(40,t+.11); | |
| g.gain.setValueAtTime(.9,t); | |
| g.gain.exponentialRampToValueAtTime(.001,t+.18); | |
| o.connect(g); g.connect(actx.destination); | |
| o.start(t); o.stop(t+.2); | |
| } | |
| function hat(t,open){ | |
| if(!actx) return; | |
| const len=Math.floor(actx.sampleRate*(open?.08:.03)); | |
| const buf=actx.createBuffer(1,len,actx.sampleRate), d=buf.getChannelData(0); | |
| for(let i=0;i<len;i++) d[i]=(Math.random()*2-1)*(1-i/len); | |
| const src=actx.createBufferSource(); src.buffer=buf; | |
| const f=actx.createBiquadFilter(); f.type='highpass'; f.frequency.value=6000; | |
| const g=actx.createGain(); | |
| g.gain.setValueAtTime(open?.22:.14,t); | |
| g.gain.exponentialRampToValueAtTime(.001,t+(open?.08:.03)); | |
| src.connect(f); f.connect(g); g.connect(actx.destination); | |
| src.start(t); | |
| } | |
| function bassNote(m,t,dur){ | |
| if(!actx) return; | |
| const vol = musicTrack.intense ? .5 : (musicTrack.western ? .34 : .28); | |
| const o=actx.createOscillator(), g=actx.createGain(); | |
| o.type=musicTrack.bass||'sawtooth'; o.frequency.value=midiToFreq(m); | |
| g.gain.setValueAtTime(vol,t); | |
| g.gain.exponentialRampToValueAtTime(.001,t+dur); | |
| o.connect(g); g.connect(actx.destination); | |
| o.start(t); o.stop(t+dur+.02); | |
| } | |
| function leadNote(m,t,dur){ | |
| if(!actx) return; | |
| const vol = musicTrack.intense ? .16 : (musicTrack.western ? .12 : .10); | |
| const o=actx.createOscillator(), g=actx.createGain(); | |
| o.type=musicTrack.lead||'square'; o.frequency.value=midiToFreq(m+12); | |
| g.gain.setValueAtTime(vol,t); | |
| g.gain.exponentialRampToValueAtTime(.001,t+dur); | |
| o.connect(g); g.connect(actx.destination); | |
| o.start(t); o.stop(t+dur+.02); | |
| } | |
| function musicTick(){ | |
| if(!actx || !musicTrack) return; | |
| const spb=60/musicTrack.bpm/4; // seconds per 16th note | |
| const t0=actx.currentTime + .05; | |
| const step=musicStep%16; | |
| const sc=musicTrack.scale, root=musicTrack.root; | |
| const intense = musicTrack.intense || false; | |
| if(musicTrack.western){ | |
| // relaxing western victory theme: warm bass drone + slow plucked melody | |
| if(step===0||step===8) bassNote(root-12,t0,spb*6); | |
| else if(step%4===2) bassNote(root,t0,spb*3); | |
| const mel=[root+sc[1], root+sc[0]+7, root+sc[2], root+sc[0], | |
| root+sc[1]-12, root+sc[0], root+sc[2]+5, root+sc[1]]; | |
| if(step%4===0){ | |
| const idx=Math.floor((musicStep/16)%8); | |
| leadNote(mel[idx],t0,spb*3.2); | |
| } | |
| musicStep++; | |
| return; | |
| } | |
| // kick on every beat (steps 0,4,8,12) | |
| if(step%4===0) kick(t0); | |
| // hats: denser + louder when intense | |
| if(intense){ hat(t0,(step%2===1)); } | |
| else { if(step%2===1) hat(t0,false); else if(step===8) hat(t0,true); } | |
| // driving bassline; final-form theme plays nearly every step for a wall of sound | |
| const bM = (step%4===0)?root+12 : root; | |
| if(intense ? true : (step%2===0 || step%4===3)) bassNote(bM,t0,spb*.9); | |
| // lead: final-form theme plays fast arpeggios on every beat | |
| const idx=[0,2,1,3][Math.floor((musicStep/16)%4)]; | |
| if(intense){ | |
| if(step%2===0) leadNote(root+sc[idx],t0,spb*.9); | |
| if(step%4===1) leadNote(root+sc[(idx+2)%sc.length]+12,t0,spb*.7); // harmony stab | |
| } else { | |
| if(step%4===1) leadNote(root+sc[idx],t0,spb*1.8); | |
| } | |
| musicStep++; | |
| } | |
| function startMusic(lv){ | |
| stopMusic(); | |
| if(!actx) return; | |
| const key=Math.min(Math.max(0,lv),8); // allow final-form (7) & victory (8) tracks | |
| musicTrack=MUSIC[key]||MUSIC[0]; | |
| musicStep=0; | |
| // schedule from a fixed interval; Web Audio timestamps keep it tight | |
| musicTimer=setInterval(musicTick, 60/musicTrack.bpm/4*1000); | |
| } | |
| function stopMusic(){ | |
| if(musicTimer){ clearInterval(musicTimer); musicTimer=null; } | |
| musicTrack=null; | |
| } | |
| // ---------- Game state ---------- | |
| let W = c.width, H = c.height; | |
| // cached glow gradients (centered at origin; safe to reuse after translate) | |
| const enemyGlow=ctx.createRadialGradient(0,0,2,0,0,26); | |
| enemyGlow.addColorStop(0,'rgba(255,150,180,.4)'); | |
| enemyGlow.addColorStop(1,'transparent'); | |
| // shared hull shading (cached; reused after translate so no per-enemy gradients) | |
| const hullSheen=ctx.createLinearGradient(0,-20,0,22); | |
| hullSheen.addColorStop(0,'rgba(255,255,255,.5)'); | |
| hullSheen.addColorStop(.45,'rgba(120,180,240,.08)'); | |
| hullSheen.addColorStop(1,'rgba(10,4,20,.55)'); | |
| // shared enemy eye glows (cached) | |
| const enemyEyeYellow=ctx.createRadialGradient(0,0,.5,0,0,6); | |
| enemyEyeYellow.addColorStop(0,'#fff'); enemyEyeYellow.addColorStop(.45,'#ffd23b'); enemyEyeYellow.addColorStop(1,'transparent'); | |
| const enemyEyeRed=ctx.createRadialGradient(0,0,.5,0,0,7); | |
| enemyEyeRed.addColorStop(0,'#fff'); enemyEyeRed.addColorStop(.4,'#ff3355'); enemyEyeRed.addColorStop(1,'transparent'); | |
| let state = 'menu'; // menu | playing | levelclear | gameover | win | |
| const MAX_HP = 20; | |
| let hp = MAX_HP, score = 0, hiScore = loadHi(); | |
| let keys = {}; | |
| let mouse = { x: W/2, y: H-80, down: false }; | |
| let shake = 0; | |
| let bombFlash = 0; // timer for the periodic orange flame flash after a bomb | |
| // ---------- Entities ---------- | |
| let player, bullets = [], ebullets = [], enemies = [], powerups = [], | |
| particles = [], stars = [], floaters = []; | |
| // ---------- Level config ---------- | |
| const LEVELS = [ | |
| { name:'Asteroid Belt', rows:3, cols:8, hp:1, speed:.6, shoot:.012, color:'#ff5d73', types:['drone'] }, | |
| { name:'Scrap Fields', rows:4, cols:9, hp:2, speed:.85,shoot:.02, color:'#ffb45d', types:['drone','dart'] }, | |
| { name:'The Gauntlet', rows:5, cols:10, hp:3, speed:1.1, shoot:.028,color:'#c15dff', types:['drone','weaver'] }, | |
| { name:'Ion Storm', rows:5, cols:11, hp:4, speed:1.2, shoot:.035,color:'#39e6a8', types:['sentinel','drone'] }, | |
| { name:'Void Reach', rows:6, cols:12, hp:5, speed:1.3, shoot:.04, color:'#ff9d3b', types:['weaver','dart','sentinel'] }, | |
| { name:'The Core', rows:6, cols:13, hp:6, speed:1.4, shoot:.045,color:'#e63bf0', types:['drone','weaver','sentinel','dart'] }, | |
| ]; | |
| // Enemy type definitions (size + HP multiplier for each variant) | |
| const ETYPES = { | |
| drone: { w:34,h:26, mult:1 }, // default teardrop | |
| dart: { w:22,h:30, mult:.6 }, // fast dive-rammer | |
| weaver: { w:28,h:24, mult:1.4 }, // zigzag shooter | |
| sentinel:{ w:42,h:34, mult:3 } // slow tank with spread fire | |
| }; | |
| // consistent per-type speed multiplier (same type always moves the same). | |
| // fast movers (dart/weaver) are 10% slower than before. | |
| const ENEMY_SPEED = { drone:1, dart:2.34, weaver:1.35, sentinel:.7 }; | |
| const BOSS_THEME = 6; // background theme index for the final fight | |
| const MINI_THEME = 2; // background theme for the mid-game mini boss | |
| const MINIBOSS_AT = 3; // appears in the middle of the level list | |
| let MINI_DONE=false; // only fought once per run | |
| const BOSS = { | |
| hp: 3600*2.25, maxHp: 7200*2.15, baseMaxHp: 16200, x: W/2, y: -80, vy: 4, | |
| phase:0, timer:0, color:'#5defff', flash:0, enraged:false, final:false | |
| }; | |
| let cutT=0; // frames elapsed in the boss-fight cutscene | |
| // mid-game mini boss (simpler than the final Dreadnought) | |
| const MINIBOSS = { | |
| hp:1350, maxHp:2700, x:W/2, y:-80, vy:4, | |
| timer:0, color:'#ffb45d', flash:0 | |
| }; | |
| // ---------- Scenery / stars ---------- | |
| // parallax background: three layers scrolling at different speeds | |
| let bgLayers=[], scrollY=[0,0,0]; | |
| function drawAsteroid(bctx,x,y,r,col){ | |
| bctx.fillStyle=col; | |
| bctx.beginPath(); | |
| const pts=7+Math.floor(Math.random()*4); | |
| for(let i=0;i<pts;i++){ | |
| const a=i/pts*Math.PI*2, rr=r*(.6+Math.random()*.5); | |
| const px=x+Math.cos(a)*rr, py=y+Math.sin(a)*rr; | |
| if(i===0) bctx.moveTo(px,py); else bctx.lineTo(px,py); | |
| } | |
| bctx.closePath(); bctx.fill(); | |
| } | |
| function drawScrap(bctx,x,y,col){ | |
| bctx.save(); | |
| bctx.translate(x,y); | |
| bctx.rotate(Math.random()*Math.PI*2); | |
| bctx.fillStyle=col; | |
| const w=6+Math.random()*18, h=3+Math.random()*8; | |
| bctx.fillRect(-w/2,-h/2,w,h); | |
| // a bolt/hole | |
| bctx.strokeStyle='rgba(0,0,0,.4)'; bctx.lineWidth=1.5; | |
| bctx.beginPath(); bctx.arc(0,0,Math.min(w,h)*.25,0,Math.PI*2); bctx.stroke(); | |
| bctx.restore(); | |
| } | |
| function drawCrystal(bctx,x,y,col){ | |
| bctx.save(); | |
| bctx.translate(x,y); | |
| const s=6+Math.random()*14; | |
| bctx.fillStyle=col; bctx.globalAlpha=.8; | |
| bctx.beginPath(); bctx.moveTo(0,-s); bctx.lineTo(s*.5,s*.4); bctx.lineTo(-s*.55,s*.3); | |
| bctx.closePath(); bctx.fill(); | |
| bctx.restore(); | |
| } | |
| function drawPlanet(bctx,x,y,r,col){ | |
| // soft-lit planet body (no hard edge, so it blends into the scene) | |
| const pg=bctx.createRadialGradient(x-r*.3,y-r*.4,r*.1,x,y,r); | |
| pg.addColorStop(0,'#fff'); pg.addColorStop(.25,col); pg.addColorStop(1,'rgba(10,5,20,.95)'); | |
| bctx.fillStyle=pg; | |
| bctx.beginPath(); bctx.arc(x,y,r,0,Math.PI*2); bctx.fill(); | |
| // terminator shadow for depth | |
| const sh=bctx.createRadialGradient(x+r*.4,y-r*.3,r*.1,x,y,r); | |
| sh.addColorStop(0,'rgba(5,10,25,0)'); sh.addColorStop(.6,'rgba(8,12,30,.35)'); sh.addColorStop(1,'rgba(2,4,15,.85)'); | |
| bctx.fillStyle=sh; | |
| bctx.beginPath(); bctx.arc(x,y,r,0,Math.PI*2); bctx.fill(); | |
| } | |
| function drawStarBase(bctx,x,y,s,col){ | |
| // small sci-fi station: elliptical platform + glowing hub + antenna | |
| bctx.save(); bctx.translate(x,y); | |
| bctx.fillStyle=col; | |
| bctx.beginPath(); bctx.ellipse(0,0,s*1.4,s*.7,0,0,Math.PI*2); bctx.fill(); | |
| bctx.strokeStyle='rgba(255,255,255,.45)'; bctx.lineWidth=1.5; | |
| bctx.beginPath(); bctx.ellipse(0,0,s*1.4,s*.7,0,0,Math.PI*2); bctx.stroke(); | |
| const hg=bctx.createRadialGradient(-s*.3,-s*.35,s*.05,0,0,s); | |
| hg.addColorStop(0,'#fff'); hg.addColorStop(.5,col); hg.addColorStop(1,'rgba(12,10,28,.9)'); | |
| bctx.fillStyle=hg; | |
| bctx.beginPath(); bctx.arc(0,0,s*.55,0,Math.PI*2); bctx.fill(); | |
| bctx.strokeStyle='rgba(255,255,255,.6)'; bctx.lineWidth=1.5; | |
| bctx.beginPath(); bctx.moveTo(-s*.3,-s*.4); bctx.lineTo(s*.25,-s*1.2); bctx.stroke(); | |
| bctx.fillStyle='#ffd23b'; | |
| bctx.beginPath(); bctx.arc(0,s*.55,s*.12,0,Math.PI*2); bctx.fill(); | |
| bctx.restore(); | |
| } | |
| function buildBackground(lv){ | |
| // Pre-render a themed background once to an offscreen canvas (2x screen | |
| // height so the vertical scroll wraps smoothly). Each frame we just drawImage | |
| // it twice with an offset — far cheaper than drawing scenery live. | |
| const themes=[ | |
| { // Level 1: Asteroid Belt | |
| grad:['#0a1628','#12263f','#20101c'], | |
| nebula:[['rgba(90,140,220,.07)',180],['rgba(200,80,40,.06)',150]], | |
| starCol:'#dfeaff', stars:130, | |
| decor:{type:'asteroid',count:22,col:'rgba(160,120,85,.5)'} | |
| }, | |
| { // Level 2: Scrap Fields | |
| grad:['#0b1a14','#12301f','#1c1810'], | |
| nebula:[['rgba(80,200,140,.06)',170],['rgba(220,150,50,.05)',160]], | |
| starCol:'#eaffea', stars:110, | |
| decor:{type:'scrap',count:40,col:'#8a6b3f'} | |
| }, | |
| { // Level 3: The Gauntlet | |
| grad:['#140a28','#2a0f38','#1c0430'], | |
| nebula:[['rgba(200,80,220,.09)',190],['rgba(40,180,255,.07)',170]], | |
| starCol:'#ffd6ff', stars:150, | |
| decor:{type:'crystal',count:26,col:'#e05dff'} | |
| }, | |
| { // Level 4: Ion Storm | |
| grad:['#04120f','#0a3a28','#10301e'], | |
| nebula:[['rgba(80,255,180,.07)',190],['rgba(60,120,250,.06)',170]], | |
| starCol:'#d8ffe9', stars:140, | |
| decor:{type:'crystal',count:30,col:'#39e6a8'} | |
| }, | |
| { // Level 5: Void Reach | |
| grad:['#1a0f05','#3a2008','#241004'], | |
| nebula:[['rgba(255,150,50,.08)',180],['rgba(120,40,20,.07)',160]], | |
| starCol:'#ffe6c9', stars:130, | |
| decor:{type:'asteroid',count:30,col:'rgba(200,140,60,.5)'} | |
| }, | |
| { // Level 6: The Core | |
| grad:['#1a0420','#3b0650','#18022a'], | |
| nebula:[['rgba(230,59,240,.10)',190],['rgba(120,40,255,.08)',170]], | |
| starCol:'#ffd6ff', stars:160, | |
| decor:{type:'crystal',count:34,col:'#e63bf0'} | |
| }, | |
| { // Final Boss: Dreadnought | |
| grad:['#02030a','#070b1f','#12041a'], | |
| nebula:[['rgba(90,220,255,.08)',200],['rgba(180,40,80,.06)',170]], | |
| starCol:'#cfeaff', stars:150, | |
| decor:{type:'scrap',count:26,col:'#3d4f66'} | |
| } | |
| ]; | |
| const th=themes[Math.min(lv,themes.length-1)]; | |
| // keep large scenery clear of the wrap seam so it tiles seamlessly | |
| const SEAM=40; | |
| // build three parallax layers: far (slow), mid, near (fast) | |
| bgLayers=[]; | |
| const bh=H*2; | |
| function newLayer(){ const c=document.createElement('canvas'); c.width=W; c.height=bh; return {c:c,cx:c.getContext('2d'),spd:1}; } | |
| // far layer = deep space (gradient + nebula), scrolls slowest | |
| { | |
| const L=newLayer(); bgLayers.push(L); L.spd=.25; | |
| const g=L.cx.createLinearGradient(0,0,0,bh); | |
| th.grad.forEach((c,i)=>g.addColorStop(i/(th.grad.length-1),c)); | |
| L.cx.fillStyle=g; L.cx.fillRect(0,0,W,bh); | |
| for(let i=0;i<14;i++){ | |
| const x=Math.random()*W, y=Math.random()*bh; | |
| const nb=th.nebula[i%2]; | |
| const r=nb[1]*(.5+Math.random()); | |
| L.cx.fillStyle=nb[0]; | |
| L.cx.beginPath(); L.cx.arc(x,y,r,0,Math.PI*2); L.cx.fill(); | |
| } | |
| } | |
| // mid layer = distant stars + planets/bases | |
| { | |
| const L=newLayer(); bgLayers.push(L); L.spd=.6; | |
| for(let i=0;i<th.stars;i++){ | |
| const x=Math.random()*W, y=Math.random()*bh; | |
| const r=.4+Math.random()*1.3; | |
| L.cx.globalAlpha=.5+Math.random()*.45; | |
| L.cx.fillStyle=i%7===0?'#fff':th.starCol; | |
| L.cx.beginPath(); L.cx.arc(x,y,r,0,Math.PI*2); L.cx.fill(); | |
| } | |
| L.cx.globalAlpha=1; | |
| const nPlanets=2+Math.floor(Math.random()*3); | |
| for(let i=0;i<nPlanets;i++){ | |
| drawPlanet(L.cx,20+Math.random()*(W-40),SEAM+Math.random()*(bh-2*SEAM),12+Math.random()*26,th.grad[1]); | |
| } | |
| } | |
| // near layer = themed scenery + star bases, scrolls fastest | |
| { | |
| const L=newLayer(); bgLayers.push(L); L.spd=1; | |
| const d=th.decor; | |
| for(let i=0;i<d.count;i++){ | |
| const x=Math.random()*W, y=SEAM+Math.random()*(bh-2*SEAM); | |
| if(d.type==='asteroid') drawAsteroid(L.cx,x,y,15+Math.random()*35,d.col); | |
| else if(d.type==='scrap') drawScrap(L.cx,x,y,d.col); | |
| else if(d.type==='crystal') drawCrystal(L.cx,x,y,d.col); | |
| } | |
| const nBases=2+Math.floor(Math.random()*3); | |
| for(let i=0;i<nBases;i++){ | |
| drawStarBase(L.cx,20+Math.random()*(W-40),SEAM+Math.random()*(bh-2*SEAM),9+Math.random()*11,'#6b7f9e'); | |
| } | |
| } | |
| scrollY=[0,0,0]; | |
| } | |
| function makeFloaters(){ | |
| floaters = []; | |
| } | |
| // ---------- Player ---------- | |
| function resetPlayer(){ | |
| player = { | |
| x: W/2, y: H-70, w:34, h:26, | |
| fireRate:.18, lastShot:0, power:1, speed:5.5, shield:0, | |
| bombs:1, // start with 1 smart bomb (max 3) | |
| lvl:{ rapid:0, triple:0, shield:0, homing:0 } // 0 = not collected yet | |
| }; | |
| } | |
| function drawShip(x,y,w,h,col){ | |
| const t=performance.now()/100; | |
| const s=w/34; // scale factor (base width ~34) | |
| ctx.save(); | |
| ctx.translate(x,y); | |
| ctx.scale(s,s); | |
| // twin engine flames (flickering, layered teal-orange) | |
| for(const ex of [-5.5,5.5]){ | |
| const fl=(Math.random()*7+10)*(0.8+0.3*Math.sin(t)); | |
| const fg=ctx.createLinearGradient(0,h/2-4,0,h/2+fl); | |
| fg.addColorStop(0,'rgba(255,220,120,.95)'); | |
| fg.addColorStop(.5,'rgba(90,180,250,.85)'); | |
| fg.addColorStop(1,'transparent'); | |
| ctx.fillStyle=fg; | |
| ctx.beginPath(); | |
| ctx.moveTo(ex-3,h/2-4); ctx.quadraticCurveTo(ex-1.5,h/2+fl*0.55,ex,h/2+fl); | |
| ctx.lineTo(ex+.5,h/2+fl*.6); ctx.quadraticCurveTo(ex+2,h/2+fl*.3,ex+3,h/2-4); | |
| ctx.closePath(); ctx.fill(); | |
| } | |
| // delta wings (swept back) | |
| const wg=ctx.createLinearGradient(-w/2/s,0,w/2/s,0); | |
| wg.addColorStop(0,'#1c2740'); wg.addColorStop(.5,col); wg.addColorStop(1,'#1c2740'); | |
| ctx.fillStyle=wg; | |
| ctx.beginPath(); | |
| ctx.moveTo(-6,-h*0.28); // left wing root | |
| ctx.lineTo(-w/2/s,h*0.18); // left wingtip (out & back) | |
| ctx.lineTo(-w*.22/s,h*0.5); | |
| ctx.lineTo(0,h*0.34); // tail center notch | |
| ctx.lineTo(w*.24/s,h*0.52); | |
| ctx.lineTo(w/2/s,h*0.18); // right wingtip | |
| ctx.lineTo(6,-h*0.28); // right wing root | |
| ctx.closePath(); ctx.fill(); | |
| // wing highlight lines | |
| ctx.strokeStyle='rgba(255,255,240,.35)'; ctx.lineWidth=1; | |
| ctx.beginPath(); ctx.moveTo(-5,-h*0.2); ctx.lineTo(-w*.3/s,h*0.16); ctx.stroke(); | |
| ctx.beginPath(); ctx.moveTo(5,-h*0.22); ctx.lineTo(w*.32/s,h*0.14); ctx.stroke(); | |
| // fuselage (central body, pointed nose up) | |
| const bg=ctx.createLinearGradient(0,-h/2,0,h/2); | |
| bg.addColorStop(0,'#eafcff'); | |
| bg.addColorStop(.45,col); | |
| bg.addColorStop(1,'rgba(15,22,45,.95)'); | |
| ctx.fillStyle=bg; | |
| ctx.strokeStyle='rgba(255,255,240,.6)'; ctx.lineWidth=1.2; | |
| ctx.beginPath(); | |
| ctx.moveTo(0,-h/2); // nose tip | |
| ctx.quadraticCurveTo(w*.16/s,-h*0.05,w*.13/s,h*0.18); | |
| ctx.lineTo(-w*.14/s,h*0.28); | |
| ctx.lineTo(-w*.17/s,h*0.42); | |
| ctx.quadraticCurveTo(0,h*0.5, w*.16/s,h*0.4); // tail | |
| ctx.lineTo(w*.15/s,h*0.2); | |
| ctx.quadraticCurveTo(-w*.14/s,-h*0.02,-w*.04/s,-h/2+1); | |
| ctx.closePath(); ctx.fill(); ctx.stroke(); | |
| // central spine highlight | |
| ctx.strokeStyle='rgba(255,255,240,.5)'; ctx.lineWidth=1; | |
| ctx.beginPath(); ctx.moveTo(0,-h*0.46); ctx.lineTo(0,h*0.3); ctx.stroke(); | |
| // cockpit canopy (teardrop) | |
| const cg=ctx.createRadialGradient(-w*.02/s,-h*0.16,1,-w*.01/s,-h*0.14,w*.12); | |
| cg.addColorStop(0,'#ffffff'); cg.addColorStop(.45,'#6fd4ff'); cg.addColorStop(1,'rgba(20,40,80,.9)'); | |
| ctx.fillStyle=cg; | |
| ctx.beginPath(); | |
| ctx.moveTo(-w*.02/s,-h*0.3); | |
| ctx.quadraticCurveTo(w*.14/s,-h*0.18,w*.09/s,-h*0.03); | |
| ctx.lineTo(-w*.11/s,-h*0.01); | |
| ctx.quadraticCurveTo(-w*.15/s,-h*0.2,-w*.02/s,-h*0.3); | |
| ctx.closePath(); ctx.fill(); | |
| // wingtip nav lights | |
| ctx.fillStyle='#ff4dd2'; | |
| ctx.beginPath(); ctx.arc(-w/2/s+1,h*0.14,2.2,0,Math.PI*2); ctx.fill(); | |
| ctx.fillStyle='#5dff9a'; | |
| ctx.beginPath(); ctx.arc(w/2/s-1,h*0.15,2.2,0,Math.PI*2); ctx.fill(); | |
| // engine nozzle glows | |
| ctx.fillStyle='rgba(120,220,255,.8)'; | |
| ctx.beginPath(); ctx.ellipse(-5.5,h*0.34,2.6,3,0,0,Math.PI*2); ctx.fill(); | |
| ctx.beginPath(); ctx.ellipse(5.5,h*0.33,2.6,3,0,0,Math.PI*2); ctx.fill(); | |
| ctx.restore(); | |
| } | |
| // ---------- Spawn level (cluster-based pacing) ---------- | |
| let clusterQueue=[]; // pending clusters awaiting release | |
| // enemies queue their shots here and fire one volley at a time, so a big | |
| // cluster never dumps all its bullets simultaneously. | |
| let shootQueue=[], shootCooldown=0; | |
| // powerup pacing: drop one random powerup every `killsPerPowerup` kills | |
| let killCount=0, killsPerPowerup=1; | |
| function buildClusters(L,lv){ | |
| // how far through the game we are: drives density + break timing | |
| const progress = Math.min(1,(LEVELS.length>1? lv/(LEVELS.length-1):0)); | |
| // breaks shrink from [3,6]s at level 1 down to [1.5,3]s by the final stage | |
| const bMin=3 - 1.5*progress; | |
| const bMax=6 - 3*progress; | |
| // clusters get bigger with each level and grow within a single stage too | |
| const baseSize = Math.round(4 + 8*progress); | |
| const nClusters = (4+lv)*2; // levels are 2x longer: doubled clusters | |
| // enemy hitpoints ramp up as levels go on: previously reached 2x, now an | |
| // extra ~15% more (up to ~2.3x) by the final stage. | |
| const hpMult = (1 + progress) * (115/100); | |
| clusterQueue=[]; | |
| for(let i=0;i<nClusters;i++){ | |
| // pick this cluster's mix of up to 3 distinct movement patterns now so we | |
| // can size the following break by how fast those enemies move. | |
| const chosen=[]; | |
| while(chosen.length < Math.min(3,L.types.length)){ | |
| const t=L.types[Math.floor(Math.random()*L.types.length)]; | |
| if(!chosen.includes(t)) chosen.push(t); | |
| } | |
| // wait time is ~75% proportional to the cluster's average enemy speed: | |
| // faster clusters get a longer break so the player has time to deal with them. | |
| const avgSpd = chosen.reduce((a,t)=>a+(ENEMY_SPEED[t]||0.6),0)/chosen.length; | |
| const breakScale = 0.25 + 0.75*avgSpd; // drone(1)->1, dart(~2.3)->~2 | |
| // per-cluster variety: pick a lane pattern and size jitter so each wave feels distinct | |
| const patterns=[ | |
| {lanes:[W*.5]}, // center push | |
| {lanes:[W*.25,W*.75]}, // split flanks (two lanes) | |
| {lanes:[W*.2]}, // far left rush | |
| {lanes:[W*.8]}, // far right rush | |
| {lanes:[W*.35,W*.65]}, // inner pair | |
| {lanes:[W/2], spread:1.4} // wide center swarm | |
| ]; | |
| const pattern=patterns[Math.floor(Math.random()*patterns.length)]; | |
| clusterQueue.push({ | |
| t:0, | |
| // first cluster arrives almost immediately; then a scaled break between | |
| // each. Breaks are 33% longer than before (x4/3) so stages breathe more. | |
| spawnDelaySecs: i===0 ? .2 : (bMin+Math.random()*(bMax-bMin))*breakScale*1.333, | |
| // cluster growth within a stage is 25% slower, with per-cluster size jitter | |
| size: baseSize + Math.floor(i*1.125) + Math.round(Math.random()*3), | |
| heavyChance:.07, L, hpMult, chosen, pattern | |
| }); | |
| } | |
| // each level hands out fewer powerups: one every N kills. The drop rate also | |
| // falls ~3% per progressive level (later stages are stingier with loot). | |
| const totalEnemies = clusterQueue.reduce((a,c)=>a+c.size,0); | |
| killCount=0; | |
| const lvlFactor = Math.pow(1.03, Math.max(0,lv)); // +3%/level fewer drops | |
| killsPerPowerup = Math.max(1, Math.round(totalEnemies/28.2*lvlFactor)); | |
| } | |
| function spawnCluster(c){ | |
| const L=c.L; | |
| // reuse the type mix + lane pattern decided when this cluster was scheduled | |
| const chosen = c.chosen || L.types.slice(0,Math.min(3,L.types.length)); | |
| const pat = c.pattern || {lanes:[W*.5]}; | |
| for(let i=0;i<c.size;i++){ | |
| const type = chosen[i%chosen.length]; | |
| const T = ETYPES[type]||ETYPES.drone; | |
| // rare heavy tank inside the cluster | |
| const isHeavy = Math.random()<c.heavyChance; | |
| // anchor each enemy around one of this pattern's lanes (round-robin), | |
| // with a spread that scales for wide-swarm patterns | |
| const laneX = pat.lanes[i%pat.lanes.length]; | |
| const spdSpread = 70*(pat.spread||1); | |
| const sx = Math.max(20,Math.min(W-20,laneX+(Math.random()-.5)*spdSpread)); | |
| enemies.push({ | |
| x:sx, | |
| y: -40-Math.random()*130, // stream in as a tight group | |
| w:T.w*(isHeavy?2:1), h:T.h*(isHeavy?2:1), type, | |
| hp:(L.hp*c.hpMult*(isHeavy?32:1))*T.mult, maxHp:(L.hp*c.hpMult*(isHeavy?32:1))*T.mult, color:L.color, | |
| speed:(L.speed*(ENEMY_SPEED[type]||0.6)) * (isHeavy?.4:1), | |
| vMult:1, amp:15+Math.random()*30, | |
| sway:.03+Math.random()*.09, | |
| baseX:sx, t:i*2, | |
| fireT:Math.random()*120, | |
| delay:(i%3===0)?8:0, // tiny stagger within the cluster | |
| hoverY:60+Math.random()*(H*.6), | |
| heavy:isHeavy, | |
| // bigger clusters drop powerups less often per enemy (density control) | |
| dropMult: Math.min(1, 12/c.size) | |
| }); | |
| } | |
| } | |
| function updateClusterSpawn(dt){ | |
| if(state!=='playing') return; | |
| for(let i=clusterQueue.length-1;i>=0;i--){ | |
| const c=clusterQueue[i]; | |
| c.t+=dt; | |
| if(c.t >= c.spawnDelaySecs*55){ spawnCluster(c); clusterQueue.splice(i,1); } | |
| } | |
| } | |
| function spawnLevel(lv){ | |
| enemies = []; ebullets=[]; powerups=[]; | |
| shootQueue=[]; shootCooldown=0; | |
| buildClusters(LEVELS[lv], lv); | |
| } | |
| // ---------- Boss ---------- | |
| function spawnMinion(side){ | |
| enemies.push({ | |
| isMinion:true, side, | |
| x:BOSS.x+side*130, y:BOSS.y+90, | |
| w:30,h:24, hp:4, maxHp:4, color:'#ff5d73', | |
| ang:Math.random()*6.28, fireT:0 | |
| }); | |
| } | |
| function spawnBoss(){ | |
| enemies = []; ebullets=[]; | |
| BOSS.final=false; | |
| BOSS.maxHp=BOSS.baseMaxHp; BOSS.hp=BOSS.maxHp; | |
| BOSS.x=W/2; BOSS.y=-80; BOSS.phase=0; | |
| BOSS.timer=0; BOSS.minionTimer=0; BOSS.enraged=false; | |
| enemies.push({ isBoss:true, x:BOSS.x, y:BOSS.y, w:120, h:110 }); | |
| spawnMinion(-1); | |
| spawnMinion(1); | |
| } | |
| // the boss's true form: +50% life and comes with two minions | |
| function spawnFinalBoss(){ | |
| enemies = []; ebullets=[]; | |
| BOSS.final=true; | |
| BOSS.maxHp=Math.round(BOSS.baseMaxHp*1.5); BOSS.hp=BOSS.maxHp; // +50% life | |
| BOSS.x=W/2; BOSS.y=-80; BOSS.phase=0; | |
| BOSS.timer=0; BOSS.minionTimer=0; BOSS.enraged=false; BOSS.redT=0; | |
| enemies.push({ isBoss:true, x:BOSS.x, y:BOSS.y, w:120, h:110 }); | |
| spawnMinion(-1); | |
| spawnMinion(1); // two minions from the start | |
| state='playing'; // leave cutscene and begin the final-form fight | |
| startMusic(7); // super intense final-form theme | |
| } | |
| function spawnMiniBoss(){ | |
| enemies = []; ebullets=[]; | |
| MINIBOSS.hp=MINIBOSS.maxHp; MINIBOSS.x=W/2; MINIBOSS.y=-80; | |
| MINIBOSS.timer=0; MINIBOSS.flash=0; MINIBOSS.pattern=0; MINIBOSS.fanT=-99; MINIBOSS.ringT=-99; | |
| enemies.push({ isMiniBoss:true, x:MINIBOSS.x, y:MINIBOSS.y, w:90,h:78 }); | |
| } | |
| function updateMiniBoss(dt){ | |
| const b=MINIBOSS; | |
| enemies[0].x=b.x; enemies[0].y=b.y; | |
| if(b.flash>0) b.flash-=dt*30; | |
| // descend to fighting position | |
| if(b.y<120){ b.y+=b.vy*dt; return; } | |
| b.timer+=dt; | |
| b.x += Math.sin(Date.now()/300)*1.8; | |
| // three rotating attack patterns for variety | |
| const phase = (b.pattern||0)%3; | |
| if(phase===0){ | |
| // aimed shots at the player (spread of 3) | |
| if(Math.random()<.012){ | |
| const a=Math.atan2(player.y-b.y,player.x-b.x); | |
| for(let i=-1;i<=1;i++){ | |
| ebullets.push({x:b.x,y:b.y+30,w:8,h:10, | |
| vx:Math.cos(a+i*.18)*3,vy:Math.sin(a+i*.16)*3,col:'#ff9d5d'}); | |
| } | |
| } | |
| } else if(phase===1){ | |
| // periodic fan volley | |
| if(b.timer>70 && b.fanT!==b.timer){ | |
| b.fanT=b.timer; | |
| for(let i=-2;i<=2;i++){ | |
| const a=i*.24 + Math.sin(Date.now()/400)*.3; | |
| ebullets.push({x:b.x,y:b.y+30,w:7,h:9,vx:a*1.6,vy:3,col:'#ffb45d'}); | |
| } | |
| } | |
| } else { | |
| // radial ring burst | |
| if(b.timer>110 && b.ringT!==b.timer){ | |
| b.ringT=b.timer; | |
| for(let i=0;i<12;i++){ | |
| const a=i/12*Math.PI*2 + Date.now()*.0005; | |
| ebullets.push({x:b.x,y:b.y+20,w:7,h:9, | |
| vx:Math.cos(a)*3.4,vy:Math.sin(a)*3.4,col:'#ff6b8a'}); | |
| } | |
| } | |
| } | |
| // advance to the next pattern every ~2.5s | |
| if(b.timer>150){ | |
| b.pattern=(b.pattern||0)+1; | |
| b.timer=0; b.fanT=-99; b.ringT=-99; | |
| } | |
| } | |
| function miniBossDeath(){ | |
| score+=500; shake=18; | |
| enemies=[]; | |
| boom(MINIBOSS.x,MINIBOSS.y,'#ffb45d',70,6); | |
| SFX.bossDie(); | |
| for(let i=0;i<20;i++) spawnPowerup(Math.random()*W,Math.random()*200); | |
| MINI_DONE=true; | |
| // continue with the normal level that follows it | |
| buildBackground(level); spawnLevel(level); | |
| state='playing'; | |
| } | |
| function drawMiniBoss(){ | |
| const b=MINIBOSS, flash=b.flash>0; | |
| const t=performance.now()/100; | |
| ctx.save(); | |
| ctx.translate(b.x,b.y); | |
| // pulsing core | |
| const pulse=.5+.5*Math.sin(t*2.4); | |
| ctx.globalAlpha=(.3+.25*pulse); ctx.fillStyle='#ffb45d'; | |
| ctx.beginPath(); ctx.arc(0,0,(42+pulse*8),0,Math.PI*2); ctx.fill(); | |
| ctx.globalAlpha=.35; ctx.fillStyle='#fff4dd'; | |
| ctx.beginPath(); ctx.arc(0,0,28,0,Math.PI*2); ctx.fill(); | |
| ctx.globalAlpha=1; | |
| // hull | |
| const hg=ctx.createLinearGradient(0,-40,0,10); | |
| hg.addColorStop(0,'#fff4dd'); hg.addColorStop(.5,b.color); hg.addColorStop(1,'rgba(20,15,30,.95)'); | |
| ctx.fillStyle = flash ? '#ffffff' : hg; | |
| ctx.strokeStyle='#ffd9a8'; ctx.lineWidth=3; | |
| ctx.beginPath(); | |
| ctx.moveTo(0,-40); | |
| ctx.quadraticCurveTo(32,-22,42,6); | |
| ctx.lineTo(-30,12); ctx.lineTo(-44,6); | |
| ctx.quadraticCurveTo(-34,-14,-18,-28); | |
| ctx.closePath(); ctx.fill(); ctx.stroke(); | |
| // eye | |
| const ey=Math.sin(t*3)*4; | |
| ctx.fillStyle='#1a0f05'; | |
| ctx.beginPath(); ctx.ellipse(0,ey+2,16,9,0,0,Math.PI*2); ctx.fill(); | |
| ctx.fillStyle = flash?'#fff':'#ff5d3b'; | |
| ctx.beginPath(); ctx.arc(-4,ey+2,5,0,Math.PI*2); ctx.fill(); | |
| // side cannons | |
| ctx.strokeStyle='#ffe9c8'; ctx.lineWidth=3; ctx.lineCap='round'; | |
| for(let i=-1;i<=1;i+=2){ | |
| ctx.beginPath(); ctx.moveTo(i*42,6); ctx.quadraticCurveTo(i*52,-4,i*58,-10); ctx.stroke(); | |
| } | |
| ctx.restore(); | |
| } | |
| function drawMiniBossBar(){ | |
| const w=W-160,x=80,y=20,h=16; | |
| ctx.fillStyle='rgba(0,0,0,.5)'; | |
| ctx.fillRect(x,y,w,h); | |
| ctx.strokeStyle='#ffd9a8'; ctx.lineWidth=2; ctx.strokeRect(x,y,w,h); | |
| const pct=Math.max(0,MINIBOSS.hp/MINIBOSS.maxHp); | |
| const g=ctx.createLinearGradient(x,0,x+w,0); | |
| g.addColorStop(0,'#ffb45d'); g.addColorStop(1,'#ff5d3b'); | |
| ctx.fillStyle=g; ctx.fillRect(x+2,y+2,(w-4)*pct,h-4); | |
| ctx.font='bold 14px monospace'; ctx.textAlign='center'; ctx.fillStyle='#fff'; | |
| ctx.fillText('WARLORD',W/2,y+34); | |
| } | |
| function drawBoss(){ | |
| const b=BOSS, flash=b.flash>0; | |
| const t=performance.now()/100; | |
| ctx.save(); | |
| ctx.translate(b.x,b.y); | |
| // pulsing core glow (turns red when enraged) | |
| const pulse=.5+.5*Math.sin(t*(b.enraged?4:2)); | |
| const coreCol = b.enraged ? '#ff3355' : '#3fd4e8'; | |
| ctx.globalAlpha=(.35+.25*pulse)*(b.enraged?1.6:1); ctx.fillStyle=coreCol; | |
| ctx.beginPath(); ctx.arc(0,0,(60+pulse*10),0,Math.PI*2); ctx.fill(); | |
| ctx.globalAlpha=.3; ctx.fillStyle=b.enraged?'#ff5577':'#5defff'; | |
| ctx.beginPath(); ctx.arc(0,0,40,0,Math.PI*2); ctx.fill(); | |
| ctx.globalAlpha=1; | |
| // hull (gradient) | |
| const hg=ctx.createLinearGradient(0,-55,0,15); | |
| hg.addColorStop(0,'#eaffff'); | |
| hg.addColorStop(.4,b.enraged?'#c0153a':b.color); | |
| hg.addColorStop(1,'rgba(10,20,40,.95)'); | |
| ctx.fillStyle = flash ? '#ffffff' : hg; | |
| ctx.strokeStyle='#c9fbff'; ctx.lineWidth=3; | |
| ctx.beginPath(); | |
| ctx.moveTo(0,-55); | |
| ctx.quadraticCurveTo(45,-30,60,10); | |
| ctx.lineTo(-40,18); ctx.lineTo(-60,10); | |
| ctx.quadraticCurveTo(-50,-20,-25,-38); | |
| ctx.closePath(); ctx.fill(); ctx.stroke(); | |
| // armor plates | |
| ctx.strokeStyle='rgba(255,255,255,.15)'; ctx.lineWidth=2; | |
| for(let i=-1;i<=1;i++){ | |
| ctx.beginPath(); ctx.moveTo(i*18,-40); ctx.quadraticCurveTo(i*20,0,i*14,16); ctx.stroke(); | |
| } | |
| // eye (menacing) | |
| const ey = Math.sin(t*3)*4; | |
| ctx.fillStyle='#060a18'; | |
| ctx.beginPath(); ctx.ellipse(0,ey+5,22,12,0,0,Math.PI*2); ctx.fill(); | |
| const eg=ctx.createRadialGradient(-6,ey+5,1,-6,ey+5,10); | |
| eg.addColorStop(0,'#fff'); eg.addColorStop(.3,'#ff4d88'); eg.addColorStop(1,'transparent'); | |
| ctx.fillStyle = flash? '#ffffff' : eg; | |
| ctx.beginPath(); ctx.arc(-7,ey+5,6,0,Math.PI*2); ctx.fill(); | |
| ctx.fillStyle=flash?'#fff':'#ff3b6b'; | |
| ctx.beginPath(); ctx.arc(9,ey+5,4.5,0,Math.PI*2); ctx.fill(); | |
| // spikes | |
| ctx.strokeStyle='#7fe8f5'; ctx.lineWidth=3; ctx.lineCap='round'; | |
| for(let i=-1;i<=1;i+=2){ | |
| ctx.beginPath(); ctx.moveTo(i*60,10); ctx.quadraticCurveTo(i*74,-6,i*82,-14); ctx.stroke(); | |
| } | |
| // under-glow cannons | |
| ctx.fillStyle='#ff9d5d'; | |
| for(let i=-1;i<=1;i+=2){ | |
| const cg=ctx.createRadialGradient(0,24,1,0,24,8); | |
| cg.addColorStop(0,'rgba(255,180,90,.9)'); cg.addColorStop(1,'transparent'); | |
| ctx.fillStyle=cg; | |
| ctx.beginPath(); ctx.arc(i*30,26,8+pulse*3,0,Math.PI*2); ctx.fill(); | |
| } | |
| ctx.restore(); | |
| } | |
| // ---------- Powerups ---------- | |
| const PTYPES = [ | |
| { id:'rapid', col:'#ffd23b', label:'RAPID' }, | |
| { id:'triple', col:'#5dff9a', label:'TRIPLE' }, | |
| { id:'shield', col:'#6fb8ff', label:'SHIELD' }, | |
| { id:'homing', col:'#ff4dd2', label:'HOMING' }, | |
| { id:'life', col:'#ffffff', label:'+1 LIFE' }, | |
| { id:'bomb', col:'#ffd23b', label:'BOMB' } | |
| ]; | |
| function spawnPowerup(x,y){ | |
| let p; | |
| const roll=Math.random(); | |
| if(roll<0.14){ p=PTYPES[5]; } // BOMB (14%) | |
| else if(roll<0.50){ p=PTYPES[4]; } // LIFE (36%) | |
| else { p=PTYPES[[0,1,2,3][Math.floor(Math.random()*4)]]; } // rapid/triple/shield/homing | |
| // powerups fall ~2x faster than enemies so they're a bit harder to grab | |
| powerups.push({ x, y, vy:3.6, w:22, h:16, col:p.col, id:p.id, label:p.label, t:0 }); | |
| } | |
| // Called when an enemy dies. Tanks always drop; otherwise one random powerup | |
| // drops every `killsPerPowerup` kills (so each stage yields ~24 total). | |
| function tryDropFromKill(e){ | |
| if(e.heavy){ spawnPowerup(e.x,e.y); return true; } | |
| killCount++; | |
| if(killCount>=killsPerPowerup){ | |
| killCount=0; | |
| spawnPowerup(e.x,e.y); | |
| return true; | |
| } | |
| return false; | |
| } | |
| // ---------- Input ---------- | |
| addEventListener('keydown',e=>{ | |
| ensureAudio(); // unlock audio on first user gesture | |
| keys[e.key.toLowerCase()]=true; | |
| // Left Ctrl launches a smart bomb | |
| if(e.code==='ControlLeft'){ | |
| e.preventDefault(); | |
| launchBomb(); | |
| } | |
| if(e.key===' '||e.key==='Enter'){ | |
| e.preventDefault(); | |
| if(state==='menu'||state==='gameover'||state==='win') startGame(); | |
| else if(state==='levelclear') nextLevel(); | |
| } | |
| }); | |
| addEventListener('keyup',e=>keys[e.key.toLowerCase()]=false); | |
| c.addEventListener('mousemove',e=>{ | |
| const r=c.getBoundingClientRect(); | |
| mouse.x=(e.clientX-r.left)*(W/r.width); | |
| mouse.y=(e.clientY-r.top)*(H/r.height); | |
| }); | |
| addEventListener('mousedown',()=>mouse.down=true); | |
| addEventListener('mouseup',()=>mouse.down=false); | |
| // ---------- Game flow ---------- | |
| let level = 0; | |
| function startGame(){ | |
| hp=MAX_HP; score=0; level=0; MINI_DONE=false; | |
| clearTimer=0; | |
| resetPlayer(); buildBackground(0); spawnLevel(0); state='playing'; | |
| ensureAudio(); startMusic(level); | |
| } | |
| function nextLevel(){ | |
| level++; | |
| clearTimer=0; | |
| if(level<LEVELS.length){ | |
| // mini boss appears in the middle of the game (once per run) | |
| if(!MINI_DONE && level===MINIBOSS_AT){ buildBackground(MINI_THEME); spawnMiniBoss(); } | |
| else { buildBackground(level); spawnLevel(level); } | |
| } else { | |
| buildBackground(BOSS_THEME); spawnBoss(); | |
| } | |
| state='playing'; | |
| startMusic(level); | |
| } | |
| // ---------- Helpers ---------- | |
| function hitTest(a,b){ | |
| return Math.abs(a.x-b.x)<(a.w/2+b.w/2) && Math.abs(a.y-b.y)<(a.h/2+b.h/2); | |
| } | |
| function boom(x,y,col,n,spd){ | |
| for(let i=0;i<n;i++){ | |
| const a=Math.random()*Math.PI*2,v=(.5+Math.random())*spd; | |
| particles.push({x,y,vx:Math.cos(a)*v,vy:Math.sin(a)*v, | |
| r:.8+Math.random()*3,col,t:0,life:20+Math.random()*25}); | |
| } | |
| } | |
| function addText(x,y,txt,col,size){ | |
| const f={x,y,txt,col,size,t:0}; | |
| floaters.push(f); return f; | |
| } | |
| // ---------- Update ---------- | |
| let last=performance.now(); | |
| function update(dt){ | |
| if(state!=='playing'){ | |
| for(let i=particles.length-1;i>=0;i--){ | |
| const p=particles[i]; | |
| p.t++; p.x+=p.vx; p.y+=p.vy; p.vy+=.05; p.vx*=.98; p.vy*=.985; | |
| if(p.t>p.life) particles.splice(i,1); | |
| } | |
| return; | |
| } | |
| // player movement | |
| const sp=player.speed*dt; | |
| let dx=0, dy=0; | |
| if(keys['a']||keys['arrowleft']) dx-=sp; | |
| if(keys['d']||keys['arrowright']) dx+=sp; | |
| if(keys['w']||keys['arrowup']) dy-=sp; | |
| if(keys['s']||keys['arrowdown']) dy+=sp; | |
| // mouse control | |
| if(mouse.down){ | |
| const mdx=mouse.x-player.x, mdy=mouse.y-player.y; | |
| const d=Math.hypot(mdx,mdy)||1; | |
| player.x+=mdx/d*sp; player.y+=mdy/d*sp; | |
| } | |
| player.x+=dx; player.y+=dy; | |
| player.x=Math.max(20,Math.min(W-20,player.x)); | |
| // allow the ship to fly up near the top of the screen | |
| player.y=Math.max(24,Math.min(H-30,player.y)); | |
| // shooting | |
| const now=performance.now()/1000; | |
| if((keys[' ']||mouse.down)&&now-player.lastShot>player.fireRate){ | |
| player.lastShot=now; | |
| shoot(); | |
| } | |
| // bullets up (homing missiles steer toward the nearest enemy) | |
| for(let i=bullets.length-1;i>=0;i--){ | |
| const b=bullets[i]; | |
| if(b.missile){ | |
| let target=null, best=Infinity; | |
| for(const e of enemies){ | |
| if(e.isBoss||e.isMiniBoss) continue; // missiles ignore boss armor | |
| const d=(e.x-b.x)**2+(e.y-b.y)**2; | |
| if(d<best){ best=d; target=e; } | |
| } | |
| // direct lock-on: aim straight at the nearest enemy every frame. | |
| let dx=0, dy=-1; | |
| if(target){ | |
| const dist=Math.hypot(target.x-b.x,target.y-b.y)||1; | |
| dx=(target.x-b.x)/dist; dy=(target.y-b.y)/dist; | |
| } | |
| // snap heading toward the target (fast turn), keep constant speed | |
| b.vx += (dx - b.vx)*0.55*dt; | |
| b.vy += (dy - b.vy)*0.60*dt; | |
| const spd=Math.hypot(b.vx,b.vy)||1; | |
| const want = 10 + Math.min(5,(b.level||1)-1); | |
| if(spd>want){ b.vx*=want/spd; b.vy*=want/spd; } | |
| else { b.vx*=want/spd; b.vy*=want/spd; } | |
| b.x+=b.vx*dt; b.y+=b.vy*dt; | |
| } else { | |
| b.y-=b.vy*dt; | |
| } | |
| if(b.x<0||b.x>W||b.y<-20) bullets.splice(i,1); | |
| } | |
| // enemy bullets down | |
| for(let i=ebullets.length-1;i>=0;i--){ | |
| const b=ebullets[i]; | |
| b.x+=(b.vx||0)*dt; b.y+=b.vy*dt; | |
| if(b.y>H+20||b.x<-10||b.x>W+10) ebullets.splice(i,1); | |
| } | |
| updateEnemies(dt,now); | |
| // powerups | |
| for(let i=powerups.length-1;i>=0;i--){ | |
| const p=powerups[i]; | |
| p.t+=dt; p.y+=p.vy*dt; | |
| if(hitTest(p,player)){ | |
| applyPowerup(p); boom(p.x,p.y,p.col,12,2); | |
| powerups.splice(i,1); continue; | |
| } | |
| if(p.y>H+20) powerups.splice(i,1); | |
| } | |
| // collisions bullets vs enemies | |
| for(let i=bullets.length-1;i>=0;i--){ | |
| const b=bullets[i]; | |
| let hit=false; | |
| // missiles detonate on proximity so fast homing shots connect reliably | |
| const mRad = b.missile ? 34 : 0; // extra blast radius for homing warheads | |
| for(let j=enemies.length-1;j>=0;j--){ | |
| const e=enemies[j]; | |
| if(hitTest(b,e) || (mRad>0 && Math.abs(e.x-b.x)<(e.w/2+mRad) && Math.abs(e.y-b.y)<(e.h/2+mRad))){ | |
| boom(e.x,e.y,b.col,6,3); | |
| // weapon damage: each power level deals ~25% more than the last (progressive) | |
| const p=Math.max(1,Math.min(12,player.power||1)); | |
| const dmg = Math.pow(119/100, p-1); // +19% per tier (added points cut 5%) | |
| if(e.isBoss){ | |
| BOSS.hp-=dmg; BOSS.flash=8; | |
| shake=Math.max(shake,10); | |
| score+=5; | |
| if(BOSS.hp<=0){ bossDeath(); } | |
| } else if(e.isMiniBoss){ | |
| MINIBOSS.hp-=dmg; MINIBOSS.flash=8; | |
| shake=Math.max(shake,10); | |
| score+=5; | |
| if(MINIBOSS.hp<=0){ miniBossDeath(); } | |
| } else { | |
| e.hp-=dmg; e.flashT=6; // brief flash on hit | |
| if(e.hp<=0){ | |
| enemies.splice(j,1); boom(e.x,e.y,e.color,18,3.5); | |
| SFX.boom(); | |
| score+=25; | |
| tryDropFromKill(e); | |
| } | |
| } | |
| hit=true; | |
| } | |
| } | |
| if(hit) bullets.splice(i,1); | |
| } | |
| // player vs enemy / ebullet | |
| for(let i=ebullets.length-1;i>=0;i--){ | |
| const b=ebullets[i]; | |
| if(player.shield>0 && hitTest(b,player)){ | |
| boom(b.x,b.y,'#6fb8ff',5,2); | |
| player.shield--; SFX.shieldTick(); ebullets.splice(i,1); break; | |
| } | |
| else if(hitTest(b,player)){ playerHit(); ebullets.splice(i,1); break; } | |
| } | |
| for(let i=enemies.length-1;i>=0;i--){ | |
| const e=enemies[i]; | |
| if(player.shield>0){ | |
| // shield absorbs the collision with an enemy | |
| if(hitTest(e,player)){ | |
| player.shield--; SFX.shieldTick(); | |
| enemies.splice(i,1); | |
| boom(e.x,e.y,'#6fb8ff',14,3.5); | |
| break; | |
| } | |
| continue; | |
| } | |
| if(hitTest(e,player)){ | |
| playerHit(); | |
| enemies.splice(i,1); | |
| boom(e.x,e.y,e.color,20,3.5); | |
| break; | |
| } | |
| } | |
| // particles | |
| for(let i=particles.length-1;i>=0;i--){ | |
| const p=particles[i]; | |
| p.t++; p.x+=p.vx; p.y+=p.vy; p.vy+=.05; p.vx*=.98; p.vy*=.985; | |
| if(p.t>p.life) particles.splice(i,1); | |
| } | |
| } | |
| let lastMissile=0; // timestamp for homing-missile fire rate | |
| function shoot(){ | |
| SFX.laser(); | |
| const nowMs=performance.now()/1000; | |
| const pw=player.w/2+6; | |
| // homing missiles: independent fire cadence, up to ~6/sec at L12 | |
| const mLevel=(player.lvl&&player.lvl.homing)||0; | |
| if(mLevel>0 && player.missileRate){ | |
| if(nowMs-lastMissile > player.missileRate){ | |
| lastMissile=nowMs; | |
| // more missiles per volley as the homing upgrade grows (fan spread) | |
| const n = mLevel>=10?5 : mLevel>=7?4 : mLevel>=4?3 : mLevel>=2?2 : 1; | |
| for(let k=0;k<n;k++){ | |
| const span = Math.min(pw*(3+n), W*0.75); | |
| const off = (n===1)? 0 : ((k-(n-1)/2)/(n-1))*span; | |
| bullets.push({ | |
| x:player.x+off, y:player.y-10, | |
| vx:(k-(n-1)/2)*0.5, vy:-9, col:'#ff4dd2', missile:true, level:mLevel | |
| }); | |
| } | |
| } | |
| } | |
| // TRIPLE tiers map to weapon power 1..12 | |
| const p=Math.min(12,player.power||1); | |
| // bullet speed scales with level: +50% at max (power 12) | |
| const spdM = 1 + (p-1)/11*.5; | |
| // center beam (always fires) | |
| bullets.push({x:player.x,y:player.y-20,w:4,h:14,vy:11*spdM,col:'#7df9ff',hp:1}); | |
| if(p>=2){ // L1 dual | |
| bullets.push({x:player.x-pw*.55,y:player.y-13,w:3.5,h:8,vy:12*spdM,col:'#39e6a8'}); | |
| } | |
| if(p>=3){ // L2 triple (adds right beam) | |
| bullets.push({x:player.x+pw*.7,y:player.y-14,w:4,h:10,vy:11.5*spdM,col:'#5dff9a'}); | |
| } | |
| if(p>=4){ // L3 wide (outer shots) | |
| bullets.push({x:player.x-pw*2.1,y:player.y-12,w:3.5,h:9,vy:13*spdM,col:'#39e6a8'}); | |
| } | |
| if(p>=5){ // L4 extra far outer | |
| bullets.push({x:player.x+pw*2.05,y:player.y-11,w:3,h:8,vy:14*spdM,col:'#ffd23b'}); | |
| } | |
| if(p>=6){ // L5 (adds angled flanking shots) | |
| const a=.16; | |
| bullets.push({x:player.x-pw*2,y:player.y-13,w:3,h:9,vx:-Math.sin(a)*11,vy:12.8*spdM,col:'#ff4dd2'}); | |
| } | |
| if(p>=7){ // L6 (inner angled pair) | |
| const a=.22; | |
| bullets.push({x:player.x+pw*1.3,y:player.y-14,w:3,h:9,vx:Math.sin(a)*11,vy:12.4*spdM,col:'#39e6a8'}); | |
| } | |
| if(p>=8){ // L7 (full spread barrage) | |
| const a=.30; | |
| bullets.push({x:player.x,y:player.y-16,w:3,h:9,vx:-Math.sin(a)*11,vy:13.2*spdM,col:'#ff4dd2'}); | |
| } | |
| if(p>=9){ // L8 (outer angled pair) | |
| const a=.20; | |
| bullets.push({x:player.x-pw*3,y:player.y-12,w:3,h:9,vx:-Math.sin(a)*11,vy:13.6*spdM,col:'#ff4dd2'}); | |
| } | |
| if(p>=10){ // L9 (mirrored outer pair) | |
| const a=.20; | |
| bullets.push({x:player.x+pw*3,y:player.y-12,w:3,h:9,vx:Math.sin(a)*11,vy:13.6*spdM,col:'#5dff9a'}); | |
| } | |
| if(p>=11){ // L10 (tight center spread) | |
| const a=.14; | |
| bullets.push({x:player.x-pw*.4,y:player.y-16,w:3,h:9,vx:-Math.sin(a)*11,vy:13.8*spdM,col:'#ffd23b'}); | |
| } | |
| if(p>=12){ // L11-L12 max (final barrage) | |
| const a=.34; | |
| bullets.push({x:player.x+pw*.4,y:player.y-16,w:3,h:9,vx:Math.sin(a)*11,vy:13.8*spdM,col:'#ff4dd2'}); | |
| } | |
| } | |
| function updateEnemies(dt,now){ | |
| if(enemies.length && enemies[0].isMiniBoss){ updateMiniBoss(dt); return; } | |
| if(enemies.length && enemies[0].isBoss){ updateBoss(dt); return; } | |
| // per-level firing cadence (frames between shots) | |
| const interval=[130,105,85,70,60,50][level]||110; | |
| for(let i=enemies.length-1;i>=0;i--){ | |
| const e=enemies[i]; | |
| if(e.baseX===undefined) e.baseX=e.x; | |
| // tiny stagger within a cluster (a few frames at most) | |
| if((e.delay||0)>0){ e.delay-=dt; continue; } | |
| const type = e.type || 'drone'; | |
| const vm = e.vMult || 1; | |
| let fireEvery=interval, spread=false, col='#ff5d73'; | |
| // --- distinct movement patterns & positions per variant --- | |
| if(type==='weaver'){ | |
| // aggressive zigzag: wide fast sway while descending (3x faster) | |
| e.t+=dt*e.sway; | |
| e.y += e.speed*vm*4.8*.4*dt; // 2x faster descent | |
| e.x = e.baseX + Math.sin(e.t*1.3)*e.amp*1.7; | |
| col='#ff9d5b'; | |
| } else if(type==='sentinel'){ | |
| // turret: descend to its own hover row, then hold position and sway | |
| const target=e.hoverY||(60+Math.random()*(H*.6)); | |
| e.t+=dt*e.sway; | |
| if(e.y<target){ e.y += e.speed*vm*1.74*.4*dt; } // 2x faster descent | |
| else { e.y = target + Math.sin(e.t*2)*6; } | |
| e.x = e.baseX + Math.sin(e.t)*e.amp*.55; | |
| fireEvery=interval*1.5; spread=true; col='#ff9d3b'; | |
| } else if(type==='dart'){ | |
| // fast dive-rammer: plunges down with an evasive weave, doesn't shoot | |
| e.t+=dt*(e.sway||0); | |
| e.y += e.speed*vm*10.9*.4*dt; // slightly slower descent (was 13.62) | |
| e.x = e.baseX + Math.sin(e.t*2.2)*e.amp*.9; | |
| fireEvery=-1; // never fires (rams the player) | |
| } else { | |
| // drone: gentle sway, speed variation spreads the wave out (3x faster) | |
| e.t+=dt*e.sway; | |
| e.y += e.speed*vm*3.6*.4*dt; // 2x faster descent | |
| e.x = e.baseX + Math.sin(e.t)*e.amp; | |
| } | |
| // don't start shooting until this enemy is actually visible on screen | |
| if(fireEvery>0 && e.y>-10){ | |
| e.fireT=(e.fireT||0)+dt; | |
| if(e.fireT>fireEvery){ | |
| e.fireT=0; | |
| // queue a reference to the shooter; it fires when its turn comes | |
| // (one volley per 0.05s) only if it's still alive and on screen. | |
| shootQueue.push({e,spread,col}); | |
| } | |
| } | |
| // enemies that fall off the screen leave play (keeps clusters discrete) | |
| if(e.y > H+40){ enemies.splice(i,1); continue; } | |
| } | |
| } | |
| // fire queued enemy shots one volley at a time (~every 0.05s) so a large | |
| // cluster of shooters never releases too many bullets all at once. | |
| function updateShootQueue(dt){ | |
| if(!shootQueue.length){ return; } | |
| shootCooldown-=dt; | |
| while(shootCooldown<=0 && shootQueue.length){ | |
| const s=shootQueue.shift(); | |
| // skip shots whose shooter died or left the screen before its turn came | |
| if(!enemies.includes(s.e) || s.e.y<-10 || s.e.y>H+40){ continue; } | |
| const a=Math.atan2(player.y-s.e.y,player.x-s.e.x); | |
| if(s.spread){ | |
| for(let k=-1;k<=1;k++){ | |
| ebullets.push({x:s.e.x,y:s.e.y+12,w:6,h:8,vx:Math.cos(a+k*.22)*1.5,vy:3,col:s.col}); | |
| } | |
| } else { | |
| ebullets.push({x:s.e.x,y:s.e.y+10,w:6,h:8,vx:Math.cos(a)*1.5,vy:3,col:s.col}); | |
| } | |
| shootCooldown+=3; // ~0.05s between volleys at 60fps | |
| } | |
| } | |
| function updateMinion(e,dt){ | |
| // orbit around the boss while bobbing vertically | |
| e.ang+=dt*.02; | |
| const r=120+Math.sin(e.ang)*20; | |
| e.x = BOSS.x + Math.cos(e.ang*2+(e.side>0?Math.PI:0))*r; | |
| e.y = BOSS.y + 90 + Math.sin(e.ang)*45; | |
| // fire aimed shots at the player | |
| e.fireT=(e.fireT||0)+dt; | |
| if(e.fireT>70){ | |
| e.fireT=0; | |
| const a=Math.atan2(player.y-e.y,player.x-e.x); | |
| ebullets.push({x:e.x,y:e.y+10,w:7,h:9,vx:Math.cos(a)*3,vy:Math.sin(a)*3,col:'#ff5d73'}); | |
| } | |
| } | |
| function updateBoss(dt){ | |
| const b=BOSS; | |
| enemies[0].x=b.x; enemies[0].y=b.y; | |
| if(b.flash>0) b.flash-=dt*30; | |
| // move minions (they trail the boss even during entry) | |
| let aliveMinions=0; | |
| for(let i=enemies.length-1;i>=0;i--){ | |
| const e=enemies[i]; | |
| if(e.isMinion){ updateMinion(e,dt); aliveMinions++; } | |
| } | |
| // enrage below half health: faster everything + a radial burst | |
| const wasEnraged=b.enraged; | |
| b.enraged = b.hp < b.maxHp*0.5; | |
| if(b.enraged && !wasEnraged){ | |
| shake=Math.max(shake,18); | |
| for(let i=0;i<24;i++){ | |
| const a=i/24*Math.PI*2; | |
| ebullets.push({x:b.x,y:b.y,w:8,h:10,vx:Math.cos(a)*4,vy:Math.sin(a)*4,col:'#ff3b6b'}); | |
| } | |
| } | |
| // enter | |
| if(b.y<90){ b.y+=b.vy*dt; return; } | |
| // difficulty scalar: lower = harder. Both forms bumped +10% (base 1→0.9, final 0.72). | |
| const hard = b.final ? 0.7 : 0.91; | |
| const spd=b.enraged?1.7:1; | |
| b.timer+=dt*spd; | |
| b.x += Math.sin(Date.now()/400)*1.4; | |
| // spiral barrage (fires faster when enraged / in final form) | |
| if(b.phase===0 && b.timer>12){ | |
| b.phase=1; b.timer=0; | |
| } else if(b.phase===1){ | |
| const spinEvery=(b.enraged?10:16)*hard; | |
| b.spinT=(b.spinT||0)+dt; | |
| if(b.spinT>spinEvery){ | |
| b.spinT=0; | |
| const nB=b.enraged?8:6; | |
| for(let i=0;i<nB;i++){ | |
| const a=b.timer*4 + i*(Math.PI*2/nB); | |
| ebullets.push({x:b.x+Math.cos(a)*50,y:b.y+30,w:8,h:10,vy:b.enraged?3.2:2.5,col:'#ff9d5d', | |
| vx:Math.cos(a+.6)*(b.enraged?1.9:1.5)}); | |
| } | |
| } | |
| if(b.timer>16){ b.phase=0; b.timer=0; } | |
| } | |
| // aimed shots (more frequent when enraged / in final form) | |
| if(Math.random()<((b.enraged?.012:.006)/hard)){ | |
| const a=Math.atan2(player.y-b.y,player.x-b.x); | |
| ebullets.push({x:b.x,y:b.y+40,w:8,h:10,vx:Math.cos(a)*(b.enraged?3.6:3),vy:Math.sin(a)*(b.enraged?3.6:3),col:'#ff5d73'}); | |
| } | |
| // final form periodically fires an expanding ring of red bullets | |
| if(b.final){ | |
| b.redT=(b.redT||0)+dt; | |
| const every = b.enraged ? 70 : 100; // faster when enraged | |
| if(b.redT>every){ | |
| b.redT=0; | |
| for(let i=0;i<20;i++){ | |
| const a=i/20*Math.PI*2 + Date.now()*.001; | |
| ebullets.push({x:b.x,y:b.y+10,w:7,h:9, | |
| vx:Math.cos(a)*3.6,vy:Math.sin(a)*3.6,col:'#ff1f4d'}); | |
| } | |
| } | |
| } | |
| // respawn fallen minions so the fight stays intense (faster when enraged). | |
| // final form always keeps two minions on screen. | |
| b.minionTimer=(b.minionTimer||0)+dt; | |
| const wantMinions = b.final ? 2 : (b.enraged?2:1); | |
| if(aliveMinions<wantMinions && b.minionTimer>((b.enraged?90:150)*hard)){ | |
| b.minionTimer=0; | |
| spawnMinion(Math.random()>.5?1:-1); | |
| } | |
| } | |
| function applyPowerup(p){ | |
| // each type has 12 levels of progression; collecting again upgrades it | |
| if(p.id==='rapid'){ | |
| player.lvl.rapid=Math.min(12,(player.lvl.rapid||0)+1); | |
| const lv=player.lvl.rapid; | |
| player.fireRate=[0,.18,.15,.13,.115,.10,.088,.076,.066,.057,.05,.044,.039][lv]; | |
| addText(player.x,player.y-30,'RAPID L'+lv+'!','#ffd23b',16); SFX.powerup(); | |
| } | |
| else if(p.id==='triple'){ | |
| player.lvl.triple=Math.min(12,(player.lvl.triple||0)+1); | |
| const lv=player.lvl.triple; | |
| player.power=Math.min(12,1+player.lvl.triple); | |
| addText(player.x,player.y-30,'TRIPLE L'+lv+'!','#5dff9a',16); SFX.powerup(); | |
| } | |
| else if(p.id==='shield'){ | |
| player.lvl.shield=Math.min(12,(player.lvl.shield||0)+1); | |
| const lv=player.lvl.shield; | |
| player.shield=[0,3,4,6,8,10,12,14,16,18,20,22,24][lv]; | |
| // visual handled in draw | |
| addText(player.x,player.y-30,'SHIELD L'+lv+'!','#6fb8ff',16); | |
| SFX.powerup(); | |
| } | |
| else if(p.id==='homing'){ | |
| player.lvl.homing=Math.min(12,(player.lvl.homing||0)+1); | |
| const lv=player.lvl.homing; | |
| // fire interval shrinks as homing levels up: ~2.5/s at L1 up to ~10/s at L12 | |
| player.missileRate = [0,.40,.34,.29,.25,.22,.19,.165,.145,.128,.115,.105,.095][lv]; | |
| addText(player.x,player.y-42,'HOMING L'+lv+'!','#ff4dd2',16); SFX.powerup(); | |
| } | |
| else if(p.id==='life'){ | |
| hp=Math.min(MAX_HP,hp+2); | |
| addText(player.x,player.y-34,'+2 HP','#ff4dd2',18); | |
| SFX.life(); | |
| } | |
| else if(p.id==='bomb'){ | |
| player.bombs=Math.min(3,(player.bombs||0)+1); | |
| addText(player.x,player.y-30,'BOMB +1!','#ffffff',16); SFX.powerup(); | |
| } | |
| } | |
| function launchBomb(){ | |
| if((player.bombs||0)<=0 || state!=='playing') return; | |
| player.bombs--; | |
| shake=Math.max(shake,22); | |
| bombFlash = Math.max(bombFlash||0, 60); // ~1s of periodic orange flashes | |
| SFX.boom(); | |
| // clear enemy bullets | |
| for(let i=ebullets.length-1;i>=0;i--){ | |
| boom(ebullets[i].x,ebullets[i].y,'#ffd23b',6,2); ebullets.splice(i,1); | |
| } | |
| // only enemies whose graphics are fully visible get destroyed | |
| function onScreen(e){ | |
| return e.y-e.h/2>=0 && e.y+e.h/2<=H && | |
| e.x-e.w/2>=0 && e.x+e.w/2<=W; | |
| } | |
| let bombDrops=0; // a single bomb may drop at most 5 powerups | |
| for(let i=enemies.length-1;i>=0;i--){ | |
| const e=enemies[i]; | |
| if(!onScreen(e)) continue; // skip enemies still entering / off-screen | |
| if(e.isBoss){ | |
| BOSS.hp-=50; BOSS.flash=10; | |
| score+=100; | |
| boom(e.x,e.y,'#ffd23b',30,4); | |
| if(BOSS.hp<=0){ bossDeath(); } | |
| } else if(e.isMiniBoss){ | |
| MINIBOSS.hp-=50; MINIBOSS.flash=12; | |
| score+=75; | |
| boom(e.x,e.y,'#ffd23b',26,4); | |
| if(MINIBOSS.hp<=0){ miniBossDeath(); } | |
| } else { | |
| enemies.splice(i,1); boom(e.x,e.y,e.color,22,4); | |
| SFX.boom(); | |
| score+=25; | |
| if(bombDrops<5 && tryDropFromKill(e)) bombDrops++; | |
| } | |
| } | |
| } | |
| function playerHit(){ | |
| hp-=2; | |
| shake=Math.max(shake,14); | |
| player.flashT=20; // ship flashes briefly when hit | |
| boom(player.x,player.y,'#7df9ff',25,4); | |
| SFX.hurt(); | |
| if(hp<=0){ state='gameover'; stopMusic(); hiScore=Math.max(hiScore,score); saveHi(hiScore); } | |
| } | |
| function bossDeath(){ | |
| score+=1000; shake=18; | |
| enemies=[]; | |
| boom(BOSS.x,BOSS.y,'#5defff',80,6); | |
| SFX.bossDie(); | |
| for(let i=0;i<30;i++) spawnPowerup(Math.random()*W,Math.random()*200); | |
| if(!BOSS.final){ | |
| // first form down -> cutscene, then the true final form | |
| state='cutscene'; | |
| cutT=0; | |
| stopMusic(); | |
| } else { | |
| // defeated the final form: congratulations + relaxing western theme | |
| startMusic(8); | |
| state='win'; | |
| hiScore=Math.max(hiScore,score); saveHi(hiScore); | |
| } | |
| } | |
| // ---------- Draw ---------- | |
| function draw(){ | |
| // reset any leftover transform (e.g. from screen shake) so the clear and | |
| // background are always drawn at exact pixel alignment. | |
| ctx.setTransform(1,0,0,1,0,0); | |
| ctx.clearRect(0,0,W,H); | |
| // parallax background: three layers scroll at different speeds | |
| for(let li=0;li<bgLayers.length;li++){ | |
| const L=bgLayers[li]; | |
| if(!L) continue; | |
| scrollY[li]=(scrollY[li]+L.spd)%L.c.height; | |
| ctx.drawImage(L.c,0,scrollY[li]); | |
| ctx.drawImage(L.c,0,scrollY[li]-L.c.height); | |
| } | |
| // shake | |
| if(shake>0){ const o=(Math.random()-.5)*shake; ctx.translate(o,(Math.random()-.5)*shake); } | |
| drawPowerups(); | |
| // enemies / boss | |
| for(const e of enemies){ | |
| if(e.isBoss) continue; | |
| drawEnemy(e); | |
| } | |
| if(enemies.length && enemies[0].isMiniBoss){ drawMiniBoss(); drawMiniBossBar(); } | |
| else if(enemies.length && enemies[0].isBoss){ drawBoss(); drawBossBar(); } | |
| // player bullets (glowing core + trail; homing missiles get a smoky trail) | |
| for(const b of bullets){ | |
| if(b.missile){ | |
| ctx.globalAlpha=.5; | |
| ctx.fillStyle='rgba(255,77,210,.4)'; | |
| ctx.beginPath(); ctx.arc(b.x,b.y+6,7,0,Math.PI*2); ctx.fill(); | |
| ctx.globalAlpha=1; | |
| // missile body | |
| ctx.save(); ctx.translate(b.x,b.y); | |
| const ang = Math.atan2(-b.vy||-9,(b.vx||0)); | |
| ctx.rotate(ang); | |
| ctx.fillStyle='#ff4dd2'; ctx.strokeStyle='#fff'; | |
| ctx.beginPath(); | |
| ctx.moveTo(0,-8); ctx.lineTo(3,6); ctx.lineTo(-3,6); ctx.closePath(); | |
| ctx.fill(); ctx.stroke(); | |
| ctx.restore(); | |
| } else { | |
| const g=b.col==='#5dff9a'?'rgba(93,255,154,.4)':'rgba(125,249,255,.45)'; | |
| ctx.globalAlpha=.6; | |
| ctx.fillStyle=g; | |
| ctx.beginPath(); | |
| ctx.moveTo(b.x-b.w/2-3,b.y+b.h); ctx.lineTo(b.x,b.y-b.h*1.5); | |
| ctx.lineTo(b.x+b.w/2+3,b.y+b.h); ctx.closePath(); ctx.fill(); | |
| ctx.globalAlpha=1; | |
| // bright core | |
| ctx.fillStyle='#fff'; | |
| ctx.beginPath(); ctx.arc(b.x,b.y-4,2.5,0,Math.PI*2); ctx.fill(); | |
| ctx.fillStyle=b.col; | |
| ctx.fillRect(b.x-b.w/2,b.y-b.h/2,b.w,b.h); | |
| } | |
| } | |
| // enemy bullets (energy orbs with pulsing glow) | |
| for(const b of ebullets){ | |
| const pulse=.5+.5*Math.sin(performance.now()/60+b.x); | |
| ctx.globalAlpha=.25+ .3*pulse; | |
| ctx.fillStyle=b.col; | |
| ctx.beginPath(); ctx.arc(b.x,b.y,9+pulse*2,0,Math.PI*2); ctx.fill(); | |
| ctx.globalAlpha=1; | |
| ctx.fillStyle='#fff'; | |
| ctx.beginPath(); ctx.arc(b.x,b.y,3,0,Math.PI*2); ctx.fill(); | |
| ctx.fillStyle=b.col; | |
| ctx.beginPath(); ctx.arc(b.x,b.y,4.5,0,Math.PI*2); ctx.fill(); | |
| } | |
| // player (flashes white briefly after being hit) | |
| if((player.flashT||0)>0) player.flashT-=1; | |
| const pCol = (player.flashT||0)>0 && Math.floor(Date.now()/40)%2===0 ? '#ffffff' : '#5dff9a'; | |
| if(state==='playing'||state==='levelclear'){ | |
| drawShip(player.x,player.y,player.w,player.h,pCol); | |
| if(player.shield>0){ | |
| const maxSh=[3,4,6,8,10,12,14,16,18,20,22,24][(player.lvl&&player.lvl.shield||1)-1]||5; | |
| const sA=.35+.25*(player.shield/maxSh); | |
| ctx.strokeStyle=`rgba(111,184,255,${sA+.2*Math.sin(Date.now()/100)})`; | |
| ctx.lineWidth=2; | |
| ctx.beginPath(); ctx.arc(player.x,player.y,34,0,Math.PI*2); ctx.stroke(); | |
| } | |
| } | |
| // particles | |
| for(const p of particles){ | |
| ctx.globalAlpha=1-p.t/p.life; | |
| ctx.fillStyle=p.col; | |
| ctx.beginPath(); ctx.arc(p.x,p.y,p.r,0,Math.PI*2); ctx.fill(); | |
| } | |
| ctx.globalAlpha=1; | |
| // floaters (text) | |
| for(let i=floaters.length-1;i>=0;i--){ | |
| const f=floaters[i]; | |
| if(f.txt){ | |
| f.t+=.05; f.y-=1; | |
| ctx.font=`bold ${f.size}px monospace`; | |
| ctx.textAlign='center'; | |
| ctx.globalAlpha=Math.max(0,1-f.t); | |
| ctx.fillStyle='#000'; | |
| ctx.fillText(f.txt,f.x+2,f.y+2); | |
| ctx.fillStyle=f.col; | |
| ctx.fillText(f.txt,f.x,f.y); | |
| if(f.t>1) floaters.splice(i,1); | |
| } | |
| } | |
| ctx.globalAlpha=1; | |
| // periodic orange flame flash after a bomb (~50% intensity, pulsing) | |
| if(bombFlash>0){ | |
| const pulse = .5+.5*Math.sin(performance.now()/90); | |
| const alpha = (bombFlash<20 ? bombFlash/20 : 1) * (.25 + .15*pulse); // ~40-50% peak | |
| ctx.fillStyle=`rgba(255,120,30,${alpha})`; | |
| ctx.fillRect(0,0,W,H); | |
| } | |
| drawHUD(); | |
| if(state==='menu') drawMenu(); | |
| else if(state==='gameover') overlay('GAME OVER','Press SPACE to retry'); | |
| else if(state==='cutscene'){ | |
| ctx.fillStyle='rgba(0,0,10,.8)'; ctx.fillRect(0,0,W,H); | |
| ctx.textAlign='center'; | |
| // dramatic pause, then the boss's line | |
| if(cutT>40){ | |
| const t=(performance.now()/100)%2; | |
| ctx.font='bold 34px monospace'; ctx.fillStyle='#ff3b6b'; | |
| ctx.fillText('"THIS ISN\'T EVEN', W/2, H/2-30); | |
| ctx.fillText('MY FINAL FORM!"', W/2, H/2+15); | |
| } | |
| } | |
| else if(state==='win') overlay('VICTORY!','You destroyed the Dreadnought!\nPress SPACE to play again',true); | |
| else if(state==='levelclear'){ | |
| const n=LEVELS[level].name; | |
| ctx.fillStyle='rgba(0,0,0,.6)'; ctx.fillRect(0,H/2-70,W,140); | |
| ctx.textAlign='center'; | |
| ctx.font='bold 44px monospace'; ctx.fillStyle='#fff'; | |
| ctx.fillText('LEVEL CLEAR',W/2,H/2-10); | |
| ctx.font='22px monospace'; ctx.fillStyle='#bfeaff'; | |
| ctx.fillText(level<2? 'Press SPACE for next level' : 'Press SPACE to face the BOSS!',W/2,H/2+35); | |
| } | |
| } | |
| function drawEnemy(e){ | |
| // only flash briefly right after being hit (flashT counts down) | |
| if((e.flashT||0)>0) e.flashT-=1; | |
| const flash = (e.flashT||0)>0 && Math.floor(Date.now()/40)%2===0; | |
| ctx.save(); | |
| ctx.translate(e.x,e.y); | |
| // bright glow (cached gradient) | |
| ctx.fillStyle=enemyGlow; ctx.beginPath(); ctx.arc(0,0,30,0,Math.PI*2); ctx.fill(); | |
| if(e.isMinion){ | |
| const col = flash? '#fff' : e.color; | |
| ctx.save(); | |
| ctx.rotate(Math.PI/4); | |
| ctx.fillStyle=col; ctx.strokeStyle='#ffe0e8'; ctx.lineWidth=2; | |
| ctx.beginPath(); ctx.rect(-14,-11,28,22); ctx.fill(); ctx.stroke(); | |
| ctx.restore(); | |
| // core eye | |
| ctx.globalAlpha=.9; ctx.fillStyle=enemyEyeRed; | |
| ctx.beginPath(); ctx.arc(0,2,8,0,Math.PI*2); ctx.fill(); | |
| ctx.globalAlpha=1; | |
| ctx.restore(); | |
| return; | |
| } | |
| // heavy tanks get a distinct bronze armor color | |
| const col = flash? '#fff' : (e.heavy ? '#c98a3b' : e.color); | |
| const type = e.type || 'drone'; | |
| ctx.strokeStyle= e.heavy ? 'rgba(255,220,160,.9)' : 'rgba(255,220,240,.8)'; ctx.lineWidth=e.heavy?2.5:2; | |
| // per-type hull outline | |
| ctx.beginPath(); | |
| if(type==='dart'){ | |
| // slim downward arrowhead (dive-bomber) | |
| ctx.moveTo(-e.w*.3,-e.h/2); | |
| ctx.quadraticCurveTo(e.w*.4,-e.h*0.1, e.w*.32,e.h*0.05); | |
| ctx.lineTo(0,e.h/2+8); | |
| ctx.lineTo(-e.w*.34,e.h*0.02); | |
| ctx.quadraticCurveTo(-e.w*.42,-e.h*0.12,-e.w*.3,-e.h/2); | |
| } else if(type==='weaver'){ | |
| // angular delta with swept wings | |
| ctx.moveTo(0,-e.h/2-6); | |
| ctx.lineTo(e.w/2,e.h*0.05); | |
| ctx.lineTo(e.w*.28,e.h/2+4); | |
| ctx.lineTo(-e.w*.3,e.h/2+2); | |
| ctx.lineTo(-e.w/2,e.h*0.02); | |
| } else if(type==='sentinel'){ | |
| // wide armored tank with cannon nubs | |
| ctx.moveTo(0,-e.h/2-6); | |
| ctx.lineTo(e.w*.42,-e.h*.25); | |
| ctx.lineTo(e.w/2,e.h*0.15); | |
| ctx.lineTo(e.w*.3,e.h/2+4); | |
| ctx.lineTo(-e.w*.32,e.h/2+2); | |
| ctx.lineTo(-e.w/2,e.h*0.12); | |
| ctx.lineTo(-e.w*.42,-e.h*.28); | |
| } else { | |
| // drone: teardrop | |
| ctx.moveTo(-e.w/2,e.h/4); | |
| ctx.quadraticCurveTo(-e.w/3,-e.h/2,0,-e.h/2-6); | |
| ctx.quadraticCurveTo(e.w/3,-e.h/2,e.w/2,e.h/4); | |
| ctx.lineTo(0,e.h/2+8); | |
| } | |
| ctx.closePath(); | |
| // base hull | |
| ctx.fillStyle=col; ctx.fill(); | |
| // shared sheen for depth (cached — no per-enemy gradient) | |
| ctx.globalAlpha=.55; | |
| ctx.fillStyle=hullSheen; ctx.fill(); | |
| ctx.globalAlpha=1; | |
| ctx.stroke(); | |
| // heavy enemies (8x HP) get a gold ring + pulsing accent to stand out | |
| if(e.heavy){ | |
| const pulse=.5+.5*Math.sin(Date.now()/150); | |
| ctx.strokeStyle=`rgba(255,210,59,${.55+.35*pulse})`; | |
| ctx.lineWidth=2; | |
| ctx.beginPath(); ctx.arc(0,0,e.w*.75+4,0,Math.PI*2); ctx.stroke(); | |
| } | |
| // eyes / accents per type | |
| if(type==='sentinel'){ | |
| ctx.fillStyle=enemyEyeRed; | |
| ctx.beginPath(); ctx.arc(-e.w*.12,0,7,0,Math.PI*2); ctx.fill(); | |
| ctx.beginPath(); ctx.arc(e.w*.14,-4,6,0,Math.PI*2); ctx.fill(); | |
| } else if(type==='weaver'){ | |
| ctx.fillStyle=enemyEyeYellow; | |
| ctx.beginPath(); ctx.arc(-e.w*.1,0,5,0,Math.PI*2); ctx.fill(); | |
| ctx.beginPath(); ctx.arc(e.w*.12,-4,5,0,Math.PI*2); ctx.fill(); | |
| } else { | |
| ctx.fillStyle=enemyEyeYellow; | |
| ctx.beginPath(); ctx.arc(0,0,6,0,Math.PI*2); ctx.fill(); | |
| } | |
| // wing accent lines (drone only) | |
| if(type==='drone'){ | |
| ctx.strokeStyle='rgba(255,255,255,.35)'; ctx.lineWidth=1.5; | |
| ctx.beginPath(); ctx.moveTo(-e.w*.28,e.h*0.05); ctx.lineTo(-e.w*.42,-e.h*.2); ctx.stroke(); | |
| ctx.beginPath(); ctx.moveTo(e.w*.3,e.h*0.02); ctx.lineTo(e.w*.44,-e.h*.22); ctx.stroke(); | |
| } | |
| ctx.restore(); | |
| } | |
| function drawPowerups(){ | |
| const t=performance.now()/100; | |
| for(const p of powerups){ | |
| // gentle bob only, no jitter on top of fast downward movement | |
| const bob=Math.sin(p.t*2.5)*3; | |
| const pulse=.5+.5*Math.sin(t*3+p.x); | |
| ctx.save(); | |
| ctx.translate(p.x,p.y+bob); | |
| // pulsing glow halo | |
| ctx.globalAlpha=.25+.35*pulse; ctx.fillStyle=p.col; | |
| ctx.beginPath(); ctx.arc(0,0,18+pulse*6,0,Math.PI*2); ctx.fill(); | |
| ctx.globalAlpha=1; | |
| // spinning diamond with gradient | |
| const dg=ctx.createRadialGradient(-3,-3,1,0,0,14); | |
| dg.addColorStop(0,'#ffffff'); dg.addColorStop(.5,p.col); dg.addColorStop(1,'rgba(20,10,30,.9)'); | |
| const spin=Math.PI/4+Math.sin(p.t*1.5)*.12; | |
| ctx.rotate(spin); | |
| ctx.fillStyle=dg; ctx.strokeStyle='#fff'; ctx.lineWidth=2; | |
| const s=11; | |
| ctx.beginPath(); ctx.rect(-s,-s,s*2,s*2); ctx.fill(); ctx.stroke(); | |
| // label | |
| ctx.rotate(-spin); | |
| ctx.font='bold 12px monospace'; ctx.textAlign='center'; | |
| ctx.shadowColor=p.col; ctx.shadowBlur=6; | |
| ctx.fillStyle=p.col; | |
| ctx.fillText(p.label||'',0,28); | |
| ctx.shadowBlur=0; | |
| ctx.restore(); | |
| } | |
| } | |
| function drawBossBar(){ | |
| const w=W-160,x=80,y=20,h=16; | |
| ctx.fillStyle='rgba(0,0,0,.5)'; | |
| ctx.fillRect(x,y,w,h); | |
| ctx.strokeStyle='#9ffcff'; ctx.lineWidth=2; ctx.strokeRect(x,y,w,h); | |
| const pct=Math.max(0,BOSS.hp/BOSS.maxHp); | |
| const g=ctx.createLinearGradient(x,0,x+w,0); | |
| if(BOSS.enraged){ g.addColorStop(0,'#ff3355'); g.addColorStop(1,'#ff9d3b'); } | |
| else { g.addColorStop(0,'#5defff'); g.addColorStop(1,'#ff3b6b'); } | |
| ctx.fillStyle=g; ctx.fillRect(x+2,y+2,(w-4)*pct,h-4); | |
| ctx.font='bold 14px monospace'; | |
| ctx.textAlign='center'; | |
| ctx.fillStyle='#fff'; | |
| ctx.fillText('DREADNOUGHT',W/2,y+34); | |
| } | |
| function drawHUD(){ | |
| ctx.font='bold 18px monospace'; | |
| ctx.textAlign='left'; | |
| ctx.fillStyle='#fff'; | |
| ctx.fillText('SCORE '+score,16,31); | |
| ctx.fillText('HI '+hiScore,16,53); | |
| // health bar | |
| const hbW=180,hbX=20,hbY=H-30; | |
| ctx.fillStyle='rgba(0,0,10,.55)'; | |
| ctx.fillRect(hbX-3,hbY-8,hbW+6,22); | |
| ctx.strokeStyle='#9ffcff'; ctx.lineWidth=2; ctx.strokeRect(hbX-3,hbY-8,hbW+6,22); | |
| const hpPct=Math.max(0,hp/MAX_HP); | |
| const hg=ctx.createLinearGradient(hbX,0,hbX+hbW,0); | |
| if(hpPct>.5){ hg.addColorStop(0,'#7df9ff'); hg.addColorStop(1,'#39e6a8'); } | |
| else { hg.addColorStop(0,'#ffd23b'); hg.addColorStop(1,'#ff3b6b'); } | |
| ctx.fillStyle=hg; | |
| ctx.fillRect(hbX,hbY-4,(hbW)*(hpPct),12); | |
| // segment ticks (each = 2 HP, matching the +2 life powerup) | |
| ctx.strokeStyle='rgba(0,0,10,.5)'; ctx.lineWidth=1; | |
| for(let i=1;i<MAX_HP/2;i++){ | |
| const sx=hbX+(hbW)*(i/(MAX_HP/2)); | |
| ctx.beginPath(); ctx.moveTo(sx,hbY-4); ctx.lineTo(sx,hbY+8); ctx.stroke(); | |
| } | |
| // label | |
| ctx.font='bold 11px monospace'; ctx.textAlign='left'; | |
| ctx.fillStyle='#fff'; | |
| ctx.fillText('HP '+hp+'/'+MAX_HP, hbX, hbY-12); | |
| if(state==='playing'){ | |
| // show a bonus-collection countdown after clearing all enemies | |
| if(clearTimer>0){ | |
| const remain=Math.max(0,Math.ceil((385-clearTimer)/55)); // 7s window | |
| ctx.textAlign='center'; | |
| ctx.fillStyle='#ffd23b'; | |
| ctx.font='bold 26px monospace'; | |
| ctx.shadowColor='#ffd23b'; ctx.shadowBlur=12; | |
| ctx.fillText('GRAB POWERUPS! '+remain, W/2, H-40); | |
| ctx.shadowBlur=0; | |
| } | |
| ctx.textAlign='right'; | |
| ctx.fillStyle='#bfeaff'; | |
| ctx.font='bold 20px monospace'; | |
| if(level<LEVELS.length){ | |
| const label = LEVELS[level].name; | |
| ctx.fillText(label,W-15,30); | |
| } | |
| // powerup status (bottom-right): name + level pips out of 12 | |
| drawPowerStatus(); | |
| } | |
| } | |
| function drawPowerStatus(){ | |
| const items=[ | |
| { id:'rapid', col:'#ffd23b' }, | |
| { id:'triple',col:'#5dff9a' }, | |
| { id:'shield',col:'#6fb8ff' }, | |
| { id:'homing',col:'#ff4dd2' } | |
| ]; | |
| ctx.textAlign='right'; | |
| let y=H-22; | |
| for(const it of items){ | |
| const lv=(player.lvl&&player.lvl[it.id])||0; | |
| // label | |
| ctx.font='bold 13px monospace'; ctx.fillStyle=it.col; | |
| ctx.fillText(it.id.toUpperCase(), W-14, y); | |
| // level pips (12 max), drawn to the left of the label | |
| const pipW=6,gap=1,pipY=y-10; | |
| let px = W-20 - it.id.length*8; // start just left of the text | |
| for(let i=0;i<12;i++){ | |
| ctx.fillStyle = i<lv ? it.col : 'rgba(255,255,240,.18)'; | |
| ctx.beginPath(); ctx.rect(px,pipY,pipW,7); ctx.fill(); | |
| px -= (pipW+gap); | |
| } | |
| y-=22; | |
| } | |
| // bomb counter (max 3) | |
| ctx.textAlign='right'; | |
| const bx=W-14, by=y+8; | |
| ctx.font='bold 13px monospace'; ctx.fillStyle='#ffffff'; | |
| ctx.fillText('BOMBS', bx, by); | |
| let bxp=bx - 'BOMBS'.length*8; | |
| for(let i=0;i<3;i++){ | |
| ctx.fillStyle = i<(player.bombs||0) ? '#ffd23b' : 'rgba(255,240,220,.18)'; | |
| ctx.beginPath(); ctx.arc(bxp-4, by-5, 6, 0, Math.PI*2); ctx.fill(); | |
| bxp-=16; | |
| } | |
| } | |
| function drawMenu(){ | |
| const t=Date.now()/1000; | |
| ctx.fillStyle='rgba(3,4,14,.55)'; ctx.fillRect(0,0,W,H); | |
| // rotating star-burst rays behind the title | |
| ctx.save(); | |
| ctx.translate(W/2,205); | |
| ctx.rotate(t*.12); | |
| const rayCols=['#ffd23b','#ff5d73','#7df9ff']; | |
| for(let i=0;i<16;i++){ | |
| ctx.rotate(Math.PI*2/16); | |
| const a=.10+.05*Math.sin(t*3+i); | |
| ctx.fillStyle='rgba(255,210,59,'+a.toFixed(3)+')'; | |
| ctx.beginPath(); | |
| ctx.moveTo(0,0); ctx.lineTo(-26,-140); ctx.lineTo(26,-140); | |
| ctx.closePath(); ctx.fill(); | |
| } | |
| // spinning dashed ring | |
| ctx.restore(); | |
| // pulsing radial glow behind the logo | |
| const pulse=.5+.4*Math.sin(t*2.6); | |
| const g=ctx.createRadialGradient(W/2,205,10,W/2,205,220); | |
| g.addColorStop(0,'rgba(125,249,255,'+(pulse*.28).toFixed(3)+')'); | |
| g.addColorStop(1,'rgba(125,249,255,0)'); | |
| ctx.fillStyle=g; ctx.beginPath(); ctx.arc(W/2,205,220,0,Math.PI*2); ctx.fill(); | |
| // dashed orbit ring (rotating) | |
| ctx.save(); | |
| ctx.translate(W/2,205); | |
| ctx.rotate(t*.5); | |
| ctx.strokeStyle='rgba(255,93,115,.6)'; | |
| ctx.lineWidth=3; | |
| for(let i=0;i<24;i++){ | |
| const a=i/24*Math.PI*2; | |
| ctx.beginPath(); | |
| ctx.moveTo(Math.cos(a)*185,Math.sin(a)*185); | |
| ctx.arc(0,0,185,a+.09,a+.22); | |
| ctx.stroke(); | |
| } | |
| ctx.restore(); | |
| // title with layered glow + slight bob | |
| const bob=Math.sin(t*2.6)*4; | |
| ctx.textAlign='center'; | |
| const cy=205+bob; | |
| // "DEEPSEEK" logo with a chunky 3D extrusion | |
| const big='bold 96px monospace'; | |
| const depth=14; // how far the block extrudes (down-right) | |
| ctx.textAlign='center'; | |
| function drawExtrude(text,size,cx,cyy){ | |
| ctx.font=size; | |
| // side faces of the extrusion (drawn first so they sit behind the front) | |
| for(let d=depth;d>0;d--){ | |
| const shade=.12 + .5*(1-d/depth); | |
| ctx.fillStyle='rgba(20,90,160,'+shade.toFixed(3)+')'; | |
| ctx.fillText(text,cx+d*1.15,cyy+d); | |
| } | |
| // front face with a vertical gradient | |
| const fg=ctx.createLinearGradient(cx-220,0,cx+220,0); | |
| fg.addColorStop(0,'#39e6a8'); fg.addColorStop(.5,'#ffffff'); fg.addColorStop(1,'#7df9ff'); | |
| ctx.fillStyle=fg; | |
| ctx.fillText(text,cx,cyy); | |
| } | |
| drawExtrude('DEEPSEEK',big,W/2,cy+10); | |
| // "SHOOTER" in gold beneath the logo | |
| const g3=ctx.createLinearGradient(W/2-150,0,W/2+140,0); | |
| g3.addColorStop(0,'#ff8a00'); g3.addColorStop(.5,'#ffe259'); g3.addColorStop(1,'#ffd23b'); | |
| ctx.font='bold 40px monospace'; | |
| ctx.fillStyle=g3; ctx.globalAlpha=.6+.4*pulse; | |
| ctx.fillText('SHOOTER',W/2,cy+86); | |
| ctx.globalAlpha=1; | |
| // subtitle tagline with a quick fade-in loop | |
| const subA=.5+.45*Math.sin(t*2.0); | |
| ctx.font='bold 18px monospace'; | |
| ctx.fillStyle='rgba(191,234,255,'+subA.toFixed(3)+')'; | |
| ctx.fillText('— A POLITE GALACTIC BLAST —',W/2,cy+122); | |
| // instructions | |
| ctx.font='22px monospace'; ctx.fillStyle='#bfeaff'; | |
| const lines=[ | |
| 'Move: WASD / Arrows', | |
| 'Aim & Fire: Mouse or SPACE', | |
| '', | |
| '6 levels + the Dreadnought. Grab powerups!' | |
| ]; | |
| let yy=340; | |
| for(const l of lines){ ctx.fillText(l,W/2,yy); yy+=32; } | |
| if(Math.floor(Date.now()/500)%2===0){ | |
| ctx.font='bold 26px monospace'; ctx.fillStyle='#ffd23b'; | |
| ctx.fillText('PRESS SPACE TO START',W/2,505); | |
| } | |
| // credit line at the bottom of the intro | |
| ctx.textAlign='center'; | |
| ctx.font='16px monospace'; ctx.fillStyle='rgba(191,234,255,.75)'; | |
| ctx.fillText('a short game by David S and DeepSeek',W/2,H-24); | |
| } | |
| function overlay(title,sub,won){ | |
| ctx.fillStyle='rgba(0,0,10,.6)'; ctx.fillRect(0,0,W,H); | |
| ctx.textAlign='center'; | |
| const col = won? '#ffd23b' : '#ff5d73'; | |
| ctx.font='bold 52px monospace'; | |
| // proper drop shadow so the title reads as centered (not shifted) | |
| ctx.textAlign='center'; | |
| ctx.fillStyle='rgba(0,0,10,.85)'; | |
| ctx.fillText(title,W/2+3,H/2-24); | |
| ctx.fillStyle=col; | |
| ctx.fillText(title,W/2,H/2-27); | |
| ctx.font='20px monospace'; ctx.fillStyle='#bfeaff'; | |
| const lines=sub.split('\n'); | |
| let yy=H/2+15; | |
| for(const l of lines){ ctx.fillText(l,W/2,yy); yy+=30; } | |
| } | |
| // ---------- Level clear check ---------- | |
| let clearTimer=0; | |
| function spawnEndPowerups(){ | |
| // provide ~2.7 powerups spread across the top of the screen after each stage | |
| for(let i=0;i<3;i++){ | |
| if(i===2 && Math.random()>.68) continue; // third drop only ~32% of the time (5% rarer) | |
| const x=(i+1)*W/4 + (Math.random()*30-15); | |
| spawnPowerup(x, -20-Math.random()*40); | |
| } | |
| } | |
| function checkLevelClear(){ | |
| if(state!=='playing') return; | |
| // boss level is cleared via bossDeath() | |
| if(level>=LEVELS.length) return; | |
| const stageDone = enemies.length===0 && !clusterQueue.length; | |
| if(stageDone){ | |
| // give the player ~15 seconds to collect bonus powerups | |
| clearTimer+=1; | |
| if(clearTimer===1){ spawnEndPowerups(); } | |
| else if(Math.random()<.0225 && powerups.length<5){ // trickle 25% rarer, cap lower | |
| spawnPowerup(Math.random()*W, -20); | |
| } | |
| if(clearTimer>385){ state='levelclear'; } // 7s to grab bonus powerups | |
| } else { | |
| clearTimer=0; | |
| } | |
| } | |
| // ---------- Main loop ---------- | |
| let prev=performance.now(); | |
| function frame(t){ | |
| // dt in units of one 60fps frame (speeds are authored as px/frame). | |
| // Scaling seconds by ~55 keeps movement correct regardless of FPS. | |
| const dt=Math.min((t-prev)/1000*55,3); prev=t; | |
| update(dt); | |
| updateClusterSpawn(dt); | |
| updateShootQueue(dt); | |
| draw(); | |
| checkLevelClear(); | |
| // boss cutscene: let the line play out, then begin the final-form fight | |
| if(state==='cutscene'){ | |
| cutT+=dt; | |
| if(cutT>150){ spawnFinalBoss(); } | |
| } | |
| if(shake>0) shake*= .9; if(shake<.2) shake=0; | |
| if(bombFlash>0) bombFlash-=dt; | |
| requestAnimationFrame(frame); | |
| } | |
| buildBackground(0); makeFloaters(); resetPlayer(); | |
| requestAnimationFrame(frame); | |
| </script> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment