-
Notifications
You must be signed in to change notification settings - Fork 17
/
legacy.html
4 lines (4 loc) · 10 KB
/
legacy.html
1
2
3
4
<!DOCTYPE html>
<meta charset="utf-8">
<title>Canvas TD</title>
<style>@import "http://fonts.googleapis.com/css?family=Droid+Sans+Mono";a{color:blue;cursor:pointer;text-decoration:none}body>div{-moz-box-shadow:0 0 10px #000;-webkit-box-shadow:0 0 10px #000;box-shadow:0 0 10px #000;display:inline-block;}#ts,#up{float:left;height:30px}#ts>a{float:left;text-align:center;width:90px}#s,#e{background:rgba(255,255,255,.8);height:399px;padding:50px;position:absolute;width:600px;}#up>a{border:1px solid #00f;float:left;height:30px;margin:5px;text-align:center;width:75px}</style><body style="background:#fff;font:12px 'Droid Sans Mono';margin:5px"><div style="float:left;margin-bottom:10px"><div id="s"><div id="maps" style="float:left">Choose map:</div><div style="float:right;width:300px">Place and upgrade turrets (which cost money) to kill creeps (which give you money).</div></div><div id="e" style="display:none;text-align:center"></div><canvas id="c" width="700" height="450" style="display:block"></canvas><div id="ct" style="background:#ddd;font-size:10px;height:43px;padding:3px 6px"><div id="ts"></div><div id="up" style="display:none"><a id="Damage"></a><a id="Rate"></a><a id="Range"></a><a id="sell"></a></div><div style="float:right"><a id="pause">Pause</a><br><br><a onclick="confirm('Really restart?')&&location.reload()">Restart</a></div><div style="float:right;width:70px">FPS <span id="fps">60</span><br><br><a id="wt">20s</a></div><div style="float:right;width:80px">Cash $<span id="cash">35</span><br>Lives <span id="lives">10</span><br>Wave #<span id="wn">1</span></div></div></div><div id="t" style="float:right;height:491px;margin-left:10px;padding:4px 6px;width:300px;overflow:auto">Loading tweets...</div><canvas id="tc" width="25" height="25" style="display:none"></canvas><script src="http://ajax.microsoft.com/ajax/jquery/jquery-1.4.2.min.js"></script><script>(function(o,A,i,g){var v=i("#c"),f=v[0].getContext("2d"),w=i("#tc"),j=w[0].getContext("2d"),q=i(A),r=i("#ct"),t=i("#ts"),x=i("#up"),y=i("#wt");g.K=g.PI*2;g.j=function(a){return g.floor(g.random()*a)};g.N=function(a,d,b){return(d.x-a.x)*(d.x-a.x)+(d.y-a.y)*(d.y-a.y)<b*b};g.H=function(a,d,b){var e=d.x-a.x;d=d.y-a.y;var h=g.atan2(d,e);a.x+=b*g.cos(h);a.y+=b*g.sin(h);return g.abs(e)+g.abs(d)<2};var l={R:{Loops:"0,50|650,50|650,400|50,400|50,125|575,125|575,325|125,325|125,200|700,200",Test:"0,150|100,150|100,350|400,350|400,150|200,150|200,50|300,50|300,250|500,250|700,250",Line:"0,225|700,225"},c:{Laser:{f:15,g:"15,38,85|25,36,90|50,34,95|75,32,100|100,30,105|150,28,110|200,26,120|400,25,130|600,24,140|1000,22,160",color:"#808",s:function(){j.fillStyle="violet";j.fillRect(10,10,5,5)},l:80,q:40,d:10,z:function(a){var d=a[0],b=this;d.e-=b.d;if(b.o&&g.j(10)===0){a=c.map[0];d.x=a.x;d.y=a.y;d.w=0}c.t.push({b:6,B:function(){f.lineCap="round";f.lineWidth=2;f.strokeStyle="violet";f.beginPath();f.moveTo(b.x,b.y);f.lineTo(d.x,d.y);f.stroke()}})}},Missile:{f:25,g:"20,57,125|35,54,130|50,51,135|100,48,140|180,45,145|300,42,150|500,40,160|800,38,170|1000,36,180|1300,33,200",color:"#2b5a38",s:function(){j.fillStyle="grey";j.fillRect(5,5,5,5);j.fillRect(15,5,5,5);j.fillRect(15,15,5,5);j.fillRect(5,15,5,5)},l:120,q:60,d:15,z:function(a){var d=a[g.j(a.length)],b=this,e={x:b.x+(g.j(2)?-5:5),y:b.y+(g.j(2)?-5:5)};c.I.push(function(){if(d.e<=0)if(b.o){var h=c.n.filter(function(){return true});if(h.length)d=h[g.j(h.length)];else return false}else return false;if(g.H(e,d,3)){d.e-=b.d;return false}else{f.fillStyle="#fff";f.fillRect(e.x-2,e.y-2,4,4)}})}},Tazer:{f:40,g:"5,38,62|10,36,64|15,34,66|25,32,68|50,30,70|100,29,75|200,28,80|300,27,85|400,26,90|500,24,100",color:"orange",s:function(){j.fillStyle="#ff0";j.fillRect(10,10,5,5)},l:60,q:40,d:1,z:function(a){var d=a[g.j(a.length)],b=this;a=0.9-b.d/1E3;var e=60+b.d;d.e-=b.d;d.k=d.k>a?a:d.k;d.A=b.o?9e9:d.A<e?e:d.A;c.t.push({b:6,B:function(){f.lineCap="round";f.lineWidth=3;f.strokeStyle="blue";f.beginPath();f.moveTo(b.x,b.y);f.lineTo(d.x,d.y);f.stroke();f.strokeStyle="#fff";f.lineWidth=2;f.beginPath();f.moveTo(b.x,b.y);f.lineTo(d.x,d.y);f.stroke()}})}},Mortar:{f:60,g:"75,115,205|100,110,210|150,105,215|250,100,220|400,96,225|600,92,230|800,88,235|1000,84,240|1200,80,245|1500,75,250",color:"grey",s:function(){j.fillStyle="#444";j.fillRect(5,10,5,5);j.fillRect(10,5,5,5);j.fillRect(10,15,5,5);j.fillRect(15,10,5,5)},l:200,q:120,d:50,z:function(a){a=a[0];var d=this,b={x:a.x/1,y:a.y/1},e={x:d.x/1,y:d.y/1},h=25+d.d/150;c.I.push(function(){if(g.H(e,b,1.5)){c.n.forEach(function(k){if(g.N(k,b,h)){k.e-=d.d;if(d.o)k.u=25}});c.t.push({b:3,B:function(){f.fillStyle="#ff0";f.beginPath();f.moveTo(b.x,b.y);f.arc(b.x,b.y,h,0,g.K,true);f.fill()}});return false}else{f.fillStyle="grey";f.fillRect(e.x-3,e.y-3,6,6)}})}}},V:function(a,d,b){a=i.extend({x:d,y:b,o:false,dl:0,ql:0,ll:0,v:new Image,Y:function(){j.clearRect(0,0,25,25);j.fillStyle=this.color;j.fillRect(5,0,15,25);j.fillRect(0,5,25,15);this.s();this.v.src=w[0].toDataURL()}},l.c[a]);a.g=a.g.split("|").map(function(e){e=e.split(",");return{d:e[0]/1,q:e[1]/1,l:e[2]/1}});a.Y();return a},g:[25,40,75,150,250,400,500,700,900,1E3]},c={b:0,P:0,U:-1,t:[],I:[],J:0,F:0,e:1,C:1.3,n:[],D:0,W:35,r:0,Q:10,c:[],m:{},p:false,get h(){return c.W;},set h(v){$("#cash").html(c.W=v);},ca:function(){c.b%60===0&&y.text(g.floor((c.F-c.b)/60)+20+"s >>");c.F+1200<=c.b&&c.b>=1200&&c.T();f.fillStyle="#000";f.fillRect(0,0,700,450);var a=c.map.slice(1),d=c.map[0];f.lineCap="square";f.lineWidth=40;f.strokeStyle="blue";f.beginPath();f.moveTo(d.x,d.y);a.forEach(function(b){f.lineTo(b.x,b.y)});f.stroke();f.lineWidth=30;f.strokeStyle="#004";f.beginPath();f.moveTo(d.x,d.y);a.forEach(function(b){f.lineTo(b.x,b.y)});f.stroke();c.n.forEach(function(b,e,h){if(b.e<=0){c.D++;c.h+=b.h;delete h[e]}else if(b.w===c.map.length){i("#lives").html(--c.Q);delete h[e];c.Q<=0&&c.z()}else{if(--b.A<=0)b.k=b.$;e=c.map[b.w];g.H(b,{x:e.x-7+b.S,y:e.y-7+b.S},b.k)&&b.w++;f.fillStyle="red";f.fillRect(b.x-5,b.y-5,10,10);if(b.u>0||b.k<1){b.e-=b.u;f.fillStyle=b.u>0?b.k<1?"#808":"orange":"blue";f.fillRect(b.x-2,b.y-2,4,4)}}});c.c.forEach(function(b){if(b.O+b.q<=c.b){var e=c.n.filter(function(h){return g.N(h,b,b.l)});if(e.length>0){b.z(e);b.O=c.b}}f.drawImage(b.v,b.x-12.5,b.y-12.5)});if(a=c.c.i||c.c.s){f.beginPath();f.fillStyle=("G"in a?a.G:true)?"rgba(255,255,255,.3)":"rgba(255,0,0,.3)";f.arc(a.x,a.y,a.l,0,g.K,true);f.fill();f.drawImage(a.v,a.x-12.5,a.y-12.5)}c.I.forEach(function(b,e,h){b()===false&&delete h[e]});c.t.forEach(function(b,e,h){b.B();--b.b<=0&&delete h[e]});c.b++},T:function(){c.F=c.b;i("#wn").html(++c.J);c.C={10:1.2,25:1.1,50:1.06,100:1.04,150:1.02,200:1.01}[c.J]||c.C;c.e*=c.C;for(var a=1;a<=10;a++)c.n.push({x:-(a*20)-10,y:c.map[0].y,S:g.j(15),w:0,k:1,A:0,$:1,e:c.e,u:0,h:c.J})},y:function(){c.x();c.U=o.setInterval(c.ca,1E3/60);c.p=false},x:function(){o.clearInterval(c.U);c.p=true},z:function(){c.x();var a=" scored "+c.D*c.r+" ("+c.D+" kills, $"+c.r+" spent) on "+c.map.name,d=location.href.split("/");d[3]="Entry";i("#e").html("Game over! You"+a+".<br>Feel free to <a onclick='location.reload()'>play again</a>, <a href='http://twitter.com/?status="+o.encodeURIComponent("I"+a+" in #canvastd "+location.href)+"' target='_blank'>tweet your score</a>, and <a href='"+d.join("/")+"' target='_blank'>rate this app</a>.").show()}};i.each(l.R,function(a){i("<br> <a>"+a+"</a>").appendTo("#maps")});i("#s a").click(function(){c.map=l.R[this.innerHTML].split("|").map(function(a){a=a.split(",");return{x:a[0]/1,y:a[1]/1}});c.map.name=this.innerHTML;i("#s").remove();i.extend(true,[],c.map).forEach(function(a,d,b){b=b[d+1]||a;var e=b.x-a.x,h=b.y-a.y;if(g.abs(e)>g.abs(h)){a.x+=e<0?21:-16;var k=h/e,s=a.y-k*a.x;for(e=e<0?-1:1;a.x!==b.x;){a.x+=e;for(d=-3;d<=4;d++)c.m[g.round(a.x/5)+","+(g.round(k*a.x+s)/5+d)]=true}}else if(h!==0){a.y+=h<0?21:-16;k=e/h;s=a.x-k*a.y;for(h=h<0?-1:1;a.y!=b.y;){a.y+=h;for(d=-3;d<=4;d++)c.m[g.round(k*a.y+s)/5+d+","+g.round(a.y/5)]=true}}});t.find("a").click(function(){var a=this.id,d=c.c,b=l.c[a];if(!("i"in d)&&c.h-b.f>=0)d.i=l.V(a,-1000,-1000);return false});v.click(function(a){var d=c.c,b=d.i,e=c.m[g.round((a.clientX-5-q.scrollLeft())/5)+","+g.round((a.clientY-5-q.scrollTop())/5)];"s"in d&&r.click();if(b){if(b.G){c.h-=b.f;c.r+=b.f;b.O=0;d.i.M=d.push(d.i)-1;delete d.i;a=(b.x+2.5)/5;d=(b.y+2.5)/5;for(var h=5;h--;)for(var k=5;k--;)c.m[a+h-2+","+(d+k-2)]=b}}else if(typeof e==="object"){t.hide();x.show();e.s=true;d.s=e;(function s(){i("#Damage, #Rate, #Range").unbind().each(function(){var m=e[({Damage:"d",Rate:"q",Range:"l"})[this.id]+"l"],html=l.g[m];this.innerHTML=this.id+" ("+m+")<br>";if(html)this.innerHTML+="$"+html}).click(function(){var m=({Damage:"d",Rate:"q",Range:"l"})[this.id],html=e[m+"l"],n=l.g[html];if(n&&c.h-n>=0){e[m+"l"]++;e[m]=e.g[html][m];e.f+=n;e.o=e.dl===10&&e.ql===10&&e.ll===10;c.h-=n;c.r+=n;s()}return false});var u=g.round(e.f*0.7);i("#sell").unbind().html("Sell<br>+$"+u).click(function(){c.h+=u;c.r-=u;delete c.c[e.M];r.click();for(var m=(e.x+2.5)/5,html=(e.y+2.5)/5,n=5;n--;)for(var z=5;z--;)c.m[m+n-2+","+(html+z-2)]=false})})()}else r.click()}).mousemove(function(a){var d=c.c;if("i"in d){d=d.i;var b=g.floor((a.clientX+q.scrollLeft())/5);a=g.floor((a.clientY+q.scrollTop())/5);d.x=b*5-2.5;d.y=a*5-2.5;d.G=b>=3&&b<=138&&a>=3&&a<=88;for(var e=5;e--;)for(var h=5;h--;)if(c.m[b+e-2+","+(a+h-2)]){d.G=false;return}}});r.click(function(){var a=c.c;if("s"in a){a.s.s=false;delete a.s;x.hide();t.show()}if("i"in a){delete a.i}});i("#pause").toggle(c.x,c.y);y.click(function(a){!c.p&&c.T();return false});c.y();o.setInterval(function(){i("#fps").html(c.b-c.P);c.P=c.b},1E3);o.na=c});i.each(l.c,function(a,d){t.append("<a id='"+a+"'><img src='"+l.V(a,0,0).v.src+"'><br>"+a+" ($"+d.f+")</a>")})})(this,document,$,Math);function t(c){var b="";c.results.length&&c.results.forEach(function(d){var a=d.text.match(/^I scored( (\d+) \((\d+) kills, \$(\d+) spent\) on (\w+)) in #canvastd/);if(a&&a[2]==a[3]*a[4])b+="<div>"+d.from_user+":"+a[1]+"<br><br>"});$("#t").html(b?"<div style='text-align:center'>Latest tweeted scores</div><br>"+b:"No tweeted scores yet :(")}</script><script src="http://search.twitter.com/search.json?q=%23canvastd&result_type=recent&callback=t" defer="true"></script></body>