Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions packages/scratch-gui/src/lib/make-toolbox-xml.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,18 @@ const motion = function (isInitialSetup, isStage, targetId, colors) {
</shadow>
</value>
</block>
<block type="motion_pointtowardsxy">
<value name="X">
<shadow type="math_number">
<field name="NUM"/>
</shadow>
</value>
<value name="Y">
<shadow type="math_number">
<field name="NUM"/>
</shadow>
</value>
</block>
${blockSeparator}
<block type="motion_changexby">
<value name="DX">
Expand Down
11 changes: 11 additions & 0 deletions packages/scratch-vm/src/blocks/scratch3_motion.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
motion_xposition: this.getX,
motion_yposition: this.getY,
motion_direction: this.getDirection,
motion_pointtowardsxy: this.pointTowardsXY,
// Legacy no-op blocks:
motion_scroll_right: () => {},
motion_scroll_up: () => {},
Expand Down Expand Up @@ -275,6 +276,16 @@
return util.target.direction;
}

pointTowardsXY (args, util) {
let targetX = Cast.toNumber(args.X);

Check failure on line 280 in packages/scratch-vm/src/blocks/scratch3_motion.js

View workflow job for this annotation

GitHub Actions / Test scratch-vm

'targetX' is never reassigned. Use 'const' instead
let targetY = Cast.toNumber(args.Y);

Check failure on line 281 in packages/scratch-vm/src/blocks/scratch3_motion.js

View workflow job for this annotation

GitHub Actions / Test scratch-vm

'targetY' is never reassigned. Use 'const' instead

const dx = targetX - util.target.x;
const dy = targetY - util.target.y;
const direction = 90 - MathUtil.radToDeg(Math.atan2(dy, dx));
util.target.setDirection(direction);
}

// This corresponds to snapToInteger in Scratch 2
limitPrecision (coordinate) {
const rounded = Math.round(coordinate);
Expand Down
Loading