summaryrefslogtreecommitdiff
path: root/threads.js
diff options
context:
space:
mode:
authorjmoenig <jens@moenig.org>2013-08-12 13:05:42 +0200
committerjmoenig <jens@moenig.org>2013-08-12 13:05:42 +0200
commitfe50029b1c727b932f4f47cc69fcaf246a92df4e (patch)
treed95c075978fb2db5a66f41d723d1ab4c99c5998d /threads.js
parentbf4ebd3a5a41a90bfac9c70f6082b4fe4e20ad77 (diff)
downloadsnap-fe50029b1c727b932f4f47cc69fcaf246a92df4e.tar.gz
snap-fe50029b1c727b932f4f47cc69fcaf246a92df4e.zip
Nestable Sprites Collision Detection & fixes
Diffstat (limited to 'threads.js')
-rw-r--r--threads.js78
1 files changed, 56 insertions, 22 deletions
diff --git a/threads.js b/threads.js
index b46e18c..ab36e87 100644
--- a/threads.js
+++ b/threads.js
@@ -83,7 +83,7 @@ ArgLabelMorph, localize, XML_Element, hex_sha512*/
// Global stuff ////////////////////////////////////////////////////////
-modules.threads = '2013-August-02';
+modules.threads = '2013-August-12';
var ThreadManager;
var Process;
@@ -2161,61 +2161,95 @@ Process.prototype.createClone = function (name) {
// Process sensing primitives
Process.prototype.reportTouchingObject = function (name) {
- // also check for temparary clones, as in Scratch 2.0
- var thisObj = this.homeContext.receiver,
+ var thisObj = this.homeContext.receiver;
+
+ if (thisObj) {
+ return this.objectTouchingObject(thisObj, name);
+ }
+ return false;
+};
+
+Process.prototype.objectTouchingObject = function (thisObj, name) {
+ // helper function for reportTouchingObject()
+ // also check for temparary clones, as in Scratch 2.0,
+ // and for any parts (subsprites)
+ var myself = this,
those,
stage,
mouse;
- if (thisObj) {
- if (this.inputOption(name) === 'mouse-pointer') {
- mouse = thisObj.world().hand.position();
- if (thisObj.bounds.containsPoint(mouse)) {
- return !thisObj.isTransparentAt(mouse);
- }
- return false;
+ if (this.inputOption(name) === 'mouse-pointer') {
+ mouse = thisObj.world().hand.position();
+ if (thisObj.bounds.containsPoint(mouse) &&
+ !thisObj.isTransparentAt(mouse)) {
+ return true;
}
+ } else {
stage = thisObj.parentThatIsA(StageMorph);
if (stage) {
- if (this.inputOption(name) === 'edge') {
- return !stage.bounds.containsRectangle(thisObj.bounds);
+ if (this.inputOption(name) === 'edge' &&
+ !stage.bounds.containsRectangle(thisObj.bounds)) {
+ return true;
}
- if (this.inputOption(name) === 'pen trails') {
- return thisObj.isTouching(stage.penTrailsMorph());
+ if (this.inputOption(name) === 'pen trails' &&
+ thisObj.isTouching(stage.penTrailsMorph())) {
+ return true;
}
those = this.getObjectsNamed(name, thisObj, stage); // clones
- return those.some(
- function (any) {
+ if (those.some(function (any) {
return thisObj.isTouching(any);
- }
- );
+ })) {
+ return true;
+ }
}
}
- return false;
+ return thisObj.parts.some(
+ function (any) {
+ return myself.objectTouchingObject(any, name);
+ }
+ );
};
Process.prototype.reportTouchingColor = function (aColor) {
+ // also check for any parts (subsprites)
var thisObj = this.homeContext.receiver,
stage;
if (thisObj) {
stage = thisObj.parentThatIsA(StageMorph);
if (stage) {
- return thisObj.isTouching(stage.colorFiltered(aColor, thisObj));
+ if (thisObj.isTouching(stage.colorFiltered(aColor, thisObj))) {
+ return true;
+ }
+ return thisObj.parts.some(
+ function (any) {
+ return any.isTouching(stage.colorFiltered(aColor, any));
+ }
+ );
}
}
return false;
};
Process.prototype.reportColorIsTouchingColor = function (color1, color2) {
+ // also check for any parts (subsprites)
var thisObj = this.homeContext.receiver,
stage;
if (thisObj) {
stage = thisObj.parentThatIsA(StageMorph);
if (stage) {
- return thisObj.colorFiltered(color1).isTouching(
- stage.colorFiltered(color2, thisObj)
+ if (thisObj.colorFiltered(color1).isTouching(
+ stage.colorFiltered(color2, thisObj)
+ )) {
+ return true;
+ }
+ return thisObj.parts.some(
+ function (any) {
+ return any.colorFiltered(color1).isTouching(
+ stage.colorFiltered(color2, any)
+ );
+ }
);
}
}