Add glide (number) secs to [dropdown] block (#662)

* Add glide to dropdown block

* Use helper functions instead of copy-paste

* Wrong syntax for array 😒

* Aha

* Fix some Travis issues

* Aha!! This should work

* Wow, Travis is strict about spacing!

* Make requested changes

Rename function getTarget to getTargetXY
Rename parameter TO to targetName
This commit is contained in:
Ken 2017-08-28 19:44:34 +00:00 committed by Ray Schamp
parent f367f2d358
commit fc4f073526

View file

@ -25,6 +25,7 @@ class Scratch3MotionBlocks {
motion_pointindirection: this.pointInDirection,
motion_pointtowards: this.pointTowards,
motion_glidesecstoxy: this.glide,
motion_glideto: this.glideTo,
motion_ifonedgebounce: this.ifOnEdgeBounce,
motion_setrotationstyle: this.setRotationStyle,
motion_changexby: this.changeX,
@ -51,24 +52,31 @@ class Scratch3MotionBlocks {
util.target.setXY(x, y);
}
goTo (args, util) {
getTargetXY (targetName, util) {
let targetX = 0;
let targetY = 0;
if (args.TO === '_mouse_') {
if (targetName === '_mouse_') {
targetX = util.ioQuery('mouse', 'getX');
targetY = util.ioQuery('mouse', 'getY');
} else if (args.TO === '_random_') {
} else if (targetName === '_random_') {
const stageWidth = this.runtime.constructor.STAGE_WIDTH;
const stageHeight = this.runtime.constructor.STAGE_HEIGHT;
targetX = Math.round(stageWidth * (Math.random() - 0.5));
targetY = Math.round(stageHeight * (Math.random() - 0.5));
} else {
const goToTarget = this.runtime.getSpriteTargetByName(args.TO);
const goToTarget = this.runtime.getSpriteTargetByName(targetName);
if (!goToTarget) return;
targetX = goToTarget.x;
targetY = goToTarget.y;
}
util.target.setXY(targetX, targetY);
return [targetX, targetY];
}
goTo (args, util) {
const targetXY = this.getTargetXY(args.TO, util);
if (targetXY) {
util.target.setXY(targetXY[0], targetXY[1]);
}
}
turnRight (args, util) {
@ -139,6 +147,13 @@ class Scratch3MotionBlocks {
util.yield();
}
}
glideTo (args, util) {
const targetXY = this.getTargetXY(args.TO, util);
if (targetXY) {
this.glide({SECS: args.SECS, X: targetXY[0], Y: targetXY[1]}, util);
}
}
ifOnEdgeBounce (args, util) {
const bounds = util.target.getBounds();