Raspsnir/public_html/browserquest/js/camera.js

1 line
1.2 KiB
JavaScript

define([],function(){var e=Class.extend({init:function(e){this.renderer=e,this.x=0,this.y=0,this.gridX=0,this.gridY=0,this.offset=.5,this.rescale()},rescale:function(){var e=this.renderer.mobile?1:2;this.gridW=15*e,this.gridH=7*e,log.debug("---------"),log.debug("Factor:"+e),log.debug("W:"+this.gridW+" H:"+this.gridH)},setPosition:function(e,t){this.x=e,this.y=t,this.gridX=Math.floor(e/16),this.gridY=Math.floor(t/16)},setGridPosition:function(e,t){this.gridX=e,this.gridY=t,this.x=this.gridX*16,this.y=this.gridY*16},lookAt:function(e){var t=this.renderer,n=Math.round(e.x-Math.floor(this.gridW/2)*t.tilesize),r=Math.round(e.y-Math.floor(this.gridH/2)*t.tilesize);this.setPosition(n,r)},forEachVisiblePosition:function(e,t){var t=t||0;for(var n=this.gridY-t,r=this.gridY+this.gridH+t*2;n<r;n+=1)for(var i=this.gridX-t,s=this.gridX+this.gridW+t*2;i<s;i+=1)e(i,n)},isVisible:function(e){return this.isVisiblePosition(e.gridX,e.gridY)},isVisiblePosition:function(e,t){return t>=this.gridY&&t<this.gridY+this.gridH&&e>=this.gridX&&e<this.gridX+this.gridW?!0:!1},focusEntity:function(e){var t=this.gridW-2,n=this.gridH-2,r=Math.floor((e.gridX-1)/t)*t,i=Math.floor((e.gridY-1)/n)*n;this.setGridPosition(r,i)}});return e});