if ( !this.byId[unit.__id__] ) {
this.byId[unit.__id__] = unit;
- if (unit.active)
+ if (unit.isActive)
this.active.push(unit);
if (unit.isProjectile)
this.bullets.push(unit);
- if (unit.isCombatant)
+ if (unit.isUnit)
this.units.push(unit);
if (unit.tick)
this.toTick.push(unit);
delete this.byId[unit.__id__];
this.map.removeBlocker(unit);
- if (unit.active)
+ if (unit.isActive)
this.active.remove(unit);
if (unit.tick)
this.toTick.remove(unit);
if (unit.isProjectile)
this.bullets.remove(unit);
- if (unit.isCombatant)
+ if (unit.isUnit)
this.units.remove(unit);
return unit;
.extend(exports, {
'Map' : require('tanks/map/pathing/map').Map,
'Traversal' : require('tanks/map/pathing/traversal').Traversal,
- 'LinearTrajectory' : require('tanks/map/pathing/linear-trajectory').LinearTrajectory,
+ 'LinearTrajectory' : require('tanks/map/pathing/lineartrajectory').LinearTrajectory,
'CircularTrajectory' : require('tanks/map/pathing/circular-trajectory').CircularTrajectory
});
, manhattan = vec.manhattan
, Map = require('tanks/map/pathing/map').Map
-, LinearTrajectory = require('tanks/map/pathing/linear-trajectory').LinearTrajectory
+, LinearTrajectory = require('tanks/map/pathing/lineartrajectory').LinearTrajectory
, Bullet = require('tanks/thing/bullet').Bullet
, _X = 0, _Y = 1
function nearEnemyFilter(agent){
var me = this; // Runs in the context of the 'me' unit; @see this.findNearLike()
- return agent.isCombatant && agent.align !== me.align;
+ return agent.isUnit && agent.align !== me.align;
}
function nearEnemyInSightFilter(agent){
var me = this; // Runs in the context of the 'me' unit; @see this.findNearLike()
- return ( agent.isCombatant && agent.align !== me.align &&
+ return ( agent.isUnit && agent.align !== me.align &&
new LinearTrajectory(me, me.loc, agent.loc).canSee(agent) );
}
, stat = require('tanks/effects/stat')
, Explosion = require('tanks/fx/explosion').Explosion
, Thing = require('tanks/thing/thing').Thing
-, LinearTrajectory = require('tanks/map/pathing/linear-trajectory').LinearTrajectory
, Traversal = require('tanks/map/pathing/traversal').Traversal
+, LinearTrajectory = require('tanks/map/pathing/lineartrajectory').LinearTrajectory
,
// Instance
blocking : BoundsType.BLOCKING,
- isRenderable : true,
+
+ isCombatant : true,
isProjectile : true,
bounces : 0,
width : 6,
height : 6,
+ isRenderable : true,
color: '#FFF6AE',
stats : {
, tank = require('tanks/thing/tank')
, thing = require('tanks/thing/thing')
, tower = require('tanks/thing/tower')
-// , unit = require('tanks/thing/unit')
+, unit = require('tanks/thing/unit')
;
Y.core.extend(exports, {
'Bullet' : bullet.Bullet,
'Tank' : tank.Tank,
'Thing' : thing.Thing,
'Tower' : tower.Tower,
- // 'Unit' : unit.Unit
+ 'Unit' : unit.Unit
});
// Instance
blocking : BoundsType.IRREGULAR, // Need to allow shields etc to passthrough like-aligned units
+ isCombatant : true,
isComponent : true,
isShield : true,
, constants = require('tanks/constants')
, BoundsType = constants.BoundsType
, DensityType = constants.DensityType
-, LinearTrajectory = require('tanks/map/pathing/linear-trajectory').LinearTrajectory
+, LinearTrajectory = require('tanks/map/pathing/lineartrajectory').LinearTrajectory
, Traversal = require('tanks/map/pathing/traversal').Traversal
-, Thing = require('tanks/thing/thing').Thing
+, Unit = require('tanks/thing/unit').Unit
, Bullet = require('tanks/thing/bullet').Bullet
, Lootable = require('tanks/mixins/lootable').Lootable
, Barrel = require('tanks/fx/barrel').Barrel
Tank =
exports['Tank'] =
-Thing.subclass('Tank', function(Tank){
+Unit.subclass('Tank', function(Tank){
Y.core.descriptors(this, {
isUnit : true,
this['init'] =
function initTank(align){
- Thing.init.call(this, align);
+ Unit.init.call(this, align);
this.projectile = this.defaultProjectile = Bullet.lookup(this.projectile);
this.colors = Y.extend({}, this.colors);
this.atkGauge = new CooldownGauge(this.cooldowns.attack, this.width+1,this.height+1);
};
- this['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);
- };
-
-
/// Rendering Methods ///
new Barrel(b.width,b.height, b.originX,b.originY)
.appendTo( this.shape ) // have to append early to avoid problems with relative positioning
.position(b.x, b.y)
- // .position(w2-2, h2-bh/2)
- // .origin(2, bh/2)
.fill( colors.barrel ) ;
return this;
return this;
};
+
+ this['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);
+ };
+
+
this['rotateBarrel'] =
function rotateBarrel(x,y){
this.barrelShape.rotate(this.angleTo(x,y));
return this;
};
+ // FIXME: delegate to Barrel
this['rotateBarrelRelPage'] =
function rotateBarrelRelPage(pageX, pageY){
var shape = this.shape
isThing : true,
isUnit : false,
isCombatant : false,
- isWall : false,
isProjectile : false,
+ isWall : false,
isAccessory : false,
isComponent : false,
+ isShield : false,
isActive : true, // Agent takes actions?
isRenderable : false, // Agent will present itself for rendering when ready // FIXME: stupid hack
, constants = require('tanks/constants')
, BoundsType = constants.BoundsType
, DensityType = constants.DensityType
-, LinearTrajectory = require('tanks/map/pathing/linear-trajectory').LinearTrajectory
+, LinearTrajectory = require('tanks/map/pathing/lineartrajectory').LinearTrajectory
, Traversal = require('tanks/map/pathing/traversal').Traversal
-, Thing = require('tanks/thing/thing').Thing
+, Unit = require('tanks/thing/unit').Unit
, Bullet = require('tanks/thing/bullet').Bullet
, Lootable = require('tanks/mixins/lootable').Lootable
, Barrel = require('tanks/fx/barrel').Barrel
Tower =
exports['Tower'] =
-Thing.subclass('Tower', function(Tower){
+Unit.subclass('Tower', function(Tower){
Y.core.descriptors(this, {
isCombatant : true,
this['init'] =
function initTower(align){
- Thing.init.call(this, align);
+ Unit.init.call(this, align);
this.projectile = this.defaultProjectile = Bullet.lookup(this.projectile);
this.colors = Y.extend({}, this.colors);
this.atkGauge = new CooldownGauge(this.cooldowns.attack, this.width+1,this.height+1);
if (this.shape) this.shape.remove();
var colors = this.colors
- , w = this.width, w2 = w/2
- , h = this.height, h2 = h/2
- , r = w / 2
+ , r = this.width / 2
;
this.shape =
new Barrel(b.width,b.height, b.originX,b.originY)
.appendTo( this.shape ) // have to append early to avoid problems with relative positioning
.position(b.x, b.y)
- // .position(w2-2, h2-bh/2)
- // .origin(2, bh/2)
- .fill( colors.barrel ) ;
+ .fill( colors.barrel )
+ ;
return this;
};
+var Y = require('Y').Y
+, Thing = require('tanks/thing/thing').Thing
+, LinearTrajectory = require('tanks/map/pathing/lineartrajectory').LinearTrajectory
+, Traversal = require('tanks/map/pathing/traversal').Traversal
+,
+
+Unit =
+exports['Unit'] =
+Thing.subclass('Unit', {
+ isUnit : true,
+ isCombatant : true,
+
+ nShots : 0,
+
+
+ init : function initUnit(align){
+ Thing.init.call(this, align);
+ },
+
+ ableToShoot : function ableToShoot(){
+ return this.nShots < this.stats.shots.val && this.cooldowns.attack.ready;
+ },
+
+ move : function move(x,y){
+ if (x instanceof Array) { y=x[_Y]; x=x[_X]; }
+
+ var loc = this.loc;
+ this.trajectory = new LinearTrajectory(this, loc.x,loc.y, x,y, this.movePerMs());
+
+ var tvsl = new Traversal(this)
+ , to = tvsl.traverse(this.elapsed, x,y) ;
+
+ this.game.moveThingTo(this, to.x,to.y);
+
+ return this;
+ }
+})
+;