mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-23 14:32:59 -05:00
Implement "distance to" block (#239)
* Implement "distance-to" block * distance-to in stage should always be 10000
This commit is contained in:
parent
9b07889b3f
commit
30535d8e6e
1 changed files with 23 additions and 0 deletions
|
@ -16,6 +16,7 @@ Scratch3SensingBlocks.prototype.getPrimitives = function() {
|
|||
return {
|
||||
'sensing_touchingcolor': this.touchingColor,
|
||||
'sensing_coloristouchingcolor': this.colorTouchingColor,
|
||||
'sensing_distanceto': this.distanceTo,
|
||||
'sensing_timer': this.getTimer,
|
||||
'sensing_resettimer': this.resetTimer,
|
||||
'sensing_mousex': this.getMouseX,
|
||||
|
@ -37,6 +38,28 @@ Scratch3SensingBlocks.prototype.colorTouchingColor = function (args, util) {
|
|||
return util.target.colorIsTouchingColor(targetColor, maskColor);
|
||||
};
|
||||
|
||||
Scratch3SensingBlocks.prototype.distanceTo = function (args, util) {
|
||||
if (util.target.isStage) return 10000;
|
||||
|
||||
var targetX = 0;
|
||||
var targetY = 0;
|
||||
if (args.DISTANCETOMENU === '_mouse_') {
|
||||
targetX = util.ioQuery('mouse', 'getX');
|
||||
targetY = util.ioQuery('mouse', 'getY');
|
||||
} else {
|
||||
var distTarget = this.runtime.getSpriteTargetByName(
|
||||
args.DISTANCETOMENU
|
||||
);
|
||||
if (!distTarget) return 10000;
|
||||
targetX = distTarget.x;
|
||||
targetY = distTarget.y;
|
||||
}
|
||||
|
||||
var dx = util.target.x - targetX;
|
||||
var dy = util.target.y - targetY;
|
||||
return Math.sqrt((dx * dx) + (dy * dy));
|
||||
};
|
||||
|
||||
Scratch3SensingBlocks.prototype.getTimer = function (args, util) {
|
||||
return util.ioQuery('clock', 'projectTimer');
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue