Permalink
Browse files

Optimizing the gravity wells slightly.

Making it so that they aren't all checking all the projectiles all the time.

Adding totally broken pee launcher.
  • Loading branch information...
1 parent 1dd81f6 commit 7dadf8c9c3407dcf83814a3e6e4b689c029e181e @presstube committed Oct 27, 2011
View
@@ -55,6 +55,7 @@
<script src="src/hunted/ShipControlsAIAvoid.js"></script>
<script src="src/hunted/Launcher.js"></script>
<script src="src/hunted/LauncherHeatSeeker.js"></script>
+ <script src="src/hunted/LauncherPeePants.js"></script>
<script src="src/hunted/PTUtils.js"></script>
</head>
@@ -1,20 +1,21 @@
(function(window){
- var GravityWellRepel = function(target) {this.initialize(target);};
+ var GravityWellRepel = function(app) {this.initialize(app);};
var p = GravityWellRepel.prototype = new Container();
p.Container_initialize = p.initialize;
- p.initialize = function(target) {
+ p.initialize = function(app) {
this.Container_initialize();
- var maxPerimeter = 300,
- minPerimeter = 150,
+ var that = this,
+ maxPerimeter = 300,
+ minPerimeter = 0,
multPerimeter = maxPerimeter - minPerimeter,
maxForce = 5,
minForce = 0,
multForce = 1;
- this.addChild(PTUtils.makeCircle('#00F', maxPerimeter));
+ this.addChild(PTUtils.makeCircle('#040', maxPerimeter));
// this.addChild(PTUtils.makeCircle('#00F', minPerimeter));
this.alpha = 0.2;
@@ -23,8 +24,18 @@
// this.addChild(innerWell);
this.tick = function() {
+ checkTarget(app.ship);
+ _.each(app.chasers, function(chaser) {
+ checkTarget(chaser);
+ });
+ _.each(app.projectiles, function(projectile){
+ checkTarget(projectile);
+ });
+ };
+
+ function checkTarget(target) {
var globalTargetPos = target.localToGlobal(0,0);
- var dist = PTUtils.distance(new Point(0, 0), this.globalToLocal(globalTargetPos.x, globalTargetPos.y));
+ var dist = PTUtils.distance(new Point(0, 0), that.globalToLocal(globalTargetPos.x, globalTargetPos.y));
if (dist < maxPerimeter) {
@@ -43,7 +54,7 @@
// var force = maxForce-(maxForce*multPerimeter);
// console.log("multPerimeter: " + multPerimeter);
// console.log("force: " + force);
- var degrees = PTUtils.angleDegrees(target, this);
+ var degrees = PTUtils.angleDegrees(target, that);
degrees = PTUtils.getAdjustedRotation(degrees+180);
target.addForce(PTUtils.polarDegrees(force, degrees)); // degrees+180 for a 'repulsion well'
@@ -53,7 +64,7 @@
// target.kill(); // GAME OVER
// }
}
- };
+ }
};
window.GravityWellRepel = GravityWellRepel;
@@ -18,24 +18,38 @@
maxForce = 5,
minForce = 0,
- multForce = 1;
+ multForce = 1,
+
+ shipDist = 0;
this.addChild(PTUtils.makeCircle('#FFF', maxPushPerimeter));
this.addChild(PTUtils.makeCircle('#FFF', minPushPerimeter));
this.alpha = 0.2;
this.tick = function() {
- checkTarget(app.ship);
+
+ var globalTargetPos = app.ship.localToGlobal(0,0);
+ shipDist = PTUtils.distance(new Point(0, 0), that.globalToLocal(globalTargetPos.x, globalTargetPos.y));
_.each(app.chasers, function(chaser) {
checkTarget(chaser);
});
+ if (shipDist < 800) {
+ checkTarget(app.ship, shipDist);
+ _.each(app.projectiles, function(projectile){
+ checkTarget(projectile);
+ });
+
+ }
};
- function checkTarget(target) {
- var force, degrees,
- globalTargetPos = target.localToGlobal(0,0),
+ function checkTarget(target, dist) {
+ var force, degrees;
+
+ if (!dist) {
+ var globalTargetPos = target.localToGlobal(0,0);
dist = PTUtils.distance(new Point(0, 0), that.globalToLocal(globalTargetPos.x, globalTargetPos.y));
+ }
if (dist < maxPullPerimeter) {
multPullPerimeter = (dist - minPullPerimeter)/(maxPullPerimeter - minPullPerimeter);
@@ -82,14 +82,15 @@
scaleStage.addChild(trackingStage);
scaleStage.addChildAt(parallaxScroller, 0);
- scaleStage.setScaleMultiplier(.2);
+ scaleStage.setScaleMultiplier(0.2);
trackingStage.addChild(itemScroller);
trackingStage.addChild(ship);
trackingStage.setTrackingTarget(ship);
this.ship = ship;
this.chasers = chasers;
+ this.projectiles = projectiles;
nav.setReference(ship);
@@ -98,6 +99,8 @@
setupTicker();
rigPauseKey();
resize();
+
+
start();
@@ -115,7 +118,7 @@
if (gameState == "GAME_ON") {
scaleStage.setScaleMultiplier(nav.getDistMultiplier());
} else {
- scaleStage.setScaleMultiplier(1);
+ scaleStage.setScaleMultiplier(0.5);
}
};
}
@@ -35,13 +35,15 @@
var rand = Math.random();
item = new GravityWellRepelBubble(_p.app);
// item = new GravityWellBubble(_p.ship);
+
// if (rand < 0.3) {
- // item = new GravityWellBubble(_p.ship);
+ // item = new GravityWellRepelBubble(_p.app);
// } else if (rand < 0.6) {
- // item = new GravityWellMellow(_p.ship);
+ // item = new GravityWellRepel(_p.app);
// } else {
- // item = new GravityWellRepel(_p.ship);
+ // item = new GravityWellRepel(_p.app);
// }
+
// var item = PTUtils.makeCircle(color, 2);
var spawnPoint = PTUtils.polarDegrees(((Math.random()*(wrapRadius-500)))+500, Math.random() * 360);
item.x = spawnPoint.x;
@@ -15,6 +15,7 @@
this.addChild(skin);
this.launch = function() {
+ console.log("PPPPP: " , _p);
if (_p.projectiles.length < _p.projectileLimit) {
var projectile = this.makeProjectile();
var launchPos = this.localToLocal(0, 0, _p.ship.parent);
@@ -27,7 +27,7 @@
projectile.addForce(PTUtils.polarDegrees(adjProjThrust, projectile.rotation));
skin.y = +5;
_p.projectiles.push(projectile);
- _.delay(killProjectile, 5000000, projectile);
+ _.delay(killProjectile, 3000, projectile);
}
};
@@ -36,15 +36,15 @@
function makeShipProjectile() {
var ship = new Ship({
- thrustLimit: 5,
+ thrustLimit: 2,
steeringResponse: 1,
steeringLimit: 20,
shipSkin: ShipSkinGoon,
controlsClass: ShipControlsAIChaseDynamic,
targetFunc: _p.targetFunc,
target: _p.ship
});
- ship.scaleX = ship.scaleY = 0.5;
+ ship.scaleX = ship.scaleY = 0.2;
return ship;
}
@@ -0,0 +1,86 @@
+(function(window){
+
+ var LauncherPeePants = function(props) { this.initialize(props); };
+ var p = LauncherPeePants.prototype = new Container();
+ p.Container_initialize = p.initialize;
+
+ p.initialize = function(props) {
+ this.Container_initialize();
+
+ console.log("props ", props);
+ var that = this,
+ _p = this.props = props || {},
+ skin = PTUtils.makeTriangle('#fff', 5, 5);
+
+ _p.projectileLimit = _p.projectileLimit || 10;
+
+ this.addChild(skin);
+
+ this.launch = function() {
+ _.times(5, fire);
+ };
+
+ function fire() {
+ if (_p.projectiles.length < _p.projectileLimit) {
+ var projectile = that.makeProjectile();
+ var launchPos = that.localToLocal(0, 0, _p.ship.parent);
+ projectile.rotation = _p.ship.rotation + that.rotation;
+ projectile.x = launchPos.x;
+ projectile.y = launchPos.y;
+ _p.trackingStage.addChildAt(projectile, _p.trackingStage.getChildIndex(_p.ship));
+ projectile.addForce(_p.ship.getForce());
+ var adjProjThrust = _p.projectileThrust - (Math.random()*(_p.projectileThrust/4));
+ projectile.addForce(PTUtils.polarDegrees(adjProjThrust, projectile.rotation));
+ skin.y = +5;
+ _p.projectiles.push(projectile);
+ _.delay(killProjectile, 500, projectile);
+ }
+
+ }
+
+ // exposing this as a kind of ammo factory that can be overwritten from outside
+ function makeProjectile() {
+
+ function makeShipProjectile() {
+ var ship = new Ship({
+ thrustLimit: 5,
+ steeringResponse: 1,
+ steeringLimit: 20,
+ shipSkin: ShipSkinGoon,
+ controlsClass: ShipControlsAIChaseDynamic,
+ targetFunc: _p.targetFunc,
+ target: _p.ship
+ });
+ ship.scaleX = ship.scaleY = 0.5;
+ return ship;
+ }
+
+ function makeDumbProjectile() {
+ var dp = PTUtils.makeTriangle('#ff0', 5, 5);
+ var dpForceAbility = new ForceAbility(dp);
+ dp.tick = function() { dpForceAbility.update(); };
+
+ return dp;
+ }
+
+ // return makeShipProjectile();
+ return makeDumbProjectile();
+
+ };
+ this.makeProjectile = makeProjectile;
+
+ function killProjectile(projectile) {
+ _p.trackingStage.removeChild(projectile);
+ _p.projectiles.splice(_.indexOf(_p.projectiles, projectile), 1);
+ // console.log("killing projectile");
+ }
+
+
+ this.tick = function() {
+ skin.y += (0 - skin.y) / 2;
+ };
+ };
+
+ window.LauncherPeePants = LauncherPeePants;
+
+}(window));
@@ -4,14 +4,15 @@
var that = this;
- var upHeld, downHeld, leftHeld, rightHeld, spaceHeld, shiftHeld, sHeld;
- upHeld = downHeld = leftHeld = rightHeld = spaceHeld = shiftHeld = sHeld = false;
+ var upHeld, downHeld, leftHeld, rightHeld, spaceHeld, shiftHeld, sHeld, wHeld;
+ upHeld = downHeld = leftHeld = rightHeld = spaceHeld = shiftHeld = sHeld = wHeld = false;
this.throttle = 0;
this.steering = 0;
this.boost = false;
this.launch = false;
this.seeker = false;
+ this.peePants = false;
bindKeys();
@@ -23,6 +24,7 @@
$(document).bind('keydown', 'space',function (){ spaceHeld = true; });
$(document).bind('keydown', 'shift',function (){ shiftHeld = true; });
$(document).bind('keydown', 's',function (){ sHeld = true; });
+ $(document).bind('keydown', 'w',function (){ wHeld = true; });
$(document).bind('keyup', 'left',function (){ leftHeld = false; });
$(document).bind('keyup', 'right',function (){ rightHeld = false; });
@@ -31,6 +33,7 @@
$(document).bind('keyup', 'space',function (){ spaceHeld = false; });
$(document).bind('keyup', 'shift',function (){ shiftHeld = false; });
$(document).bind('keyup', 's',function (){ sHeld = false; });
+ $(document).bind('keyup', 'w',function (){ wHeld = false; });
}
this.update = function () {
@@ -40,6 +43,7 @@
setBoost();
setFire();
setSeeker();
+ setPeePants();
function setThrottle() {
if (upHeld && !downHeld) {
@@ -72,6 +76,10 @@
function setSeeker() {
that.seeker = sHeld ? true : false;
}
+
+ function setPeePants() {
+ that.peePants = wHeld ? true : false;
+ }
};
};
@@ -15,6 +15,7 @@
exhaustPipe = new ExhaustPipe(props),
launcher = new Launcher(props),
heatSeekerLauncher = new LauncherHeatSeeker(props);
+ peePants = new LauncherPeePants(props);
// defaults
_p.launcherSpread = _p.launcherSpread || 20;
@@ -27,9 +28,13 @@
this.addChild(tail);
tail.addChild(exhaustPipe);
exhaustPipe.y = -16;
+
this.addChild(launcher);
launcher.y = -40;
+ this.addChild(peePants);
+ peePants.y = -40;
+
this.addChild(heatSeekerLauncher);
heatSeekerLauncher.y = -40;
@@ -60,7 +65,14 @@
for (var i = 0; i < _p.shotsPerLaunch; i++) {
heatSeekerLauncher.launch();
}
- }
+ }
+
+ // if (controls.peePants) {
+ // for (var i = 0; i < _p.shotsPerLaunch; i++) {
+ // console.log("PPPEEE");
+ // peePants.launch();
+ // }
+ // }
if (controls.launch) {
for (var i = 0; i < _p.shotsPerLaunch; i++) {

0 comments on commit 7dadf8c

Please sign in to comment.