},
addBlocker : function addBlocker(obj){
+ this.removeBlocker(obj);
var bb = obj.boundingBox;
if (obj.blocking && bb)
obj.region = this.set(bb.x1,bb.y1, bb.x2,bb.y2, obj);
return obj;
},
- updateBlocker : function updateBlocker(obj){
- this.removeBlocker(obj);
- this.addBlocker(obj);
- return obj;
- },
-
-
attemptMove : function attemptMove(obj, trj, to){
var wall, blocker, what, bb = obj.boundingBox
, maxW = this.width, maxH = this.height
// }
// Check for pathmap collisions
- blocker = this.get(x1,y1, x2,y2).remove(obj).shift();
+ var blockers = this.get(x1,y1, x2,y2).remove(obj);
+ if (blockers.size() > 1){
+ console.log('multiple blockers! '+blockers._o.slice(0));
+ return { 'ok':false, 'corner':true };
+ }
+
+ blocker = blockers.shift();
if ( blocker ) {
what = blocker+' on the ';
*/
init : function initBullet(owner, x,y){
this.owner = owner;
-
- var loc = owner.loc
- , trj = this.trajectory = new math.Line(loc.x,loc.y, x,y);
Thing.init.call(this, owner.game, owner.align);
-
- this.setLocation(trj.x1, trj.y1);
- trj.setTScale(this.stats.move * REF_SIZE/1000);
+ var loc = owner.loc;
+ this.trajectory = new math.Line(loc.x,loc.y, x,y, this.stats.move*REF_SIZE/1000);
+ this.setLocation(loc.x,loc.y);
},
blocking : false,
elapsed : 0,
createCooldowns : Y.op.nop,
+ // setLocation : function setLocation(x,y){
+ // var trj = this.trajectory;
+ // this.trajectory = new math.Line(x,y, trj.x2,trj.y2, trj.tdist);
+ // this.elapsed = 0;
+ // return Thing.prototype.setLocation.call(this, x,y);
+ // },
+
+ setTarget : function setTarget(x,y){
+ var loc = this.loc
+ , trj = this.trajectory;
+ this.trajectory = new math.Line(loc.x,loc.y, x,y, trj.tdist);
+ this.elapsed = 0;
+ return this;
+ },
+
act : function act(){
this.elapsed += ELAPSED;
if (!this.dead)
// Something obstructs us -- time to reflect!
if (!test.ok) {
- to = test.to;
- var wall = test.wall, p2 = trj.p2
- , bb = this.boundingBox
- , goal = wall.isWithin(p2,bb) ? trj.near(p2.x+2*REF_SIZE, p2.y+2*REF_SIZE) : p2
- , _ng, ng = _ng = math.reflect(goal, wall)
- , x1 = bb.x1, y1 = bb.y1
- , tx = to.x, ty = to.y
- , cmp = Y.op.cmp
- ;
- // Are we pointed the wrong direction? Rotate 180 degrees around the bullet
- if ( cmp(tx,x1) !== cmp(goal.x,x1) || cmp(ty,y1) !== cmp(goal.y,y1) )
- ng = new math.Vec(tx - ng.x + tx, ty - ng.y + ty);
+ // Literal corner case :P
+ if (test.corner) {
+ var to = this.loc, ng = trj.p1;
+ // this.trajectory = new math.Line(loc.x,loc.y, p1.x,p1.y, trj.tdist);
+
+
+ // Normal reflection against one line
+ } else {
+ to = test.to;
+ var wall = test.wall, p2 = trj.p2
+ , bb = this.boundingBox
+ , goal = wall.isWithin(p2,bb) ? trj.near(p2.x+2*REF_SIZE, p2.y+2*REF_SIZE) : p2
+ , _ng, ng = _ng = math.reflect(goal, wall)
+ , x1 = bb.x1, y1 = bb.y1
+ , tx = to.x, ty = to.y
+ , cmp = Y.op.cmp
+ ;
+
+ // Are we pointed the wrong direction? Rotate 180 degrees around the bullet
+ if ( cmp(tx,x1) !== cmp(goal.x,x1) || cmp(ty,y1) !== cmp(goal.y,y1) )
+ ng = new math.Vec(tx - ng.x + tx, ty - ng.y + ty);
+ }
- this.trajectory = new math.Line(
- to.x,to.y, ng.x,ng.y,
- this.stats.move * REF_SIZE/1000 );
+ this.trajectory = new math.Line(to.x,to.y, ng.x,ng.y, trj.tdist);
- // console.log('['+this._depth+' '+TICKS+'] '+this+' reflected by', test.what);
- // console.log(' to='+to+', goal='+goal+(p2.equals(goal) ? '' : ' <~ '+p2));
- // console.log(' --> new goal='+ng+(ng.equals(_ng) ? '' : ' <~ '+_ng));
- // console.log(' --> trajectory='+this.trajectory);
+ if (this._depth) {
+ console.log('['+this._depth+' '+TICKS+'] '+this+' reflected by', test.what);
+ console.log(' to='+to+', goal='+goal+(p2.equals(goal) ? '' : ' <~ '+p2));
+ console.log(' --> new goal='+ng+(ng.equals(_ng) ? '' : ' <~ '+_ng));
+ console.log(' --> trajectory='+this.trajectory);
+ }
this.render(this.game.level).draw();
this.elapsed = ELAPSED;
- if (this._depth++ < 3)
+ if (this._depth++ < 5)
return this.move();
- console.log('['+this._depth+' '+TICKS+'] '+this+' reflected by', test.what);
- console.log(' to='+to+', goal='+goal+(p2.equals(goal) ? '' : ' <~ '+p2));
- console.log(' --> new goal='+ng+(ng.equals(_ng) ? '' : ' <~ '+_ng));
- console.log(' --> trajectory='+this.trajectory);
- throw new Error('Reflection error!');
+ console.log('Reflection limit reached!');
+ this._depth = 0;
+ return this;
}
// if (this._depth > 0)