@@ -756,7 +756,8 @@ export default {
756756 Blockly .Python .ORDER_NONE ) || ' \'\' ' ;
757757 return sbsPrefix + ' get_bot().sleep(' + elapse + ' )\n ' ;
758758 };
759-
759+
760+ // muovi bot [direzione] a velocità [velcità] per [tempo]
760761 Blockly .Blocks [' coderbot_adv_move' ] = {
761762 // Block for moving forward.
762763 init : function () {
@@ -811,6 +812,55 @@ export default {
811812 var code = sbsPrefix + " get_bot()." + action + " (speed=" + speed + " , elapse=" + elapse + " )\n " ;
812813 return code;
813814 };
815+
816+ // muovi bot [direzione] per [distanza] metri
817+ Blockly .Blocks [' coderbot_adv_move_distance' ] = {
818+ // Block for moving forward.
819+ init : function () {
820+ var ACTIONS = [
821+ [Blockly .Msg .CODERBOT_MOVE_ADV_TIP_FORWARD , ' FORWARD' ],
822+ [Blockly .Msg .CODERBOT_MOVE_ADV_TIP_BACKWARD , ' BACKWARD' ]
823+ ]
824+ this .setHelpUrl (' http://code.google.com/p/blockly/wiki/Move' );
825+ this .setColour (40 );
826+
827+ this .appendDummyInput (" ACTION" )
828+ .appendField (Blockly .Msg .CODERBOT_MOVE_ADV_MOVE )
829+ .appendField (new Blockly.FieldDropdown (ACTIONS ), ' ACTION' );
830+ this .appendValueInput (' DISTANCE' )
831+ .setCheck (' Number' )
832+ .appendField (Blockly .Msg .CODERBOT_MOVE_ADV_ELAPSE )
833+ .appendField (Blockly .Msg .MEASURE_UNIT );
834+ this .setInputsInline (true );
835+ // Assign 'this' to a variable for use in the tooltip closure below.
836+ var thisBlock = this ;
837+ this .setTooltip (function () {
838+ var mode = thisBlock .getFieldValue (' ACTION' );
839+ var TOOLTIPS = {
840+ FORWARD : Blockly .Msg .CODERBOT_MOVE_ADV_TIP_FORWARD ,
841+ BACKWARD : Blockly .Msg .CODERBOT_MOVE_ADV_TIP_BACKWARD
842+ };
843+ return TOOLTIPS [mode] + Blockly .Msg .CODERBOT_MOVE_ADV_TIP_TAIL ;
844+ });
845+ this .setPreviousStatement (true );
846+ this .setNextStatement (true );
847+ }
848+ };
849+
850+ Blockly .Python [' coderbot_adv_move_distance' ] = function (block ) {
851+ // Generate Python for moving forward.
852+ var OPERATORS = {
853+ FORWARD : [' forward' ],
854+ BACKWARD : [' backward' ]
855+ };
856+ var tuple = OPERATORS [block .getFieldValue (' ACTION' )];
857+ var action = tuple[0 ];
858+ var speed = 100 ;
859+ var distance = Blockly .Python .valueToCode (block, ' DISTANCE' , Blockly .Python .ORDER_NONE );
860+ var code = sbsPrefix + " get_bot()." + action + " (speed=" + speed + " , distance=" + distance + " )\n " ;
861+ return code;
862+ };
863+
814864
815865 Blockly .Blocks [' coderbot_motion_move' ] = {
816866 // Block for moving forward.
0 commit comments