From 306996e54c814838e3bbac7c1ebd33f547848784 Mon Sep 17 00:00:00 2001 From: jokebookservice1 Date: Sun, 11 Nov 2018 01:51:37 +0000 Subject: [PATCH] feat: Implement "point towards random direction" We subtract 180 even though the value will be clamped, for clarity. We round so that using the "direction" getter will yield a sensible result. Note that this implements 'point towards random direction', not 'point towards random position' -- they have slightly different behaviours. --- src/blocks/scratch3_motion.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/blocks/scratch3_motion.js b/src/blocks/scratch3_motion.js index 0e3420422..a33a62905 100644 --- a/src/blocks/scratch3_motion.js +++ b/src/blocks/scratch3_motion.js @@ -123,6 +123,9 @@ class Scratch3MotionBlocks { if (args.TOWARDS === '_mouse_') { targetX = util.ioQuery('mouse', 'getScratchX'); targetY = util.ioQuery('mouse', 'getScratchY'); + } else if (args.TOWARDS === '_random_') { + util.target.setDirection(Math.round(Math.random() * 360) - 180); + return; } else { const pointTarget = this.runtime.getSpriteTargetByName(args.TOWARDS); if (!pointTarget) return;