🎮ArcadeLab

TM3.8b

by DriftComet74
371 lines26.6 KB
▶ Play
<!DOCTYPE html>
<html><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>TM3.8b</title>
<style>*{margin:0;padding:0;box-sizing:border-box}html,body{width:100%;height:100%;overflow:hidden;background:#111;font-family:monospace;touch-action:none;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:6px}canvas{border:2px solid #fff;image-rendering:pixelated;max-width:100%}#c{display:flex;width:100%;max-width:500px;justify-content:space-between;padding:0 8px}.g{display:flex;gap:6px}button{width:50px;height:50px;border-radius:50%;border:2px solid #fff;background:rgba(0,0,0,.6);color:#fff;font-size:18px;font-weight:bold;touch-action:none}#j{background:#0080ff80;width:58px;height:58px}#r{background:#ff000080;width:36px;height:36px;font-size:11px;align-self:flex-end}#f{background:#ff8000b0;width:42px;height:42px;display:none}#f.on{display:block}#dn{background:#6666ff80}#m{background:#00aa00a0;width:36px;height:36px;font-size:14px;align-self:flex-end}</style>
</head><body>
<canvas id="g" width="400" height="200"></canvas>
<div id="c"><div class="g"><button id="L">◀</button><button id="dn">▼</button><button id="R">▶</button></div><div class="g"><button id="r">R</button><button id="m">♪</button><button id="f">F</button><button id="j">⤒</button></div></div>
<script>
(function(){
try{
var cv=document.getElementById('g'),c=cv.getContext('2d'),W=400,H=200,FB=document.getElementById('f'),MB=document.getElementById('m');
var sc=Math.min((window.innerWidth||360)-20,500)/W;cv.style.width=W*sc+'px';cv.style.height=H*sc+'px';
c.fillStyle='#0F0';c.fillRect(0,0,W,H);c.fillStyle='#000';c.font='bold 14px monospace';c.fillText('OK v3.8b',10,20);
function R(x,y,w,h,col){c.fillStyle=col;c.fillRect(x,y,w,h)}
function A(x,y,r,col){c.fillStyle=col;c.beginPath();c.arc(x,y,r,0,Math.PI*2);c.fill()}
function hit(a,b){return a.x<b.x+b.w&&a.x+a.w>b.x&&a.y<b.y+b.h&&a.y+a.h>b.y}
var G=.4,JU=-7,SP=2.5;
var ov=0,wn=0,cm=0,T=0,lv=1,tr=0,dr='',lives=3,coins=0;
var K={l:0,r:0,j:0,f:0,d:0};
var P={x:30,y:150,w:16,h:22,vx:0,vy:0,g:0,f:1,bg:0,rv:0,iv:0,fire:0,dying:0,dvy:0,sec:null};
var PL,BL,PP,FG,MU,EN,AX,CO,LA;
var LS=[
"0,180,1400,20;140,150,60,10;400,150,60,10;700,140,60,10|260,1;550,0;850,1|320;1050|1200,1300|900|100,164,0;600,164,1|200|500;1000||",
"0,180,1650,20;200,150,60,10;800,150,60,10;1400,150,60,10|350,1;900,0;1250,1|550;1050|1520,1600|700|150,164,0;1000,164,1|400;1200|500;1300|1,4",
"0,180,1850,20;300,130,60,10;600,130,60,10;900,130,60,10;1200,130,60,10;1600,130,60,10|250,1;750,0;1450,1|750;1300|1680,1780|550|150,164,0;850,164,1|500;1100|400;1400|",
"0,180,1750,20;400,140,60,10;900,140,60,10;1400,140,60,10|300,0;700,1;1200,0|600;1250|1550,1650|1000|150,164,1;800,164,0|350;1000|500;1300|",
""
];
// ============ AUDIO con música flautista Zelda ============
var AC=null,mute=0,musicOn=0,musicLoopTimer=null,masterFilter=null;
function scheduleNote(freq,when,dur,vol,type,isMusic){
  if(!AC||mute)return;
  try{
    var o=AC.createOscillator(),g=AC.createGain();
    o.type=type||'triangle';
    o.frequency.value=freq;
    g.gain.setValueAtTime(0.0001,when);
    g.gain.linearRampToValueAtTime(vol,when+0.015);
    g.gain.setValueAtTime(vol,when+dur*0.75);
    g.gain.linearRampToValueAtTime(0.0001,when+dur);
    o.connect(g);
    if(isMusic&&masterFilter)g.connect(masterFilter);else g.connect(AC.destination);
    o.start(when);o.stop(when+dur+0.05);
  }catch(e){}
}
function sfx(kind){
  if(!AC||mute)return;
  try{
    var t=AC.currentTime;
    if(kind==='jump'){
      var o=AC.createOscillator(),g=AC.createGain();
      o.type='square';o.frequency.setValueAtTime(320,t);
      o.frequency.exponentialRampToValueAtTime(720,t+0.1);
      g.gain.setValueAtTime(0.04,t);
      g.gain.exponentialRampToValueAtTime(0.0001,t+0.13);
      o.connect(g);g.connect(AC.destination);
      o.start(t);o.stop(t+0.15);
    }else if(kind==='coin'){
      scheduleNote(988,t,0.05,0.045,'square',false);
      scheduleNote(1319,t+0.05,0.13,0.045,'square',false);
    }else if(kind==='stomp'){
      scheduleNote(180,t,0.05,0.045,'square',false);
      scheduleNote(120,t+0.05,0.08,0.045,'square',false);
    }else if(kind==='hurt'){
      var o=AC.createOscillator(),g=AC.createGain();
      o.type='square';o.frequency.setValueAtTime(400,t);
      o.frequency.exponentialRampToValueAtTime(80,t+0.35);
      g.gain.setValueAtTime(0.05,t);
      g.gain.exponentialRampToValueAtTime(0.0001,t+0.35);
      o.connect(g);g.connect(AC.destination);
      o.start(t);o.stop(t+0.37);
    }else if(kind==='block'){
      scheduleNote(330,t,0.05,0.04,'square',false);
      scheduleNote(440,t+0.03,0.05,0.035,'square',false);
    }else if(kind==='fire'){
      scheduleNote(880,t,0.04,0.035,'sawtooth',false);
      scheduleNote(660,t+0.04,0.05,0.03,'sawtooth',false);
    }else if(kind==='power'){
      scheduleNote(523,t,0.07,0.045,'square',false);
      scheduleNote(659,t+0.07,0.07,0.045,'square',false);
      scheduleNote(784,t+0.14,0.07,0.045,'square',false);
      scheduleNote(1047,t+0.21,0.13,0.045,'square',false);
    }else if(kind==='clear'){
      scheduleNote(523,t,0.09,0.045,'square',false);
      scheduleNote(659,t+0.09,0.09,0.045,'square',false);
      scheduleNote(784,t+0.18,0.09,0.045,'square',false);
      scheduleNote(1047,t+0.27,0.28,0.045,'square',false);
    }else if(kind==='die'){
      scheduleNote(659,t,0.11,0.05,'square',false);
      scheduleNote(587,t+0.11,0.11,0.05,'square',false);
      scheduleNote(494,t+0.22,0.11,0.05,'square',false);
      scheduleNote(440,t+0.33,0.11,0.05,'square',false);
      scheduleNote(392,t+0.44,0.35,0.05,'square',false);
    }
  }catch(e){}
}
// MELODÍA tipo flautista Zelda (arpegio C mayor ascendente/descendente + variación F)
var MEL=[
  [523,1],  // C5
  [659,1],  // E5
  [784,1],  // G5
  [1047,1], // C6
  [784,1],  // G5
  [659,1],  // E5
  [523,2],  // C5 (más largo, respiro)
  [587,1],  // D5
  [698,1],  // F5
  [880,1],  // A5
  [1175,1], // D6
  [880,1],  // A5
  [698,1],  // F5
  [587,2]   // D5 (cierre)
];
function playMusic(){
  if(!AC||mute||!musicOn)return;
  if(musicLoopTimer){clearTimeout(musicLoopTimer);musicLoopTimer=null}
  var t=AC.currentTime+0.08;
  var beat=60/100; // 100 BPM = 0.6s por beat
  var totalBeats=0;
  for(var i=0;i<MEL.length;i++){
    var n=MEL[i];
    scheduleNote(n[0],t+totalBeats*beat,n[1]*beat*0.9,0.035,'triangle',true);
    totalBeats+=n[1];
  }
  var totalTime=totalBeats*beat;
  musicLoopTimer=setTimeout(playMusic,totalTime*1000);
}
function startMusic(){
  if(AC)return;
  try{
    AC=new (window.AudioContext||window.webkitAudioContext)();
    if(AC.state==='suspended')AC.resume();
    masterFilter=AC.createBiquadFilter();
    masterFilter.type='lowpass';
    masterFilter.frequency.value=4000;
    masterFilter.Q.value=0.4;
    masterFilter.connect(AC.destination);
    musicOn=1;
    playMusic();
  }catch(e){}
}
function toggleMute(){
  mute=!mute;
  MB.style.background=mute?'#aa0000a0':'#00aa00a0';
  MB.textContent=mute?'✕':'♪';
  if(musicLoopTimer){clearTimeout(musicLoopTimer);musicLoopTimer=null}
  if(!mute&&AC&&musicOn)playMusic();
}
// ============
function build(n){
if(n===5){PL=[{x:0,y:180,w:150,h:20},{x:650,y:180,w:350,h:20},{x:150,y:180,w:500,h:8}];LA=[{x:150,y:196,w:500,h:4}];BL=[];PP=[];FG=[];MU=[];CO=[];AX=[{x:940,y:155,w:20,h:20,a:1}];EN=[{x:750,y:130,w:60,h:50,tp:'b',dir:1}];P.sec=null;return}
var p=LS[n-1].split('|');
PL=[];if(p[0])p[0].split(';').forEach(function(a){var b=a.split(',');PL.push({x:+b[0],y:+b[1],w:+b[2],h:+b[3]})});
BL=[];if(p[1])p[1].split(';').forEach(function(a){var b=a.split(',');BL.push({x:+b[0],y:100,w:20,h:20,ht:0,bn:0,gv:+b[1]})});
PP=[];if(p[2])p[2].split(';').forEach(function(a){PP.push({x:+a,y:160,w:24,h:20,ph:0,pt:120})});
FG=[];if(p[3]&&p[3]!=='-1,0'){var fb=p[3].split(',');FG.push({x:+fb[0],y:60,w:12,h:120,a:1,m:0,tx:+fb[1]})}
MU=[];if(p[4])p[4].split(';').forEach(function(a){MU.push({x:+a,y:170,w:14,h:14,a:1})});
EN=[];if(p[5])p[5].split(';').forEach(function(a){var b=a.split(',');var tp=+b[2];if(tp===2)EN.push({x:+b[0],y:+b[1],w:60,h:50,tp:'b',dir:1});else EN.push({x:+b[0],y:+b[1],w:16,h:16,tp:tp===0?'g':'k',vx:-1,vy:0,bg:0})});
if(p[6])p[6].split(';').forEach(function(a){EN.push({x:+a,y:164,w:16,h:16,tp:'sp',vx:2.5,vy:0})});
CO=[];if(p[7])p[7].split(';').forEach(function(a){CO.push({x:+a,y:150,w:10,h:10,ph:Math.random()*6.28})});
AX=[];if(p[8]){var ab=p[8].split(',');AX.push({x:+ab[0],y:+ab[1],w:20,h:20,a:1})}
LA=[];if(p[9]){var lb=p[9].split(',');LA.push({x:+lb[0],y:+lb[1],w:+lb[2],h:+lb[3]})}
P.sec=p[10]?{i:+p[10].split(',')[0],t:+p[10].split(',')[1]}:null}
function reset(){ov=0;wn=0;cm=0;T=0;lv=1;tr=0;dr='';lives=3;coins=0;P.x=30;P.y=150;P.vx=0;P.vy=0;P.g=0;P.f=1;P.bg=0;P.rv=0;P.iv=0;P.fire=0;P.dying=0;P.dvy=0;P.w=16;P.h=22;FB.classList.remove('on');build(1)}
function hurt(t){if(P.dying>0)return 0;if(P.bg){var cx=P.x+P.w/2,by=P.y+P.h;P.bg=0;P.w=16;P.h=22;P.x=cx-8;P.y=by-22;P.iv=90;P.fire=0;FB.classList.remove('on');sfx('hurt');return 0}P.dying=100;P.dvy=0;dr=t?'t':'n';sfx('die');return 1}
function grav(e,mx){e.vy+=G;if(e.vy>10)e.vy=10;e.x+=e.vx;e.y+=e.vy;var all=PL.concat(PP);for(var j=0;j<all.length;j++){var s=all[j];if(hit(e,s)){if(e.vy>0&&e.y+e.h-e.vy<=s.y+2){e.y=s.y-e.h;e.vy=0}else if(e.vx>0&&e.x+e.w-e.vx<=s.x+2){e.x=s.x-e.w;e.vx*=-1}else if(e.vx<0&&e.x-e.vx>=s.x+s.w-2){e.x=s.x+s.w;e.vx*=-1}}}if(e.x<0){e.x=0;e.vx*=-1}if(e.x+e.w>mx){e.x=mx-e.w;e.vx*=-1}}
function upd(){
if(ov)return;
if(P.dying>0){P.dying--;if(P.dying<60){P.dvy+=G*.7;P.y+=P.dvy}if(P.dying<=0){lives--;if(lives<=0){ov=1;return}build(lv);P.x=30;P.y=150;P.vx=0;P.vy=0;P.bg=0;P.w=16;P.h=22;P.rv=0;P.fire=0;FB.classList.remove('on');P.iv=60;P.g=0;cm=0;P.dying=0;P.dvy=0}return}
if(tr>0){tr--;if(tr<=0){lv++;sfx('clear');if(lv>5){wn=1;ov=1;return}build(lv);P.x=30;P.y=150;P.vx=0;P.vy=0;P.iv=60;cm=0}return}
if(P.iv>0)P.iv--;
var L=K.l,Rv=K.r,J=K.j,D=K.d;
if(P.rv>0){P.rv--;var tmp=L;L=Rv;Rv=tmp}
if(D&&P.g){P.vx=0}else{P.vx=L?-SP:Rv?SP:0;if(L)P.f=-1;if(Rv)P.f=1}
if(J&&P.g){P.vy=JU;P.g=0;sfx('jump')}
if(K.f&&P.fire&&P.iv<=0&&T%20===0){EN.push({x:P.x+(P.f>0?P.w:-8),y:P.y+8,w:10,h:10,vx:P.f*5,vy:0,tp:'pf'});sfx('fire')}
P.vy+=G;if(P.vy>10)P.vy=10;P.x+=P.vx;P.y+=P.vy;
var mx=0;for(var mi=0;mi<PL.length;mi++){var mp=PL[mi];if(mp.x+mp.w>mx)mx=mp.x+mp.w}
if(P.x<0)P.x=0;if(P.x+P.w>mx)P.x=mx-P.w;
var i,j;
for(i=0;i<BL.length;i++)if(BL[i].bn>0)BL[i].bn--;
P.g=0;
var S=PL.concat(BL).concat(PP);
for(i=0;i<S.length;i++){var s=S[i];if(!hit(P,s))continue;
var pb=P.y+P.h-P.vy,pt=P.y-P.vy;
if(P.vy>0&&pb<=s.y+2){P.y=s.y-P.h;P.vy=0;P.g=1}
else if(P.vy<0&&pt>=s.y+s.h-2){P.y=s.y+s.h;P.vy=0;
if(BL.indexOf(s)>=0&&!s.ht){s.ht=1;s.bn=12;sfx('block');if(s.gv===1)EN.push({x:s.x+s.w/2-8,y:s.y-16,w:16,h:16,vx:0,vy:0,tp:P.bg?'flw':'mu',up:1,ty:s.y-16});else EN.push({x:s.x+s.w/2-8,y:s.y-16,w:16,h:16,vx:P.x<s.x?-2.5:2.5,vy:0,tp:'sp',tr:1})}}
else if(P.vx>0&&P.x+P.w-P.vx<=s.x+2){P.x=s.x-P.w;P.vx=0}
else if(P.vx<0&&P.x-P.vx>=s.x+s.w-2){P.x=s.x+s.w;P.vx=0}}
for(i=0;i<PP.length;i++){var pp=PP[i],pc=pp.x+pp.w/2,d=Math.abs(P.x+P.w/2-pc);var ot=P.g&&P.x+P.w>pp.x&&P.x<pp.x+pp.w&&Math.abs(P.y+P.h-pp.y)<10;
if(ot||d<55)pp.ph=Math.max(0,pp.ph-2);else pp.ph=Math.min(22,pp.ph+.5);
if(pp.ph>=22){pp.pt--;if(pp.pt<=0){EN.push({x:pc-6,y:pp.y-pp.ph-2,w:12,h:12,vx:P.x<pc?-7:7,vy:1,tp:'fi'});pp.pt=120}}else pp.pt=120;
if(pp.ph>6&&P.iv<=0&&!ot&&hit(P,{x:pc-8,y:pp.y-pp.ph-8,w:16,h:16})){if(hurt(0))return}
if(P.sec&&i===P.sec.i&&ot&&D){var tgt=P.sec.t;lv=tgt;sfx('clear');build(tgt);P.x=30;P.y=150;P.vx=0;P.vy=0;P.iv=60;P.dying=0;return}}
for(i=0;i<MU.length;i++)if(MU[i].a&&hit(P,MU[i])){MU[i].a=0;P.rv=120;sfx('hurt')}
for(i=0;i<CO.length;i++)if(!CO[i].got&&hit(P,CO[i])){CO[i].got=1;coins++;sfx('coin')}
for(i=0;i<LA.length;i++)if(P.dying<=0&&hit(P,LA[i])){if(hurt(0))return}
for(i=0;i<FG.length;i++){var f=FG[i];if(!f.a)continue;if(!f.m){if(Math.abs(P.x-f.x)<60){f.m=1;f.x=f.tx}}else if(hit(P,f)){tr=40;sfx('clear');return}}
if(lv===5&&AX.length){var ax=AX[0];if(ax.a&&hit(P,ax)){ax.a=0;wn=1;ov=1;dr='w';sfx('clear');return}}
for(i=0;i<EN.length;i++){var e=EN[i];if(e.dd)continue;
if(e.tp==='g'||e.tp==='k')grav(e,mx);
else if(e.tp==='sp'){e.vy+=G*.6;if(e.vy>8)e.vy=8;e.x+=e.vx;e.y+=e.vy;for(j=0;j<PL.length;j++){var pl2=PL[j];if(hit(e,pl2)&&e.vy>0&&e.y+e.h-e.vy<=pl2.y+2){e.y=pl2.y-e.h;e.vy=0}}if(e.x<0){e.x=0;e.vx*=-1}if(e.x+e.w>mx){e.x=mx-e.w;e.vx*=-1}if(P.iv<=0&&P.dying<=0&&hit(P,e)){if(hurt(e.tr===1))return}}
else if(e.tp==='fi'||e.tp==='pf'){if(!e.nog&&e.tp==='fi')e.vy+=.15;e.x+=e.vx;e.y+=e.vy;if(e.tp==='pf')for(j=0;j<EN.length;j++){var pfe=EN[j];if(pfe!==e&&!pfe.dd&&(pfe.tp==='g'||pfe.tp==='k'||pfe.tp==='sp'||pfe.tp==='b')){if(hit(e,pfe)){pfe.dd=1;e.dd=1}}}if(e.tp==='fi'&&P.iv<=0&&P.dying<=0&&hit(P,e)){if(hurt(0))return}}
else if(e.tp==='mu'||e.tp==='flw'){if(e.up){e.y-=.6;if(e.y<=e.ty){e.y=e.ty;e.up=0;if(e.tp==='mu')e.vx=P.x<e.x?-1.2:1.2}}else if(e.tp==='mu')grav(e,mx);else{e.vy+=G*.3;e.y+=e.vy;if(e.y+e.h>180){e.y=180-e.h;e.vy=0}}if(hit(P,e)){if(e.tp==='flw'){P.fire=1;FB.classList.add('on')}else if(!P.bg){var mcx=P.x+P.w/2,mby=P.y+P.h;P.bg=1;P.w=20;P.h=30;P.x=mcx-10;P.y=mby-30;P.iv=30}sfx('power');e.dd=1}}
else if(e.tp==='b'){e.x+=e.dir*.8;if(e.x>880){e.x=880;e.dir=-1}if(e.x<680){e.x=680;e.dir=1}if(T%90===0&&Math.abs(P.x-e.x)<380&&EN.length<8){var bdx=(P.x+P.w/2)-(e.x+e.w/2),bdy=(P.y+P.h/2)-(e.y+20),bdd=Math.sqrt(bdx*bdx+bdy*bdy)||1;EN.push({x:e.x+e.w/2-6,y:e.y+16,w:12,h:12,vx:bdx/bdd*4.5,vy:bdy/bdd*4.5,tp:'fi',nog:1})}if(P.iv<=0&&P.dying<=0&&hit(P,e)){if(hurt(0))return}}
else if(e.tp==='sh'){grav(e,mx);if(e.cool>0)e.cool--;if(hit(P,e)){if(e.vx!==0&&P.iv<=0&&P.dying<=0){if(hurt(0))return}else if(e.vx===0&&e.cool<=0){e.vx=P.f*6;if(P.vy>0)P.vy=K.j?-8:-5;sfx('stomp')}}}
if(e.y>250||e.x<-50||e.x>mx+100)e.dd=1;
if(!e.dd&&e.tp!=='mu'&&e.tp!=='flw'&&e.tp!=='b'&&e.tp!=='sh'&&e.tp!=='pf'&&e.tp!=='fi'&&e.tp!=='sp'&&hit(P,e)){var wa=P.vy>0&&(P.y+P.h-P.vy)<=e.y+e.h*0.5;if(wa&&(e.tp==='g'||e.tp==='k')&&!e.bg){e.dd=1;P.vy=K.j?-9:-5;sfx('stomp');if(e.tp==='k')EN.push({x:e.x+1,y:e.y+1,w:14,h:14,tp:'sh',vx:0,vy:0,cool:30})}else if(P.iv<=0&&P.dying<=0){if(hurt(e.tr===1))return;if(!e.bg)e.dd=1}}}
for(i=0;i<EN.length;i++){var shl=EN[i];if(shl.tp!=='sh'||shl.dd||shl.vx===0)continue;for(j=0;j<EN.length;j++){var sk=EN[j];if(sk===shl||sk.dd)continue;if(sk.tp==='g'||sk.tp==='k'||sk.tp==='sp'){if(hit(shl,sk)){sk.dd=1;sfx('stomp')}}}}
EN=EN.filter(function(e){return !e.dd});
cm=Math.max(0,P.x-200);cm=Math.min(cm,mx-W);
if(P.y>250){if(hurt(0))return}}
function drawM(){
var cx=P.x+P.w/2,py=P.y;
if(P.dying>0){
R(cx-8,py,16,3,'#E52521');R(cx-7,py+3,14,3,'#B01818');
R(cx-6,py+6,12,7,'#FFC69A');
R(cx-4,py+8,2,2,'#000');R(cx+2,py+8,2,2,'#000');
R(cx-5,py+11,4,1,'#5C3317');R(cx+1,py+11,4,1,'#5C3317');
R(cx-7,py+13,14,6,'#E52521');R(cx-6,py+19,12,6,'#0060C0');
R(cx-4,py+20,2,2,'#FFD700');R(cx+2,py+20,2,2,'#FFD700');
R(cx-11,py-2,3,12,'#E52521');R(cx+8,py-2,3,12,'#E52521');
R(cx-11,py-6,3,5,'#FFC69A');R(cx+8,py-6,3,5,'#FFC69A');
R(cx-5,py+25,4,7,'#0060C0');R(cx+1,py+25,4,7,'#0060C0');
R(cx-6,py+32,6,3,'#5C3317');R(cx,py+32,6,3,'#5C3317');return}
var capCol=P.fire?'#FFFFFF':'#E52521';
var st=!P.g?'j':Math.abs(P.vx)>.1?'w':'i';var fl=P.f===-1;
R(P.x+2,py,12,3,capCol);R(P.x+3,py+3,10,5,'#FFC69A');
R(P.x+4,py+3,3,1,'#5C3317');R(P.x+10,py+3,3,1,'#5C3317');
R(fl?P.x+4:P.x+9,py+4,2,2,'#000');
R(P.x+6,py+6,5,1,'#5C3317');
R(P.x+2,py+8,12,3,'#E52521');R(P.x+2,py+11,12,6,'#0060C0');
R(P.x+4,py+12,2,2,'#FFD700');R(P.x+10,py+12,2,2,'#FFD700');
var sw=st==='w'?Math.sin(T/5)*1.5:0;
if(!P.g){R(P.x-1,py+6,2,4,'#FFC69A');R(P.x+15,py+6,2,4,'#FFC69A');R(P.x-1,py+9,2,2,capCol);R(P.x+15,py+9,2,2,capCol)}
else{R(P.x-1+sw,py+10,2,4,capCol);R(P.x+15-sw,py+10,2,4,capCol);R(P.x-1+sw,py+13,2,2,'#FFC69A');R(P.x+15-sw,py+13,2,2,'#FFC69A')}
if(st==='j'){R(P.x+2,py+17,4,4,'#0060C0');R(P.x+10,py+17,4,4,'#0060C0');R(P.x+1,py+20,5,2,'#5C3317');R(P.x+9,py+20,5,2,'#5C3317')}
else if(st==='w'){var ph=Math.floor(T/6)%4;var off=ph===1?-2:ph===3?2:0;R(P.x+3+off,py+17,4,5,'#0060C0');R(P.x+9-off,py+17,4,5,'#0060C0');R(P.x+2+off,py+21,5,2,'#5C3317');R(P.x+9-off,py+21,5,2,'#5C3317')}
else{R(P.x+2,py+17,4,5,'#0060C0');R(P.x+10,py+17,4,5,'#0060C0');R(P.x+1,py+21,5,2,'#5C3317');R(P.x+10,py+21,5,2,'#5C3317')}
if(P.fire){R(P.x+6,py-2,4,2,'#FF6600');A(P.x+8,py-3,2,'#FFEE00')}
}
function drawE(e){
var x=e.x,y=e.y,w=e.w,h=e.h,cx=x+w/2,cy=y+h/2;
if(e.tp==='g'){var ph=Math.floor(T/8)%2;
R(x+(ph?1:3),y+h-3,w*.3,3,'#3A1A00');R(x+w*.65-(ph?0:2),y+h-3,w*.3,3,'#3A1A00');
A(cx,y+h*.42,w*.55,'#4A2200');R(x+w*.05,y+h*.42,w*.9,h*.32,'#4A2200');
R(x+w*.1,y+h*.68,w*.8,3,'#2A1000');
c.fillStyle='#FFE8C0';c.beginPath();c.ellipse(cx,y+h*.62,w*.42,h*.24,0,0,Math.PI*2);c.fill();
c.fillStyle='#2A1000';c.beginPath();c.moveTo(cx-w*.3,y+h*.44);c.lineTo(cx-w*.05,y+h*.48);c.lineTo(cx-w*.3,y+h*.53);c.closePath();c.fill();
c.beginPath();c.moveTo(cx+w*.3,y+h*.44);c.lineTo(cx+w*.05,y+h*.48);c.lineTo(cx+w*.3,y+h*.53);c.closePath();c.fill();
R(cx-w*.22,y+h*.5,w*.13,h*.13,'#FFF');R(cx+w*.09,y+h*.5,w*.13,h*.13,'#FFF');
R(cx-w*.19,y+h*.53,w*.08,h*.1,'#000');R(cx+w*.11,y+h*.53,w*.08,h*.1,'#000')}
else if(e.tp==='k'){var ph=Math.floor(T/6)%4,lf=ph===1?1:ph===3?-1:0;
R(x+2+lf,y+h-4,4,4,'#E8A820');R(x+w-6-lf,y+h-4,4,4,'#E8A820');
A(cx,y+h*.68,w*.55,'#0A3A0A');A(cx,y+h*.68,w*.42,'#2A802A');A(cx,y+h*.68,w*.28,'#3AA83A');A(cx,y+h*.68,w*.14,'#5CD85C');
A(cx,y+h*.28,w*.32,'#F0C030');
R(cx-w*.18,y+h*.22,w*.12,h*.1,'#FFF');R(cx+w*.06,y+h*.22,w*.12,h*.1,'#FFF');
R(cx-w*.15,y+h*.25,w*.06,h*.08,'#000');R(cx+w*.09,y+h*.25,w*.06,h*.08,'#000');
var hs=ph===1?1:ph===3?-1:0;R(x-1,y+h*.5+hs,3,3,'#F0C030');R(x+w-2,y+h*.5-hs,3,3,'#F0C030')}
else if(e.tp==='sh'){A(cx,cy,w*.58,'#0A3A0A');A(cx,cy,w*.42,'#2A802A');A(cx,cy,w*.24,'#5CD85C');R(cx-1,cy-w*.4,2,3,'#0A3A0A');R(cx-1,cy+w*.3,2,3,'#0A3A0A')}
else if(e.tp==='sp'){var br=y+h-2;
c.fillStyle='#4A0000';c.beginPath();c.moveTo(x+1,br);c.lineTo(cx,y+2);c.lineTo(x+w-1,br);c.closePath();c.fill();
c.fillStyle='#C00000';c.beginPath();c.moveTo(x+3,br);c.lineTo(cx,y+4);c.lineTo(x+w-3,br);c.closePath();c.fill();
c.fillStyle='#FF3030';c.beginPath();c.moveTo(cx-1,y+6);c.lineTo(cx+1,y+6);c.lineTo(cx+2,br-1);c.lineTo(cx-2,br-1);c.closePath();c.fill()}
else if(e.tp==='fi'||e.tp==='pf'){var fir=w/2;
c.fillStyle=e.tp==='pf'?'rgba(255,80,0,.4)':'rgba(255,150,0,.3)';c.beginPath();c.arc(cx,cy,fir*1.8,0,Math.PI*2);c.fill();
A(cx,cy,fir,e.tp==='pf'?'#FF6600':'#FF4400');A(cx,cy,fir*.7,'#FFAA00');A(cx,cy,fir*.4,'#FFEE00');A(cx-1,cy-1,fir*.2,'#FFFFFF')}
else if(e.tp==='mu'){R(x+3,y+h*.55,w-6,h*.45,'#FFE0B0');
c.fillStyle='#E52521';c.beginPath();c.arc(cx,y+h*.55,w/2,Math.PI,0);c.closePath();c.fill();
A(cx-4,y+h*.35,2.5,'#FFF');A(cx+4,y+h*.35,2.5,'#FFF');A(cx,y+h*.12,2.5,'#FFF');
R(cx-3,y+h*.7,2,2,'#000');R(cx+1,y+h*.7,2,2,'#000')}
else if(e.tp==='flw'){for(var fi=0;fi<5;fi++){var fa=fi/5*Math.PI*2+T/20;A(cx+Math.cos(fa)*w*.4,cy+Math.sin(fa)*h*.4,w*.2,'#FF3300');A(cx+Math.cos(fa)*w*.4,cy+Math.sin(fa)*h*.4,w*.12,'#FF6600')}A(cx,cy+2,w*.2,'#FFCC00');A(cx,cy+2,w*.12,'#FFFF66')}
else if(e.tp==='b'){
R(x+2,y+h-3,w-4,3,'#1A1A1A');
R(x+10,y+18,w-20,h-22,'#1A5C3A');R(x+12,y+20,w-24,h-26,'#2E8B57');
for(var pw=0;pw<3;pw++){var pxx=x+14+pw*11;c.fillStyle='#FFF';c.beginPath();c.moveTo(pxx,y+20);c.lineTo(pxx+4,y+14);c.lineTo(pxx+8,y+20);c.closePath();c.fill()}
R(x+14,y+28,w-28,10,'#D4A030');R(x+16,y+30,w-32,4,'#F5D060');
R(x+8,y,w-16,22,'#E8A020');R(x+10,y+2,w-20,4,'#C88010');
R(x+14,y-6,4,8,'#F0E0D0');R(x+w-18,y-6,4,8,'#F0E0D0');
A(x+18,y+9,4,'#FFF');A(x+w-18,y+9,4,'#FFF');A(x+18,y+9,2,'#C00');A(x+w-18,y+9,2,'#C00');A(x+18,y+9,1,'#000');A(x+w-18,y+9,1,'#000');
R(x+13,y+4,8,2,'#8B4513');R(x+w-21,y+4,8,2,'#8B4513');
R(x+16,y+15,w-32,5,'#400');
for(var tw=0;tw<3;tw++)R(x+18+tw*5,y+15,2,4,'#FFF');
R(x+8,y+h-8,14,8,'#D4A030');R(x+w-22,y+h-8,14,8,'#D4A030');
R(x+8,y+h-8,3,4,'#FFF');R(x+w-11,y+h-8,3,4,'#FFF')}}
function drawPl(pp){var pc=pp.x+pp.w/2,py=pp.y-pp.ph,h=pp.ph;if(h<=.5)return;
var sw=Math.sin(T/18)*2,hx=pc+sw;
R(hx-3,py,6,h,'#0A7A0A');R(hx-1,py,2,h,'#38C038');
A(hx,py,11,'#500000');A(hx,py,10,'#E81818');A(hx-2,py-3,5,'#FF4040');
A(hx-4,py-4,2,'#FFF');A(hx+4,py-4,2,'#FFF');A(hx,py-6,1.5,'#FFF');
var ch=Math.sin(T/7)*2+2;R(hx-8,py+2,16,ch+3,'#200000');
for(var pi=0;pi<4;pi++){R(hx-7+pi*3.5,py+2,2,2,'#FFF');R(hx-7+pi*3.5,py+2+ch,2,2,'#FFF')}
A(hx-6,py-5,2,'rgba(255,255,255,.5)')}
function draw(){
var sg=c.createLinearGradient(0,0,0,H);
sg.addColorStop(0,'#4A90E2');sg.addColorStop(.5,'#7EC8F0');sg.addColorStop(1,'#C8E8FF');
c.fillStyle=sg;c.fillRect(0,0,W,H);
var sx=W-50,sy=32;
for(var sri=0;sri<10;sri++){var sra=sri/10*Math.PI*2+T*.008;
c.fillStyle='rgba(255,238,0,.4)';
c.beginPath();c.moveTo(sx+Math.cos(sra-.08)*14,sy+Math.sin(sra-.08)*14);c.lineTo(sx+Math.cos(sra)*20,sy+Math.sin(sra)*20);c.lineTo(sx+Math.cos(sra+.08)*14,sy+Math.sin(sra+.08)*14);c.closePath();c.fill()}
A(sx,sy,13,'#FFDD00');A(sx,sy,10,'#FFEE33');A(sx-2,sy-2,3,'#FFFF99');
for(var ci=0;ci<6;ci++){var cxx=ci*250-cm*.3;if(cxx<-50||cxx>W+50)continue;var cyy=40+(ci%3)*22;
c.fillStyle='#FFF';A(cxx,cyy,11,'#FFF');A(cxx+13,cyy-3,13,'#FFF');A(cxx+28,cyy,11,'#FFF');A(cxx+14,cyy+4,10,'#FFF');
c.fillStyle='#D8E8F8';A(cxx+2,cyy+7,6,'#D8E8F8');A(cxx+15,cyy+8,7,'#D8E8F8');A(cxx+24,cyy+6,6,'#D8E8F8')}
c.save();c.translate(-cm,0);
for(var i=0;i<PL.length;i++){var pl=PL[i];
R(pl.x,pl.y,pl.w,pl.h,'#C84C0C');
for(var by=0;by<pl.h;by+=8){var off=Math.floor(by/8)%2*8;for(var bx=-off;bx<pl.w;bx+=16){R(pl.x+bx+1,pl.y+by+1,14,6,'#E08030');R(pl.x+bx+1,pl.y+by+1,14,1,'#FFA050');R(pl.x+bx+1,pl.y+by+6,14,1,'#A06020')}}
if(pl.w>200&&pl.y<170){R(pl.x,pl.y,pl.w,4,'#2C9E2C');R(pl.x,pl.y,pl.w,1,'#5CE05C')}
R(pl.x,pl.y+pl.h-1,pl.w,1,'#5C2408')}
for(var i=0;i<LA.length;i++){var l=LA[i];R(l.x,l.y,l.w,l.h,'#FF4400');R(l.x,l.y,l.w,2,'#FFAA00');R(l.x,l.y+2,l.w,1,'#FFFF66');
for(var lx=0;lx<l.w;lx+=8){var lph=Math.sin(T/4+lx)*1.5;A(l.x+lx+4,l.y+1+lph,2.5,'#FFEE00')}}
for(var i=0;i<BL.length;i++){var b=BL[i],oy=b.bn>0?-Math.sin(b.bn/12*Math.PI)*4:0;
if(b.ht){R(b.x,b.y+oy,b.w,b.h,'#666');R(b.x+2,b.y+oy+2,b.w-4,b.h-4,'#444');R(b.x+3,b.y+oy+3,2,2,'#222');R(b.x+b.w-5,b.y+oy+3,2,2,'#222');R(b.x+3,b.y+oy+b.h-5,2,2,'#222');R(b.x+b.w-5,b.y+oy+b.h-5,2,2,'#222')}
else{R(b.x,b.y+oy,b.w,b.h,'#8B4513');R(b.x+2,b.y+oy+2,b.w-4,b.h-4,'#FFA500');R(b.x+2,b.y+oy+2,b.w-4,2,'#FFD700');R(b.x+2,b.y+oy+2,2,b.h-4,'#FFD700');R(b.x+2,b.y+oy+b.h-4,b.w-4,2,'#CC7700');R(b.x+b.w-4,b.y+oy+2,2,b.h-4,'#CC7700');
R(b.x+3,b.y+oy+3,2,2,'#5C3317');R(b.x+b.w-5,b.y+oy+3,2,2,'#5C3317');R(b.x+3,b.y+oy+b.h-5,2,2,'#5C3317');R(b.x+b.w-5,b.y+oy+b.h-5,2,2,'#5C3317');
var br2=Math.sin(T/10)*.15+.15;c.fillStyle='rgba(255,255,200,'+br2+')';c.fillRect(b.x+3,b.y+oy+3,b.w-6,b.h-6);
c.fillStyle='#FFF';c.font='bold 14px monospace';c.textAlign='center';c.fillText('?',b.x+b.w/2,b.y+oy+b.h/2+5);c.textAlign='left'}}
for(var i=0;i<PP.length;i++){var pp=PP[i];R(pp.x+2,pp.y+8,pp.w-4,pp.h-8,'#005500');R(pp.x+3,pp.y+8,pp.w-6,pp.h-8,'#00AA00');R(pp.x+4,pp.y+9,2,pp.h-10,'#60E060');R(pp.x+6,pp.y+9,2,pp.h-10,'#30D030');R(pp.x+pp.w-8,pp.y+9,2,pp.h-10,'#007700');R(pp.x,pp.y,pp.w,8,'#005500');R(pp.x+1,pp.y+1,pp.w-2,6,'#00AA00');R(pp.x+2,pp.y+2,pp.w-4,1,'#60E060');drawPl(pp)}
for(var i=0;i<MU.length;i++)if(MU[i].a){var m=MU[i];R(m.x+3,m.y+m.h*.55,m.w-6,m.h*.45,'#CCC');c.fillStyle='#8800AA';c.beginPath();c.arc(m.x+m.w/2,m.y+m.h*.55,m.w/2,Math.PI,0);c.closePath();c.fill();A(m.x+m.w/2-3,m.y+m.h*.3,1.5,'#EE66FF');A(m.x+m.w/2+3,m.y+m.h*.3,1.5,'#EE66FF');R(m.x+m.w/2-3,m.y+m.h*.7,2,2,'#F00');R(m.x+m.w/2+1,m.y+m.h*.7,2,2,'#F00')}
for(var i=0;i<CO.length;i++)if(!CO[i].got){var co=CO[i],g2=Math.sin(T/3+co.ph)*.5+.5;
if(g2>.4)A(co.x+5,co.y+5,9,'rgba(255,255,100,'+(g2*.35)+')');
A(co.x+5,co.y+5,5,'#FFD700');A(co.x+5,co.y+5,4,'#FFEE00');R(co.x+4,co.y+2,2,6,'#DAA000');
if(g2>.7)A(co.x+3,co.y+3,1.5,'#FFF')}
for(var i=0;i<FG.length;i++)if(FG[i].a){var f=FG[i];R(f.x-2,f.y,3,f.h,'#888');R(f.x-2,f.y,1,f.h,'#CCC');A(f.x-.5,f.y-3,3,'#FFD700');A(f.x-1,f.y-3,1,'#FFFF99');
var wv=Math.sin(T/8)*2;c.fillStyle='#E52521';c.beginPath();c.moveTo(f.x+1,f.y+3);c.lineTo(f.x+20+wv,f.y+3+f.h/3);c.lineTo(f.x+1,f.y+3+f.h/2);c.closePath();c.fill();
c.fillStyle='#FFF';c.beginPath();c.moveTo(f.x+1,f.y+3+f.h/6);c.lineTo(f.x+11+wv,f.y+3+f.h/3);c.lineTo(f.x+1,f.y+3+f.h/2);c.closePath();c.fill()}
for(var i=0;i<AX.length;i++)if(AX[i].a){R(AX[i].x+6,AX[i].y,4,20,'#8B4513');R(AX[i].x,AX[i].y,14,8,'#C0C0C0');R(AX[i].x,AX[i].y,14,2,'#E8E8E8');R(AX[i].x,AX[i].y,2,8,'#888')}
for(var i=0;i<EN.length;i++)if(!EN[i].dd)drawE(EN[i]);
if(P.dying<=0||Math.floor(T/2)%2===0)drawM();
c.restore();
c.fillStyle='#FFF';c.font='bold 11px monospace';c.fillText('TM v3.8b - N'+lv+'/5',8,15);
c.fillStyle='#FFD700';c.fillText('C:'+coins,8,30);
for(var li=0;li<lives;li++)A(300+li*14,10,5,'#E52521');
if(tr>0){c.fillStyle='rgba(0,0,0,.7)';c.fillRect(0,0,W,H);c.textAlign='center';c.fillStyle='#FFF';c.font='bold 18px monospace';c.fillText('NIVEL '+lv+' OK',W/2,H/2);c.textAlign='left'}
if(ov){c.fillStyle='rgba(0,0,0,.85)';c.fillRect(0,0,W,H);c.textAlign='center';var ms=wn?'GANASTE':(dr==='t'?'TROLEADO':'GAME OVER');c.fillStyle=wn?'#FFD700':(dr==='t'?'#FF4444':'#FFF');c.font='bold 22px monospace';c.fillText(ms,W/2,H/2-5);c.fillStyle='#FFF';c.font='12px monospace';c.fillText('Toca R',W/2,H/2+20);c.textAlign='left'}}
var last=0;
function loop(now){if(!now)now=Date.now();if(now-last<16){requestAnimationFrame(loop);return}last=now;upd();draw();T++;requestAnimationFrame(loop)}
document.addEventListener('keydown',function(e){
if(e.key==='ArrowLeft'||e.key==='a')K.l=1;
if(e.key==='ArrowRight'||e.key==='d')K.r=1;
if(e.key==='ArrowDown'||e.key==='s')K.d=1;
if(e.key==='ArrowUp'||e.key==='w'||e.key===' ')K.j=1;
if(e.key==='x'||e.key==='X')K.f=1;
if(e.key==='r')reset();
if(e.key==='m'||e.key==='M')toggleMute();
startMusic()});
document.addEventListener('keyup',function(e){
if(e.key==='ArrowLeft'||e.key==='a')K.l=0;
if(e.key==='ArrowRight'||e.key==='d')K.r=0;
if(e.key==='ArrowDown'||e.key==='s')K.d=0;
if(e.key==='ArrowUp'||e.key==='w'||e.key===' ')K.j=0;
if(e.key==='x'||e.key==='X')K.f=0});
function bd(id,k){
var el=document.getElementById(id);
el.addEventListener('touchstart',function(e){e.preventDefault();K[k]=1;startMusic()},{passive:false});
el.addEventListener('touchend',function(e){e.preventDefault();K[k]=0},{passive:false});
el.addEventListener('mousedown',function(e){e.preventDefault();K[k]=1;startMusic()});
el.addEventListener('mouseup',function(e){e.preventDefault();K[k]=0})}
bd('L','l');bd('R','r');bd('j','j');bd('f','f');bd('dn','d');
var rb=document.getElementById('r');
rb.addEventListener('touchstart',function(e){e.preventDefault();reset()},{passive:false});
rb.addEventListener('click',function(e){e.preventDefault();reset()});
MB.addEventListener('click',function(e){e.preventDefault();toggleMute()});
MB.addEventListener('touchstart',function(e){e.preventDefault();toggleMute()},{passive:false});
reset();requestAnimationFrame(loop);
}catch(err){try{var cv2=document.getElementById('g'),c2=cv2.getContext('2d');c2.fillStyle='#F00';c2.fillRect(0,0,400,200);c2.fillStyle='#FFF';c2.font='bold 11px monospace';c2.fillText('INIT ERR:',10,20);c2.fillText(String(err.message||err).slice(0,45),10,40)}catch(e){}}
})();
</script>
</body></html>

Game Source: TM3.8b

Creator: DriftComet74

Libraries: none

Complexity: complex (371 lines, 26.6 KB)

The full source code is displayed above on this page.

Remix Instructions

To remix this game, copy the source code above and modify it. Add a ARCADELAB header at the top with "remix_of: tm3-8b-driftcomet74" to link back to the original. Then publish at arcadelab.ai/publish.