Skip to content
This repository has been archived by the owner on Apr 15, 2022. It is now read-only.

Commit

Permalink
Updated CollisionBasic to turn collision on and off for an individual…
Browse files Browse the repository at this point in the history
… component. Also swapped in indexOf for various array checks.
  • Loading branch information
probityrules committed Jan 22, 2016
1 parent bb30d4e commit 6b25f47
Show file tree
Hide file tree
Showing 16 changed files with 156 additions and 303 deletions.
225 changes: 75 additions & 150 deletions lib/platypus.combined.js

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions lib/platypus.min.js

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion src/PIXIAnimation.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"use strict";

var Application = include('springroll.Application'), // Import SpringRoll classes
//cache = PIXI.utils.TextureCache,
animationCache = {},
createFramesArray = function (frame, bases) {
var i = 0,
Expand Down
9 changes: 3 additions & 6 deletions src/components/AudioSFX.js
Original file line number Diff line number Diff line change
Expand Up @@ -446,13 +446,10 @@
},

removeClip: function (audioClip) {
var i = 0;
var i = this.activeAudioClips.indexOf(audioClip);

for (i = 0; i < this.activeAudioClips.length; i++) {
if (this.activeAudioClips[i] === audioClip) {
this.activeAudioClips.splice(i, 1);
break;
}
if (i >= 0) {
this.activeAudioClips.splice(i, 1);
}
},

Expand Down
36 changes: 26 additions & 10 deletions src/components/CollisionBasic.js
Original file line number Diff line number Diff line change
Expand Up @@ -490,29 +490,48 @@
*
* @method 'collide-on'
*/
"collide-on": function () {
"collide-on": function (type) {
/**
* On receiving 'collide-on', this message is triggered on the parent to turn on collision.
*
* @event 'add-collision-entity'
* @param entity {platypus.Entity} The entity this component is attached to.
*/
this.owner.parent.trigger('add-collision-entity', this.owner);
if (!type || (type === this.collisionType)) {
this.owner.collisionTypes.union([this.collisionType]);
this.owner.parent.trigger('add-collision-entity', this.owner);
this.active = true;
}
},

/**
* On receiving this message, the component triggers `remove-collision-entity` on the parent.
*
* @method 'collide-off'
*/
"collide-off": function () {
"collide-off": function (type) {
var index = 0;

/**
* On receiving 'collide-off', this message is triggered on the parent to turn off collision.
*
* @event 'remove-collision-entity'
* @param entity {platypus.Entity} The entity this component is attached to.
*/
this.owner.parent.trigger('remove-collision-entity', this.owner);
if (!type) {
this.owner.parent.trigger('remove-collision-entity', this.owner);
this.active = false;
} else if (type === this.collisionType) {
this.owner.parent.trigger('remove-collision-entity', this.owner);
index = this.owner.collisionTypes.indexOf(this.collisionType);
if (index >= 0) {
this.owner.collisionTypes.splice(index, 1);
}
if (this.owner.collisionTypes.length) {
this.owner.parent.trigger('add-collision-entity', this.owner);
}
this.active = false;
}
},

/**
Expand Down Expand Up @@ -642,7 +661,7 @@
},

destroy: function () {
var i = 0;
var i = this.owner.collisionTypes.indexOf(this.collisionType);

this.owner.parent.trigger('remove-collision-entity', this.owner);

Expand All @@ -651,11 +670,8 @@
delete this.aabb;
delete this.prevAABB;

for (i = 0; i < this.owner.collisionTypes.length; i++) {
if (this.owner.collisionTypes[i] === this.collisionType) {
this.owner.collisionTypes.splice(i, 1);
break;
}
if (i >= 0) {
this.owner.collisionTypes.splice(i, 1);
}
if (this.owner.solidCollisionMap[this.collisionType]) {
this.owner.solidCollisionMap[this.collisionType].length = 0;
Expand Down
41 changes: 10 additions & 31 deletions src/components/CollisionGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,8 @@
(function () {
"use strict";

//set here to make them reusable objects
var AABB = include('platypus.AABB'),
Vector = include('platypus.Vector'),
appendUniqueItems = function (hostArray, insertArray) {
var i = 0,
j = 0,
length = hostArray.length,
found = false;

for (i = 0; i < insertArray.length; i++) {
found = false;
for (j = 0; j < length; j++) {
if (insertArray[i] === hostArray[j]) {
found = true;
break;
}
}
if (!found) {
hostArray.push(insertArray[i]);
}
}

return hostArray;
};
var AABB = include('platypus.AABB'),
Vector = include('platypus.Vector');

return platypus.createComponentClass({
id: 'CollisionGroup',
Expand Down Expand Up @@ -179,11 +157,9 @@
if (types) {
for (i = 0; i < types.length; i++) {
if (entity.solidCollisionMap[types[i]].length) {
for (x in this.solidEntities) {
if (this.solidEntities[x] === entity) {
this.solidEntities.splice(x, 1);
break;
}
x = this.solidEntities.indexOf(entity);
if (x >= 0) {
this.solidEntities.splice(x, 1);
}
}
}
Expand All @@ -201,7 +177,7 @@
if ((childEntity !== this.owner) && childEntity.collisionGroup) {
childEntity = childEntity.collisionGroup;
}
compiledList = appendUniqueItems(compiledList, childEntity.getCollisionTypes());
compiledList.union(childEntity.getCollisionTypes());
}

return compiledList;
Expand All @@ -222,7 +198,10 @@
entityList = childEntity.getSolidCollisions();
for (key in entityList) {
if (entityList.hasOwnProperty(key)) {
compiledList[key] = appendUniqueItems(compiledList[key] || [], entityList[key]);
if (!compiledList[key]) {
compiledList[key] = [];
}
compiledList[key].union(entityList[key]);
}
}
}
Expand Down
16 changes: 6 additions & 10 deletions src/components/HandlerCollision.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,20 +219,16 @@

if (types) {
for (i = 0; i < types.length; i++) {
for (x = 0; x < this.entitiesByType[types[i]].length; x++) {
if (this.entitiesByType[types[i]][x] === entity) {
this.entitiesByType[types[i]].splice(x, 1);
break;
}
x = this.entitiesByType[types[i]].indexOf(entity);
if (x >= 0) {
this.entitiesByType[types[i]].splice(x, 1);
}
}

if (!entity.immobile) {
for (j = 0; j < this.allEntities.length; j++) {
if (this.allEntities[j] === entity) {
this.allEntities.splice(j, 1);
break;
}
i = this.allEntities.indexOf(entity);
if (i >= 0) {
this.allEntities.splice(i, 1);
}
}
this.updateLiveList = true;
Expand Down
9 changes: 3 additions & 6 deletions src/components/HandlerLogic.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,10 @@
* @param entity {platypus.Entity} The entity to be removed from the handler.
*/
"child-entity-removed": function (entity) {
var j = 0;
var j = this.entities.indexOf(entity);

for (j = this.entities.length - 1; j > -1; j--) {
if (this.entities[j] === entity) {
this.entities.splice(j, 1);
break;
}
if (j >= 0) {
this.entities.splice(j, 1);
}
},

Expand Down
7 changes: 3 additions & 4 deletions src/components/LogicRebounder.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,9 @@ Requires: ["../Vector.js"]
otherRelevantV = 0,
reboundV = 0;

for (x = 0; x < this.hitThisTick.length; x++) {
if (other === this.hitThisTick[x]) {
return;
}
x = this.hitThisTick.indexOf(other);
if (x >= 0) {
return;
}
this.hitThisTick.push(other);

Expand Down
8 changes: 3 additions & 5 deletions src/components/Mover.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,11 +261,9 @@
var i = 0;

if (component.type === 'Motion') {
for (i = 0; i < this.movers.length; i++) {
if (component === this.movers[i]) {
this.movers.splice(i, 1);
break;
}
i = this.movers.indexOf(component);
if (i >= 0) {
this.movers.splice(i, 1);
}
}
},
Expand Down
11 changes: 2 additions & 9 deletions src/components/NodeMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,21 +249,14 @@
m = 0,
list = including || this.map,
closest = null,
exclude = false,
d = Infinity;

for (i = 0; i < list.length; i++) {
m = p2.set(p1).subtractVector(list[i].position).magnitude();
if (m < d) {
if (excluding) {
exclude = false;
for (j = 0; j < excluding.length; j++) {
if (excluding[j] === list[i]) {
exclude = true;
break;
}
}
if (exclude) {
j = excluding.indexOf(list[i]);
if (j >= 0) {
break;
}
}
Expand Down
24 changes: 6 additions & 18 deletions src/components/Orientation.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,22 +290,13 @@
* @param vector {platypus.Vector} The vector whose orientation will be maintained.
*/
"orient-vector": function (vector) {
var i = 0,
found = false,
aligned = vector.aligned || false;
var aligned = vector.aligned || false;

if (vector.vector) {
vector = vector.vector;
}

for (i = 0; i < this.vectors.length; i++) {
if (vector === this.vectors[i]) {
found = true;
break;
}
}

if (!found) {
if (this.vectors.indexOf(vector) === -1) {
if (!aligned) {
vector.multiply(this.matrix);
}
Expand All @@ -321,14 +312,11 @@
* @param vector {platypus.Vector} The vector to be removed.
*/
"remove-vector": function (vector) {
var i = 0;
var i = this.vectors.indexOf(vector);

for (i = 0; i < this.vectors.length; i++) {
if (vector === this.vectors[i]) {
this.vectors.splice(i, 1);
this.inverses.splice(i, 1);
break;
}
if (i >= 0) {
this.vectors.splice(i, 1);
this.inverses.splice(i, 1);
}
},

Expand Down
9 changes: 3 additions & 6 deletions src/components/RelayFamily.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,10 @@

methods: {
destroy: function () {
var i = 0;
var i = this.owner.familyLinks.indexOf(this.owner);

for (i = 0; i < this.owner.familyLinks.length; i++) {
if (this.owner === this.owner.familyLinks[i]) {
this.owner.familyLinks.splice(i, 1);
break;
}
if (i >= 0) {
this.owner.familyLinks.splice(i, 1);
}
trigger(this.owner.familyLinks, 'family-member-removed', this.owner);
this.events = null;
Expand Down
21 changes: 4 additions & 17 deletions src/components/RelayLinker.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,19 +115,9 @@
* @param toLink {platypus.Entity} The enquiring entity.
*/
"link-entity": function (toLink) {
var i = 0,
already = false;

if ((toLink.linkId === this.linkId) && (toLink.entity !== this.owner)) {
// Make sure this link is not already in place
for (i = 0; i < this.links.length; i++) {
if (this.links[i] === toLink.entity) {
already = true;
break;
}
}

if (!already) {
if (this.links.indexOf(toLink.entity) === -1) {
this.links.push(toLink.entity);
if (toLink.reciprocate) {
this.linkMessage.reciprocate = false;
Expand All @@ -144,13 +134,10 @@
* @param toUnlink {platypus.Entity} The enquiring entity.
*/
"unlink-entity": function (toUnlink) {
var i = 0;
var i = this.links.indexOf(toUnlink.entity);

for (i = 0; i < this.links.length; i++) {
if (toUnlink.entity === this.links[i]) {
this.links.splice(i, 1);
break;
}
if (i >= 0) {
this.links.splice(i, 1);
}
}
},
Expand Down
12 changes: 2 additions & 10 deletions src/components/RenderDestroyMe.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,9 @@ This component will destroy the entity once an animation has finished. This is u

events: {// These are messages that this component listens for
"animation-ended": function (animation) {
var id = animation.name,
x = 0;
var id = animation.name;

if (this.animationIds) {
for (x = 0; x < this.animationIds.length; x++) {
if (this.animationIds[x] === id) {
this.owner.parent.removeEntity(this.owner);
break;
}
}
} else {
if (!this.animationIds || (this.animationIds.indexOf(id) >= 0)) {
this.owner.parent.removeEntity(this.owner);
}
}
Expand Down
Loading

0 comments on commit 6b25f47

Please sign in to comment.