Permalink
Browse files

fixed errors when wall crawlers and wall avoiders weren't near any walls

  • Loading branch information...
1 parent d310509 commit 72be85afcc0ea4588ada3c5509d309c33ea40da4 Evan Wallace committed Jan 10, 2011
Showing with 28 additions and 21 deletions.
  1. +2 −0 closure_compiler/rapt.externs.js
  2. +5 −3 game/src/entities/wallavoider.js
  3. +21 −18 game/src/entities/wallcrawler.js
@@ -5,4 +5,6 @@ Player.prototype.leftKey;
Player.prototype.rightKey;
Player.prototype.crouchKey;
+function GameState() {}
+
GameState.prototype.killKey;
@@ -46,9 +46,11 @@ WallAvoider.prototype.move = function(seconds) {
return this.accelerate(new Vector(0, 0), seconds);
}
this.acceleration = targetDelta.unit();
- var closestPointDelta = ref_worldPoint.ref.sub(this.getCenter());
- var wallAvoidance = closestPointDelta.mul(-1 / (closestPointDist * closestPointDist));
- this.acceleration.inplaceAdd(wallAvoidance);
+ if (closestPointDist < Number.POSITIVE_INFINITY) {
+ var closestPointDelta = ref_worldPoint.ref.sub(this.getCenter());
+ var wallAvoidance = closestPointDelta.mul(-1 / (closestPointDist * closestPointDist));
+ this.acceleration.inplaceAdd(wallAvoidance);
+ }
this.acceleration.normalize();
this.acceleration.inplaceMul(WALL_AVOIDER_ACCEL);
@@ -39,27 +39,30 @@ function WallCrawler(center, direction) {
WallCrawler.prototype.move = function(seconds) {
var ref_shapePoint = {};
var ref_worldPoint = {};
- CollisionDetector.closestToEntityWorld(this, 2, ref_shapePoint, ref_worldPoint, gameState.world);
+ var closestPointDist = CollisionDetector.closestToEntityWorld(this, 2, ref_shapePoint, ref_worldPoint, gameState.world);
- var delta = this.getCenter().sub(ref_worldPoint.ref);
- // Make sure it doesn't get too far away or get stuck in corners
- var flip = delta.flip();
+ if (closestPointDist < Number.POSITIVE_INFINITY) {
+ var delta = this.getCenter().sub(ref_worldPoint.ref);
+ // Make sure it doesn't get too far away or get stuck in corners
+ var flip = delta.flip();
- if (this.firstTick) {
- if (this.velocity.dot(flip) < 0) this.clockwise = true;
- else this.clockwise = false;
- this.firstTick = false;
+ if (this.firstTick) {
+ if (this.velocity.dot(flip) < 0) this.clockwise = true;
+ else this.clockwise = false;
+ this.firstTick = false;
+ }
+ if (delta.lengthSquared() > (WALL_CRAWLER_RADIUS * WALL_CRAWLER_RADIUS * 1.1)) {
+ // Pull the crawler towards the wall
+ if (this.clockwise) this.velocity = flip.mul(-1).sub(delta.mul(PULL_FACTOR));
+ else this.velocity = flip.sub(delta.mul(PULL_FACTOR));
+ } else {
+ // Push the crawler away from the wall
+ if (this.clockwise) this.velocity = flip.mul(-1).add(delta.mul(PUSH_FACTOR));
+ else this.velocity = flip.add(delta.mul(PUSH_FACTOR));
+ }
+ this.velocity.normalize();
}
- if (delta.lengthSquared() > (WALL_CRAWLER_RADIUS * WALL_CRAWLER_RADIUS * 1.1)) {
- // Pull the crawler towards the wall
- if (this.clockwise) this.velocity = flip.mul(-1).sub(delta.mul(PULL_FACTOR));
- else this.velocity = flip.sub(delta.mul(PULL_FACTOR));
- } else {
- // Push the crawler away from the wall
- if (this.clockwise) this.velocity = flip.mul(-1).add(delta.mul(PUSH_FACTOR));
- else this.velocity = flip.add(delta.mul(PUSH_FACTOR));
- }
- this.velocity.normalize();
+
return this.velocity.mul(WALL_CRAWLER_SPEED * seconds);
};

0 comments on commit 72be85a

Please sign in to comment.