Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adding a bunch of gravity well implementations

including a fun semi-permiable one that you can hide inside
that one is rigged to affect foes as well
  • Loading branch information...
commit 3c00e9ff905c72c38667146fc4887dfbfa15ccd1 1 parent 39f3778
James Paterson authored
5 index.html
View
@@ -36,7 +36,10 @@
<script src="src/hunted/ScaleStage.js"></script>
<script src="src/hunted/TrackingStage.js"></script>
<script src="src/hunted/ParallaxScroller.js"></script>
- <script src="src/hunted/GravityWell.js"></script>
+ <script src="src/hunted/GravityWellMellow.js"></script>
+ <script src="src/hunted/GravityWellBubble.js"></script>
+ <script src="src/hunted/GravityWellRepel.js"></script>
+ <script src="src/hunted/GravityWellRepelBubble.js"></script>
<script src="src/hunted/ItemScroller.js"></script>
<script src="src/hunted/ShipControlsKeyboard.js"></script>
<script src="src/hunted/ExhaustPipe.js"></script>
15 src/hunted/GravityWell.js
View
@@ -1,7 +1,7 @@
(function(window){
- var GravityWell = function(target) {this.initialize(target);};
- var p = GravityWell.prototype = new Container();
+ var GravityWellMellow = function(target) {this.initialize(target);};
+ var p = GravityWellMellow.prototype = new Container();
p.Container_initialize = p.initialize;
p.initialize = function(target) {
@@ -14,9 +14,9 @@
minForce = 0,
multForce = 1;
- this.addChild(PTUtils.makeCircle('#FFF', maxPerimeter));
+ this.addChild(PTUtils.makeCircle('#F00', maxPerimeter));
- this.alpha = 0.8
+ this.alpha = 0.8;
this.tick = function() {
@@ -36,8 +36,11 @@
// multForce = 1 - multForce;
+ // var force = (maxForce*multPerimeter);
+ var force = maxForce-(maxForce*multPerimeter);
+
var degrees = PTUtils.angleDegrees(target, this);
- target.addForce(PTUtils.polarDegrees(maxForce-(maxForce*multPerimeter), degrees/*+180*/)); // degrees+180 for a 'repulsion well'
+ target.addForce(PTUtils.polarDegrees(force, degrees/*+180*/)); // degrees+180 for a 'repulsion well'
@@ -48,6 +51,6 @@
};
};
- window.GravityWell = GravityWell;
+ window.GravityWellMellow = GravityWellMellow;
}(window));
56 src/hunted/GravityWellBubble.js
View
@@ -0,0 +1,56 @@
+(function(window){
+
+ var GravityWellBubble = function(target) {this.initialize(target);};
+ var p = GravityWellBubble.prototype = new Container();
+ p.Container_initialize = p.initialize;
+
+ p.initialize = function(target) {
+ this.Container_initialize();
+
+ var maxPerimeter = 150,
+ minPerimeter = 0,
+ multPerimeter = maxPerimeter - minPerimeter,
+ maxForce = 5,
+ minForce = 0,
+ multForce = 1;
+
+ this.addChild(PTUtils.makeCircle('#FFF', maxPerimeter));
+
+ this.alpha = 0.2;
+
+
+ this.tick = function() {
+ var globalTargetPos = target.localToGlobal(0,0);
+ var dist = PTUtils.distance(new Point(0, 0), this.globalToLocal(globalTargetPos.x, globalTargetPos.y));
+
+ if (dist < maxPerimeter) {
+
+ // console.log("perimeter: " + maxPerimeter);
+ // console.log("dist: " + dist);
+
+ multPerimeter = (dist - minPerimeter)/(maxPerimeter - minPerimeter);
+ multPerimeter = (multPerimeter>maxPerimeter) ? maxPerimeter : multPerimeter;
+ multPerimeter = (multPerimeter<0) ? 0 : multPerimeter;
+
+ console.log("bubbleWell: " + multPerimeter);
+
+ // multForce = 1 - multForce;
+
+ var force = (maxForce*multPerimeter);
+ // var force = maxForce-(maxForce*multPerimeter);
+
+ var degrees = PTUtils.angleDegrees(target, this);
+ target.addForce(PTUtils.polarDegrees(force, degrees/*+180*/)); // degrees+180 for a 'repulsion well'
+
+
+
+ // if (dist < 20) {
+ // target.kill(); // GAME OVER
+ // }
+ }
+ };
+ };
+
+ window.GravityWellBubble = GravityWellBubble;
+
+}(window));
56 src/hunted/GravityWellMellow.js
View
@@ -0,0 +1,56 @@
+(function(window){
+
+ var GravityWellMellow = function(target) {this.initialize(target);};
+ var p = GravityWellMellow.prototype = new Container();
+ p.Container_initialize = p.initialize;
+
+ p.initialize = function(target) {
+ this.Container_initialize();
+
+ var maxPerimeter = 300,
+ minPerimeter = 0,
+ multPerimeter = maxPerimeter - minPerimeter,
+ maxForce = 5,
+ minForce = 0,
+ multForce = 1;
+
+ this.addChild(PTUtils.makeCircle('#F00', maxPerimeter));
+
+ this.alpha = 0.2;
+
+
+ this.tick = function() {
+ var globalTargetPos = target.localToGlobal(0,0);
+ var dist = PTUtils.distance(new Point(0, 0), this.globalToLocal(globalTargetPos.x, globalTargetPos.y));
+
+ if (dist < maxPerimeter) {
+
+ // console.log("perimeter: " + maxPerimeter);
+ // console.log("dist: " + dist);
+
+ multPerimeter = (dist - minPerimeter)/(maxPerimeter - minPerimeter);
+ multPerimeter = (multPerimeter>maxPerimeter) ? maxPerimeter : multPerimeter;
+ multPerimeter = (multPerimeter<0) ? 0 : multPerimeter;
+
+ // console.log("multPerimeter: " + multPerimeter);
+
+ // multForce = 1 - multForce;
+
+ // var force = (maxForce*multPerimeter);
+ var force = maxForce-(maxForce*multPerimeter);
+
+ var degrees = PTUtils.angleDegrees(target, this);
+ target.addForce(PTUtils.polarDegrees(force, degrees/*+180*/)); // degrees+180 for a 'repulsion well'
+
+
+
+ // if (dist < 20) {
+ // target.kill(); // GAME OVER
+ // }
+ }
+ };
+ };
+
+ window.GravityWellMellow = GravityWellMellow;
+
+}(window));
61 src/hunted/GravityWellRepel.js
View
@@ -0,0 +1,61 @@
+(function(window){
+
+ var GravityWellRepel = function(target) {this.initialize(target);};
+ var p = GravityWellRepel.prototype = new Container();
+ p.Container_initialize = p.initialize;
+
+ p.initialize = function(target) {
+ this.Container_initialize();
+
+ var maxPerimeter = 300,
+ minPerimeter = 150,
+ multPerimeter = maxPerimeter - minPerimeter,
+ maxForce = 5,
+ minForce = 0,
+ multForce = 1;
+
+ this.addChild(PTUtils.makeCircle('#00F', maxPerimeter));
+ // this.addChild(PTUtils.makeCircle('#00F', minPerimeter));
+
+ this.alpha = 0.2;
+
+ // var innerWell = new GravityWellBubble(target);
+ // this.addChild(innerWell);
+
+ this.tick = function() {
+ var globalTargetPos = target.localToGlobal(0,0);
+ var dist = PTUtils.distance(new Point(0, 0), this.globalToLocal(globalTargetPos.x, globalTargetPos.y));
+
+ if (dist < maxPerimeter) {
+
+ // console.log("perimeter: " + maxPerimeter);
+ // console.log("dist: " + dist);
+
+ multPerimeter = (dist - minPerimeter)/(maxPerimeter - minPerimeter);
+ multPerimeter = (multPerimeter>maxPerimeter) ? maxPerimeter : multPerimeter;
+ multPerimeter = (multPerimeter<0) ? 0 : multPerimeter;
+
+ // console.log("multPerimeter: " + multPerimeter);
+
+ // multForce = 1 - multForce;
+
+ var force = (maxForce*multPerimeter);
+ // var force = maxForce-(maxForce*multPerimeter);
+ // console.log("multPerimeter: " + multPerimeter);
+ // console.log("force: " + force);
+ var degrees = PTUtils.angleDegrees(target, this);
+ degrees = PTUtils.getAdjustedRotation(degrees+180);
+ target.addForce(PTUtils.polarDegrees(force, degrees)); // degrees+180 for a 'repulsion well'
+
+
+
+ // if (dist < 20) {
+ // target.kill(); // GAME OVER
+ // }
+ }
+ };
+ };
+
+ window.GravityWellRepel = GravityWellRepel;
+
+}(window));
60 src/hunted/GravityWellRepelBubble.js
View
@@ -0,0 +1,60 @@
+(function(window){
+
+ var GravityWellRepelBubble = function(app) {this.initialize(app);};
+ var p = GravityWellRepelBubble.prototype = new Container();
+ p.Container_initialize = p.initialize;
+
+ p.initialize = function(app) {
+ this.Container_initialize();
+
+ var that = this,
+ maxPushPerimeter = 300,
+ minPushPerimeter = 100,
+ multPushPerimeter = maxPushPerimeter - minPushPerimeter,
+
+ maxPullPerimeter = 100,
+ minPullPerimeter = 0,
+ multPullPerimeter = 1,
+
+ maxForce = 5,
+ minForce = 0,
+ multForce = 1;
+
+ this.addChild(PTUtils.makeCircle('#FFF', maxPushPerimeter));
+ this.addChild(PTUtils.makeCircle('#FFF', minPushPerimeter));
+
+ this.alpha = 0.2;
+
+ this.tick = function() {
+ checkTarget(app.ship);
+ _.each(app.chasers, function(chaser) {
+ checkTarget(chaser);
+ });
+ };
+
+ function checkTarget(target) {
+ var force, degrees,
+ 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);
+ multPullPerimeter = (multPullPerimeter>maxPullPerimeter) ? maxPullPerimeter : multPullPerimeter;
+ multPullPerimeter = (multPullPerimeter<0) ? 0 : multPullPerimeter;
+ force = (maxForce*multPullPerimeter);
+ degrees = PTUtils.angleDegrees(target, that);
+ target.addForce(PTUtils.polarDegrees(force, degrees));
+ } else if (dist < maxPushPerimeter) {
+ multPushPerimeter = (dist - minPushPerimeter)/(maxPushPerimeter - minPushPerimeter);
+ multPushPerimeter = (multPushPerimeter>maxPushPerimeter) ? maxPushPerimeter : multPushPerimeter;
+ multPushPerimeter = (multPushPerimeter<0) ? 0 : multPushPerimeter;
+ force = maxForce-(maxForce*multPushPerimeter);
+ degrees = PTUtils.angleDegrees(target, that);
+ target.addForce(PTUtils.polarDegrees(force, degrees+180)); // degrees+180 for a 'repulsion well'
+ }
+ }
+ };
+
+ window.GravityWellRepelBubble = GravityWellRepelBubble;
+
+}(window));
7 src/hunted/HuntedApp.js
View
@@ -47,10 +47,11 @@
}),
itemScroller = new ItemScroller({
+ app: this,
scaleStage: scaleStage,
trackingStage: trackingStage,
wrapRadius: wrapRadius,
- numItems: 70,
+ numItems: 20,
ship: ship
});
@@ -87,6 +88,9 @@
trackingStage.addChild(ship);
trackingStage.setTrackingTarget(ship);
+ this.ship = ship;
+ this.chasers = chasers;
+
nav.setReference(ship);
nav.setTargetGroup(chasers);
@@ -96,6 +100,7 @@
resize();
start();
+
function setupTicker() {
Ticker.setFPS(30);
Ticker.addListener(that);
14 src/hunted/ItemScroller.js
View
@@ -19,7 +19,7 @@
direction = 0,
items = [];
- console.log("wr: " + wrapRadius);
+ console.log("_p.app: ", _p.app);
this.hitTarget = undefined;
@@ -31,7 +31,17 @@
function makeItem(i) {
var color = (i === 0) ? '#0F0' : '#0FF';
- var item = new GravityWell(_p.ship);
+ var item;
+ var rand = Math.random();
+ item = new GravityWellRepelBubble(_p.app);
+ // item = new GravityWellBubble(_p.ship);
+ // if (rand < 0.3) {
+ // item = new GravityWellBubble(_p.ship);
+ // } else if (rand < 0.6) {
+ // item = new GravityWellMellow(_p.ship);
+ // } else {
+ // item = new GravityWellRepel(_p.ship);
+ // }
// var item = PTUtils.makeCircle(color, 2);
var spawnPoint = PTUtils.polarDegrees(((Math.random()*(wrapRadius-500)))+500, Math.random() * 360);
item.x = spawnPoint.x;
2  src/hunted/ScaleStage.js
View
@@ -10,7 +10,7 @@
var that = this,
targetScale = 1,
- maxScale = .8,
+ maxScale = 0.8,
minScale = 0.35,
range = maxScale - minScale,
scaleSpeed = 10;
Please sign in to comment.
Something went wrong with that request. Please try again.