Skip to content

Commit

Permalink
Making rough weapons pack.. buggy.
Browse files Browse the repository at this point in the history
  • Loading branch information
James Paterson committed Oct 25, 2011
1 parent 34043be commit c38c2d1
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 20 deletions.
1 change: 1 addition & 0 deletions index.html
Expand Up @@ -50,6 +50,7 @@
<script src="src/hunted/ShipControlsAIChaseDynamic.js"></script>
<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/PTUtils.js"></script>

</head>
Expand Down
6 changes: 3 additions & 3 deletions src/hunted/Launcher.js
Expand Up @@ -27,7 +27,7 @@
projectile.addForce(PTUtils.polarDegrees(adjProjThrust, projectile.rotation));
skin.y = +5;
_p.projectiles.push(projectile);
_.delay(killProjectile, 5000000, projectile);
_.delay(killProjectile, 500, projectile);
}
};

Expand Down Expand Up @@ -56,8 +56,8 @@
return dp;
}

return makeShipProjectile();
// return makeDumbProjectile();
// return makeShipProjectile();
return makeDumbProjectile();

};

Expand Down
78 changes: 78 additions & 0 deletions src/hunted/LauncherHeatSeeker.js
@@ -0,0 +1,78 @@
(function(window){

var LauncherHeatSeeker = function(props) { this.initialize(props); };
var p = LauncherHeatSeeker.prototype = new Container();
p.Container_initialize = p.initialize;

p.initialize = function(props) {
this.Container_initialize();

var _p = this.props = props || {},
skin = PTUtils.makeTriangle('#fff', 5, 5);

_p.projectileLimit = _p.projectileLimit || 10;

this.addChild(skin);

this.launch = function() {
if (_p.projectiles.length < _p.projectileLimit) {
var projectile = this.makeProjectile();
var launchPos = this.localToLocal(0, 0, _p.ship.parent);
projectile.rotation = _p.ship.rotation + this.rotation;
projectile.x = launchPos.x;
projectile.y = launchPos.y;
_p.ship.parent.addChildAt(projectile, _p.ship.parent.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, 5000000, projectile);
}
};

// exposing this as a kind of ammo factory that can be overwritten from outside
this.makeProjectile = function() {

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();

};

function killProjectile(projectile) {
_p.ship.parent.removeChild(projectile);
_p.projectiles.splice(_.indexOf(_p.projectiles, projectile), 1);
console.log("killing projectile");
}


this.tick = function() {
skin.y += (0 - skin.y) / 2;
};
};

window.LauncherHeatSeeker = LauncherHeatSeeker;

}(window));
12 changes: 10 additions & 2 deletions src/hunted/ShipControlsKeyboard.js
Expand Up @@ -4,13 +4,14 @@

var that = this;

var upHeld, downHeld, leftHeld, rightHeld, spaceHeld, shiftHeld;
upHeld = downHeld = leftHeld = rightHeld = spaceHeld = shiftHeld = false;
var upHeld, downHeld, leftHeld, rightHeld, spaceHeld, shiftHeld, sHeld;
upHeld = downHeld = leftHeld = rightHeld = spaceHeld = shiftHeld = sHeld = false;

this.throttle = 0;
this.steering = 0;
this.boost = false;
this.launch = false;
this.seeker = false;

bindKeys();

Expand All @@ -21,13 +22,15 @@
$(document).bind('keydown', 'down',function (){ downHeld = true; });
$(document).bind('keydown', 'space',function (){ spaceHeld = true; });
$(document).bind('keydown', 'shift',function (){ shiftHeld = true; });
$(document).bind('keydown', 's',function (){ sHeld = true; });

$(document).bind('keyup', 'left',function (){ leftHeld = false; });
$(document).bind('keyup', 'right',function (){ rightHeld = false; });
$(document).bind('keyup', 'up',function (){ upHeld = false; });
$(document).bind('keyup', 'down',function (){ downHeld = false; });
$(document).bind('keyup', 'space',function (){ spaceHeld = false; });
$(document).bind('keyup', 'shift',function (){ shiftHeld = false; });
$(document).bind('keyup', 's',function (){ sHeld = false; });
}

this.update = function () {
Expand All @@ -36,6 +39,7 @@
setSteering();
setBoost();
setFire();
setSeeker();

function setThrottle() {
if (upHeld && !downHeld) {
Expand Down Expand Up @@ -64,6 +68,10 @@
function setFire() {
that.launch = spaceHeld ? true : false;
}

function setSeeker() {
that.seeker = sHeld ? true : false;
}
};

};
Expand Down
42 changes: 27 additions & 15 deletions src/hunted/ShipSkinGeneric.js
Expand Up @@ -13,12 +13,28 @@
tailSwingRange = 20,
tail = new Container(),
exhaustPipe = new ExhaustPipe(props),
launcher = new Launcher(props);
launcher = new Launcher(props),
heatSeekerLauncher = new LauncherHeatSeeker(props);

// defaults
_p.launcherSpread = _p.launcherSpread || 20;
_p.shotsPerLaunch = _p.shotsPerLaunch || 3;


this.addChild(PTUtils.makeTriangle('#F00', 40, 40));
tail.addChild(PTUtils.makeTriangle('#F00', 20, 20));
tail.y = -4;
tail.rotation = 180;
this.addChild(tail);
tail.addChild(exhaustPipe);
exhaustPipe.y = -16;
this.addChild(launcher);
launcher.y = -40;

this.addChild(heatSeekerLauncher);
heatSeekerLauncher.y = -40;

this.props.ship.launcher = launcher;

this.update = function() {
var controls = this.props.ship.controls;

Expand All @@ -38,27 +54,23 @@
exhaustPipe.engage();
}



if (controls.seeker) {
for (var i = 0; i < _p.shotsPerLaunch; i++) {
heatSeekerLauncher.launch();
}
}

if (controls.launch) {
for (var i = 0; i < _p.shotsPerLaunch; i++) {
launcher.rotation = (Math.random() * _p.launcherSpread) - (Math.random() * _p.launcherSpread);
launcher.launch();
// heatSeekerLauncher.launch();
}
launcher.rotation = 0;
controls.launch = false;
}
};

this.addChild(PTUtils.makeTriangle('#F00', 40, 40));
tail.addChild(PTUtils.makeTriangle('#F00', 20, 20));
tail.y = -4;
tail.rotation = 180;
this.addChild(tail);
tail.addChild(exhaustPipe);
exhaustPipe.y = -16;
this.addChild(launcher);
launcher.y = -40;

this.props.ship.launcher = launcher;
};

window.ShipSkinGeneric = ShipSkinGeneric;
Expand Down

0 comments on commit c38c2d1

Please sign in to comment.