@@ -148,6 +148,71 @@ Blockly.Python.coderbot_basic_turnRight = function (block) {
148148 return `${ sbsPrefix } get_bot().right(speed=${ Blockly . Blocks . CoderBotSettings . CODERBOT_MOV_TR_DEF_SPEED } , elapse=${ Blockly . Blocks . CoderBotSettings . CODERBOT_MOV_TR_DEF_ELAPSE } )\n` ;
149149} ;
150150
151+ Blockly . Blocks [ 'coderbot_adv_move_enc' ] = {
152+ // Block for moving forward.
153+ init : function ( ) {
154+ this . setHelpUrl ( 'http://code.google.com/p/blockly/wiki/Motor' ) ;
155+ this . setColour ( 40 ) ;
156+
157+ this . appendValueInput ( 'SPEED' )
158+ . setCheck ( 'Number' )
159+ . appendField ( Blockly . Msg . CODERBOT_MOVE_ADV_MOTOR + " " + Blockly . Msg . CODERBOT_MOVE_ADV_MOTOR_SPEED ) ;
160+ this . appendValueInput ( 'DISTANCE' )
161+ . setCheck ( 'Number' )
162+ . appendField ( Blockly . Msg . CODERBOT_MOVE_ADV_MOTOR_DISTANCE ) ;
163+ this . setInputsInline ( true ) ;
164+ // Assign 'this' to a variable for use in the tooltip closure below.
165+ var thisBlock = this ;
166+ this . setTooltip ( function ( ) {
167+ var mode = thisBlock . getFieldValue ( 'ACTION' ) ;
168+ return TOOLTIPS [ mode ] + Blockly . Msg . CODERBOT_MOVE_ADV_TIP_TAIL ;
169+ } ) ;
170+ this . setPreviousStatement ( true ) ;
171+ this . setNextStatement ( true ) ;
172+ }
173+ } ;
174+
175+ Blockly . Python [ 'coderbot_adv_move_enc' ] = function ( block ) {
176+ // Generate Python for moving forward.
177+ var speed = Blockly . Python . valueToCode ( block , 'SPEED' , Blockly . Python . ORDER_NONE ) ;
178+ var distance = Blockly . Python . valueToCode ( block , 'DISTANCE' , Blockly . Python . ORDER_NONE ) ;
179+ var code = "get_bot().move(speed=" + speed + ", distance=" + distance + ")\n" ;
180+ return code ;
181+ } ;
182+
183+ // servo
184+ Blockly . Blocks [ 'coderbot_move_servo' ] = {
185+ // Block for moving forward.
186+ init : function ( ) {
187+ this . setHelpUrl ( 'http://code.google.com/p/blockly/wiki/Motor' ) ;
188+ this . setColour ( 40 ) ;
189+
190+ this . appendDummyInput ( )
191+ . appendField ( Blockly . Msg . CODERBOT_MOVE_SERVO )
192+ . appendField ( new Blockly . FieldDropdown ( [ [ Blockly . Msg . CODERBOT_MOVE_SERVO_1 , "0" ] ,
193+ [ Blockly . Msg . CODERBOT_MOVE_SERVO_2 , "1" ] ] ) , 'SERVO' ) ;
194+ this . appendValueInput ( 'ANGLE' )
195+ . setCheck ( 'Number' )
196+ . appendField ( Blockly . Msg . CODERBOT_MOVE_SERVO_ANGLE ) ;
197+ this . setInputsInline ( true ) ;
198+ // Assign 'this' to a variable for use in the tooltip closure below.
199+ var thisBlock = this ;
200+ this . setTooltip ( function ( ) {
201+ var mode = thisBlock . getFieldValue ( 'ACTION' ) ;
202+ return TOOLTIPS [ mode ] + Blockly . Msg . CODERBOT_MOVE_SERVO_TIP_TAIL ;
203+ } ) ;
204+ this . setPreviousStatement ( true ) ;
205+ this . setNextStatement ( true ) ;
206+ }
207+ } ;
208+
209+ Blockly . Python [ 'coderbot_move_servo' ] = function ( block ) {
210+ // Generate Python for servo control.
211+ var servo = block . getFieldValue ( 'SERVO' ) ;
212+ var angle = Blockly . Python . valueToCode ( block , 'ANGLE' , Blockly . Python . ORDER_NONE ) ;
213+ var code = "get_bot().servo(servo=" + servo + ", angle=" + angle + ")\n" ;
214+ return code ;
215+ } ;
151216Blockly . Blocks . coderbot_basic_audio_say = {
152217 // Block for text to speech.
153218 init ( ) {
0 commit comments