-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
5 lines (5 loc) · 54.2 KB
/
main.js
1
2
3
4
5
/*! tinyRPG - v0.0.1 - 2015-03-17
* http://loafer-project.com/
* Copyright (c) 2015 Jan Geselle */
var Bats,Blank,Box,Character,Controls,Crosshair,DungeonGenerator,FPS,FoeView,Girl,Helpers,PauseMenu,PlayerMovement,Skeletons,Slimes,StatusInfo,TextBox,TinyRPG,Weapons,game,params,toDungeon;Helpers={GetRandom:function(a,b){return~~(Math.random()*(b-a))+a},GetDirectionFromVelocity:function(a,b){var c,d,e,f,g;return e=a.body.velocity,d=void 0,c=void 0,f=e.x,g=e.y,0===f&&(c="none"),f>0&&(c="Right"),0>f&&(c="Left"),0===g&&(d="none"),g>0&&(d="Down"),0>g&&(d="Up"),"none"===c&&"none"===d?"standDown":(f=Math.abs(f),g=Math.abs(g),f>g?c=b>f?"stand"+c:"walk"+c:d=b>g?"stand"+d:"walk"+d)}},Controls=function(){return this.up=!1,this.down=!1,this.left=!1,this.right=!1,this.esc=!1,this.f=!1,this.e=!1,this.primary=!1,this.secondary=!1,this.x=0,this.y=0,this.worldX=0,this.worldY=0,this.cursors={},this.formerMouse=-1,this},Controls.prototype.create=function(){return this.cursors.up=game.input.keyboard.addKey(Phaser.Keyboard.W),this.cursors.left=game.input.keyboard.addKey(Phaser.Keyboard.A),this.cursors.down=game.input.keyboard.addKey(Phaser.Keyboard.S),this.cursors.right=game.input.keyboard.addKey(Phaser.Keyboard.D),this.shift=game.input.keyboard.addKey(Phaser.Keyboard.SHIFT),this.esc=game.input.keyboard.addKey(Phaser.Keyboard.ESC),this.f=game.input.keyboard.addKey(Phaser.Keyboard.F),this.e=game.input.keyboard.addKey(Phaser.Keyboard.E),this},Controls.prototype.update=function(){return(-1!==game.input.mouse.button||this.fomerMouse>-1)&&(game.input.mouse.button<0&&0===this.fomerMouse?this.primary=!1:game.input.mouse.button<0&&2===this.fomerMouse?this.secondary=!1:0===game.input.mouse.button&&this.fomerMouse!==game.input.mouse.button?(this.secondary=!1,this.primary=!0):2===game.input.mouse.button&&this.fomerMouse!==game.input.mouse.button&&(this.primary=!1,this.secondary=!0),this.fomerMouse=game.input.mouse.button),this.worldX=game.input.activePointer.worldX,this.worldY=game.input.activePointer.worldY,this.x=game.input.activePointer.x,this.y=game.input.activePointer.y,this.up=this.cursors.up.isDown,this.down=this.cursors.down.isDown,this.left=this.cursors.left.isDown,this.right=this.cursors.right.isDown,this},DungeonGenerator={map:null,map_size:64,rooms:[],Generate:function(){var a,b,c,d,e,f,g,h,i,j,k,l,m;for(this.map=null,this.map_size=this.options.size,this.rooms=[],this.map=[],j=0;j<this.map_size;){for(this.map[j]=[],l=0;l<this.map_size;)this.map[j][l]=0,l++;j++}for(i=Helpers.GetRandom(this.options.rooms.count.min,this.options.rooms.count.max),c=this.options.rooms.size.min,b=this.options.rooms.size.max,a=0;i>a;)f={},f.x=Helpers.GetRandom(1,this.map_size-b-1),f.y=Helpers.GetRandom(1,this.map_size-b-1),f.w=Helpers.GetRandom(c,b),f.h=Helpers.GetRandom(c,b),f.connected=[],f.id=a,this.DoesCollide(f)||(f.w--,f.h--,this.rooms.push(f),a++);for(this.SquashRooms(),a=0;i>a;)if(g=this.rooms[a],h=this.FindClosestRoom(g)){for(d={x:Helpers.GetRandom(g.x,g.x+g.w),y:Helpers.GetRandom(g.y,g.y+g.h)},e={x:Helpers.GetRandom(h.x,h.x+h.w),y:Helpers.GetRandom(h.y,h.y+h.h)};e.x!==d.x||e.y!==d.y;)e.x!==d.x?e.x>d.x?e.x--:e.x++:e.y!==d.y&&(e.y>d.y?e.y--:e.y++),this.map[e.x][e.y]=1;a++}else a++;for(a=0;i>a;){for(f=this.rooms[a],j=f.x;j<f.x+f.w;){for(l=f.y;l<f.y+f.h;)this.map[j][l]=1,l++;j++}a++}for(j=0;j<this.map_size;){for(l=0;l<this.map_size;){if(1===this.map[j][l])for(k=j-1;j+1>=k;){for(m=l-1;l+1>=m;)0===this.map[k][m]&&(this.map[k][m]=2),m++;k++}l++}j++}this.RemoveClutter(),this.RemoveClutter()},FindClosestRoom:function(a){var b,c,d,e,f,g,h;for(h={x:a.x+a.w/2,y:a.y+a.h/2},d=null,e=1e3,g=0;g<this.rooms.length;)b=this.rooms[g],b!==a&&-1===b.connected.indexOf(a.id)?(c={x:b.x+b.w/2,y:b.y+b.h/2},f=Math.min(Math.abs(h.x-c.x)-a.w/2-b.w/2,Math.abs(h.y-c.y)-a.h/2-b.h/2),e>f&&(e=f,d=b),g++):g++;return d&&(d.connected.push(a.id),a.connected.push(d.id)),d},SquashRooms:function(){var a,b,c,d;for(a=0;10>a;){for(b=0;b<this.rooms.length;){for(d=this.rooms[b];;){if(c={x:d.x,y:d.y},d.x>32&&d.x--,d.y>32&&d.y--,d.x<32&&d.x++,d.y<32&&d.y++,32===d.x&&32===d.y)break;if(this.DoesCollide(d,b)){d.x=c.x,d.y=c.y;break}}b++}a++}},RemoveClutter:function(){var a,b,c;for(c=0;c<this.map_size;){for(b=0;b<this.map_size;)a=this.map[b][c],2===a&&(this.map[b-1]&&this.map[b+1]&&1===this.map[b-1][c]&&1===this.map[b+1][c]&&(this.map[b][c]=1),1===this.map[b][c-1]&&1===this.map[b][c+1]&&(this.map[b][c]=1),1===this.map[b][c-1]&&2===this.map[b][c+1]&&1===this.map[b][c+2]&&(this.map[b][c]=1,this.map[b][c+1]=1)),b++;c++}},DoesCollide:function(a,b){var c,d;for(d=0;d<this.rooms.length;)if(d!==b){if(c=this.rooms[d],!(a.x+a.w+2<c.x||a.x>c.x+c.w+2||a.y+a.h+3<c.y||a.y>c.y+c.h+3))return!0;d++}else d++;return!1},CheckReachability:function(){var a,b,c,d,e,f,g,h,i;for(e=!0,a=!1,h=[],i=void 0,f=void 0,g=3,h[0]=this.rooms[0];g>0;){for(i=0,c=0;c<h.length;)h[c]&&i++,c++;for(i===f&&(g--,e=f===this.rooms.length),f=i,b=h.length-1;b>=0;){if(h[b])for(d=h[b].connected.length-1;d>=0;)h[h[b].connected[d]]=this.rooms[h[b].connected[d]],d--;b--}}return e},GetOptionsByLevel:function(a){var b,c;if(c={size:64,rooms:{count:{min:5,max:10},size:{min:5,max:15}}},b=void 0,!a)return c;for(b=16>a?a:15,c.rooms.count.min=2,c.rooms.count.max=3;b>1;)c.rooms.count.min+=.5,c.rooms.count.max+=1,b--;return c.rooms.count.min=Math.round(c.rooms.count.min),c.rooms.count.max=Math.round(c.rooms.count.max),c},GetWalkableGrid:function(a){var b,c,d,e,f,g,h;for(h=a.layers[0].width,d=a.layers[0].data,g=105,f=[],b=0,e=void 0,c=0;c<d.length;)b=Math.floor(c/h),f[b]||(f[b]=[]),e=d[c]===g?0:1,f[b].push(e),c++;return f},GetTiledJSON:function(a){var b,c,d,e,f;if(b=this.GetOptionsByLevel(game.level),this.options=$.extend({},b,a||{}),!this.options.empty)for(this.Generate();!this.CheckReachability();)this.Generate();if(c={backgroundcolor:"#292634",height:64,layers:[{data:[],height:64,name:"tiny16",opacity:1,type:"tilelayer",visible:!0,width:64,x:0,y:0}],orientation:"orthogonal",properties:{},renderorder:"right-down",tileheight:64,tilesets:[{firstgid:1,image:"../tilesets/tiny16.png",imageheight:1024,imagewidth:1024,margin:0,name:"tiny16",properties:{},spacing:0,tileheight:64,tilewidth:64}],tilewidth:64,version:1,width:64},!this.options.empty)for(f=0;f<this.map_size;){for(e=0;e<this.map_size;)d=this.map[e][f],c.layers[0].data.push(0===d?2===this.map[e][f+1]&&1===this.map[e][f+2]?117:0:1===d?105:1===this.map[e][f+1]?104:1===this.map[e][f-1]&&(0===this.map[e][f+1]||2===this.map[e][f+1]&&1===this.map[e][f+2])?85:(this.map[e-1]&&1===this.map[e-1][f]&&2===this.map[e][f-1]||this.map[e-1]&&2===this.map[e-1][f]&&1===this.map[e-1][f+1])&&2===this.map[e][f+1]&&1===this.map[e][f+2]?116:this.map[e-1]&&1===this.map[e-1][f]&&2===this.map[e][f-1]||this.map[e-1]&&2===this.map[e-1][f]&&1===this.map[e-1][f+1]?100:(this.map[e+1]&&1===this.map[e+1][f]&&2===this.map[e][f-1]||this.map[e+1]&&2===this.map[e+1][f]&&1===this.map[e+1][f+1])&&2===this.map[e][f+1]&&1===this.map[e][f+2]?118:this.map[e+1]&&1===this.map[e+1][f]&&2===this.map[e][f-1]||this.map[e+1]&&2===this.map[e+1][f]&&1===this.map[e+1][f+1]?102:this.map[e+1]&&1===this.map[e+1][f]&&1===this.map[e][f-1]?86:this.map[e-1]&&1===this.map[e-1][f]&&1===this.map[e][f-1]?84:0),e++;f++}return c.walkableGrid=this.GetWalkableGrid(c),c}},Blank=function(){function a(a){var b,c,d,e;null==a&&(a={}),e=null!=(b=a.visible)?b:!1,this.color=null!=(c=a.color)?c:"#17091C",this.speed=null!=(d=a.speed)?d:400,this.width=240,this.height=160,this.x=0,this.y=0,this.scale=4,this.sprite=this.createSprite(),this.sprite.visible=e,this.sprite.alpha=e?1:0}return a.prototype.createBitmapData=function(){var a;return a=game.add.bitmapData(this.width,this.height),a.context.fillStyle=this.color,a.context.fillRect(0,0,this.width,this.height),a},a.prototype.createSprite=function(){var a;return a=game.add.sprite(0,0,this.createBitmapData()),a.scale.setTo(this.scale),a.fixedToCamera=!0,a.cameraOffset.x=this.x*this.scale,a.cameraOffset.y=this.y*this.scale,a},a.prototype.isFading=function(){var a;return 0<(a=this.sprite.alpha)&&1>a},a.prototype.show=function(){return this.isFading()?void 0:(this.sprite.alpha=1,this.sprite.visible=!0)},a.prototype.hide=function(){return this.isFading()?void 0:(this.sprite.alpha=0,this.sprite.visible=!1)},a.prototype.fadeTo=function(a){var b;if(0===this.sprite.alpha)return this.sprite.bringToTop(),this.sprite.visible=!0,b=game.add.tween(this.sprite),b.to({alpha:1},this.speed),a&&b.onComplete.add(a,this),b.start(),this},a.prototype.fadeFrom=function(a){var b;if(1===this.sprite.alpha)return b=game.add.tween(this.sprite),b.to({alpha:0},this.speed),b.onComplete.add(function(){return this.sprite.visible=!1,a?a():void 0},this),b.start(),this},a}(),Box=function(){function a(a){var b,c,d,e,f,g;null==a&&(a={}),this.color=null!=(b=a.color)?b:"#597dce",this.width=null!=(c=a.width)?c:16,this.height=null!=(d=a.height)?d:16,this.x=null!=(e=a.x)?e:0,this.y=null!=(f=a.y)?f:0,this.scale=null!=(g=a.scale)?g:4,this.asset="boxborder",this.sprite=this.createSprite()}return a.prototype.createCorners=function(){return{topLeft:new Phaser.Rectangle(0,0,5,5),topRight:new Phaser.Rectangle(4,0,5,5),bottomRight:new Phaser.Rectangle(4,4,5,5),bottomLeft:new Phaser.Rectangle(0,4,5,5)}},a.prototype.renderBackground=function(a){return a.context.fillRect(5,5,this.width-10,this.height-10),a},a.prototype.renderCorners=function(a){var b;return b=this.createCorners(),a.copyRect(this.asset,b.topLeft,0,0),a.copyRect(this.asset,b.topRight,this.width-5,0),a.copyRect(this.asset,b.bottomRight,this.width-5,this.height-5),a.copyRect(this.asset,b.bottomLeft,0,this.height-5),a},a.prototype.renderBorders=function(a){return a.copy(this.asset,4,0,1,5,5,0,this.width-10,5),a.copy(this.asset,4,4,1,5,5,this.height-5,this.width-10,5),a.copy(this.asset,0,4,5,1,0,5,5,this.height-10),a.copy(this.asset,4,4,5,1,this.width-5,5,5,this.height-10),a},a.prototype.createBitmapData=function(){var a;return a=game.add.bitmapData(this.width,this.height),a.context.fillStyle=this.color,this.renderBackground(a),this.renderCorners(a),this.renderBorders(a),a},a.prototype.createSprite=function(){var a,b;return a=this.createBitmapData(),b=game.add.sprite(0,0,a),b.scale.setTo(this.scale),b.fixedToCamera=!0,b.cameraOffset.x=this.x,b.cameraOffset.y=this.y,b},a}(),StatusInfo=function(){function a(a){null==a&&(a={}),this.scale=4,this.background=this.createBackground(),this.createBars(),this.currentWeapon=this.createCurrentWeapon()}return a.prototype.barData={health:{color:"#D04648",x:39,y:155},mana:{color:"#597DCE",x:111,y:155},xp:{color:"#6CAA2C",x:183,y:155}},a.prototype.createBackground=function(){var a;return a=game.add.sprite(0,0,"statusinfo"),a.scale.setTo(this.scale),a.fixedToCamera=!0,a.cameraOffset.x=0,a.cameraOffset.y=game.camera.height-a.height,a.visible=!1,a},a.prototype.createCurrentWeapon=function(){var a;return a=game.add.sprite(0,0,"tiny16"),a.fixedToCamera=!0,a.cameraOffset.x=2*this.scale,a.cameraOffset.y=142*this.scale,a.visible=!0,a},a.prototype.createBarBitmapData=function(a,b,c){var d;return d=game.add.bitmapData(b,c),d.context.fillStyle=a,d.context.fillRect(0,0,b,c),d},a.prototype.createBar=function(a,b,c,d){var e;return e=this[a+"bar"]=game.add.sprite(0,0,this.createBarBitmapData(b,50,3)),e.scale.setTo(this.scale),e.fixedToCamera=!0,e.cameraOffset.x=c*this.scale,e.cameraOffset.y=d*this.scale,e.visible=!1,e},a.prototype.createBars=function(){var a,b,c,d;c=this.barData,d=[];for(a in c)b=c[a],d.push(this.createBar(a,b.color,b.x,b.y));return d},a.prototype.show=function(){return this.background.visible=!0,this.healthbar.visible=!0,this.manabar.visible=!0,this.xpbar.visible=!0,this.currentWeapon.visible=!0,this},a.prototype.hide=function(){return this.background.visible=!1,this.healthbar.visible=!1,this.manabar.visible=!1,this.xpbar.visible=!1,this.currentWeapon.visible=!1,this},a.prototype.updateBarLengths=function(){return this.healthbar.width=Math.ceil(game.player.health/2)*this.scale,this.manabar.width=Math.ceil(game.player.mana/2)*this.scale,this.xpbar.width=Math.ceil(game.player.xp/2)*this.scale,this},a.prototype.updateCurrentWeapon=function(){return this.currentWeapon.frame=game.player.activeWeapon.iconFrame,this},a.prototype.update=function(){var a,b;return b=game.state.states[game.state.current],null!=b.girl&&null!=(null!=(a=game.player)?a.health:void 0)?(this.show(),this.updateBarLengths(),this.updateCurrentWeapon()):this.hide(),this},a}(),FPS=function(){function a(){this.text=game.add.bitmapText(0,0,"silkscreen","",32),this.text.fixedToCamera=!0}return a.prototype.update=function(){return 60!==game.time.fps?(this.text.visible=!0,this.text.cameraOffset.x=game.camera.width-32-this.text.width,this.text.cameraOffset.y=32,this.text.setText((game.time.fps||"--")+" FPS")):this.text.visible=!1,this},a}(),TextBox=function(){function a(){this.background=this.createBackground(),this.text=this.createText(),this.initalMode=game.mode,this.lastOpened=game.time.now,this.hide(),this.addEvents()}return a.prototype.addEvents=function(){return game.input.onDown.add(function(){"dialog"===game.mode&&game.time.now-this.lastOpened>100&&this.hide()},this)},a.prototype.createBackground=function(){var a;return a=new Box({width:224,height:48,x:32,y:game.camera.height-192-32}),a.sprite},a.prototype.createText=function(){var a;return a=game.add.bitmapText(0,0,"silkscreen","",32),a.fixedToCamera=!0,a.cameraOffset.x=56,a.cameraOffset.y=game.camera.height-200,a},a.prototype.hide=function(){return this.background.visible=!1,this.text.visible=!1,game.mode=this.initalMode,this},a.prototype.show=function(a){return null!=a&&this.text.setText(a),this.lastOpened=game.time.now,this.background.visible=!0,this.text.visible=!0,game.mode="dialog",this},a}(),PauseMenu=function(){function a(){var a;for(this.scale=4,this.background=this.createBackground(),this.texts=[],this.clickables=[],a=this.entries.length-1;a>=0;)this.entries[a].index=a,this.texts[a]=this.createText(a),this.clickables[a]=this.createClickable(a),a--;this.activeIndicator=this.createActiveIndicator(),this.initalMode=game.mode,this.lastOpened=game.time.now,this.hide(),this.bindEscDown()}return a.prototype.entries=[{name:"Character",action:function(){return alert("Character")}},{name:"Save",action:function(){return alert("Save")}},{name:"Quit",action:function(){return alert("Quit")}}],a.prototype.createBackground=function(){var a,b;return b=10+this.entries.length-1+13*this.entries.length,a=new Box({width:73,height:b,x:game.camera.width-73*this.scale-8*this.scale,y:game.camera.height-b*this.scale-8*this.scale}),a.sprite},a.prototype.createText=function(a){var b;return b=game.add.bitmapText(0,0,"silkscreen",this.entries[a].name,8*this.scale),b.fixedToCamera=!0,b.cameraOffset.x=167*this.scale,b.cameraOffset.y=game.camera.height-10*this.scale-(this.entries.length-a)*this.scale*14,b},a.prototype.bindInputOver=function(a){return a.events.onInputOver.add(function(){return this.activeIndicator.visible=!0,this.activeIndicator.cameraOffset.x=157*this.scale,this.activeIndicator.cameraOffset.y=a.cameraOffset.y+3*this.scale},this)},a.prototype.bindInputOut=function(a){return a.events.onInputOut.add(function(){return this.activeIndicator.visible=!1},this)},a.prototype.bindInputDown=function(a){return a.events.onInputDown.add(function(){var b;return this.hide(),"function"==typeof(b=this.entries[a.menuIndex]).action?b.action():void 0},this)},a.prototype.bindEscDown=function(){return game.controls.esc.onDown.add(function(){return"menu"===game.mode&&game.time.now-this.lastOpened>100?this.hide():"level"===game.mode?this.show():void 0},this)},a.prototype.createClickable=function(a){var b;return b=game.add.sprite(0,0,"menuclickable"),b.menuIndex=a,b.fixedToCamera=!0,b.scale.setTo(this.scale),b.cameraOffset.x=164*this.scale,b.cameraOffset.y=game.camera.height-12*this.scale-(this.entries.length-a)*this.scale*14,b.data=this.entries[a],b.inputEnabled=!0,this.bindInputOver(b),this.bindInputOut(b),this.bindInputDown(b),b},a.prototype.createActiveIndicator=function(){var a;return a=game.add.sprite(0,0,"boxborderactive"),a.fixedToCamera=!0,a.scale.setTo(this.scale),a.cameraOffset.x=0,a.cameraOffset.y=0,a.visible=!1,a},a.prototype.hide=function(){var a,b,c,d,e,f,g,h;for(this.background.visible=!1,this.activeIndicator.visible=!1,f=this.texts,b=0,d=f.length;d>b;b++)h=f[b],h.visible=!1;for(g=this.clickables,c=0,e=g.length;e>c;c++)a=g[c],a.visible=!1;return game.mode=this.initalMode,this},a.prototype.show=function(){var a,b,c,d,e,f,g,h;for(this.lastOpened=game.time.now,this.background.visible=!0,f=this.texts,b=0,d=f.length;d>b;b++)h=f[b],h.visible=!0;for(g=this.clickables,c=0,e=g.length;e>c;c++)a=g[c],a.visible=!0,a.input.checkPointerOver(game.input.activePointer)&&a.events.onInputOver.dispatch();return game.mode="menu",this},a}(),Crosshair=function(){function a(a){var b,c,d,e;null==a&&(a={}),this.color=null!=(b=a.color)?b:"#ffffff",this.width=null!=(c=a.width)?c:2,this.height=null!=(d=a.height)?d:2,this.scale=null!=(e=a.scale)?e:4,this.x=0,this.y=0,this.sprite=this.createSprite()}return a.prototype.createBitmapData=function(){var a;return a=game.add.bitmapData(this.width,this.height),a.context.fillStyle=this.color,a.context.fillRect(0,0,this.width,this.height),a},a.prototype.createSprite=function(){var a,b;return a=this.createBitmapData(),b=game.add.sprite(this.x,this.y,a),b.scale.setTo(this.scale),game.physics.enable(b),b.anchor.setTo(.5),b.fixedToCamera=!0,b},a.prototype.update=function(){return this.x=game.controls.worldX,this.x=this.x?this.x:0,this.y=game.controls.worldY,this.y=this.y?this.y:0,this.sprite.cameraOffset.setTo(this.x-game.camera.x,this.y-game.camera.y),this},a}(),FoeView=function(){function a(a){var b,c,d,e,f;null==a&&(a={}),this.width=null!=(b=a.width)?b:2,this.height=null!=(c=a.height)?c:2,this.scale=null!=(d=a.scale)?d:4,this.maxFoes=null!=(e=a.maxFoes)?e:100,this.foeMarkers=this.createFoeMarkers(),this.state=game.state.states[game.state.current],this.player=null!=(f=this.state.girl)?f.player:void 0}return a.prototype.createFoeMarkers=function(){var a;return a=game.add.group(),a.createMultiple(this.maxFoes,"foemarker"),a.setAll("anchor.x",.5),a.setAll("anchor.y",.5),a.setAll("scale.x",this.scale),a.setAll("scale.y",this.scale),a.setAll("fixedToCamera",!0),a},a.prototype.update=function(){return"level"===game.mode&&this.foeMarkers.forEachAlive(function(a){return a.kill()},this),this},a.prototype.getInterfaceCorners=function(){var a;return a=game.camera,{topLeft:{x:a.x,y:a.y},topRight:{x:a.x+a.width,y:a.y},bottomLeftOne:{x:a.x+20*this.scale,y:a.y+a.height-7*this.scale},bottomLeftTwo:{x:a.x+20*this.scale,y:a.y+a.height-20*this.scale},bottomLeftThree:{x:a.x,y:a.y+a.height-20*this.scale},bottomRight:{x:a.x+a.width,y:a.y+a.height-7*this.scale}}},a.prototype.getInterfaceBorders=function(){var a;return a=this.getInterfaceCorners(),[new Phaser.Line(a.topLeft.x,a.topLeft.y,a.topRight.x,a.topRight.y),new Phaser.Line(a.topRight.x,a.topRight.y,a.bottomRight.x,a.bottomRight.y),new Phaser.Line(a.bottomRight.x,a.bottomRight.y,a.bottomLeftOne.x,a.bottomLeftOne.y),new Phaser.Line(a.bottomLeftOne.x,a.bottomLeftOne.y,a.bottomLeftTwo.x,a.bottomLeftTwo.y),new Phaser.Line(a.bottomLeftTwo.x,a.bottomLeftTwo.y,a.bottomLeftThree.x,a.bottomLeftThree.y),new Phaser.Line(a.bottomLeftThree.x,a.bottomLeftThree.y,a.topLeft.x,a.topLeft.y)]},a.prototype.getLineOfSight=function(a){var b,c;return c=this.player.body.center,b=a.body.center,new Phaser.Line(c.x,c.y,b.x,b.y)},a.prototype.updateGroup=function(a){var b;return game.controls.f.isDown&&"level"===game.mode&&(b=this.getInterfaceBorders(),a.forEachAlive(function(a){var c,d,e,f,g,h,i;if(this.foeMarkers.countDead()>0){for(h=this.getLineOfSight(a),f=0,g=b.length;g>f;f++)c=b[f],i=h.intersects(c),e=i?i:e;e&&(d=this.foeMarkers.getFirstDead(),d.reset(),d.cameraOffset.x=e.x-game.camera.x,d.cameraOffset.y=e.y-game.camera.y)}},this)),this},a}(),Weapons=function(){return"undefined"==typeof game.player&&(game.player={}),"undefined"==typeof game.player.activeWeapon&&(game.player.activeWeapon=this.fireballs.orange.medium),this.aquired=[this.fireballs.orange.medium,this.fireballs.blue.medium],this},Weapons.prototype.create=function(){return this.fireballs.create(this),game.controls.e.onDown.add(function(){this.next()},this),this},Weapons.prototype.update=function(){return"Town"!==game.state.current&&"level"===game.mode&&(game.controls.primary&&game.player.activeWeapon.activeUpdatePrimary(this),game.controls.secondary&&game.player.activeWeapon.activeUpdateSecondary(this)),this.fireballs.passiveUpdate(this),this},Weapons.prototype.makeBullets=function(a){var b;return b=void 0,b=game.add.group(),b.enableBody=!0,b.physicsBodyType=Phaser.Physics.ARCADE,b.createMultiple(a,"tiny16"),b.setAll("checkWorldBounds",!0),b.setAll("outOfBoundsKill",!0),b.setAll("anchor.x",.5),b.setAll("anchor.y",.5),b},Weapons.prototype.collide=function(a){return this.fireballs.collide(a),this},Weapons.prototype.hitTest=function(a){return this.fireballs.hitTest(a),this},Weapons.prototype.next=function(){var a,b,c;return a=this.aquired.indexOf(game.player.activeWeapon),b=this.aquired.length-1,c=a+1,c>b&&(c=0),game.player.activeWeapon=this.aquired[c],this},Weapons.prototype.fireballs={},Weapons.prototype.fireballs.create=function(a){return a.fireballs.orange.create(a),a.fireballs.blue.create(a),this},Weapons.prototype.fireballs.activeUpdatePrimary=function(a){return a.fireballs.orange.activeUpdatePrimary(a),a.fireballs.blue.activeUpdatePrimary(a),this},Weapons.prototype.fireballs.activeUpdateSecondary=function(a){return a.fireballs.orange.activeUpdateSecondary(a),a.fireballs.blue.activeUpdateSecondary(a),this},Weapons.prototype.fireballs.passiveUpdate=function(a){return a.fireballs.orange.passiveUpdate(a),a.fireballs.blue.passiveUpdate(a),this},Weapons.prototype.fireballs.pauseProjectiles=function(a){return a.forEach(function(a){a.animations.paused||(a.body.savedVelocity={},a.body.savedVelocity.x=a.body.velocity.x,a.body.savedVelocity.y=a.body.velocity.y,a.body.velocity.x=0,a.body.velocity.y=0,a.animations.paused=!0)}),this},Weapons.prototype.fireballs.unpauseProjectiles=function(a){return a.forEach(function(a){a.animations.paused&&a.body.savedVelocity&&(a.body.velocity.x=a.body.savedVelocity.x,a.body.velocity.y=a.body.savedVelocity.y,a.body.savedVelocity=!1,a.animations.paused=!1)}),this},Weapons.prototype.fireballs.collide=function(a){return this.orange.collide(a),this.blue.collide(a),this},Weapons.prototype.fireballs.hitTest=function(a){return this.orange.hitTest(a),this.blue.hitTest(a),this},Weapons.prototype.fireballs.orange={},Weapons.prototype.fireballs.orange.create=function(a){return a.fireballs.orange.medium.create(a),this},Weapons.prototype.fireballs.orange.activeUpdatePrimary=function(a){return a.fireballs.orange.medium.activeUpdatePrimary(a),this},Weapons.prototype.fireballs.orange.activeUpdateSecondary=function(a){return a.fireballs.orange.medium.activeUpdateSecondary(a),this},Weapons.prototype.fireballs.orange.passiveUpdate=function(a){return a.fireballs.orange.medium.passiveUpdate(a),this},Weapons.prototype.fireballs.orange.collide=function(a){return this.medium.collide(a),this},Weapons.prototype.fireballs.orange.hitTest=function(a){return this.medium.hitTest(a),this},Weapons.prototype.fireballs.orange.medium={iconFrame:257},Weapons.prototype.fireballs.orange.medium.create=function(a){var b;return b=this,this.damage={primary:10,secondary:20},this.cost={primary:2,secondary:15},this.fireCooldown=game.time.now,this.bullets=a.makeBullets(50),this.bullets.forEach(function(a){a.animations.add("flameOrangeMedium",[256,257,258,257],10,!0),a.animations.play("flameOrangeMedium"),a.body.setSize(24,24,0,16),a.weapon=b}),this},Weapons.prototype.fireballs.orange.medium.activeUpdatePrimary=function(){var a;return this.girl=game.state.states[game.state.current].girl,this.player=this.girl.player,game.time.elapsedSince(this.fireCooldown)>500&&this.bullets.countDead()>0&&this.girl.costMana(this.cost.primary)&&(a=this.bullets.getFirstDead(),a.reset(this.player.body.center.x,this.player.body.center.y-16),game.physics.arcade.moveToPointer(a,300),a.body.velocity.x=a.body.velocity.x+this.player.body.velocity.x,a.body.velocity.y=a.body.velocity.y+this.player.body.velocity.y,a.attack="primary",this.fireCooldown=game.time.now),this},Weapons.prototype.fireballs.orange.medium.activeUpdateSecondary=function(){var a,b;if(this.girl=game.state.states[game.state.current].girl,this.player=this.girl.player,game.time.elapsedSince(this.fireCooldown)>500&&this.bullets.countDead()>0&&this.girl.costMana(this.cost.secondary)){for(b=0;5>b;)a=this.bullets.getFirstDead(),a.reset(this.player.body.center.x,this.player.body.center.y-16),game.physics.arcade.moveToPointer(a,200+100*b),a.body.velocity.x=a.body.velocity.x+this.player.body.velocity.x,a.body.velocity.y=a.body.velocity.y+this.player.body.velocity.y,a.attack="secondary",b++;this.fireCooldown=game.time.now}return this},Weapons.prototype.fireballs.orange.medium.passiveUpdate=function(a){return"level"===game.mode&&a.fireballs.unpauseProjectiles(this.bullets),"level"!==game.mode&&a.fireballs.pauseProjectiles(this.bullets),this},Weapons.prototype.fireballs.orange.medium.hit=function(a,b){a.kill(),b.hitTimeout=game.time.now,b.blendMode=PIXI.blendModes.ADD,b.damage(a.weapon.damage[a.attack])},Weapons.prototype.fireballs.orange.medium.collide=function(a){return game.physics.arcade.overlap(this.bullets,a,function(a){a.kill()}),this},Weapons.prototype.fireballs.orange.medium.hitTest=function(a){return game.physics.arcade.overlap(this.bullets,a.group,this.hit),this},Weapons.prototype.fireballs.blue={},Weapons.prototype.fireballs.blue.create=function(a){return a.fireballs.blue.medium.create(a),this},Weapons.prototype.fireballs.blue.activeUpdatePrimary=function(a){return a.fireballs.blue.medium.activeUpdatePrimary(a),this},Weapons.prototype.fireballs.blue.activeUpdateSecondary=function(a){return a.fireballs.blue.medium.activeUpdateSecondary(a),this},Weapons.prototype.fireballs.blue.passiveUpdate=function(a){return a.fireballs.blue.medium.passiveUpdate(a),this},Weapons.prototype.fireballs.blue.collide=function(a){return this.medium.collide(a),this},Weapons.prototype.fireballs.blue.hitTest=function(a){return this.medium.hitTest(a),this},Weapons.prototype.fireballs.blue.medium={iconFrame:260},Weapons.prototype.fireballs.blue.medium.create=function(a){var b;return b=this,this.damage={primary:4,secondary:5},this.cost={primary:.75,secondary:35},this.fireCooldown=game.time.now,this.bullets=a.makeBullets(300),this.bullets.forEach(function(a){a.animations.add("flameBlueMedium",[259,260,261,260],10,!0),a.animations.play("flameBlueMedium"),a.body.setSize(24,24,0,16),a.weapon=b}),this},Weapons.prototype.fireballs.blue.medium.activeUpdatePrimary=function(){var a,b,c;return this.girl=game.state.states[game.state.current].girl,this.player=this.girl.player,game.time.elapsedSince(this.fireCooldown)>40&&this.bullets.countDead()>0&&this.girl.costMana(this.cost.primary)&&(b=this.bullets.getFirstDead(),b&&(b.reset(this.player.body.center.x,this.player.body.center.y-16),a=game.physics.arcade.angleToPointer(b,game.input.activePointer),c=500,a+=game.rnd.realInRange(-.5,.5),b.body.velocity.x=Math.cos(a)*c,b.body.velocity.y=Math.sin(a)*c,b.body.velocity.x=b.body.velocity.x+this.player.body.velocity.x,b.body.velocity.y=b.body.velocity.y+this.player.body.velocity.y,b.attack="primary",b.enemiesTouched=[]),this.fireCooldown=game.time.now),this},Weapons.prototype.fireballs.blue.medium.activeUpdateSecondary=function(){var a,b,c,d,e,f,g;if(this.girl=game.state.states[game.state.current].girl,this.player=this.girl.player,game.time.elapsedSince(this.fireCooldown)>500&&this.bullets.countDead()>0&&this.girl.costMana(this.cost.secondary)){for(a=36,f=-1*Math.PI,g=Math.PI/a*2,d=a;d>0;)c=this.bullets.getFirstDead(),c&&(c.reset(this.player.body.center.x,this.player.body.center.y-16),b=f+d*g,e=500,c.body.velocity.x=Math.cos(b)*e,c.body.velocity.y=Math.sin(b)*e,c.body.velocity.x=c.body.velocity.x+this.player.body.velocity.x,c.body.velocity.y=c.body.velocity.y+this.player.body.velocity.y,c.attack="secondary"),d--;this.fireCooldown=game.time.now}return this},Weapons.prototype.fireballs.blue.medium.passiveUpdate=function(a){return"level"===game.mode&&a.fireballs.unpauseProjectiles(this.bullets),"level"!==game.mode&&a.fireballs.pauseProjectiles(this.bullets),this},Weapons.prototype.fireballs.blue.medium.hit=function(a,b){b.hitTimeout=game.time.now,b.blendMode=PIXI.blendModes.ADD,"primary"===a.attack?-1===a.enemiesTouched.indexOf(b)&&(a.enemiesTouched.push(b),b.damage(a.weapon.damage.primary)):b.damage(a.weapon.damage.secondary)},Weapons.prototype.fireballs.blue.medium.collide=function(a){return game.physics.arcade.overlap(this.bullets,a,function(a){a.kill()}),this},Weapons.prototype.fireballs.blue.medium.hitTest=function(a){return game.physics.arcade.overlap(this.bullets,a.group,this.hit),this},Character=function(){function a(a){null==a&&(a={}),this.scale=4,this.paused=!1,this.animations=[],this.health=100,this.hitTimeout=!1,this.bodySize={width:32,height:32,x:-16,y:0}}return a.prototype.addAnimations=function(){var a,b,c,d,e;for(d=this.animations,e=[],b=0,c=d.length;c>b;b++)a=d[b],e.push(this.sprite.animations.add(a));return e},a}(),Skeletons=function(a){return this.count=a,this},Skeletons.prototype.create=function(){var a,b,c,d,e,f,g;for(c=game.map,this.group=game.add.group(),this.group.enableBody=!0,b=0,d=void 0,e=void 0,a=105,f=void 0,g=3;b<this.count;)d=Helpers.GetRandom(0,c.width),e=Helpers.GetRandom(0,c.height),c.getTile(d,e)&&c.getTile(d,e).index===a&&(d>=15||e>=10)&&(f=this.group.create(d*c.tileWidth,e*c.tileHeight,"tiny16"),f.frame=134,f.body.setSize(32,32,16,28),f.health=50,f.hitTimeout=!1,b++,f.animations.add("standDown",[134],0,!1),f.animations.add("walkDown",[135,136],g,!0),f.animations.add("standLeft",[150],0,!1),f.animations.add("walkLeft",[151,152],g,!0),f.animations.add("standRight",[166],0,!1),f.animations.add("walkRight",[167,168],g,!0),f.animations.add("standUp",[182],0,!1),f.animations.add("walkUp",[183,184],g,!0),f.animations.play("standDown"),f.animations.currentAnim.timeLastChange=game.time.now-100);return this},Skeletons.prototype.update=function(){var a,b;return b=game.map,a=game.collision,this.group.setAll("body.velocity.x",0),this.group.setAll("body.velocity.y",0),"level"===game.mode?(this.group.forEach(function(c){var d,e,f,g,h;if(c.hitTimeout&&game.time.now-c.hitTimeout>100&&(c.hitTimeout=!1,c.blendMode=PIXI.blendModes.NORMAL),c.visible&&c.inCamera){if(f=new Phaser.Line(game.state.states[game.state.current].girl.player.body.center.x,game.state.states[game.state.current].girl.player.body.center.y,c.body.center.x,c.body.center.y),g=void 0,d=void 0,h=320,f.length<=h){if(g=a.getRayCastTiles(f,4,!1,!1),d=!0,g.length>0)for(e=0;e<g.length;)-1!==b.collideIndexes.indexOf(g[e].index)&&(d=!1),e++;d&&game.physics.arcade.moveToXY(c,game.state.states[game.state.current].girl.player.body.center.x-c.body.offset.x-c.body.width/2,game.state.states[game.state.current].girl.player.body.center.y-c.body.offset.y-c.body.height/2,Helpers.GetRandom(150,200))}Helpers.GetDirectionFromVelocity(c)!==c.animations.currentAnim.name&&game.time.elapsedSince(c.animations.currentAnim.timeLastChange)>25&&(c.animations.play(Helpers.GetDirectionFromVelocity(c,10)),c.animations.currentAnim.timeLastChange=game.time.now)}c.animations.paused&&(c.animations.paused=!1)}),game.ui.foeView.updateGroup(this.group)):this.group.forEach(function(a){a.animations.paused||(a.animations.paused=!0)}),this},Slimes=function(a){return this.count=a,this.paused=!1,this},Slimes.prototype.create=function(){var a,b,c,d,e,f,g;for(c=game.map,this.group=game.add.group(),this.group.enableBody=!0,b=0,d=void 0,e=void 0,a=105,f=void 0,g=4;b<this.count;)d=Helpers.GetRandom(0,c.width),e=Helpers.GetRandom(0,c.height),c.getTile(d,e)&&c.getTile(d,e).index===a&&(d>=15||e>=10)&&(f=this.group.create(d*c.tileWidth,e*c.tileHeight,"tiny16"),f.frame=192,f.body.setSize(40,44,12,16),f.health=30,b++,f.animations.add("standDown",[192],0,!1),f.animations.add("walkDown",[193,194],g,!0),
f.animations.add("standLeft",[208],0,!1),f.animations.add("walkLeft",[209,210],g,!0),f.animations.add("standRight",[224],0,!1),f.animations.add("walkRight",[225,226],g,!0),f.animations.add("standUp",[240],0,!1),f.animations.add("walkUp",[241,242],g,!0),f.animations.play("standDown"),f.animations.currentAnim.timeLastChange=game.time.now-100);return this},Slimes.prototype.update=function(){return"level"===game.mode?this.paused?(this.group.forEach(function(a){a.body.velocity=a.body.savedVelocity,a.animations.paused&&(a.animations.paused=!1)}),this.paused=!1):(this.group.forEach(function(a){a.hitTimeout&&game.time.now-a.hitTimeout>100&&(a.hitTimeout=!1,a.blendMode=PIXI.blendModes.NORMAL),a.visible&&a.inCamera&&(0===a.body.velocity.x&&0===a.body.velocity.y?(a.body.velocity.x=Helpers.GetRandom(-80,80),a.body.velocity.y=Helpers.GetRandom(-80,80)):(a.body.velocity.x=(Helpers.GetRandom(-800,800)+120*a.body.velocity.x)/121,a.body.velocity.y=(Helpers.GetRandom(-800,800)+120*a.body.velocity.y)/121),Helpers.GetDirectionFromVelocity(a)!==a.animations.currentAnim.name&&game.time.elapsedSince(a.animations.currentAnim.timeLastChange)>1e3&&(a.animations.play(Helpers.GetDirectionFromVelocity(a,10)),a.animations.currentAnim.timeLastChange=game.time.now))}),game.ui.foeView.updateGroup(this.group)):this.paused||(this.group.forEach(function(a){a.body.savedVelocity=a.body.velocity,a.body.velocity.x=0,a.body.velocity.y=0,a.animations.paused||(a.animations.paused=!0)}),this.paused=!0),this},Bats=function(a){return this.count=a,this},Bats.prototype.create=function(){var a,b,c,d,e,f,g;for(d=game.map,this.group=game.add.group(),this.group.enableBody=!0,c=0,e=void 0,f=void 0,b=105,a=void 0,g=3;c<this.count;)e=Helpers.GetRandom(0,d.width),f=Helpers.GetRandom(0,d.height),d.getTile(e,f)&&d.getTile(e,f).index===b&&(e>=15||f>=10)&&(a=this.group.create(e*d.tileWidth,f*d.tileHeight,"tiny16"),a.frame=195,a.body.setSize(32,32,16,28),a.health=30,a.hitTimeout=!1,c++,a.animations.add("standDown",[195],0,!1),a.animations.add("walkDown",[196,197],g,!0),a.animations.add("standLeft",[211],0,!1),a.animations.add("walkLeft",[212,213],g,!0),a.animations.add("standRight",[227],0,!1),a.animations.add("walkRight",[228,229],g,!0),a.animations.add("standUp",[243],0,!1),a.animations.add("walkUp",[244,245],g,!0),a.animations.play("standDown"),a.animations.currentAnim.timeLastChange=game.time.now-100);return this},Bats.prototype.update=function(){var a,b,c,d,e,f;return c=void 0,a=void 0,e=void 0,f=void 0,b=void 0,d=void 0,this.group.setAll("body.velocity.x",0),this.group.setAll("body.velocity.y",0),"level"===game.mode?(this.group.forEach(function(e){var f,g,h,i,j,k,l,m,n;e.hitTimeout&&game.time.now-e.hitTimeout>100&&(e.hitTimeout=!1,e.blendMode=PIXI.blendModes.NORMAL),k=new Phaser.Line(game.state.states[game.state.current].girl.player.body.center.x,game.state.states[game.state.current].girl.player.body.center.y,e.body.center.x,e.body.center.y),m=void 0,j=void 0,n=1e3,l=128,k.length<=n&&k.length>l?(c=game.state.states[game.state.current].grid,a=new PF.AStarFinder({allowDiagonal:!0,dontCrossCorners:!0}),b=game.state.states[game.state.current].girl,h=Math.floor(b.player.body.center.x/64),i=Math.floor(b.player.body.center.y/64),f=Math.floor(e.body.center.x/64),g=Math.floor(e.body.center.y/64),d=a.findPath(f,g,h,i,c.clone()),d.length>2&&(d=PF.Util.smoothenPath(c,d)),d.length>1&&game.physics.arcade.moveToXY(e,64*d[1][0]+32-e.body.offset.x-e.body.width/2,64*d[1][1]+32-e.body.offset.y-e.body.height/2,Helpers.GetRandom(150,200))):k.length<=l&&game.physics.arcade.moveToXY(e,game.state.states[game.state.current].girl.player.body.center.x-e.body.offset.x-e.body.width/2,game.state.states[game.state.current].girl.player.body.center.y-e.body.offset.y-e.body.height/2,Helpers.GetRandom(200,300)),Helpers.GetDirectionFromVelocity(e)!==e.animations.currentAnim.name&&game.time.elapsedSince(e.animations.currentAnim.timeLastChange)>25&&(e.animations.play(Helpers.GetDirectionFromVelocity(e,10)),e.animations.currentAnim.timeLastChange=game.time.now),e.animations.paused&&(e.animations.paused=!1)}),game.ui.foeView.updateGroup(this.group)):this.group.forEach(function(a){a.animations.paused||(a.animations.paused=!0)}),this},PlayerMovement=function(a){return this.girl=a,this.player=this.girl.player,this},PlayerMovement.prototype.create=function(){var a;return this.player.facing={up:!1,down:!0,left:!1,right:!1},this.player.walking={up:!1,down:!1,left:!1,right:!1,any:!1},this.addAnimations(),this.player.animations.play("standDown"),a=this,game.controls.cursors.up.onDown.add(function(){"level"===game.mode&&(a.player.walking.any||(a.player.facing.up=!1,a.player.facing.down=!1,a.player.facing.left=!1,a.player.facing.right=!1),a.player.facing.up=!0,a.player.walking.up=!0,a.player.walking.any=!0,a.player.animations.play("standUp"))}),game.controls.cursors.down.onDown.add(function(){"level"===game.mode&&(a.player.walking.any||(a.player.facing.up=!1,a.player.facing.down=!1,a.player.facing.left=!1,a.player.facing.right=!1),a.player.facing.down=!0,a.player.walking.down=!0,a.player.walking.any=!0,a.player.animations.play("standDown"))}),game.controls.cursors.left.onDown.add(function(){"level"===game.mode&&(a.player.walking.any||(a.player.facing.up=!1,a.player.facing.down=!1,a.player.facing.left=!1,a.player.facing.right=!1),a.player.facing.left=!0,a.player.walking.left=!0,a.player.walking.any=!0,a.player.animations.play("standLeft"))}),game.controls.cursors.right.onDown.add(function(){"level"===game.mode&&(a.player.walking.any||(a.player.facing.up=!1,a.player.facing.down=!1,a.player.facing.left=!1,a.player.facing.right=!1),a.player.facing.right=!0,a.player.walking.right=!0,a.player.walking.any=!0,a.player.animations.play("standRight"))}),game.controls.cursors.up.onUp.add(function(){a.player.walking.up=!1,a.player.facing.down||a.player.facing.left||a.player.facing.right?(a.player.facing.up=!1,a.player.facing.right&&a.player.animations.play("standRight"),a.player.facing.left&&a.player.animations.play("standLeft")):a.player.walking.any=!1}),game.controls.cursors.down.onUp.add(function(){a.player.walking.down=!1,a.player.facing.up||a.player.facing.left||a.player.facing.right?(a.player.facing.down=!1,a.player.facing.right&&a.player.animations.play("standRight"),a.player.facing.left&&a.player.animations.play("standLeft")):a.player.walking.any=!1}),game.controls.cursors.left.onUp.add(function(){a.player.walking.left=!1,a.player.facing.up||a.player.facing.down||a.player.facing.right?(a.player.facing.left=!1,a.player.facing.up&&a.player.animations.play("standUp"),a.player.facing.down&&a.player.animations.play("standDown")):a.player.walking.any=!1}),game.controls.cursors.right.onUp.add(function(){a.player.walking.right=!1,a.player.facing.up||a.player.facing.down||a.player.facing.left?(a.player.facing.right=!1,a.player.facing.up&&a.player.animations.play("standUp"),a.player.facing.down&&a.player.animations.play("standDown")):a.player.walking.any=!1}),this.speed=200,this},PlayerMovement.prototype.update=function(){var a,b,c,d;if(this.player.body.velocity.x=0,this.player.body.velocity.y=0,"level"===game.mode){if(this.player.animations.paused&&(this.player.animations.paused=!1,game.controls.cursors.up.isDown&&game.controls.cursors.up.onDown.dispatch(),game.controls.cursors.down.isDown&&game.controls.cursors.down.onDown.dispatch(),game.controls.cursors.left.isDown&&game.controls.cursors.left.onDown.dispatch(),game.controls.cursors.right.isDown&&game.controls.cursors.right.onDown.dispatch()),c=0,d=0,a=void 0,b=this.speed,game.controls.cursors.up.isDown&&(d-=1),game.controls.cursors.down.isDown&&(d+=1),game.controls.cursors.left.isDown&&(c-=1),game.controls.cursors.right.isDown&&(c+=1),(0!==c||0!==d)&&(1===c&&0===d&&(a=0),1===c&&1===d&&(a=45),0===c&&1===d&&(a=90),-1===c&&1===d&&(a=135),-1===c&&0===d&&(a=180),-1===c&&-1===d&&(a=225),0===c&&-1===d&&(a=270),1===c&&-1===d&&(a=315),game.controls.shift.isDown&&this.girl.costMana(.2)&&(b=2*b),this.player.body.velocity=game.physics.arcade.velocityFromAngle(a,b)),this.player.walking.any&&-1===this.player.animations.currentAnim.name.indexOf("walk"))switch(this.player.animations.currentAnim.name){case"standUp":this.player.animations.play("walkUp");break;case"standDown":this.player.animations.play("walkDown");break;case"standLeft":this.player.animations.play("walkLeft");break;case"standRight":this.player.animations.play("walkRight")}if(!this.player.walking.any&&-1===this.player.animations.currentAnim.name.indexOf("stand"))switch(this.player.animations.currentAnim.name){case"walkUp":this.player.animations.play("standUp");break;case"walkDown":this.player.animations.play("standDown");break;case"walkLeft":this.player.animations.play("standLeft");break;case"walkRight":this.player.animations.play("standRight")}}return("level"!==game.mode||game.inactive)&&(this.player.animations.paused||(game.controls.cursors.up.onUp.dispatch(),game.controls.cursors.down.onUp.dispatch(),game.controls.cursors.left.onUp.dispatch(),game.controls.cursors.right.onUp.dispatch(),this.player.animations.paused=!0)),this},PlayerMovement.prototype.addAnimations=function(){var a;a=4,this.player.animations.add("standDown",[131],0,!1),this.player.animations.add("walkDown",[132,133],a,!0),this.player.animations.add("standLeft",[147],0,!1),this.player.animations.add("walkLeft",[148,149],a,!0),this.player.animations.add("standRight",[163],0,!1),this.player.animations.add("walkRight",[164,165],a,!0),this.player.animations.add("standUp",[179],0,!1),this.player.animations.add("walkUp",[180,181],a,!0)},Girl=function(){return this},Girl.prototype.create=function(){var a,b,c,d;if(b=game.map,this.scale=4,this.weapons=new Weapons,this.weapons.create(),this.player=game.add.sprite(128,128,"tiny16"),this.movement=new PlayerMovement(this),"undefined"==typeof game.player&&(game.player={}),"undefined"==typeof game.player.health&&(game.player.health=100),"undefined"==typeof game.player.mana&&(game.player.mana=100),"undefined"==typeof game.player.xp&&(game.player.xp=0),"undefined"==typeof game.player.maxMana&&(game.player.maxMana=100),"undefined"==typeof game.player.manaRegeneration&&(game.player.manaPerSecond=3),"undefined"==typeof game.player.lastManaRegeneration&&(game.player.lastManaRegeneration=!1),game.physics.enable(this.player),this.player.anchor.set(1),this.player.body.setSize(32,32,-16,0),this.player.body.x=128,this.player.body.y=128,this.player.body.collideWorldBounds=!0,this.player.hitTimeout=!1,this.playerPlaced=!1,"Town"===game.state.current)this.player.position.setTo(2176,2112);else for(c=void 0,d=void 0,a=105;!this.playerPlaced;)c=Helpers.GetRandom(0,b.width-1),d=Helpers.GetRandom(0,b.height-1),b.getTile(c,d)&&b.getTile(c,d).index===a&&(this.playerPlaced=!0,this.player.position.setTo(c*b.tileWidth+b.tileWidth,d*b.tileHeight+b.tileHeight));return this.playerPlaced=!1,game.camera.follow(this.player),game.camera.roundPx=!1,this.movement.create(),this},Girl.prototype.update=function(){return this.regenerateMana(),this.movement.update(),"level"===game.mode&&this.player.hitTimeout&&game.time.now-this.player.hitTimeout>100&&(this.player.hitTimeout=!1,this.player.blendMode=PIXI.blendModes.NORMAL),this.weapons.update(),this},Girl.prototype.costMana=function(a){return game.player.mana-a>=0?(game.player.mana=game.player.mana-a,!0):!1},Girl.prototype.regenerateMana=function(){return"level"===game.mode?(game.player.lastManaRegeneration&&(game.player.mana+=game.player.manaPerSecond*game.time.elapsedSecondsSince(game.player.lastManaRegeneration),game.player.mana>game.player.maxMana&&(game.player.mana=game.player.maxMana),game.player.mana<0&&(game.player.mana=0)),game.player.lastManaRegeneration=game.time.now):game.player.lastManaRegeneration=!1,!1},TinyRPG={},TinyRPG.Boot=function(){},TinyRPG.Boot.prototype={preload:function(){game.time.advancedTiming=!0,this.load.image("preloaderBar","asset/sprites/loading.png")},create:function(){game.scale.scaleMode=Phaser.ScaleManager.SHOW_ALL,game.scale.setScreenSize(),game.scale.refresh(),game.stage.disableVisibilityChange=!0,game.onBlur.add(function(){game.input.reset(),game.inactive=!0},this),game.onFocus.add(function(){game.inactive=!1},this),this.state.start("Preloader")}},TinyRPG.Default=function(){},TinyRPG.Default.prototype={create:function(){null==game.controls&&(game.controls=new Controls,game.controls.create()),null==game.ui&&(game.ui={}),game.ui.foeView=new FoeView,game.ui.fps=new FPS,game.ui.statusInfo=new StatusInfo,game.ui.blank=new Blank({visible:!0}),game.ui.textbox=new TextBox,game.ui.pauseMenu=new PauseMenu,game.ui.crosshair=new Crosshair},update:function(){game.controls.update(),game.ui.foeView.update(),game.ui.fps.update(),game.ui.statusInfo.update(),game.ui.crosshair.update()},render:function(){}},TinyRPG.Preloader=function(){},TinyRPG.Preloader.prototype={preload:function(){this.stage.backgroundColor="#6DC2CA",this.preloadBar=this.add.sprite(0,game.height-256,"preloaderBar"),this.preloadBar.scale.setTo(4),this.load.setPreloadSprite(this.preloadBar),this.load.image("menubg","asset/backgrounds/main-menu.png"),this.load.image("boxborder","asset/sprites/box_border.png"),this.load.image("boxborderactive","asset/sprites/box_border_active.png"),this.load.image("menuclickable","asset/sprites/menu_clickable.png"),this.load.spritesheet("startbutton","asset/sprites/start_button.png",59,38),this.load.spritesheet("textbox","asset/sprites/textbox.png"),this.load.spritesheet("foemarker","asset/sprites/foe_marker.png"),this.load.spritesheet("statusinfo","asset/sprites/status_info.png"),this.load.spritesheet("tiny16","asset/tilesets/tiny16.png",64,64),this.load.spritesheet("collision","asset/tilesets/collision.png",64,64),this.load.tilemap("level",null,DungeonGenerator.GetTiledJSON({empty:!0}),Phaser.Tilemap.TILED_JSON),this.load.tilemap("town","asset/rooms/town.json",null,Phaser.Tilemap.TILED_JSON),this.load.bitmapFont("silkscreen","asset/fonts/silkscreen/silkscreen.png","asset/fonts/silkscreen/silkscreen.fnt")},create:function(){this.state.start(params.debug&&"dungeon"===params.debug?"DungeonDebugger":"MainMenu")},render:function(){}},TinyRPG.MainMenu=function(){},TinyRPG.MainMenu.prototype={create:function(){var a,b;game.mode="menu",game.stage.setBackgroundColor("#17091C"),b=this.add.sprite(0,0,"menubg"),b.scale.set(4),a=game.add.button(480,550,"startbutton",this.startGame,this,2,1,0),a.scale.setTo(4),a.anchor.setTo(.5),this.menuMusic=game.add.audio("menu"),this.highscore=game.add.bitmapText(0,0,"silkscreen","--",32),this.highscore.fixedToCamera=!0,this.highscore.setText("Highscore "+(localStorage.highestLevel?localStorage.highestLevel:0)),game.state.states.Default.create(),game.ui.blank.hide()},startGame:function(){game.ui.blank.fadeTo(function(){return game.state.clearCurrentState(),game.state.start("Town")})},update:function(){this.highscore.cameraOffset.x=game.camera.width/2-this.highscore.width/2,this.highscore.cameraOffset.y=240,game.state.states.Default.update()},render:function(){}},TinyRPG.Town=function(){},TinyRPG.Town.prototype={create:function(){game.mode="level",game.physics.startSystem(Phaser.Physics.ARCADE),game.stage.setBackgroundColor("#17091C"),this.map=game.add.tilemap("town"),this.map.addTilesetImage("tiny16"),this.map.addTilesetImage("collision"),this.map.setCollision([1]),this.collision=this.map.createLayer("collision"),this.collision.resizeWorld(),this.collision.visible=!1,this.map.createLayer("deco3"),this.map.createLayer("deco2"),this.map.createLayer("deco1"),this.map.createLayer("deco0"),this.girl=new Girl,this.girl.create(),this.stateChange=!1,this.waterTimer=0,this.fireplaceTimer=0,this.torchTimer=0,game.input.onDown.add(function(){var a,b,c,d,e,f;if(a=void 0,e=void 0,f=void 0,d=void 0,c=void 0,"level"===game.mode)for(b=this.events.length-1;b>=0;)a=this.events[b],"onTileClick"===a.trigger.type&&(e=Math.floor(game.input.worldX/64),f=Math.floor(game.input.worldY/64),a.trigger.location.x===e&&a.trigger.location.y===f&&("undefined"!=typeof a.trigger.layer&&(d=game.state.states[game.state.current].map.getTile(e,f,a.trigger.layer)),"undefined"!=typeof a.trigger.maxDistance&&(c=new Phaser.Line(this.girl.player.x-this.girl.player.width/2,this.girl.player.y-this.girl.player.height/2,64*e+32,64*f+32)),"undefined"!=typeof a.trigger.layer&&d.index!==a.trigger.index||!("undefined"==typeof a.trigger.maxDistance||c.length<=a.trigger.maxDistance)||"textbox"===a.action.type&&game.ui.textbox.show(a.action.text))),b--},this),game.state.states.Default.create(),game.ui.blank.fadeFrom()},update:function(){var a;a=this,game.state.states.Default.update(),game.ui.crosshair.update(),this.girl.update(),"level"===game.mode&&(0===this.torchTimer?(this.map.swap(214,213,void 0,void 0,void 0,void 0,"deco2"),this.torchTimer=64):16===this.torchTimer?this.map.swap(213,214,void 0,void 0,void 0,void 0,"deco2"):32===this.torchTimer?this.map.swap(214,215,void 0,void 0,void 0,void 0,"deco2"):48===this.torchTimer&&this.map.swap(215,214,void 0,void 0,void 0,void 0,"deco2"),this.torchTimer--,0===this.fireplaceTimer?(this.map.swap(89,88,void 0,void 0,void 0,void 0,"deco3"),this.fireplaceTimer=64):16===this.fireplaceTimer?this.map.swap(88,89,void 0,void 0,void 0,void 0,"deco3"):32===this.fireplaceTimer?this.map.swap(89,90,void 0,void 0,void 0,void 0,"deco3"):48===this.fireplaceTimer&&this.map.swap(90,89,void 0,void 0,void 0,void 0,"deco3"),this.fireplaceTimer--,0===this.waterTimer&&(this.map.swap(134,135,void 0,void 0,void 0,void 0,"deco2"),this.waterTimer=60),this.waterTimer--),this.stateChange&&this.stateChange(),game.physics.arcade.collide(this.girl.player,this.collision,function(b,c){42===c.x&&43===c.y&&(a.stateChange=function(){game.mode="stateChange",game.ui.blank.fadeTo(function(){return game.state.start("Dungeon",!0),game.state.clearCurrentState()})})}),game.physics.arcade.overlap(this.girl.bullets,this.collision,function(a){a.kill()})},render:function(){},events:[{name:"home_sign",trigger:{type:"onTileClick",location:{x:33,y:34},maxDistance:127,layer:"deco2",index:97},action:{type:"textbox",text:"You stand in front of your house\nreading your own address.\n\nWhat a pointless waste of time..."}},{name:"dungeon_sign",trigger:{type:"onTileClick",location:{x:43,y:45},maxDistance:127,layer:"deco2",index:97},action:{type:"textbox",text:"Evil Dungeon of Eternal Darkness"}},{name:"townhall_sign",trigger:{type:"onTileClick",location:{x:16,y:20},maxDistance:127,layer:"deco2",index:97},action:{type:"textbox",text:"Town Hall"}},{name:"shop_sign",trigger:{type:"onTileClick",location:{x:17,y:31},maxDistance:127,layer:"deco2",index:97},action:{type:"textbox",text:"Shop"}},{name:"lodging_sign",trigger:{type:"onTileClick",location:{x:13,y:39},maxDistance:127,layer:"deco2",index:97},action:{type:"textbox",text:"Night's Lodging"}},{name:"shop_dialog",trigger:{type:"onTileClick",location:{x:15,y:26},maxDistance:127,layer:"deco0",index:136},action:{type:"textbox",text:"His cold dead eyes are staring at you.\nHe doesn't say a word."}}]},TinyRPG.Dungeon=function(){},TinyRPG.Dungeon.prototype={create:function(){var a,b,c,d,e;for(d=void 0,b=2,c=3,game.mode="level","undefined"==typeof game.level&&(game.level=1),d=game.level;d>1;)b+=game.level,d--;b=b>100?100:b,b=Math.round(b/c),e=DungeonGenerator.GetTiledJSON(),game.cache._tilemaps.level.data=e,game.physics.startSystem(Phaser.Physics.ARCADE),this.grid=new PF.Grid(64,64,e.walkableGrid),game.stage.setBackgroundColor("#140C1C"),game.map=game.add.tilemap("level"),game.map.addTilesetImage("tiny16"),game.map.setCollisionByExclusion([105]),a=game.map.createLayer("tiny16"),game.collision=a,a.resizeWorld(),game.enemies={skeletons:new Skeletons(b),slimes:new Slimes(b),bats:new Bats(b)},game.enemies.skeletons.create(),game.enemies.slimes.create(),game.enemies.bats.create(),this.enemiesLeft=game.add.bitmapText(0,0,"silkscreen","--",32),this.enemiesLeft.fixedToCamera=!0,this.enemiesLeft.cameraOffset.x=32,this.enemiesLeft.cameraOffset.y=32,this.girl=new Girl,this.girl.create(),game.state.states.Default.create(),game.ui.blank.fadeFrom()},update:function(){var a,b,c,d;b=game.collision,c=game.enemies.skeletons,d=game.enemies.slimes,a=game.enemies.bats,game.state.states.Default.update(),c.update(),d.update(),a.update(),this.girl.update(),game.physics.arcade.collide(this.girl.player,b),this.girl.weapons.hitTest(c),this.girl.weapons.hitTest(d),this.girl.weapons.hitTest(a),this.girl.weapons.collide(b),game.physics.arcade.collide(c.group,b),game.physics.arcade.collide(d.group,b),game.physics.arcade.collide(a.group,b),game.physics.arcade.collide(c.group,c.group),game.physics.arcade.collide(d.group,d.group),game.physics.arcade.collide(a.group,a.group),game.physics.arcade.collide(c.group,d.group),game.physics.arcade.collide(c.group,a.group),game.physics.arcade.collide(d.group,a.group),this.enemiesLeft.setText(c.group.length+d.group.length+a.group.length-c.group.countDead()-d.group.countDead()-a.group.countDead()+" enemies left // level "+game.level),c.group.length+d.group.length+a.group.length-c.group.countDead()-d.group.countDead()-a.group.countDead()===0&&(game.mode="stateChange",game.ui.blank.fadeTo(function(a){return function(){return game.state.clearCurrentState(),game.level++,a.state.start("Dungeon")}}(this))),(game.physics.arcade.collide(this.girl.player,c.group)||game.physics.arcade.collide(this.girl.player,d.group)||game.physics.arcade.collide(this.girl.player,a.group))&&(game.player.health--,this.girl.player.hitTimeout=game.time.now,this.girl.player.blendMode=PIXI.blendModes.ADD,game.player.health<=0&&(this.girl.player.kill(),(!localStorage.highestLevel||localStorage.highestLevel<game.level)&&(localStorage.highestLevel=game.level),game.level=1,game.player.health=100,game.player.mana=100,game.player.xp=0,game.state.clearCurrentState(),this.state.start("MainMenu")))},render:function(){}},TinyRPG.DungeonDebugger=function(){},TinyRPG.DungeonDebugger.prototype={create:function(){var a,b,c;this.updateCounter=0,c=Phaser.Net.prototype.getQueryString(),game.level=1,c.level&&c.level>0&&(game.level=1*c.level),game.mode="level",game.cache._tilemaps.level.data=DungeonGenerator.GetTiledJSON(),game.stage.setBackgroundColor("#140C1C"),b=game.add.tilemap("level"),b.addTilesetImage("tiny16"),a=b.createLayer("tiny16"),a.resizeWorld()},update:function(){if(this.updateCounter<5)return this.updateCounter++;throw new Error("code execution stopped")},render:function(){}},params=Phaser.Net.prototype.getQueryString(),game=void 0,toDungeon=function(){game.state.states.Town.girl.player.position.setTo(2754,2864)},game=params.debug&&"dungeon"===params.debug?new Phaser.Game(4096,4096,Phaser.CANVAS,"tinyRPG",{},!1,!1):new Phaser.Game(960,640,Phaser.CANVAS,"tinyRPG",{},!1,!1),game.state.add("Boot",TinyRPG.Boot),game.state.add("Default",TinyRPG.Default),game.state.add("Preloader",TinyRPG.Preloader),game.state.add("MainMenu",TinyRPG.MainMenu),game.state.add("Town",TinyRPG.Town),game.state.add("Dungeon",TinyRPG.Dungeon),game.state.add("DungeonDebugger",TinyRPG.DungeonDebugger),game.state.start("Boot"),$(function(){return $(window).konami({code:[38,38,40,40,37,39,37,39],cheat:function(){return $("body").toggleClass("retro")}}),$(window).konami({code:[84,79,68,85,78,71,69,79,78],cheat:function(){return toDungeon()}}),$(window).konami({code:[84,72,69,82,69,73,83,78,79,83,80,79,79,78],cheat:function(){return setInterval(function(){return game.player.mana=100},1e3)}})});