, Vec = require('ezl/math/vec').Vec
, Rect = require('ezl/shape').Rect
-// , ORIGIN = new Vec(0,0)
+, ORIGIN = new Vec(0,0)
// , FACING_RIGHT = exports['FACING_RIGHT'] = 'right'
// , FACING_LEFT = exports['FACING_LEFT'] = 'left'
,
*/
barrelTipLoc : function barrelTipLoc(wiggle, relParent){
var theta = this.transform.rotate
- , sin = Math.sin(theta), cos = Math.cos(theta)
// (sqrt(2)/2 * wiggle) is max diagonal to ensure projectile doesn't overlap with firing unit
, len = this.bbox.originRight + (wiggle || 0)*0.707
- // , len = this.bbox.originDist(this.facing) + (wiggle || 0)*0.707
- // , olen = (this.facing === FACING_LEFT ? this.bbox.originLeft : this.bbox.originRight)
- // , len = olen + (wiggle || 0)*0.707
-
, o = ((relParent && this.parent) ? this.parent.loc : ORIGIN)
- , x = o.x + this.loc.x + len*cos
- , y = o.y + this.loc.y + len*sin
+ , x = o.x + len*Math.cos(theta)
+ , y = o.y + len*Math.sin(theta)
;
return new Vec(x,y);
}
getTurretLoc : function getTurretLoc(){
- var WIGGLE = 2
- , loc = this.loc
- , barrel = this.barrelShape
-
- , theta = barrel.transform.rotate
- , sin = Math.sin(theta), cos = Math.cos(theta)
-
- // sqrt(2)/2 * (P.width + WIGGLE)
- // is max diagonal to ensure we don't overlap with the firing unit
- , pw = this.projectile.fn.width
- , len = barrel.bbox.width + 0.707*(pw+WIGGLE)
-
- , x = loc.x + len*cos
- , y = loc.y + len*sin
- ;
- return new Vec(x,y);
+ var WIGGLE = 2, pw = this.projectile.fn.width;
+ return this.barrelShape.barrelTipLoc(WIGGLE+pw, true);
},
getBarrelAngle : function getBarrelAngle(){
return this;
},
- // FIXME: delegate to Barrel
rotateBarrelRelPage : function rotateBarrelRelPage(pageX, pageY){
- var shape = this.shape
- , off = shape.offset()
- , w = this.width, h = this.height
- , x = off.left + w/2 - pageX
- , y = off.top + h/2 - pageY
- , theta = Math.atan2(-y,-x)
- ;
- this.barrelShape.rotate(theta);
+ this.barrelShape.rotateRelPage(pageX, pageY);
return this;
}
});
+// TODO: Move to Layer
var NUM_OR_PERCENT = /^\s*[\d\.]+\s*%?\s*$/;
function calcValue(v){
var unit = this;
},
+ getTurretLoc : function getTurretLoc(){
+ var WIGGLE = 2, pw = this.projectile.fn.width;
+ return this.barrelShape.barrelTipLoc(WIGGLE+pw, true);
+ },
+
+ getBarrelAngle : function getBarrelAngle(){
+ return this.barrelShape.transform.rotate;
+ },
+
rotateBarrel : function rotateBarrel(x,y){
this.barrelShape.rotate(this.angleTo(x,y));
return this;
},
rotateBarrelRelPage : function rotateBarrelRelPage(pageX, pageY){
- var shape = this.shape
- , off = shape.offset()
- , w = this.width, h = this.height
- , x = off.left + w/2 - pageX
- , y = off.top + h/2 - pageY
- , theta = Math.atan2(-y,-x)
- ;
- this.barrelShape.rotate(theta);
+ this.barrelShape.rotateRelPage(pageX, pageY);
return this;
}
});
+// TODO: Move to Layer
var NUM_OR_PERCENT = /^\s*[\d\.]+\s*%?\s*$/;
function calcValue(v){
var unit = this;