/** * @license * Visual Blocks Editor * * Copyright 2016 Massachusetts Institute of Technology * All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ 'use strict'; goog.provide('Blockly.Blocks.motion'); goog.require('Blockly.Blocks'); goog.require('Blockly.Colours'); goog.require('Blockly.constants'); goog.require('Blockly.ScratchBlocks.VerticalExtensions'); Blockly.Blocks['motion_movesteps'] = { /** * Block to move steps. * @this Blockly.Block */ init: function() { this.jsonInit({ "message0": Blockly.Msg.MOTION_MOVESTEPS, "args0": [ { "type": "input_value", "name": "STEPS" } ], "category": Blockly.Categories.motion, "extensions": ["colours_motion", "shape_statement"] }); } }; Blockly.Blocks['motion_movebacksteps'] = { /** * pm: Block to move back steps. * @this Blockly.Block */ init: function() { this.jsonInit({ "message0": "move back %1 steps", "args0": [ { "type": "input_value", "name": "STEPS" } ], "category": Blockly.Categories.motion, "extensions": ["colours_motion", "shape_statement"] }); } }; Blockly.Blocks['motion_moveupdownsteps'] = { /** * pm: Block to move up or down steps. * @this Blockly.Block */ init: function() { this.jsonInit({ "message0": "move %1 %2 steps", "args0": [ { "type": "field_dropdown", "name": "DIRECTION", "options": [ ['up', 'up'], ['down', 'down'] ] }, { "type": "input_value", "name": "STEPS" } ], "category": Blockly.Categories.motion, "extensions": ["colours_motion", "shape_statement"] }); } }; Blockly.Blocks['motion_turnright'] = { /** * Block to turn right. * @this Blockly.Block */ init: function() { this.jsonInit({ "message0": Blockly.Msg.MOTION_TURNRIGHT, "args0": [ { "type": "field_image", "src": Blockly.mainWorkspace.options.pathToMedia + "rotate-right.svg", "width": 24, "height": 24 }, { "type": "input_value", "name": "DEGREES" } ], "category": Blockly.Categories.motion, "extensions": ["colours_motion", "shape_statement"] }); } }; Blockly.Blocks['motion_turnleft'] = { /** * Block to turn left. * @this Blockly.Block */ init: function() { this.jsonInit({ "message0": Blockly.Msg.MOTION_TURNLEFT, "args0": [ { "type": "field_image", "src": Blockly.mainWorkspace.options.pathToMedia + "rotate-left.svg", "width": 24, "height": 24 }, { "type": "input_value", "name": "DEGREES" } ], "category": Blockly.Categories.motion, "extensions": ["colours_motion", "shape_statement"] }); } }; Blockly.Blocks['motion_turnrightaroundxy'] = { /** * pm: Block to turn right around a certain point. * @this Blockly.Block */ init: function () { this.jsonInit({ "message0": "turn %1 %2 degrees around x: %3 y: %4", "args0": [ { "type": "field_image", "src": Blockly.mainWorkspace.options.pathToMedia + "rotate-right.svg", "width": 24, "height": 24 }, { "type": "input_value", "name": "DEGREES" }, { "type": "input_value", "name": "X" }, { "type": "input_value", "name": "Y" } ], "category": Blockly.Categories.motion, "extensions": ["colours_motion", "shape_statement"] }); } }; Blockly.Blocks['motion_turnleftaroundxy'] = { /** * pm: Block to turn left around a certain point. * @this Blockly.Block */ init: function () { this.jsonInit({ "message0": "turn %1 %2 degrees around x: %3 y: %4", "args0": [ { "type": "field_image", "src": Blockly.mainWorkspace.options.pathToMedia + "rotate-left.svg", "width": 24, "height": 24 }, { "type": "input_value", "name": "DEGREES" }, { "type": "input_value", "name": "X" }, { "type": "input_value", "name": "Y" } ], "category": Blockly.Categories.motion, "extensions": ["colours_motion", "shape_statement"] }); } }; Blockly.Blocks['motion_pointindirection'] = { /** * Block to point in direction. * @this Blockly.Block */ init: function() { this.jsonInit({ "message0": Blockly.Msg.MOTION_POINTINDIRECTION, "args0": [ { "type": "input_value", "name": "DIRECTION" } ], "category": Blockly.Categories.motion, "extensions": ["colours_motion", "shape_statement"] }); } }; Blockly.Blocks['motion_pointtowards_menu'] = { /** * Point towards drop-down menu. * @this Blockly.Block */ init: function() { this.jsonInit({ "message0": "%1", "args0": [ { "type": "field_dropdown", "name": "TOWARDS", "options": [ [Blockly.Msg.MOTION_POINTTOWARDS_POINTER, '_mouse_'], [Blockly.Msg.MOTION_POINTTOWARDS_RANDOM, '_random_'] ] } ], "colour": Blockly.Colours.motion.secondary, "colourSecondary": Blockly.Colours.motion.secondary, "colourTertiary": Blockly.Colours.motion.tertiary, "extensions": ["output_string"] }); } }; Blockly.Blocks['motion_turnaround'] = { /** * pm: Block to point in the opposite direction. * @this Blockly.Block */ init: function() { this.jsonInit({ "message0": "turn around", "category": Blockly.Categories.motion, "extensions": ["colours_motion", "shape_statement"] }); } }; Blockly.Blocks['motion_pointinrandomdirection'] = { /** * pm: Block to point in a random direction. * @this Blockly.Block */ init: function () { this.jsonInit({ "message0": "point in random direction", "category": Blockly.Categories.motion, "extensions": ["colours_motion", "shape_statement"] }); } }; Blockly.Blocks['motion_pointtowardsxy'] = { /** * pm: Block to point towards an x and y position. * @this Blockly.Block */ init: function () { this.jsonInit({ "message0": "point towards x: %1 y: %2", "args0": [ { "type": "input_value", "name": "X" }, { "type": "input_value", "name": "Y" } ], "category": Blockly.Categories.motion, "extensions": ["colours_motion", "shape_statement"] }); } }; Blockly.Blocks['motion_pointtowards'] = { /** * Block to point in direction. * @this Blockly.Block */ init: function() { this.jsonInit({ "message0": Blockly.Msg.MOTION_POINTTOWARDS, "args0": [ { "type": "input_value", "name": "TOWARDS" } ], "category": Blockly.Categories.motion, "extensions": ["colours_motion", "shape_statement"] }); } }; Blockly.Blocks['motion_goto_menu'] = { /** * Go to drop-down menu. * @this Blockly.Block */ init: function() { this.jsonInit({ "message0": "%1", "args0": [ { "type": "field_dropdown", "name": "TO", "options": [ [Blockly.Msg.MOTION_GOTO_POINTER, '_mouse_'], [Blockly.Msg.MOTION_GOTO_RANDOM, '_random_'] ] } ], "colour": Blockly.Colours.motion.secondary, "colourSecondary": Blockly.Colours.motion.secondary, "colourTertiary": Blockly.Colours.motion.tertiary, "extensions": ["output_string"] }); } }; Blockly.Blocks['motion_gotoxy'] = { /** * Block to go to X, Y. * @this Blockly.Block */ init: function() { this.jsonInit({ "message0": Blockly.Msg.MOTION_GOTOXY, "args0": [ { "type": "input_value", "name": "X" }, { "type": "input_value", "name": "Y" } ], "category": Blockly.Categories.motion, "extensions": ["colours_motion", "shape_statement"] }); } }; Blockly.Blocks['motion_goto'] = { /** * Block to go to a menu item. * @this Blockly.Block */ init: function() { this.jsonInit({ "message0": Blockly.Msg.MOTION_GOTO, "args0": [ { "type": "input_value", "name": "TO" } ], "category": Blockly.Categories.motion, "extensions": ["colours_motion", "shape_statement"] }); } }; Blockly.Blocks['motion_glidesecstoxy'] = { /** * Block to glide for a specified time. * @this Blockly.Block */ init: function() { this.jsonInit({ "message0": Blockly.Msg.MOTION_GLIDESECSTOXY, "args0": [ { "type": "input_value", "name": "SECS" }, { "type": "input_value", "name": "X" }, { "type": "input_value", "name": "Y" } ], "category": Blockly.Categories.motion, "extensions": ["colours_motion", "shape_statement"] }); } }; Blockly.Blocks['motion_glidedirectionstepsinseconds'] = { /** * pm: Block to glide for a specified time in a specified direction. * @this Blockly.Block */ init: function() { this.jsonInit({ "message0": "glide %1 steps %2 in %3 secs", "args0": [ { "type": "input_value", "name": "STEPS" }, { "type": "field_dropdown", "name": "DIRECTION", "options": [ ['forwards', 'forwards'], ['backwards', 'backwards'], ['up', 'up'], ['down', 'down'] ] }, { "type": "input_value", "name": "SECS" }, ], "category": Blockly.Categories.motion, "extensions": ["colours_motion", "shape_statement"] }); } }; Blockly.Blocks['motion_glideto_menu'] = { /** * Glide to drop-down menu * @this Blockly.Block */ init: function() { this.jsonInit({ "message0": "%1", "args0": [ { "type": "field_dropdown", "name": "TO", "options": [ [Blockly.Msg.MOTION_GLIDETO_POINTER, '_mouse_'], [Blockly.Msg.MOTION_GLIDETO_RANDOM, '_random_'] ] } ], "colour": Blockly.Colours.motion.secondary, "colourSecondary": Blockly.Colours.motion.secondary, "colourTertiary": Blockly.Colours.motion.tertiary, "extensions": ["output_string"] }); } }; Blockly.Blocks['motion_glideto'] = { /** * Block to glide to a menu item * @this Blockly.Block */ init: function() { this.jsonInit({ "message0": Blockly.Msg.MOTION_GLIDETO, "args0": [ { "type": "input_value", "name": "SECS" }, { "type": "input_value", "name": "TO" } ], "category": Blockly.Categories.motion, "extensions": ["colours_motion", "shape_statement"] }); } }; Blockly.Blocks['motion_changebyxy'] = { /** * pm: Block to change X and Y at the same time. * @this Blockly.Block */ init: function() { this.jsonInit({ "message0": "change by x: %1 y: %2", "args0": [ { "type": "input_value", "name": "DX" }, { "type": "input_value", "name": "DY" } ], "category": Blockly.Categories.motion, "extensions": ["colours_motion", "shape_statement"] }); } }; Blockly.Blocks['motion_changexby'] = { /** * Block to change X. * @this Blockly.Block */ init: function() { this.jsonInit({ "message0": Blockly.Msg.MOTION_CHANGEXBY, "args0": [ { "type": "input_value", "name": "DX" } ], "category": Blockly.Categories.motion, "extensions": ["colours_motion", "shape_statement"] }); } }; Blockly.Blocks['motion_setx'] = { /** * Block to set X. * @this Blockly.Block */ init: function() { this.jsonInit({ "message0": Blockly.Msg.MOTION_SETX, "args0": [ { "type": "input_value", "name": "X" } ], "category": Blockly.Categories.motion, "extensions": ["colours_motion", "shape_statement"] }); } }; Blockly.Blocks['motion_changeyby'] = { /** * Block to change Y. * @this Blockly.Block */ init: function() { this.jsonInit({ "message0": Blockly.Msg.MOTION_CHANGEYBY, "args0": [ { "type": "input_value", "name": "DY" } ], "category": Blockly.Categories.motion, "extensions": ["colours_motion", "shape_statement"] }); } }; Blockly.Blocks['motion_sety'] = { /** * Block to set Y. * @this Blockly.Block */ init: function() { this.jsonInit({ "message0": Blockly.Msg.MOTION_SETY, "args0": [ { "type": "input_value", "name": "Y" } ], "category": Blockly.Categories.motion, "extensions": ["colours_motion", "shape_statement"] }); } }; Blockly.Blocks['motion_ifonedgebounce'] = { /** * Block to bounce on edge. * @this Blockly.Block */ init: function() { this.jsonInit({ "message0": Blockly.Msg.MOTION_IFONEDGEBOUNCE, "category": Blockly.Categories.motion, "extensions": ["colours_motion", "shape_statement"] }); } }; Blockly.Blocks['motion_ifonspritebounce'] = { /** * pm: Block to bounce on a sprite. * @this Blockly.Block */ init: function () { this.jsonInit({ "message0": "if touching %1, bounce", "args0": [ { "type": "input_value", "name": "SPRITE" } ], "category": Blockly.Categories.motion, "extensions": ["colours_motion", "shape_statement"] }); } }; Blockly.Blocks['motion_ifonxybounce'] = { /** * pm: Block to bounce on x and y. * @this Blockly.Block */ init: function () { this.jsonInit({ "message0": "if touching x: %1 y: %2, bounce", "args0": [ { "type": "input_value", "name": "X" }, { "type": "input_value", "name": "Y" } ], "category": Blockly.Categories.motion, "extensions": ["colours_motion", "shape_statement"] }); } }; Blockly.Blocks['motion_setrotationstyle'] = { /** * Block to set rotation style. * @this Blockly.Block */ init: function() { this.jsonInit({ "message0": Blockly.Msg.MOTION_SETROTATIONSTYLE, "args0": [ { "type": "field_dropdown", "name": "STYLE", "options": [ [Blockly.Msg.MOTION_SETROTATIONSTYLE_LEFTRIGHT, 'left-right'], ['up-down', 'up-down'], ['look at', 'look at'], [Blockly.Msg.MOTION_SETROTATIONSTYLE_DONTROTATE, 'don\'t rotate'], [Blockly.Msg.MOTION_SETROTATIONSTYLE_ALLAROUND, 'all around'] ] } ], "category": Blockly.Categories.motion, "extensions": ["colours_motion", "shape_statement"] }); } }; Blockly.Blocks['motion_xposition'] = { /** * Block to report X. * @this Blockly.Block */ init: function() { this.jsonInit({ "message0": Blockly.Msg.MOTION_XPOSITION, "category": Blockly.Categories.motion, "checkboxInFlyout": true, "extensions": ["colours_motion", "output_number"] }); } }; Blockly.Blocks['motion_yposition'] = { /** * Block to report Y. * @this Blockly.Block */ init: function() { this.jsonInit({ "message0": Blockly.Msg.MOTION_YPOSITION, "category": Blockly.Categories.motion, "checkboxInFlyout": true, "extensions": ["colours_motion", "output_number"] }); } }; Blockly.Blocks['motion_direction'] = { /** * Block to report direction. * @this Blockly.Block */ init: function() { this.jsonInit({ "message0": Blockly.Msg.MOTION_DIRECTION, "category": Blockly.Categories.motion, "checkboxInFlyout": true, "extensions": ["colours_motion", "output_number"] }); } }; Blockly.Blocks['motion_scroll_right'] = { /** * Block to scroll the stage right. Does not actually do anything. This is * an obsolete block that is implemented for compatibility with Scratch 2.0 * projects. * @this Blockly.Block */ init: function() { this.jsonInit({ "message0": Blockly.Msg.MOTION_SCROLLRIGHT, "args0": [ { "type": "input_value", "name": "DISTANCE" } ], "category": Blockly.Categories.motion, "extensions": ["colours_motion", "shape_statement"] }); } }; Blockly.Blocks['motion_scroll_up'] = { /** * Block to scroll the stage up. Does not actually do anything. This is an * obsolete block that is implemented for compatibility with Scratch 2.0 * projects. * @this Blockly.Block */ init: function() { this.jsonInit({ "message0": Blockly.Msg.MOTION_SCROLLUP, "args0": [ { "type": "input_value", "name": "DISTANCE" } ], "category": Blockly.Categories.motion, "extensions": ["colours_motion", "shape_statement"] }); } }; Blockly.Blocks['motion_move_sprite_to_scene_side'] = { /** * pm: Block to move the sprite to the stage's side. * @this Blockly.Block */ init: function () { this.jsonInit({ "message0": "move to stage %1", "args0": [ { "type": "field_dropdown", "name": "ALIGNMENT", "options": [ [Blockly.Msg.MOTION_ALIGNSCENE_BOTTOMLEFT, 'bottom-left'], ['bottom', 'bottom'], [Blockly.Msg.MOTION_ALIGNSCENE_BOTTOMRIGHT, 'bottom-right'], [Blockly.Msg.MOTION_ALIGNSCENE_MIDDLE, 'middle'], [Blockly.Msg.MOTION_ALIGNSCENE_TOPLEFT, 'top-left'], ['top', 'top'], [Blockly.Msg.MOTION_ALIGNSCENE_TOPRIGHT, 'top-right'], ['left', 'left'], ['right', 'right'], ] } ], "category": Blockly.Categories.motion, "extensions": ["colours_motion", "shape_statement"] }); } }; Blockly.Blocks['motion_align_scene'] = { /** * Block to change the stage's scrolling alignment. Does not actually do * anything. This is an obsolete block that is implemented for compatibility * with Scratch 2.0 projects. * @this Blockly.Block */ init: function() { this.jsonInit({ "message0": Blockly.Msg.MOTION_ALIGNSCENE, "args0": [ { "type": "field_dropdown", "name": "ALIGNMENT", "options": [ [Blockly.Msg.MOTION_ALIGNSCENE_BOTTOMLEFT, 'bottom-left'], [Blockly.Msg.MOTION_ALIGNSCENE_BOTTOMRIGHT, 'bottom-right'], [Blockly.Msg.MOTION_ALIGNSCENE_MIDDLE, 'middle'], [Blockly.Msg.MOTION_ALIGNSCENE_TOPLEFT, 'top-left'], [Blockly.Msg.MOTION_ALIGNSCENE_TOPRIGHT, 'top-right'] ] } ], "category": Blockly.Categories.motion, "extensions": ["colours_motion", "shape_statement"] }); } }; Blockly.Blocks['motion_xscroll'] = { /** * Block to report the stage's scroll position's X value. Does not actually * do anything. This is an obsolete block that is implemented for * compatibility with Scratch 2.0 projects. * @this Blockly.Block */ init: function() { this.jsonInit({ "message0": Blockly.Msg.MOTION_XSCROLL, "category": Blockly.Categories.motion, "extensions": ["colours_motion", "output_number"] }); } }; Blockly.Blocks['motion_yscroll'] = { /** * Block to report the stage's scroll position's Y value. Does not actually * do anything. This is an obsolete block that is implemented for * compatibility with Scratch 2.0 projects. * @this Blockly.Block */ init: function() { this.jsonInit({ "message0": Blockly.Msg.MOTION_YSCROLL, "category": Blockly.Categories.motion, "extensions": ["colours_motion", "output_number"] }); } };