mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-23 14:32:59 -05:00
Implement move steps, turn right, turn left, point in direction
This commit is contained in:
parent
727d2c0d23
commit
42f0f66acd
1 changed files with 22 additions and 5 deletions
|
@ -1,3 +1,5 @@
|
||||||
|
var MathUtil = require('../util/math-util');
|
||||||
|
|
||||||
function Scratch3MotionBlocks(runtime) {
|
function Scratch3MotionBlocks(runtime) {
|
||||||
/**
|
/**
|
||||||
* The runtime instantiating this block package.
|
* The runtime instantiating this block package.
|
||||||
|
@ -12,20 +14,35 @@ function Scratch3MotionBlocks(runtime) {
|
||||||
*/
|
*/
|
||||||
Scratch3MotionBlocks.prototype.getPrimitives = function() {
|
Scratch3MotionBlocks.prototype.getPrimitives = function() {
|
||||||
return {
|
return {
|
||||||
|
'motion_movesteps': this.moveSteps,
|
||||||
'motion_gotoxy': this.goToXY,
|
'motion_gotoxy': this.goToXY,
|
||||||
'motion_turnright': this.turnRight
|
'motion_turnright': this.turnRight,
|
||||||
|
'motion_turnleft': this.turnLeft,
|
||||||
|
'motion_pointindirection': this.pointInDirection
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Scratch3MotionBlocks.prototype.moveSteps = function (args, util) {
|
||||||
|
var radians = MathUtil.degToRad(util.target.direction);
|
||||||
|
var dx = args.STEPS * Math.cos(radians);
|
||||||
|
var dy = args.STEPS * Math.sin(radians);
|
||||||
|
util.target.setXY(util.target.x + dx, util.target.y + dy);
|
||||||
|
};
|
||||||
|
|
||||||
Scratch3MotionBlocks.prototype.goToXY = function (args, util) {
|
Scratch3MotionBlocks.prototype.goToXY = function (args, util) {
|
||||||
util.target.setXY(args.X, args.Y);
|
util.target.setXY(args.X, args.Y);
|
||||||
};
|
};
|
||||||
|
|
||||||
Scratch3MotionBlocks.prototype.turnRight = function (args, util) {
|
Scratch3MotionBlocks.prototype.turnRight = function (args, util) {
|
||||||
if (args.DEGREES !== args.DEGREES) {
|
util.target.setDirection(util.target.direction + args.DEGREES);
|
||||||
throw "Bad degrees" + args.DEGREES;
|
};
|
||||||
}
|
|
||||||
util.target.setDirection(args.DEGREES + util.target.direction);
|
Scratch3MotionBlocks.prototype.turnLeft = function (args, util) {
|
||||||
|
util.target.setDirection(util.target.direction - args.DEGREES);
|
||||||
|
};
|
||||||
|
|
||||||
|
Scratch3MotionBlocks.prototype.pointInDirection = function (args, util) {
|
||||||
|
util.target.setDirection(args.DIRECTION);
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = Scratch3MotionBlocks;
|
module.exports = Scratch3MotionBlocks;
|
||||||
|
|
Loading…
Reference in a new issue