Permalink
Browse files

Spiking Splat

Adding some notes about observations of poor implementation.

Going around replacing direct references with some getters.

Refactoring some stuff with cleaner underscore ways.

Added in rough splat implementation.
  • Loading branch information...
1 parent 97745db commit ba5142f0353736d7cc14b315c174790971090396 @presstube committed Nov 5, 2011
View
@@ -37,7 +37,6 @@
<script src="src/hunted/ParallaxScroller.js"></script>
<script src="src/hunted/Bubble.js"></script>
<script src="src/hunted/Boost.js"></script>
- <script src="src/hunted/Boom.js"></script>
<script src="src/hunted/ItemScroller.js"></script>
<script src="src/hunted/ShipControlsKeyboard.js"></script>
<script src="src/hunted/ExhaustPipe.js"></script>
@@ -57,6 +56,7 @@
<script src="src/hunted/LauncherPeePants.js"></script>
<script src="src/hunted/PTUtils.js"></script>
<script src="src/hunted/Venn.js"></script>
+ <script src="src/hunted/Splat.js"></script>
</head>
View
@@ -70,12 +70,12 @@
// would be good if targets were added and removed via an api instead of hard coded like this
- _.each(app.chasers, function(chaser) {
+ _.each(app.getChasers(), function(chaser) {
checkTarget(chaser);
});
if (playerDist < 800) { // if the player is close enough check the projectiles too, otherwise it become too heavy
checkTarget(app.player, playerDist);
- _.each(app.projectiles, function(projectile){
+ _.each(app.getProjectiles(), function(projectile){
checkTarget(projectile);
});
}
View
@@ -2,13 +2,18 @@
var HuntedApp = function() {
+ // all this instantiation in one go here is stupid. split it up.
+ // it causes things like for instance on like 14 when you are passing app into that new Nav object
+ // that nav in its constructor can't pull any values from app b/c app hasn't finished constructing itself yet.
+ // like if Nav calls app.scaleStage, it will be undefined.
+
var app = this,
canvas = document.getElementById("canvas"),
stage = new Stage(canvas),
fpsLabel = PTUtils.makeFPSLabel(),
scaleStage = new ScaleStage(),
trackingStage = new TrackingStage(),
- nav = new Nav(scaleStage),
+ nav = new Nav({app: app}),
venn = new Venn({app: app}),
drag = 0.95,
wrapRadius = 3000,
@@ -54,10 +59,7 @@
projectileThrust: 40,
shotsPerLaunch: 1,
projectileLife: 20,
- projectileLimit: 200,
-
- // for the heatseeker
- targetFunc: nav.getTarget
+ projectileLimit: 200
}),
itemScroller = new ItemScroller({
@@ -66,21 +68,27 @@
wrapRadius: wrapRadius
});
-
-
-
stage.addChild(fpsLabel, levelText, scaleStage);
levelText.x = 10; levelText.y = 40;
scaleStage.addChild(trackingStage);
scaleStage.addChildAt(parallaxScroller, 0);
- scaleStage.setScaleMultiplier(0.2);
+ scaleStage.setScaleMultiplier(0.3);
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.
+
this.stage = stage;
this.scaleStage = scaleStage;
this.trackingStage = trackingStage;
@@ -89,9 +97,10 @@
this.projectiles = projectiles;
this.drag = drag;
- nav.setReference(player);
+ // this is how it should be
- nav.setTargetGroup(chasers);
+ this.getChasers = function() { return chasers; };
+ this.getProjectiles = function() { return projectiles; };
setupTicker();
rigPauseKey();
@@ -118,11 +127,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;
@@ -216,25 +225,20 @@
var hit = chaser.hitTest(localHitPoint.x, localHitPoint.y);
if (hit) {
- var k;
-
trackingStage.removeChild(projectile);
- for (k = 0; k < projectiles.length; k++) {
- if (projectile === projectiles[k]) {
- projectiles.splice(k, 1);
- }
- }
+ projectiles = _.without(projectiles, projectile);
trackingStage.removeChild(chaser);
- for (k = 0; k < chasers.length; k++) {
- if (chaser === chasers[k]) {
- chasers.splice(k, 1);
- }
- }
-
- if (chasers.length === 0) {
- spawnChasers();
- }
+ chasers = _.without(chasers, chaser);
+
+ // var splat = new Splat({app: app, force: chaser.getForce()});
+ var splat = new Splat({app: app, force: PTUtils.addPoints(chaser.getForce(), projectile.getForce())});
+ splat.x = chaser.x;
+ splat.y = chaser.y;
+ trackingStage.addChild(splat);
+
+ if (chasers.length === 0) spawnChasers();
+
}
}
View
@@ -26,7 +26,7 @@
this.addChild(skin);
this.launch = function() {
- if (app.projectiles.length < _p.projectileLimit) {
+ if (app.getProjectiles().length < _p.projectileLimit) {
var projectile = this.makeProjectile(),
launchPos = this.localToLocal(0, 0, _p.ship.parent),
@@ -39,7 +39,7 @@
projectile.addForce(_p.ship.getForce());
projectile.addForce(PTUtils.polarDegrees(adjProjThrust, projectile.rotation));
skin.y = +5;
- app.projectiles.push(projectile);
+ app.getProjectiles().push(projectile);
_.delay(killProjectile, 500, projectile);
}
};
@@ -64,7 +64,7 @@
function makeDumbProjectile() {
var dp = PTUtils.makeTriangle('#ff0', 5, 5);
- var dpForceAbility = new ForceAbility({app: app, target: dp});
+ var dpForceAbility = new ForceAbility({target: dp, app: app});
dp.tick = function() { dpForceAbility.update(); };
return dp;
@@ -77,7 +77,10 @@
function killProjectile(projectile) {
app.trackingStage.removeChild(projectile);
- app.projectiles.splice(_.indexOf(app.projectiles, projectile), 1);
+ var projectiles = app.getProjectiles();
+ projectiles.splice(_.indexOf(projectiles, projectile), 1);
+ // vs
+ // projectiles = _.without(projectiles, projectile);
// console.log("killing projectile");
}
@@ -15,7 +15,7 @@
this.addChild(skin);
this.launch = function() {
- if (_p.projectiles.length < _p.projectileLimit) {
+ if (_p.app.getProjectiles().length < _p.projectileLimit) {
var projectile = this.makeProjectile();
var launchPos = this.localToLocal(0, 0, _p.ship.parent);
projectile.rotation = _p.ship.rotation + this.rotation;
@@ -26,7 +26,7 @@
var adjProjThrust = _p.projectileThrust - (Math.random()*(_p.projectileThrust/4));
projectile.addForce(PTUtils.polarDegrees(adjProjThrust, projectile.rotation));
skin.y = +5;
- _p.projectiles.push(projectile);
+ _p.app.getProjectiles().push(projectile);
_.delay(killProjectile, 3000, projectile);
}
};
@@ -63,7 +63,8 @@
function killProjectile(projectile) {
_p.trackingStage.removeChild(projectile);
- _p.projectiles.splice(_.indexOf(_p.projectiles, projectile), 1);
+ var projectiles = _p.app.getProjectiles();
+ projectiles.splice(_.indexOf(projectiles, projectile), 1); ////naaasssty
// console.log("killing projectile");
}
@@ -24,7 +24,7 @@
};
function fire() {
- if (_p.projectiles.length < _p.projectileLimit) {
+ if (_p.app.getProjectiles().length < _p.projectileLimit) {
// that.rotation = 90;
that.rotation = Math.random()*spread - Math.random()*spread;
var projectile = that.makeProjectile();
@@ -37,7 +37,7 @@
var adjProjThrust = _p.projectileThrust - (Math.random()*(_p.projectileThrust/4));
projectile.addForce(PTUtils.polarDegrees(adjProjThrust, _p.ship.rotation + that.rotation));
skin.y = +5;
- _p.projectiles.push(projectile);
+ _p.app.getProjectiles().push(projectile);
_.delay(killProjectile, ammoLifeSpan, projectile);
// that.rotation = 0;
}
@@ -78,7 +78,7 @@
function killProjectile(projectile) {
_p.trackingStage.removeChild(projectile);
- _p.projectiles.splice(_.indexOf(_p.projectiles, projectile), 1);
+ _p.app.getProjectiles().splice(_.indexOf(_p.app.getProjectiles(), projectile), 1);
// console.log("killing projectile");
}
View
@@ -1,15 +1,22 @@
(function(window){
+
+ // this is kind of crappily hard-coded and not thought out well.
- var Nav = function(reference) {
+ /*
+ props {
+ app: app,
+ }
+ */
+
+ var Nav = function(props) {
var target,
targetGroup = [],
navItems = [],
maxPerimeter = 1200,
minPerimeter = 400,
range = maxPerimeter - minPerimeter,
- distMultiplier = 1,
- ref = reference;
+ distMultiplier = 1;
function setTarget(newTarget) {
target = newTarget;
@@ -62,10 +69,10 @@
var closest, closestDist = 99999999999; // dirty
- _.each(targetGroup, function(target) {
- var globalReferencePos = ref.localToGlobal(0,0);
+ _.each(props.app.getChasers(), function(target) {
+ var globalReferencePos = props.app.scaleStage.localToGlobal(0,0);
var globalTargetPos = target.localToGlobal(0,0);
- var localReferencePos = ref.globalToLocal(globalTargetPos.x, globalTargetPos.y);
+ var localReferencePos = props.app.scaleStage.globalToLocal(globalTargetPos.x, globalTargetPos.y);
var dist = PTUtils.distance(new Point(0, 0), localReferencePos);
if (dist < closestDist) {
closestDist = dist;
@@ -95,13 +102,11 @@
if (navItems.length > 0) rotateNavItems();
- if (targetGroup.length > 0) {
+ if (props.app.chasers.length > 0) {
targetClosest();
}
};
-
-
// api
this.setTarget = setTarget;
this.setTargetGroup = setTargetGroup;
View
@@ -93,6 +93,10 @@
return rotation;
};
+ PTUtils.addPoints = function(pointA, pointB) {
+ return new Point(pointA.x + pointB.x, pointA.y + pointB.y);
+ };
+
window.PTUtils = PTUtils;
}(window));
View
@@ -0,0 +1,47 @@
+(function(window){
+
+ /*
+ props {
+ app: App,
+ force: Point
+ }
+ */
+
+ var Splat = function(props) { this.initialize(props); };
+ var p = Splat.prototype = new Container();
+ p.Container_initialize = p.initialize;
+
+ p.initialize = function(props) {
+ this.Container_initialize();
+
+ var splat = this;
+
+ for(var i = 0; i < 10; i++) {
+ makeChunk(i);
+ }
+
+ function makeChunk(i) {
+ var chunk = PTUtils.makeTriangle("#f00", 10, 10);
+ var chunkForceAbility = new ForceAbility({target: chunk, app: app});
+ chunk.addForce(PTUtils.polarDegrees(Math.random()*10, Math.random()*360));
+ chunk.addForce(props.force);
+ chunk.rotAmount = Math.random()*5 - Math.random()*5;
+ chunk.tick = function() {
+ chunkForceAbility.update();
+ chunk.rotation += chunk.rotAmount;
+ chunk.alpha -= 0.05;
+ };
+ splat.addChild(chunk);
+ }
+
+ _.delay(function() {
+ splat.parent.removeChild(splat);
+ }, 1000);
+
+ };
+
+
+
+ window.Splat = Splat;
+
+}(window));
@@ -25,7 +25,7 @@
this.tick = function() {
checkTarget(app.ship);
- _.each(app.chasers, function(chaser) {
+ _.each(app.getChasers(), function(chaser) {
checkTarget(chaser);
});
_.each(app.projectiles, function(projectile){

0 comments on commit ba5142f

Please sign in to comment.