Permalink
Browse files

Refactoring.

  • Loading branch information...
1 parent 1961bac commit a5a1b3f4bfa58272c1bd051826ffee87567eb0a2 @presstube committed Nov 8, 2011
Showing with 19 additions and 28 deletions.
  1. +8 −6 src/hunted/Bubble.js
  2. +9 −20 src/hunted/HuntedApp.js
  3. +1 −1 src/hunted/Nav.js
  4. +1 −1 src/hunted/Venn.js
View
@@ -58,14 +58,16 @@
gravityWell.trigger(Bubble.VACATED, gravityWell);
} else if (state === Bubble.OCCUPIED) {
- app.player.skin.setBoostFuel(app.player.props.boostFuelLimit);
+ var player = app.getPlayer();
+ player.skin.setBoostFuel(player.props.boostFuelLimit);
gravityWell.trigger(Bubble.OCCUPIED, gravityWell);
}
}
this.tick = function() {
- var globalTargetPos = app.player.localToGlobal(0,0);
+ var player = app.getPlayer();
+ var globalTargetPos = player.localToGlobal(0,0);
playerDist = PTUtils.distance(new Point(0, 0), gravityWell.globalToLocal(globalTargetPos.x, globalTargetPos.y));
// would be good if targets were added and removed via an api instead of hard coded like this
@@ -74,23 +76,23 @@
checkTarget(chaser);
});
if (playerDist < 800) { // if the player is close enough check the projectiles too, otherwise it become too heavy
- checkTarget(app.player, playerDist);
+ checkTarget(player, playerDist);
_.each(app.getProjectiles(), function(projectile){
checkTarget(projectile);
});
}
};
function checkTarget(target, dist) {
- var force, degrees;
+ var force, degrees, player = app.getPlayer();
if (!dist) {
var globalTargetPos = target.localToGlobal(0,0);
dist = PTUtils.distance(new Point(0, 0), gravityWell.globalToLocal(globalTargetPos.x, globalTargetPos.y));
}
if (dist < maxPullPerimeter) {
- if (state === Bubble.VACATED && target === app.player) { setState(Bubble.OCCUPIED); }
+ if (state === Bubble.VACATED && target === player) { setState(Bubble.OCCUPIED); }
multPullPerimeter = (dist - minPullPerimeter)/(maxPullPerimeter - minPullPerimeter);
multPullPerimeter = (multPullPerimeter>maxPullPerimeter) ? maxPullPerimeter : multPullPerimeter;
multPullPerimeter = (multPullPerimeter<0) ? 0 : multPullPerimeter;
@@ -99,7 +101,7 @@
target.addForce(PTUtils.polarDegrees(force, degrees));
} else if (dist < maxPushPerimeter) {
- if (state === Bubble.OCCUPIED && target === app.player) { setState(Bubble.VACATED); }
+ if (state === Bubble.OCCUPIED && target === player) { setState(Bubble.VACATED); }
multPushPerimeter = (dist - minPushPerimeter)/(maxPushPerimeter - minPushPerimeter);
multPushPerimeter = (multPushPerimeter>maxPushPerimeter) ? maxPushPerimeter : multPushPerimeter;
multPushPerimeter = (multPushPerimeter<0) ? 0 : multPushPerimeter;
View
@@ -79,26 +79,15 @@
trackingStage.addChild(itemScroller);
trackingStage.addChild(player);
trackingStage.setTrackingTarget(player);
-
-
- // this is bullshit
- // on line 234 you are performing a destructive operation on chasers ( chasers = _.without(chasers, chaser))
- // anyone object who is referencing app.chasers will only be looking at the chasers array referenced here
- // that was first referenced here, not the newly created one.
-
- // you should either ditch private vars for all these guys alltogether
- // or you should create proper getters for them.. exposing them like this isn't good.
+ // because these objects are permanent its ok, at least for now.
this.stage = stage;
this.scaleStage = scaleStage;
this.trackingStage = trackingStage;
- this.player = player;
- this.chasers = chasers;
- this.projectiles = projectiles;
this.drag = drag;
-
- // this is how it should be
-
+
+ // this is how it should be for impermanent objects
+ this.getPlayer = function() { return player; };
this.getChasers = function() { return chasers; };
this.getProjectiles = function() { return projectiles; };
@@ -127,11 +116,11 @@
checkForHits();
stage.update();
// set scaleStage's setScaleMultiplier with nav's getDistMultiplier()
- // if (gameState == "GAME_ON") {
- // scaleStage.setScaleMultiplier(nav.getDistMultiplier());
- // } else {
- // scaleStage.setScaleMultiplier(0.5);
- // }
+ if (gameState == "GAME_ON") {
+ scaleStage.setScaleMultiplier(nav.getDistMultiplier());
+ } else {
+ scaleStage.setScaleMultiplier(0.5);
+ }
// move stage back to 0,0 to compensate for Boost shudder
stage.x += (0 - stage.x) / 1.5;
View
@@ -102,7 +102,7 @@
if (navItems.length > 0) rotateNavItems();
- if (props.app.chasers.length > 0) {
+ if (props.app.getChasers().length > 0) {
targetClosest();
}
};
View
@@ -24,7 +24,7 @@
function trigger(level) {
console.log("!!VENN: " + occupied.length + "!!");
- player = props.app.player;
+ player = props.app.getPlayer();
if (level === 2) player.setSkin(new ShipSkinBee(player.props));
}

0 comments on commit a5a1b3f

Please sign in to comment.