Merge pull request #1214 from ericrosenbaum/feature/when-touching

Add when touching hat
This commit is contained in:
Eric Rosenbaum 2018-06-07 15:26:09 -04:00 committed by GitHub
commit 173fb6127c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 10 deletions

View file

@ -24,6 +24,7 @@ class Scratch3EventBlocks {
*/
getPrimitives () {
return {
event_whentouchingobject: this.touchingObject,
event_broadcast: this.broadcast,
event_broadcastandwait: this.broadcastAndWait,
event_whengreaterthan: this.hatGreaterThanPredicate
@ -41,6 +42,10 @@ class Scratch3EventBlocks {
event_whenthisspriteclicked: {
restartExistingThreads: true
},
event_whentouchingobject: {
restartExistingThreads: false,
edgeActivated: true
},
event_whenstageclicked: {
restartExistingThreads: true
},
@ -57,6 +62,10 @@ class Scratch3EventBlocks {
};
}
touchingObject (args, util) {
return util.target.isTouchingObject(args.TOUCHINGOBJECTMENU);
}
hatGreaterThanPredicate (args, util) {
const option = Cast.toString(args.WHENGREATERTHANMENU).toLowerCase();
const value = Cast.toNumber(args.VALUE);

View file

@ -150,16 +150,7 @@ class Scratch3SensingBlocks {
}
touchingObject (args, util) {
const requestedObject = args.TOUCHINGOBJECTMENU;
if (requestedObject === '_mouse_') {
const mouseX = util.ioQuery('mouse', 'getClientX');
const mouseY = util.ioQuery('mouse', 'getClientY');
return util.target.isTouchingPoint(mouseX, mouseY);
} else if (requestedObject === '_edge_') {
return util.target.isTouchingEdge();
}
return util.target.isTouchingSprite(requestedObject);
return util.target.isTouchingObject(args.TOUCHINGOBJECTMENU);
}
touchingColor (args, util) {

View file

@ -765,6 +765,23 @@ class RenderedTarget extends Target {
return null;
}
/**
* Return whether this target is touching the mouse, an edge, or a sprite.
* @param {string} requestedObject an id for mouse or edge, or a sprite name.
* @return {boolean} True if the sprite is touching the object.
*/
isTouchingObject (requestedObject) {
if (requestedObject === '_mouse_') {
if (!this.runtime.ioDevices.mouse) return false;
const mouseX = this.runtime.ioDevices.mouse.getClientX();
const mouseY = this.runtime.ioDevices.mouse.getClientY();
return this.isTouchingPoint(mouseX, mouseY);
} else if (requestedObject === '_edge_') {
return this.isTouchingEdge();
}
return this.isTouchingSprite(requestedObject);
}
/**
* Return whether touching a point.
* @param {number} x X coordinate of test point.