forked from satanas/pariah
-
Notifications
You must be signed in to change notification settings - Fork 0
/
all.min.js
1 lines (1 loc) · 30.7 KB
/
all.min.js
1
$.PW={F:{n:"Fire",v:1,m:5},E:{n:"Earth",v:2,m:7},W:{n:"Water",v:3,m:3},A:{n:"Air",v:4,m:6}},$.HCOLOR="hsl(141,100%,48%)",$.MCOLOR="hsl(208,100%,48%)",$.C={f:"hsl(326,10%,25%)",b:"rgb(0,0,0)",w:"rgb(255,255,255)",o:"hsl(13,100%,51%)",u:"hsl(196,90%,76%)",e:"hsl(28,66%,26%)",s:"hsl(78,100%,92%)",yw:"rgb(255,255,0)",gy:"rgb(154,154,154)",rd:"rgb(200,0,0)",gd:"rgb(219,190,117)"},$.Rect=function(e,t,n,$){this.x=e,this.y=t,this.w=n,this.h=$,this.b=t+$,this.t=t,this.l=e,this.r=e+n};var abs=Math.abs,cos=Math.cos,sin=Math.sin,ceil=Math.ceil,floor=Math.floor,max=Math.max,pow=Math.pow,sqrt=Math.sqrt,round=Math.round,rand=Math.random;$.n=Date.now,$.u={fading:[],instID:null},$.u.range=function(e,t,n){return t>e?t:e>n?n:e},$.u.fadeOut=function(e,t){$.u.fading[e]=setInterval($.u._fade,50,e,t)},$.u._fade=function(e,t){var n=$.u.byId(e);n.style.opacity-=.03,n.style.opacity<=0&&(clearInterval($.u.fading[e]),$.u.fading.splice($.u.fading.indexOf(e),1),void 0!==t&&t())},$.u.show=function(e){$.u.byId(e).style.opacity=1},$.u.hide=function(e){$.u.byId(e).style.opacity=0},$.u.v=function(e,t){$.u.byId(e).style.visibility=t?"visible":"hidden"},$.u.rand=function(e,t){return floor(Math.random()*(t-e))+e},$.u.canMiss=function(e){var t=$.u.rand(1,100);return t<=floor(100*e)},$.u.byId=function(e){return document.getElementById(e)},$.u.i=function(e,t){var n=t||3e3;$.u.instID&&(clearTimeout($.u.instID),clearInterval($.u.fading.m1)),$.u.byId("m1").innerHTML=e,$.u.show("m1"),$.u.instID=setTimeout(function(){$.u.fadeOut("m1",$.cleanMsg)},n)},$.u.ts=function(){return $.u.byId("ts")};var __nativeST__=window.setTimeout,__nativeSI__=window.setInterval;window.setTimeout=function(e,t){var n=this,$=Array.prototype.slice.call(arguments,2);return __nativeST__(e instanceof Function?function(){e.apply(n,$)}:e,t)},window.setInterval=function(e,t){var n=this,$=Array.prototype.slice.call(arguments,2);return __nativeSI__(e instanceof Function?function(){e.apply(n,$)}:e,t)},window.raf=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||function(e){window.setTimeout(e,1e3/60)},window.caf=window.cancelAnimationFrame||window.mozCancelAnimationFrame,$.Input=function(){var e={},t={};return document.body.addEventListener("keydown",function(n){n.keyCode in e&&(n.preventDefault(),t[n.keyCode]=-1,e[n.keyCode]=1)}),document.body.addEventListener("keyup",function(n){n.keyCode in e&&(n.preventDefault(),t[n.keyCode]=1,e[n.keyCode]=0)}),{p:function(t){return!!e[t]},r:function(e){return 1===t[e]},d:function(e){return-1===t[e]},u:function(){Object.keys(e).forEach(function(e){t[e]=0})},bind:function(n){n.forEach(function(n){e[n]=0,t[n]=0})}}}(),$.Camera=function(e,t,n,$){var r=this;r.w=e,r.h=t,r.ww=n,r.wh=$,r.ofx=0,r.ofy=0,r.tg=0,r.setTarget=function(e){r.tg=e},r.transCoord=function(e){return{x:e.x-r.ofx,y:e.y-r.ofy,r:e.bounds.r-r.ofx,b:e.bounds.b-r.ofy}},r.inView=function(e){var t=r.transCoord(e);return(t.r>=0&&t.r<=r.w||t.x>=0&&t.x<=r.w)&&(t.b>=0&&t.b<=r.h||t.y>=0&&t.y<=r.h)},r.update=function(){if(r.tg){var e,t=0,n=r.w/2,$=r.h/2;r.ww<=r.w?e=r.tg.x:r.tg.x<=n?e=r.tg.x:r.tg.x>n&&r.tg.x+n<=r.ww?e=n:r.tg.x>n&&r.tg.x+n>r.ww&&(e=r.w-(r.ww-r.tg.x)),r.wh<=r.h?e=r.tg.y:r.tg.y<=$?t=r.tg.y:r.tg.y>$&&r.tg.y+$<=r.wh?t=$:r.tg.y>$&&r.tg.y+$>r.wh&&(t=r.h-(r.wh-r.tg.y)),r.ofx=r.tg.x-e,r.ofy=r.tg.y-t}},r.render=function(e){e&&e.forEach(function(e){if(r.inView(e)){var t=r.transCoord(e);e.render(t.x,t.y)}})}},$.Collide=function(){var e=this;e.rect=function(e,t){return 0===Object.keys(e.bounds).length||0===Object.keys(t.bounds).length?!1:!(e.bounds.b<t.bounds.t||e.bounds.t>t.bounds.b||e.bounds.l>t.bounds.r||e.bounds.r<t.bounds.l)},e.faces=function(e,t){return{top:abs(e.bounds.b-t.bounds.t),bottom:abs(e.bounds.t-t.bounds.b),left:abs(e.bounds.r-t.bounds.l),right:abs(e.bounds.l-t.bounds.r)}},e.isTop=function(t,n){var $=e.faces(t,n);return $.top<$.bottom&&$.top<$.left&&$.top<$.right},e.isBottom=function(t,n){var $=e.faces(t,n);return $.bottom<$.top&&$.bottom<$.left&&$.bottom<$.right},e.isLeft=function(t,n){var $=e.faces(t,n);return $.left<$.bottom&&$.left<$.top&&$.left<$.right},e.isRight=function(t,n){var $=e.faces(t,n);return $.right<$.bottom&&$.right<$.left&&$.right<$.top}},$.Power=function(e,t,n,r,o,a){var i=this;i.x=e,i.y=t,i.w=n,i.h=r,i.t=a,i.u=0,"l"===o?(i.dirX=-1,i.dirY=0):"r"===o?(i.dirX=1,i.dirY=0):"d"===o?(i.dirX=0,i.dirY=1):"u"===o&&(i.dirX=0,i.dirY=-1),i.getb=function(){return{b:i.y+i.h,t:i.y,l:i.x,r:i.x+i.w}},i.chk=function(e){i.bounds=i.getb(),$.enemies.forEach(function(t){if($.collide.rect(i,t)&&!i.u){var n=t.damage(i);null!==n&&0!==n&&i.t==$.PW.W.v&&$.hero.heal(n),i.t==$.PW.F.v&&i.die(e)}}),$.walls.forEach(function(t){!$.collide.rect(i,t)||i.t!=$.PW.F.v&&i.t!=$.PW.A.v||i.die(e)}),(i.x+i.w>$.ww||i.x<0)&&i.die(e),(i.y+i.h>$.wh||i.y<0)&&i.die(e)},i.die=function(e){i.u=1,$.powers.splice(e,1),i.t==$.PW.W.v&&($.hero.shield=!1)}},$.Fire=function(e,t,n){var r=this;$.Power.call(r,e,t,16,16,n,$.PW.F.v),"u"===n||"d"===n?$.lvl.isWall(floor(e/32)-1,floor(t/32))?r.x+=4:$.lvl.isWall(floor(e/32)+1,floor(t/32))?r.x-=3:r.x+=1:("r"===n||"l"===n)&&(r.y+=4),r.a=.55,r.maxS=6,r.dx=r.dy=0,r.bounds=r.getb(),r.anim={x:18,y:17},r.ts=$.u.ts(),r.angle=0,r.attack=$.u.rand(8,12),r.update=function(e){r.angle=(r.angle+15)%360,r.dx+=r.a*r.dirX,r.dy+=r.a*r.dirY,r.dx=$.u.range(r.dx,-r.maxS,r.maxS),r.dy=$.u.range(r.dy,-r.maxS,r.maxS),r.x+=r.dx,r.y+=r.dy,r.chk(e)},r.render=function(e,t){$.x.s(),$.x.fillStyle=$.C.o,$.x.beginPath(),$.x.arc(e+8,t+8,8,0,2*Math.PI,!1),$.x.fill(),$.x.sc(2,2),$.x.d(r.ts,0,28,8,8,e/2,t/2,8,8),$.x.r()}},$.Earth=function(e,t,n,r){var o=this,a=30;$.Power.call(o,e,t,15,25,n,$.PW.E.v),"u"===n?(o.y-=a,1===r&&(o.x+=2)):"r"===n?(o.x+=a,1===r&&(o.y+=6)):"d"===n?(o.y+=a,1===r&&(o.x+=2)):"l"===n&&(o.x-=a,1===r&&(o.y+=6)),o.n=r,o.o=n,o.bounds=o.getb(),o.ltime=400,o.stime=350,o.ctime=$.n(),o.attack=0,o.anim={x:5,y:17},o.ts=$.u.ts(),o.summon=0,o.update=function(e){var t=$.n()-o.ctime;t>o.ltime&&o.die(e),t>o.stime&&!o.summon&&o.n<3&&(o.summon=1,$.powers.push(new $.Earth(o.x,o.y,o.o,o.n+1))),o.chk(e)},o.render=function(e,t){$.x.s(),$.x.sc(3,3),$.x.d(o.ts,o.anim.x,o.anim.y,5,10,e/3,t/3,5,10),$.x.r()}},$.Water=function(e,t,n){var r=this;$.Power.call(r,e,t,20,20,null,$.PW.W.v),r.vw=2*Math.PI,r.a=n*Math.PI/180,r.d=35,r.r=10,r.ltime=6e3,r.ctime=$.n(),r.bounds=r.getb(),r.attack=$.u.rand(3,6),r.update=function(e){var t=$.n()-r.ctime;r.ctime=$.n(),r.ltime-=t,r.ltime<=0&&r.die(e),r.cx=$.hero.x+$.hero.w/2,r.cy=$.hero.y+$.hero.h/2,r.a+=r.vw*t/1e3,r.x=r.cx+r.d*cos(r.a),r.y=r.cy+r.d*sin(r.a),r.chk(e)},r.render=function(e,t){$.x.s();var n=e-11,r=t-11;$.x.fillStyle="hsla(190,90%,76%,0.59)",$.x.fr(n+7,r+7,8,8),$.x.fillStyle="hsl(190,90%,76%)",$.x.fr(n+4,r+10,14,2),$.x.fr(n+10,r+4,2,14),$.x.fr(n+10,r,2,2),$.x.fr(n+3,r+3,2,2),$.x.fr(n+17,r+3,2,2),$.x.fr(n,r+10,2,2),$.x.fr(n+20,r+10,2,2),$.x.fr(n+3,r+17,2,2),$.x.fr(n+17,r+17,2,2),$.x.fr(n+10,r+20,2,2),$.x.r()}},$.Air=function(e,t,n){var r=this;$.Power.call(r,e,t,12,24,n,$.PW.A.v),("u"===n||"d"===n)&&(r.x+=6),r.a=.65,r.maxS=7,r.dx=r.dy=0,r.bounds=r.getb(),r.attack=$.u.rand(7,10),r.anim={x:11,y:17},r.ts=$.u.ts(),r.blink=0,r.bcount=0,r.ctime=$.n(),r.update=function(e){r.dx+=r.a*r.dirX,r.dy+=r.a*r.dirY,r.dx=$.u.range(r.dx,-r.maxS,r.maxS),r.dy=$.u.range(r.dy,-r.maxS,r.maxS),r.x+=r.dx,r.y+=r.dy;var t=$.n()-r.ctime,n=floor(t/100);n>r.bcount&&(r.bcount=n,r.blink=!r.blink),r.chk(e)},r.render=function(e,t){$.x.s(),$.x.fillStyle="hsla(207,100%,83%,0.1)",$.x.fr(e,t,r.w,r.h),$.x.globalAlpha=.7,r.blink?($.x.translate(e+r.w/2-6,t+r.h/2),$.x.sc(-2,2)):($.x.translate(e+r.w/2+6,t+r.h/2),$.x.sc(2,2)),$.x.d(r.ts,r.anim.x,r.anim.y,r.w/2,r.h/2,-r.w/4,-r.h/4,6,12),$.x.r()}},$.Item=function(e,t,n,r){var o=this;o.x=e,o.y=t,o.w=16,o.h=16,o.t=n,o.c=r||!1,o.ts=$.u.ts(),o.bounds={b:o.y+o.h,t:o.y,l:o.x,r:o.x+o.w},o.update=function(e){$.collide.rect(o,$.hero)&&($.hero.gain(o),o.die(e))},o.die=function(e){$.items.splice(e,1)},o.render=function(e,t){$.x.s(),$.x.fillStyle=o.k,$.x.fr(e,t,o.w,o.h),$.x.sc(2,2),$.x.d(o.ts,0,28,8,8,e/2,t/2,8,8),$.x.r()}},$.FireItem=function(e,t){var n=this;$.Item.call(n,e,t,$.PW.F),n.k=$.C.o},$.WaterItem=function(e,t){var n=this;$.Item.call(n,e,t,$.PW.W),n.k=$.C.u},$.EarthItem=function(e,t){var n=this;$.Item.call(n,e,t,$.PW.E),n.k=$.C.e},$.AirItem=function(e,t){var n=this;$.Item.call(n,e,t,$.PW.A),n.k=$.C.s},$.Key=function(e,t){var n=this;$.Item.call(n,e,t,"k",!0),n.anim={x:0,y:17},n.ts=$.u.ts(),n.w=6,n.h=20,n.render=function(e,t){$.x.s(),$.x.sc(2,2),$.x.d(n.ts,n.anim.x,n.anim.y,5,10,e/2,t/2,5,10),$.x.r()}},$.HealthPack=function(e,t){$.Item.call(this,e,t,"h",!0),this.w=10,this.render=function(e,t){$.x.s(),$.DrawBottle(e,t,$.HCOLOR),$.x.r()}},$.ManaPack=function(e,t){$.Item.call(this,e,t,"m",!0),this.w=10,this.render=function(e,t){$.x.s(),$.DrawBottle(e,t,$.MCOLOR),$.x.r()}},$.DrawBottle=function(e,t,n){$.x.globalAlpha=.7,$.x.fillStyle="rgb(255,0,0)",$.x.fr(e,t,this.w,this.h),$.x.fillStyle="hsl(36,43%,59%)",$.x.fr(e+3,t+1,3,3),$.x.fillStyle=$.C.g;for(var r=[[2,7],[3,6],[3,6],[2,7],[1,8]],o=2;6>=o;o++)$.x.fr(e+r[o-2][0],t+o,1,1),$.x.fr(e+r[o-2][1],t+o,1,1);$.x.fr(e,t+7,1,11),$.x.fr(e+9,t+7,1,11),$.x.fr(e,t+17,10,1),$.x.fillStyle="rgb(255,255,255)",$.x.fr(e+3,t+6,1,1),$.x.fr(e+2,t+7,1,1),$.x.fillStyle=n,$.x.fr(e+7,t+7,2,1),$.x.fr(e+3,t+8,6,1),$.x.fr(e+1,t+9,8,8),$.x.fillStyle="hsl(208,50%,48%)",$.x.fr(e+6,t+10,2,2),$.x.fr(e+3,t+14,1,1)},$.Sw=function(e,t,n){var r=this;r.x=e,r.y=t,r.w=32,r.h=32,r.t=n,r.filled=0,r.ts=$.u.ts(),r.bounds={b:r.y+r.h,t:r.y,l:r.x,r:r.x+r.w},r.update=function(){if(!r.filled&&$.collide.rect(r,$.hero)){$.hero.lose(r.t),r.fill();var e=$.sws;e[0].filled&&e[1].filled&&e[2].filled&&e[3].filled&&4===e.length&&($.sws.push(new $.LifeSw(304,100)),$.u.i("You can only create life from life, now go and make the ultimate offer",7e3))}},r.fill=function(){r.filled=1},r.render=function(e,t){$.x.s(),$.x.fillStyle=$.C.gd,$.x.fr(e,t,32,32),$.x.fillStyle=r.filled?$.C.gy:r.k,$.x.fr(e+8,t+8,16,16),$.x.r()}},$.FireSw=function(e,t){var n=this;$.Sw.call(n,e,t,$.PW.F),n.k=$.C.o},$.EarthSw=function(e,t){var n=this;$.Sw.call(n,e,t,$.PW.E),n.k=$.C.e},$.WaterSw=function(e,t){var n=this;$.Sw.call(n,e,t,$.PW.W),n.k=$.C.u},$.AirSw=function(e,t){var n=this;$.Sw.call(n,e,t,$.PW.A),n.k=$.C.s},$.LifeSw=function(e,t){var n=this;$.Sw.call(n,e,t),n.k=$.C.rd,n.bounds={b:n.y+8,t:n.y,l:n.x+12,r:n.x+n.w-12},n.update=function(){n.filled||$.collide.rect(n,$.hero)&&(n.filled=1,$.ended=1,$.fadeOut.start(4e3,"255,255,255"))}},$.Hero=function(e,t,n){var r=this;r.x=e,r.y=t,r.w=16,r.h=32,r.bounds={},r.maxS=2,r.maxH=100,r.maxM=100,r.maxCD=380,r.mRegen=1.75,r.ts=$.u.ts(),r.s=.13,r.dx=0,r.dy=0,r.o=n||"d",r.pows=[],r.hurt=0,r.he=r.maxH,r.ma=r.maxM,r.shield=0,r.ctime=$.n(),r.htime=$.n(),r.etimeH=0,r.itime=1e3,r.blink=0,r.bcount=0,r.cd=0,r.rs=.15,r.key=!1,r.exit=!1,r.dead=!1,r.count=0,r.frameDuration=5,r.currFrame=0,r.totalFrames=2,r.anim={run:{d:[{x:22,y:0},{x:32,y:0}],u:[{x:22,y:16},{x:32,y:16}],r:[{x:22,y:32},{x:32,y:32}],l:[{x:22,y:48},{x:32,y:48}]},idle:{d:{x:22,y:0},u:{x:22,y:16},r:{x:22,y:32},l:{x:22,y:48}}},this.damage=function(e){if(!r.hurt&&!r.dead){var t=floor(e.attack-e.attack*$.u.rand(100*r.rs,0)/100);r.he-=t,r.hurt=1,r.htime=$.n(),r.etimeH=0,$.textPops.push(new $.TextPop("-"+t,r.x+7,r.y-5,"red")),r.he<=0&&(r.he=0,r.dead=!0,$.deco.push(new $.Blood(r.x,r.y)),$.fadeOut.start(3e3,"0,0,0"))}},this.heal=function(e){r.he+=e;var t=r.he>r.maxH?"full":"+"+e;r.he=$.u.range(r.he,0,r.maxH),$.textPops.push(new $.TextPop(t,r.x+7,r.y-5,"green"))},this.charge=function(e){r.ma+=e;var t=r.ma>r.maxM?"full":"+"+e;r.ma=$.u.range(r.ma,0,r.maxM),$.textPops.push(new $.TextPop(t,r.x+7,r.y-5,"blue"))},this.gain=function(e){if(e.c===!1){if(r.pows.indexOf(e.t.v)>=0)return;e.t.v===$.PW.F.v&&($.fow.radius=6),r.pows.push(e.t.v),$.epow.push(e.t.v),$.u.i(["You now control the",e.t.n,"element. Press",e.t.v,"to use it"].join(" "))}else"k"===e.t?($.sco+=50,r.key=!0,$.u.i("You got the key of this dungeon")):"h"===e.t?r.heal(20):"m"===e.t&&r.charge(20)},this.lose=function(e){var t=r.pows.indexOf(e.v);r.pows.splice(t,1)},this.update=function(){if(!r.dead){r.exit=!1;var e=$.n(),t=e-r.ctime;if(r.ctime=e,r.hurt){r.etimeH=$.n()-r.htime;var n=floor(r.etimeH/100);n>r.bcount&&(r.bcount=n,r.blink=!r.blink),r.etimeH>=r.itime&&(r.hurt=0,r.bcount=0,r.blink=0)}$.input.p(37)?(r.o="l",r.dx-=r.s):$.input.p(39)&&(r.o="r",r.dx+=r.s),$.input.p(38)?(r.o="u",r.dy-=r.s):$.input.p(40)&&(r.o="d",r.dy+=r.s),r.dx=$.u.range(r.dx,-r.maxS,r.maxS),r.dy=$.u.range(r.dy,-r.maxS,r.maxS),$.input.p(37)||$.input.p(39)||(r.dx=0),$.input.p(38)||$.input.p(40)||(r.dy=0),r.cd>0&&(r.cd-=t,r.cd<=0&&(r.cd=0)),r.x+=r.dx,r.y+=r.dy,r.x+r.w>$.ww&&(r.x=$.ww-r.w),r.y+r.h>$.wh&&(r.y=$.wh-r.h),r.x<0&&(r.x=0),r.y<0&&(r.y=0),r.bounds={b:r.y+r.h,t:r.y,l:r.x,r:r.x+r.w},r.shield?r.ma-=t*$.PW.W.m/1e3:r.ma+=t*r.mRegen/1e3,r.ma=$.u.range(r.ma,0,r.maxM),r.he=$.u.range(r.he,0,r.maxH);var o=null;$.input.p(49)&&r.pows.indexOf($.PW.F.v)>=0?o=$.PW.F:$.input.p(50)&&r.pows.indexOf($.PW.E.v)>=0?o=$.PW.E:$.input.p(51)&&r.pows.indexOf($.PW.W.v)>=0?o=$.PW.W:$.input.p(52)&&r.pows.indexOf($.PW.A.v)>=0&&(o=$.PW.A),0===r.cd&&o&&(r.ma>=o.m&&(o.v!==$.PW.W.v||!r.shield)?(r.ma-=o.m,r.cd=r.maxCD,o.v===$.PW.F.v?$.powers.push(new $.Fire(r.x,r.y,r.o)):o.v===$.PW.E.v?$.powers.push(new $.Earth(r.x,r.y,r.o,1)):o.v===$.PW.W.v?([0,120,240].forEach(function(e){$.powers.push(new $.Water(r.x,r.y,e))}),r.shield=1):o.v===$.PW.A.v&&$.powers.push(new $.Air(r.x,r.y,r.o))):r.ma<o.m&&$.u.i("You do not have enough mana to cast the "+o.n+" element")),$.walls.forEach(function(e){$.collide.rect(r,e)&&($.collide.isTop(r,e)?r.y=e.bounds.t-r.h:$.collide.isBottom(r,e)?r.y=e.bounds.b:$.collide.isLeft(r,e)?r.x=e.bounds.l-r.w:$.collide.isRight(r,e)&&(r.x=e.bounds.r))}),$.enemies.forEach(function(e){$.collide.rect(r,e)&&r.damage(e)}),$.exit&&$.collide.rect(r,$.exit[0])&&(r.exit=!0),r.count=(r.count+1)%r.frameDuration,r.count===r.frameDuration-1&&(r.currFrame=(r.currFrame+1)%r.totalFrames)}},this.render=function(e,t){if(!r.dead){$.x.s(),$.x.sc(2,2);var n=0===r.dx&&0===r.dy?r.anim.idle[r.o]:r.anim.run[r.o][r.currFrame];r.blink&&($.x.globalAlpha=.3),$.x.d(r.ts,n.x,n.y,8,16,e/2,t/2,8,16),$.x.r()}}},$.Zombie=function(e,t){var n=this;n.x=e,n.y=t,n.w=16,n.h=32,n.he=35,n.maxH=35,n.miss=.05,n.ptime=4e3,n.itime=300,n.ts=$.u.ts(),n.dx=0,n.dy=0,n.o="d",n.hurt=!1,n.planted=0,n.blink=0,n.ctimeH=0,n.ctimeP=0,n.etimeH=0,n.etimeP=0,n.bcount=0,n.minD=300,n.hasRoute=0,n.route=[],n.nextPt=[],n.lastPt=[],n.speed=.7,n.attack=$.u.rand(40,50),n.count=0,n.frameDuration=10,n.currFrame=0,n.totalFrames=2,n.anim={run:{d:[{x:42,y:0},{x:52,y:0}],u:[{x:42,y:16},{x:52,y:16}],r:[{x:42,y:32},{x:52,y:32}],l:[{x:42,y:48},{x:52,y:48}]},idle:{d:{x:42,y:0},u:{x:42,y:16},r:{x:42,y:32},l:{x:42,y:48}}},n.getb=function(){return{b:n.y+n.h,t:n.y,l:n.x,r:n.x+n.w}},n.bounds=n.getb(),n.damage=function(e){if(n.hurt)return null;if(e.t===$.PW.E.v)return void(n.planted||(n.planted=!0,n.ctimeP=$.n(),n.etimeP=0,$.textPops.push(new $.TextPop("bounded",n.x+2,n.y-5,$.C.w))));if($.u.canMiss(n.miss))return $.textPops.push(new $.TextPop("miss",n.x,n.y-5,$.C.w)),0;var t=e.attack;return n.he-=t,n.hurt=!0,n.ctimeH=$.n(),n.etimeH=0,$.textPops.push(new $.TextPop("-"+t,n.x+7,n.y-5,$.C.yw)),t},n.die=function(e){if($.enemies.splice(e,1),0===$.enemies.length)$.items.push(new $.Key(n.x+n.w/2,n.y+4));else if($.u.rand(0,10)>6){var t=[$.HealthPack,$.ManaPack],r=$.u.rand(0,2);$.items.push(new t[r](n.x+n.w/2,n.y+4))}$.deco.push(new $.Blood(n.x,n.y)),$.sco+=10*n.attack},n.update=function(e){if(n.bounds=n.getb(),n.dx=0,n.dy=0,n.planted&&(n.etimeP=$.n()-n.ctimeP,n.etimeP>=n.ptime&&(n.planted=0)),n.hurt){n.etimeH=$.n()-n.ctimeH;var t=floor(n.etimeH/100);t>n.bcount&&(n.bcount=t,n.blink=!n.blink),n.etimeH>=n.itime&&(n.hurt=!1,n.bcount=0,n.blink=0)}if(n.he<=0&&n.die(e),n.hasRoute)floor(n.x/32)==n.nextPt[0]&&floor(n.y/32)==n.nextPt[1]?n.route.length>0?n.nextPt=n.route.shift():(n.hasRoute=0,n.route=[],n.nextPt=[],n.lastPt=[]):(floor(n.x/32)<n.nextPt[0]&&!n.planted?(n.dx=n.speed,n.o="r"):floor(n.x/32)>n.nextPt[0]&&!n.planted&&(n.dx=-n.speed,n.o="l"),floor(n.y/32)<n.nextPt[1]&&!n.planted?(n.dy=n.speed,n.o="d"):floor(n.y/32)>n.nextPt[1]&&!n.planted&&(n.dy=-n.speed,n.o="u"),(floor($.hero.x/32)!=n.lastPt[0]||floor($.hero.y/32)!=n.lastPt[1])&&(n.hasRoute=0,n.route=[],n.nextPt=[],n.lastPt=[]));else{var r=$.ai.getd({x:n.x,y:n.y},{x:$.hero.x,y:$.hero.y});r<=n.minD&&round(r)>40&&(n.route=$.ai.cPath([floor(n.x/32),floor(n.y/32)],[floor($.hero.x/32),floor($.hero.y/32)]),n.route.length>0&&(n.hasRoute=1,n.lastPt=n.route[n.route.length-1],n.nextPt=n.route.shift()))}0==n.route.length&&40>r&&!n.planted&&(n.x>$.hero.x?(n.dx=-n.speed,n.o="l"):n.x<$.hero.x&&(n.dx=n.speed,n.o="r"),n.y>$.hero.y?(n.dy=-n.speed,n.o="d"):n.y<$.hero.y&&(n.dy=n.speed,n.o="u")),n.x+=n.dx,n.y+=n.dy,$.walls.forEach(function(e){$.collide.rect(n,e)&&($.collide.isTop(n,e)?n.y=e.bounds.t-n.h-1:$.collide.isBottom(n,e)?n.y=e.bounds.b+1:$.collide.isLeft(n,e)?n.x=e.bounds.l-n.w-1:$.collide.isRight(n,e)&&(n.x=e.bounds.r+1))}),n.count=(n.count+1)%n.frameDuration,n.count===n.frameDuration-1&&(n.currFrame=(n.currFrame+1)%n.totalFrames)},n.render=function(e,t){var r=0===n.dx&&0===n.dy?n.anim.idle[n.o]:n.anim.run[n.o][n.currFrame];$.x.s(),$.x.sc(2,2),n.blink&&($.x.globalAlpha=.3),$.x.d(n.ts,r.x,r.y,8,16,e/2,t/2,8,16),$.x.r(),$.x.s(),$.x.fillStyle="rgb(0,0,0)",$.x.fr(e-8,t-10,32,5),$.x.fillStyle="rgb(255,0,0)",$.x.fr(e-8,t-10,32*n.he/n.maxH,5),$.x.r()}},$.Wall=function(e,t,n){var r=this;r.x=e,r.y=t,r.w=32,r.h=32,r.half=n,r.ts=$.u.ts(),r.bounds={b:0===r.half?r.y+r.h:r.y+r.h/2,t:r.y,l:r.x,r:r.x+r.w},r.render=function(e,t){$.x.s(),$.x.sc(2,2),$.x.d(r.ts,0,0,16,16,e/2,t/2,16,16),$.x.r()}},$.Door=function(e,t){var n=this;n.x=e,n.y=t,n.w=32,n.h=32,n.t=$.u.ts(),n.o=0,n.bounds={b:n.y+n.h/2,t:n.y,l:n.x,r:n.x+n.w},n.render=function(e,t){$.x.s(),$.x.sc(2,2),$.x.d(n.t,0,0,16,16,e/2,t/2,16,16),$.x.d(n.t,n.o,49,10,15,e/2+3,t/2+1,10,15),$.x.r()}},$.Entrance=function(e,t){$.Door.call(this,e,t)},$.Exit=function(e,t){$.Door.call(this,e,t),this.o=11},$.FoW=function(e){var t=this;t.radius=e,t.shadowOffset=ceil(e/2)+1,t.fow=[],t.mult=[[1,0,0,-1,-1,0,0,1],[0,1,-1,0,0,-1,1,0],[0,1,1,0,0,-1,-1,0],[1,0,0,1,-1,0,0,-1]],t.cast=function(e,n,r,o,a,i,l,u,s){var d=t.radius*t.radius,f=0;if(!(a>o))for(var c=r;c<=t.radius;c++){for(var x=-c-1,h=-c,w=!1;0>=x;){x+=1;var m=e+x*i+h*l,y=n+x*u+h*s;if(m<$.ww/32&&m>=0&&y<$.wh/32&&y>=0){var p=(x-.5)/(h+.5),v=(x+.5)/(h-.5);if(v>o)continue;if(a>p)break;if(d>x*x+h*h&&(t.fow[m][y]=c),w){if($.lvl.isWall(m,y)){f=v;continue}w=!1,o=f}else $.lvl.isWall(m,y)&&c<t.radius&&(w=!0,t.cast(e,n,c+1,o,p,i,l,u,s),f=v)}}if(w)break}},t.update=function(){var e,n=$.hero.x,r=$.hero.y,o=16>=n%32?floor(n/32):floor(n/32)+1,a=16>=r%32?floor(r/32):floor(r/32)+1,i=0;for(e=0;e<=$.ww/32;e++)for(t.fow[e]=[],i=0;i<=$.wh/32;i++)t.fow[e].push(0);for(t.fow[o][a]=1,e=8;e--;)t.cast(o,a,1,1,0,t.mult[0][e],t.mult[1][e],t.mult[2][e],t.mult[3][e])},t.render=function(){$.ctx1.clearRect(0,0,$.vw,$.vh),$.ctx1.fillStyle="rgba(0,0,0,1)",$.ctx1.fillRect(0,0,$.vw,$.vh),$.ctx2.clearRect(0,0,$.vw,$.vh);for(var e=0;e<$.ww/32;e++)for(var n=0;n<$.wh/32;n++){var r=t.fow[e][n];if(r>=1){var o="1.0",a=r-t.shadowOffset,i=t.radius+t.shadowOffset;a>=0&&(o=1-(a/i).toString().substr(0,3)),$.ctx2.fillStyle="rgba(255,255,255,"+o+")",$.ctx2.fillRect(32*e-$.cam.ofx,32*n-$.cam.ofy,33,33)}}$.ctx1.save(),$.ctx1.globalCompositeOperation="destination-out",$.ctx1.drawImage($.cv2,0,0,$.vw,$.vh),$.ctx1.restore(),$.x.d($.cv1,0,0,$.vw,$.vh)}},$.Hud=function(){var e=this;e.ts=$.u.ts(),e.render=function(){$.x.s(),$.x.fillStyle="hsla(0,0%,30%,1)",$.x.fr(55,5,80,10),$.x.fr(55,20,80,10),$.x.fillStyle=$.C.w,$.x.ft("HEALTH",10,15),$.x.ft("MANA",10,30),$.x.ft("LEVEL "+$.lv,560,15),$.x.ft("SCORE "+$.sco,560,30);var t,n=[$.C.o,$.C.e,$.C.u,$.C.s];for(t in $.epow)$.x.fillStyle=n[$.epow[t]-1],$.x.beginPath(),$.x.arc(150+15*$.epow[t],10,4,0,2*Math.PI,0),$.x.fill();var r=80*$.hero.he/$.hero.maxH;$.x.fillStyle=$.HCOLOR,$.x.fr(55,5,r,10),r=80*$.hero.ma/$.hero.maxM,$.x.fillStyle=$.MCOLOR,$.x.fr(55,20,r,10),$.x.sc(2,2),$.hero.key&&$.x.d(e.ts,0,17,5,10,72,2.5,5,10),$.x.r()}},$.Scene=function(){var e=this;e.r=function(t){e.s=0,e.e=0,e.t=$.n(),e.f=0,t&&(["s","s1","i","g","e"].forEach(function(e){$.u.v(e,0)}),$.u.hide("m1"))},e.l=function(t,n){caf($.animId),e.r(1),$.input.u(),t(),$.animId=raf(n)},e.u=function(){$.clr(),e.e=$.n()-e.t,$.input.u()},e.n=function(){var t=e.s;e.r(),e.s=t+1},e.r(1)},$.FadeIn=function(){var e=this;e.done=!0,e.start=function(t){e.done=!1,e.d=t,e.e=0,e.c=$.n()},e.render=function(){if(!e.done){e.e=$.n()-e.c,e.e>e.d&&(e.e=e.d,e.done=!0);var t=(1-e.e/e.d).toString().substr(0,3);$.x.fillStyle="rgba(0,0,0,"+t+")",$.x.fr(0,0,$.cam.w,$.cam.h)}}},$.FadeOut=function(){var e=this;e.done=!0,e.quit=!0,e.start=function(t,n){e.color=n||"0,0,0",e.done=!1,e.quit=!1,e.d=t,e.e=0,e.c=$.n()},e.render=function(){if(!e.quit){e.e=$.n()-e.c,e.e>e.d&&(e.e=e.d,e.done=!0);var t=(e.e/e.d).toString().substr(0,3);$.x.fillStyle="rgba("+e.color+","+t+")",$.x.fr(0,0,$.cam.w,$.cam.h)}}},$.Blood=function(e,t){var n=this;n.x=e,n.y=t,n.w=14,n.h=14,n.t=$.u.ts(),n.bounds={b:n.y+n.h,t:n.y,l:n.x,r:n.x+n.w},n.render=function(e,t){$.x.s(),$.x.sc(2,2),$.x.globalAlpha=.5,$.x.d(n.t,15,41,7,7,e/2,t/2+4,7,7),$.x.r()}},$.Level=function(e,t,n,r,o,a){function i(e){null===e.lc&&null===e.rc&&(e.w>l.maxLeafSize||e.height>l.maxLeafSize||$.u.rand(0,101)>25)&&e.split()&&(l.leafs.push(e.lc),l.leafs.push(e.rc),i.call(l,e.lc),i.call(l,e.rc))}var l=this,u=new $.Leaf(0,0,t,n);l.n=e,l.w=t,l.h=n,l.maxLeafSize=a||15,l.leafs=[],l.map=[],l.leafs.push(u),l.isWall=function(e,t){return"#"===l.map[e][t]?!0:!1},l.rPoint=function(e,t){var n=t||0;return{x:$.u.rand(e.l+n,e.r-n),y:$.u.rand(e.t+n,e.b-n)}},l.isCorner=function(e,t,n){return e===n.t&&t===n.l||e===n.t&&t===n.r||e===n.b&&t===n.l||e===n.b&&t===n.r},i.call(l,u),u.makeRooms();var s=0,d=0;for(s=0;t>s;s++)for(l.map[s]=[],d=0;n>d;d++)l.map[s][d]="#";var f=[];l.leafs.forEach(function(e){var t=e.room;if(null!==t)for(f.push(t),s=t.l;s<=t.r;s++)for(d=t.t;d<=t.b;d++)l.map[s][d]=".";e.halls.forEach(function(e){for(s=e.l;s<=e.r;s++)for(d=e.t;d<=e.b;d++)l.map[s][d]="."})});for(var c=f.pop(),x=r,h=null,w=(r/f.length,0);x>0;){var m=f[$.u.rand(0,f.length)];for(h=l.rPoint(m);"e"===l.map[h.x][h.y];)w++,w>4&&(m=f[$.u.rand(0,f.length)],w=0),h=l.rPoint(m);$.enemies.push(new $.Zombie(32*h.x,32*h.y)),x--,l.map[h.x][h.y]="e"}h=l.rPoint(c);for(var y=null;;){y={x:h.x,y:h.y};var p=$.u.rand(0,4);if(0===p?(h.y=c.t-1,y.y=h.y+2):1===p?(h.x=c.r+1,y.x=h.x-2):2===p?(h.y=c.b+1,y.y=h.y-2):3===p&&(h.x=c.l-1,y.x=h.x+2),l.isWall(h.x,h.y)&&!l.isCorner(h.x,h.y,c))break;h=l.rPoint(c)}$.hero=new $.Hero(32*y.x,32*y.y),$.walls.push(new $.Entrance(32*h.x,32*h.y)),l.map[h.x][h.y]="*",l.map[y.x][y.y]="h";var v=f[$.u.rand(0,f.length)];for(h=l.rPoint(v);;){var b=$.u.rand(0,4);if(0===b?h.y=v.t-1:1===b?h.x=v.r+1:2===b?h.y=v.b+1:3===b&&(h.x=v.l-1),l.isWall(h.x,h.y)&&!l.isCorner(h.x,h.y,v))break;h=l.rPoint(v)}for($.exit[0]=new $.Exit(32*h.x,32*h.y),l.map[h.x][h.y]="@",w=0,s=o.length;s--;){var g=f[$.u.rand(0,f.length)];for(h=l.rPoint(g);"i"===l.map[h.x][h.y];)w++,w>4&&(g=f[$.u.rand(0,f.length)],w=0),h=l.rPoint(g);$.items.push(new o[s](32*h.x+8,32*h.y+8)),l.map[h.x][h.y]="i"}},$.Leaf=function(e,t,n,r){var o=this;o.x=e,o.y=t,o.w=n,o.h=r,o.lc=null,o.rc=null,o.min=6,o.room=null,o.halls=[],o.split=function(){if(null!==o.lc||null!==o.rc)return!1;var e=!!$.u.rand(0,2);o.w>o.h&&o.w/o.h>=.25?e=!1:o.h>o.w&&o.h/o.w>=.25&&(e=!0);var t=(e?o.h:o.w)-o.min;if(t<=o.min)return!1;var n=$.u.rand(o.min,t);return e?(o.lc=new $.Leaf(o.x,o.y,o.w,n),o.rc=new $.Leaf(o.x,o.y+n,o.w,o.h-n)):(o.lc=new $.Leaf(o.x,o.y,n,o.h),o.rc=new $.Leaf(o.x+n,o.y,o.w-n,o.h)),!0},o.makeRooms=function(){if(null!==o.lc||null!==o.rc)null!==o.lc&&o.lc.makeRooms(),null!==o.rc&&o.rc.makeRooms(),null!==o.lc&&null!==o.rc&&o.makeHall(o.lc.getRoom(),o.rc.getRoom());else{var e={w:$.u.rand(3,o.w-2),h:$.u.rand(3,o.h-2)},t={x:$.u.rand(1,o.w-e.w-1),y:$.u.rand(1,o.h-e.h-1)};o.room=new $.Rect(o.x+t.x,o.y+t.y,e.w,e.h)}},o.getRoom=function(){if(null!==o.room)return o.room;var e=null,t=null;return null!==o.lc&&(e=o.lc.getRoom()),null!==o.rc&&(t=o.lc.getRoom()),null===e&&null===t?null:null===t?e:null===e?t:$.u.rand(1,11)>5?e:t},o.makeHall=function(e,t){var n=$.Rect,r={x:$.u.rand(e.l+1,e.r-2),y:$.u.rand(e.t+1,e.b-2)},a={x:$.u.rand(t.l+1,t.r-2),y:$.u.rand(t.t+1,t.b-2)},i=a.x-r.x,l=a.y-r.y;0>i?0>l?$.u.rand(0,10)>4?(o.halls.push(new n(a.x,r.y,abs(i),1)),o.halls.push(new n(a.x,a.y,1,abs(l)))):(o.halls.push(new n(a.x,a.y,abs(i),1)),o.halls.push(new n(r.x,a.y,1,abs(l)))):l>0?$.u.rand(0,10)>4?(o.halls.push(new n(a.x,r.y,abs(i),1)),o.halls.push(new n(a.x,r.y,1,abs(l)))):(o.halls.push(new n(a.x,a.y,abs(i),1)),o.halls.push(new n(r.x,r.y,1,abs(l)))):o.halls.push(new n(a.x,a.y,abs(i),1)):i>0?0>l?$.u.rand(0,10)>4?(o.halls.push(new n(r.x,a.y,abs(i),1)),o.halls.push(new n(r.x,a.y,1,abs(l)))):(o.halls.push(new n(r.x,r.y,abs(i),1)),o.halls.push(new n(a.x,a.y,1,abs(l)))):l>0?$.u.rand(0,10)>4?(o.halls.push(new n(r.x,r.y,abs(i),1)),o.halls.push(new n(a.x,r.y,1,abs(l)))):(o.halls.push(new n(r.x,a.y,abs(i),1)),o.halls.push(new n(r.x,r.y,1,abs(l)))):o.halls.push(new n(r.x,r.y,abs(i),1)):o.halls.push(0>l?new n(a.x,a.y,1,abs(l)):new n(r.x,r.y,1,abs(l)))}},$.TextPop=function(e,t,n,r){var o=this;o.x=t,o.y=n,o.oy=n-45,o.dy=.65,o.elapsed=0,o.ctime=$.n(),o.text=e,o.bounds={r:0,b:0},o.c=r,o.update=function(e){o.y>o.oy&&(o.y-=o.dy),o.elapsed=$.n()-o.ctime,o.elapsed>=800&&o.die(e)},o.render=function(e,t){$.x.s(),$.x.fillStyle=o.c,$.x.fillText(o.text,e,t),$.x.r()},o.die=function(e){$.textPops.splice(e,1)}},$.Ai=function(){var e=this,t=function(){};e.getd=function(e,t){return abs(e.x-t.x)+abs(e.y-t.y)},e.neigh=function(e,n,r,o){var a=n-1,i=n+1,l=e+1,u=e-1,s=a>-1&&!$.lvl.isWall(e,a),d=o>i&&!$.lvl.isWall(e,i),f=r>l&&!$.lvl.isWall(l,n),c=u>-1&&!$.lvl.isWall(u,n),x=[];return s&&x.push({x:e,y:a}),f&&x.push({x:l,y:n}),d&&x.push({x:e,y:i}),c&&x.push({x:u,y:n}),t(s,d,f,c,a,i,l,u,x),x},e.Node=function(e,t,n){var $={Parent:e,value:t.x+t.y*n,x:t.x,y:t.y,f:0,g:0};return $},e.cPath=function(t,n){for(var r,o,a,i,l,u,s,d,f=$.lvl.map[0].length,c=$.lvl.map.length,x=f*c,h=e.Node(null,{x:t[0],y:t[1]},f),w=e.Node(null,{x:n[0],y:n[1]},f),m=new Array(x),y=[h],p=[],v=[];i=y.length;){for(l=x,u=-1,s=0;i>s;s++)y[s].f<l&&(l=y[s].f,u=s);if(o=y.splice(u,1)[0],o.value===w.value){a=p[p.push(o)-1];do v.push([a.x,a.y]);while(a=a.Parent);m=p=y=[],v.reverse()}else{for(r=e.neigh(o.x,o.y,f,c),s=0,d=r.length;d>s;s++)a=e.Node(o,r[s],f),m[a.value]||(a.g=o.g+e.getd(r[s],o),a.f=a.g+e.getd(r[s],w),y.push(a),m[a.value]=!0);p.push(o)}}return v}},$.init=function(){$.input=$.Input,$.input.bind([13,65,37,38,39,40,49,50,51,52]),$.cfg=$.u.byId("fg"),$.cv1=document.createElement("canvas"),$.cv2=document.createElement("canvas"),$.x=$.cfg.getContext("2d"),$.x.s=$.x.save,$.x.r=$.x.restore,$.x.fr=$.x.fillRect,$.x.ft=$.x.fillText,$.x.d=$.x.drawImage,$.x.sc=$.x.scale,$.ctx1=$.cv1.getContext("2d"),$.ctx2=$.cv2.getContext("2d"),$.vw=$.cfg.width=$.cv1.width=$.cv2.width=640,$.vh=$.cfg.height=$.cv1.height=$.cv2.height=480,$.s=new $.Scene,$.animId=0,$.lv=1,$.he=0,$.ma=0,$.sco=0,$.ended=0,$.epow=[],$.fadeIn=new $.FadeIn,$.fadeOut=new $.FadeOut,$.msg={nokey:{t:"You need the key to exit the dungeon",s:0},noelem:{t:"Find the element before leaving",s:0}},$.s.l($.welcome,$.welcomeLoop)},$.welcome=function(){$.lv=1,$.sco=0,$.epow=[],$.u.v("s",1)},$.intro=function(){$.u.v("i",1),$.u.show("i0")},$.gameover=function(){$.lv=1,$.sco=0,$.epow=[],$.fadeOut.quit=!0,$.u.v("g",1)},$.end=function(){$.lv=1,$.ended=0,$.epow=[],$.fadeOut.quit=!0,$.u.show("e0"),$.u.v("e",1)},$.welcomeLoop=function(){return $.input.r(13)?$.s.l($.intro,$.introLoop):($.s.u(),$.s.e>400&&($.s.t=$.n(),$.s.e=0,0===$.s.s?($.s.s=1,$.u.v("s1",0)):($.s.s=0,$.u.v("s1",1))),void raf($.welcomeLoop))},$.introLoop=function(){if($.input.r(13))return $.start();if($.s.u(),$.s.e>=1800&&!$.s.f&&$.s.s<5)$.s.f=1,$.u.fadeOut("i"+$.s.s,function(){$.s.n(),$.u.show("i"+$.s.s)});else if($.s.e>=5e3&&5===$.s.s)return $.u.hide("i5"),$.start();raf($.introLoop)},$.gameOverLoop=function(){return $.input.r(13)?$.start():($.s.u(),void raf($.gameOverLoop))},$.endLoop=function(){return $.input.r(13)&&$.s.e>5e3?$.s.l($.welcome,$.welcomeLoop):($.s.u(),$.s.e>=2e3&&!$.s.f&&$.s.s<2?($.s.f=1,$.u.fadeOut("e"+$.s.s,function(){$.s.n(),$.u.show("e"+$.s.s)})):$.s.e>=5e3&&!$.s.f&&($.s.f=1,$.u.show("ei")),void raf($.endLoop))},$.start=function(){$.s.r(1),$.walls=[],$.enemies=[],$.items=[],$.exit=[],$.textPops=[],$.deco=[],$.powers=[],$.ai=new $.Ai,$.sws=[];var e=20,t=0,n=0,r=0;n=$.u.rand(15+6*$.lv,20+6*$.lv),r=$.u.rand(15+6*$.lv,20+6*$.lv),1===$.lv?$.u.i("Use the arrow keys to move and escape the dungeon",4500):t=3*$.lv,$.ww=32*n,$.wh=32*r;var o=[0,[$.Key,$.FireItem],[$.EarthItem],[$.WaterItem],[$.AirItem],[]];$.lvl=new $.Level($.lv,$.ww/32,$.wh/32,t,o[$.lv],e),$.fow=new $.FoW(3),$.cam=new $.Camera(640,480,$.ww,$.wh),$.cam.setTarget($.hero),$.collide=new $.Collide,$.hud=new $.Hud,$.lv>1&&($.fow.radius=6,$.hero.he=$.he,$.hero.ma=$.ma);for(o in $.epow)$.hero.pows[o]=$.epow[o];for(var a=0;a<$.lvl.h;a++)for(o=0;o<$.lvl.w;o++)$.lvl.isWall(o,a)&&$.walls.push(new $.Wall(32*o,32*a,0));$.fadeIn.start(1e3),$.animId=raf($.loop)},$.finalRoom=function(){$.s.r(1),$.walls=[],$.enemies=[],$.items=[],$.exit=[],$.deco=[],$.textPops=[],$.powers=[],$.sws=[],$.ww=640,$.wh=480;for(var e=[],t=0;t<$.ww/32;t++){e[t]=[];for(var n=0;n<$.wh/32;n++)e[t][n]=0===n||0===t||n===$.wh/32-1||t===$.ww/32-1?"#":"."}lvl=function(){var t=this;t.w=$.ww/32,t.h=$.wh/32,t.map=e,t.isWall=function(e,n){return"#"===t.map[e][n]}},$.lvl=new lvl,$.hero=new $.Hero(310,360,"u"),$.exit=0,$.fow=new $.FoW(8),$.cam=new $.Camera(640,480,$.ww,$.wh),$.collide=new $.Collide,$.hud=new $.Hud,$.hero.pows=$.epow;for(var r=0;r<$.lvl.h;r++)for(t=0;t<$.lvl.w;t++)if($.lvl.isWall(t,r)){var o=$.lvl.isWall(t,r+1)?0:1;$.walls.push(new $.Wall(32*t,32*r,o))}$.sws.push(new $.FireSw(112,256)),$.sws.push(new $.EarthSw(240,256)),$.sws.push(new $.WaterSw(368,256)),$.sws.push(new $.AirSw(496,256)),$.fadeIn.start(1e3),$.u.i("Step on the altars and offer each element to start the ritual",4500),$.animId=raf($.loop)},$.nextLevel=function(){caf($.animId),$.lv+=1,$.sco+=100,$.lv<5?($.he=$.hero.he,$.ma=$.hero.ma,$.start()):$.finalRoom()},$.cleanMsg=function(){$.msg.nokey.s=0,$.msg.noelem.s=0},$.clr=function(e){e=e||$.C.b,$.x.clearRect(0,0,$.vw,$.vh),$.x.fillStyle=e,$.x.fr(0,0,$.vw,$.vh)},$.loop=function(){$.clr($.C.f),$.fadeIn.done&&$.fadeOut.done&&!$.ended&&($.hero.update(),$.powers.forEach(function(e,t){e.update(t)}),$.enemies.forEach(function(e,t){e.update(t)}),$.textPops.forEach(function(e,t){e.update(t)}),$.items.forEach(function(e,t){e.update(t)}),$.sws.forEach(function(e,t){e.update(t)}));$.fow.update();if($.cam.update(),$.hero.exit){if($.hero.key&&$.hero.pows.indexOf($.lv)>=0)return $.nextLevel();var e=0;$.hero.key?$.hero.pows.indexOf($.lv)<0&&(e="noelem"):e="nokey",$.msg[e].s||($.msg[e].s=1,$.u.i($.msg[e].t))}return $.ended&&$.fadeOut.done?$.s.l($.end,$.endLoop):$.hero.dead&&$.fadeOut.done?$.s.l($.gameover,$.gameOverLoop):($.cam.render($.walls),$.cam.render($.exit),$.cam.render($.deco),$.cam.render($.enemies),$.cam.render($.items),$.cam.render($.sws),$.cam.render([$.hero]),$.cam.render($.powers),$.lv<5&&$.fow.render(),$.cam.render($.textPops),$.hud.render(),$.fadeIn.render(),$.fadeOut.render(),void raf($.loop))},window.addEventListener("load",function(){$.init()});